KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > utils > DriverClassHelpers


1 /*
2  * Created on 11-Jan-2005
3  */

4 package org.hibernate.eclipse.console.utils;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.HashSet JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Set JavaDoc;
13
14 /**
15  * @author max
16  */

17 public class DriverClassHelpers {
18
19     private Map JavaDoc dialectNames = new HashMap JavaDoc();
20     private Map JavaDoc connectionUrls = new HashMap JavaDoc();
21     private Map JavaDoc driverClasses = new HashMap JavaDoc();
22     
23     public DriverClassHelpers() {
24         // externalize this!
25
dialectNames.put("DB2", "org.hibernate.dialect.DB2Dialect");
26         dialectNames.put("DB2390", "org.hibernate.dialect.DB2390Dialect");
27         dialectNames.put("DB2400", "org.hibernate.dialect.DB2400Dialect");
28         dialectNames.put("Derby", "org.hibernate.dialect.DerbyDialect");
29         dialectNames.put("FrontBase", "org.hibernate.dialect.FrontbaseDialect");
30         dialectNames.put("Generic", "org.hibernate.dialect.GenericDialect");
31         dialectNames.put("HSQL", "org.hibernate.dialect.HSQLDialect");
32         dialectNames.put("Informix", "org.hibernate.dialect.InformixDialect");
33         dialectNames.put("Ingres", "org.hibernate.dialect.IngresDialect");
34         dialectNames.put("Interbase", "org.hibernate.dialect.InterbaseDialect");
35         dialectNames.put("Firebird", "org.hibernate.dialect.FirebirdDialect");
36         dialectNames.put("Mckoi SQL", "org.hibernate.dialect.MckoiDialect");
37         dialectNames.put("MySQL", "org.hibernate.dialect.MySQLDialect");
38         dialectNames.put("MySQLInnoDB", "org.hibernate.dialect.MySQLInnoDBDialect");
39         dialectNames.put("MySQLISAMDB", "org.hibernate.dialect.MySQLISAMDBDialect");
40         dialectNames.put("Oracle9", "org.hibernate.dialect.Oracle9Dialect");
41         dialectNames.put("Oracle","org.hibernate.dialect.OracleDialect");
42         dialectNames.put("Pointbase", "org.hibernate.dialect.PointbaseDialect");
43         dialectNames.put("PostgreSQL", "org.hibernate.dialect.PostgreSQLDialect");
44         dialectNames.put("Postgress", "org.hibernate.dialect.PostgressDialect");
45         dialectNames.put("SAP DB", "org.hibernate.dialect.SAPDBDialect");
46         dialectNames.put("Sybase", "org.hibernate.dialect.SybaseDialect");
47         dialectNames.put("Sybase11", "org.hibernate.dialect.Sybase11Dialect");
48         dialectNames.put("SybaseAnywhere", "org.hibernate.dialect.SybaseAnywhereDialect");
49         dialectNames.put("SQLServer", "org.hibernate.dialect.SQLServerDialect");
50
51         addDriverAndURLS("org.hibernate.dialect.HSQLDialect",
52                          "org.hsqldb.jdbcDriver",
53                          new String JavaDoc[] {
54                             "jdbc:hsqldb:hsql://<host>",
55                             "jdbc:hsqldb:<dbname>",
56                             "jdbc:hsqldb:." }
57                          );
58
59         addDriverAndURLS("org.hibernate.dialect.OracleDialect",
60                          "oracle.jdbc.driver.OracleDriver",
61                          new String JavaDoc[] {
62                             "jdbc:oracle:thin:@localhost:1521:orcl",
63                             "jdbc:oracle:thin:@<host>:<port1521>:<sid>" }
64                          );
65         
66         addDriverAndURLS("org.hibernate.dialect.Oracle9Dialect",
67                 "oracle.jdbc.driver.OracleDriver",
68                 new String JavaDoc[] {
69                    "jdbc:oracle:thin:@localhost:1521:orcl",
70                    "jdbc:oracle:thin:@<host>:<port1521>:<sid>" }
71                 );
72
73         addDriverAndURLS("org.hibernate.dialect.MySQLDialect",
74                          "org.gjt.mm.mysql.Driver",
75                          new String JavaDoc[] {
76                             "jdbc:mysql://<hostname>/<database>",
77                             "jdbc:mysql:///test",
78                             "jdbc:mysql:///<name>",
79                              }
80                         );
81         
82         addDriverAndURLS("org.hibernate.dialect.MySQLInnoDBDialect",
83                     "org.gjt.mm.mysql.Driver",
84                     new String JavaDoc[] {
85                        "jdbc:mysql://<hostname>/<database>",
86                        "jdbc:mysql:///test",
87                        "jdbc:mysql:///<name>" }
88                    );
89         
90
91         addDriverAndURLS("org.hibernate.dialect.MySQLMyISAMDBDialect",
92                     "org.gjt.mm.mysql.Driver",
93                     new String JavaDoc[] {
94                        "jdbc:mysql://<hostname>/<database>",
95                        "jdbc:mysql:///test",
96                        "jdbc:mysql:///<name>" }
97                    );
98         
99         addDriverAndURLS("org.hibernate.dialect.PostgreSQLDialect",
100                 "org.postgresql.Driver",
101                 new String JavaDoc[] {
102                    "jdbc:postgresql:template1",
103                    "jdbc:postgresql:<name>" }
104                );
105         
106         addDriverAndURLS("org.hibernate.dialect.DB2Dialect", "COM.ibm.db2.jdbc.app.DB2Driver",
107                           new String JavaDoc[] { "jdbc:db2:test", "jdbc:db2:<name>" });
108         
109         addDriverAndURLS("org.hibernate.dialect.DB2400Dialect", "COM.ibm.db2.jdbc.app.DB2Driver",
110                 new String JavaDoc[] { "jdbc:as400://<systemname>", "jdbc:db2:<name>" });
111         
112         addDriverAndURLS("org.hibernate.dialect.DerbyDialect", "org.apache.derby.jdbc.EmbeddedDriver",
113                 new String JavaDoc[] { "jdbc:derby:/test;create=true" });
114         
115         addDriverAndURLS("org.hibernate.dialect.SybaseDialect", "com.sybase.jdbc2.jdbc.SybDriver",
116                 new String JavaDoc[] { "jdbc:sybase:Tds:co3061835-a:5000/tempdb" });
117         
118         addDriverAndURLS("org.hibernate.dialect.MckoiDialect", "com.mckoi.JDBCDriver",
119                 new String JavaDoc[] { "jdbc:mckoi:///", "jdbc:mckoi:local://C:/mckoi1.00/db.conf" });
120         
121         addDriverAndURLS("org.hibernate.dialect.SAPDBDialect", "com.sap.dbtech.jdbc.DriverSapDB",
122                 new String JavaDoc[] { "jdbc:sapdb://localhost/TST" });
123         
124         addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "com.jnetdirect.jsql.JSQLDriver",
125                 new String JavaDoc[] { "jdbc:JSQLConnect://1E1/test" });
126
127         addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "com.newatlanta.jturbo.driver.Driver",
128                 new String JavaDoc[] { "jdbc:JTurbo://1E1:1433/test" });
129         
130         addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "weblogic.jdbc.mssqlserver4.Driver",
131                 new String JavaDoc[] { "jdbc:weblogic:mssqlserver4:1E1:1433" });
132         
133         addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "com.microsoft.jdbc.sqlserver.SQLServerDriver",
134                 new String JavaDoc[] { "jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor" });
135         
136         addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "net.sourceforge.jtds.jdbc.Driver",
137                 new String JavaDoc[] { "jdbc:jtds:sqlserver://1E1/test" });
138         
139         addDriverAndURLS("org.hibernate.dialect.InterbaseDialect", "interbase.interclient.Driver",
140                 new String JavaDoc[] { "jdbc:interbase://localhost:3060/C:/firebird/test.gdb" });
141         
142         addDriverAndURLS("org.hibernate.dialect.InterbaseDialect", "org.firebirdsql.jdbc.FBDriver",
143                 new String JavaDoc[] { "jdbc:interbase://localhost:3060/C:/firebird/test.gdb" });
144         
145         addDriverAndURLS("org.hibernate.dialect.PointbaseDialect", "com.pointbase.jdbc.jdbcUniversalDriver",
146                 new String JavaDoc[] { "jdbc:pointbase:embedded:sample" });
147     }
148
149     /**
150      * @param dialect TODO
151      *
152      */

