KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > util > schema > SchemaGenerator


1 /*
2  * Copyright (C) 2003 Erik Swenson - erik@oreports.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19  
20 package org.efs.openreports.util.schema;
21
22 import java.io.FileWriter JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import org.hibernate.cfg.Configuration;
26 import org.hibernate.dialect.*;
27
28 public class SchemaGenerator
29 {
30     public static void main(String JavaDoc[] args)
31     {
32         try
33         {
34             Configuration cfg = new Configuration().configure();
35             
36             String JavaDoc[] scripts = cfg.generateSchemaCreationScript(new HSQLDialect());
37             writeFile("or_ddl_hsqldb.sql", scripts);
38                     
39             scripts = cfg.generateSchemaCreationScript(new MySQLDialect());
40             writeFile("or_ddl_mysql.sql", scripts);
41             
42             scripts = cfg.generateSchemaCreationScript(new SybaseDialect());
43             writeFile("or_ddl_sybase.sql", scripts);
44                 
45             scripts = cfg.generateSchemaCreationScript(new DB2Dialect());
46             writeFile("or_ddl_db2.sql", scripts);
47             
48             // hibernate bug?
49
cfg = new Configuration().configure();
50             
51             scripts = cfg.generateSchemaCreationScript(new PostgreSQLDialect());
52             writeFile("or_ddl_postgre.sql", scripts);
53             
54             scripts = cfg.generateSchemaCreationScript(new Oracle9Dialect());
55             writeFile("or_ddl_oracle.sql", scripts);
56             
57             //hibernate bug?
58
cfg = new Configuration().configure();
59             
60             scripts = cfg.generateSchemaCreationScript(new SQLServerDialect());
61             writeFile("or_ddl_sqlserver.sql", scripts);
62             
63             //hibernate bug?
64
cfg = new Configuration().configure();
65             
66             scripts = cfg.generateSchemaCreationScript(new DerbyDialect());
67             writeFile("or_ddl_derby.sql", scripts);
68         }
69         catch(Exception JavaDoc e)
70         {
71             e.printStackTrace();
72         }
73     }
74     
75     private static void writeFile(String JavaDoc fileName, String JavaDoc[] scripts) throws IOException JavaDoc
76     {
77         FileWriter JavaDoc writer = new FileWriter JavaDoc(fileName);
78         
79         for (int i=0; i < scripts.length; i++)
80         {
81             writer.write(scripts[i] + "\n\n");
82         }
83         
84         writer.flush();
85         writer.close();
86     }
87 }
88
89  
Popular Tags