153     private void addDriverAndURLS(String JavaDoc dialect, String JavaDoc driverclass, String JavaDoc[] urls) {
154         add(driverClasses, dialect, driverclass);
155         for (int i = 0; i < urls.length; i++) {
156             String JavaDoc url = urls[i];
157             add(connectionUrls, driverclass, url);
158         }
159     }
160    
161     /**
162      * @param connectionUrls2
163      * @param string
164      * @param string2
165      */

166     private void add(Map JavaDoc map, String JavaDoc key, String JavaDoc value) {
167         Set JavaDoc existing = (Set JavaDoc) map.get(key);
168         if(existing==null) {
169             existing = new HashSet JavaDoc();
170             map.put(key,existing);
171         }
172         existing.add(value);
173     }
174
175     public String JavaDoc[] getDialectNames() {
176         List JavaDoc list = new ArrayList JavaDoc(dialectNames.keySet());
177         Collections.sort(list);
178         return (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
179     }
180     
181     /**
182      *
183      * @param dialectName
184      * @return corresponding class name if available, otherwise return dialectName assuming it is a "raw" classname
185      */

186     public String JavaDoc getDialectClass(String JavaDoc dialectName) {
187         if(dialectNames.containsKey(dialectName)) {
188             return (String JavaDoc) dialectNames.get(dialectName);
189         } else {
190             return dialectName;
191         }
192     }
193     
194     public String JavaDoc[] getDriverClasses(String JavaDoc dialectName) {
195         Set JavaDoc result = (Set JavaDoc) (driverClasses.get(dialectName));
196         if(result!=null) {
197             return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
198         } else {
199             return new String JavaDoc[0];
200         }
201     }
202     
203     public String JavaDoc[] getConnectionURLS(String JavaDoc driverclass) {
204         Set JavaDoc result = (Set JavaDoc) (connectionUrls.get(driverclass));
205         if(result!=null) {
206             return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
207         } else {
208             return new String JavaDoc[0];
209         }
210     }
211 }
212
Popular Tags