KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > sunresources > beans > DatabaseUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * DatabaseUtils.java
21  *
22  * Created on June 26, 2006, 1:55 PM
23  *
24  */

25
26 package org.netbeans.modules.j2ee.sun.sunresources.beans;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Set JavaDoc;
31
32 /**
33  *
34  * @author Nitya Doraisamy
35  */

36 public class DatabaseUtils {
37     
38     private static HashMap JavaDoc driverMap;
39     private static HashMap JavaDoc dsClassMap;
40     
41     /** Creates a new instance of DatabaseUtils */
42     private DatabaseUtils() {
43     }
44     
45     public static String JavaDoc getDriverName(String JavaDoc url){
46         String JavaDoc driverName = null;
47         Set JavaDoc urlKeys = driverMap.keySet();
48         Iterator JavaDoc it = urlKeys.iterator();
49         while(it.hasNext()){
50             String JavaDoc urlPrefix = (String JavaDoc)it.next();
51             if(url.startsWith(urlPrefix)){
52                 driverName = (String JavaDoc)driverMap.get(urlPrefix);
53                 return driverName;
54             }
55         }
56         return driverName;
57     }
58     
59     public static String JavaDoc getDSClassName(String JavaDoc url){
60         String JavaDoc dsClass = null;
61         Set JavaDoc urlKeys = dsClassMap.keySet();
62         Iterator JavaDoc it = urlKeys.iterator();
63         while(it.hasNext()){
64             String JavaDoc urlPrefix = (String JavaDoc)it.next();
65             if(url.startsWith(urlPrefix)){
66                 dsClass = (String JavaDoc)dsClassMap.get(urlPrefix);
67                 return dsClass;
68             }
69         }
70         return dsClass;
71     }
72     
73     
74     /**
75      * Gets the URL prefix fiven a Datasource Classname
76      * @param inClass Datasource Classname
77      * @return URL prefix for given Datasource Classname
78      */

79     public static String JavaDoc getUrlPrefix(String JavaDoc inClass){
80         String JavaDoc prefix = null;
81         Set JavaDoc urlKeys = dsClassMap.keySet();
82         Iterator JavaDoc it = urlKeys.iterator();
83         while(it.hasNext()){
84             String JavaDoc urlPrefix = (String JavaDoc)it.next();
85             String JavaDoc dsClass = (String JavaDoc)dsClassMap.get(urlPrefix);
86             if(dsClass.equalsIgnoreCase(inClass))
87                 return urlPrefix;
88         }
89         return prefix;
90     }
91     
92     static {
93         driverMap = new HashMap JavaDoc();
94         
95         //IBM DB2
96
driverMap.put("jdbc:db2:", "COM.ibm.db2.jdbc.net.DB2Driver");
97         //JDBC-ODBC Bridge
98
driverMap.put("jdbc:odbc:", "sun.jdbc.odbc.JdbcOdbcDriver");
99         //Microsoft SQL Server (Weblogic driver)
100
driverMap.put("jdbc:weblogic:mssqlserver4:", "weblogic.jdbc.mssqlserver4.Driver");
101         
102         //Oracle-thin
103
driverMap.put("jdbc:oracle:thin:", "oracle.jdbc.driver.OracleDriver");
104         //Oracle //OCI 8i
105
driverMap.put("jdbc:oracle:oci8:", "oracle.jdbc.driver.OracleDriver");
106         //Oracle //OCI 9i
107
driverMap.put("jdbc:oracle:oci:", "oracle.jdbc.driver.OracleDriver");
108         
109         //PointBase
110
driverMap.put("jdbc:pointbase:", "com.pointbase.jdbc.jdbcUniversalDriver");
111         //Cloudscape
112
driverMap.put("jdbc:cloudscape:", "COM.cloudscape.core.JDBCDriver");
113         //Java DB (Net)
114
driverMap.put("jdbc:derby:", "org.apache.derby.jdbc.ClientDriver");
115         //Firebird (JCA/JDBC driver)
116
driverMap.put("jdbc:firebirdsql:", "org.firebirdsql.jdbc.FBDriver");
117         //FirstSQL/J //Enterprise Server Edition
118
driverMap.put("jdbc:dbcp:", "COM.FirstSQL.Dbcp.DbcpDriver");
119         //FirstSQL/J //Professional Edition
120
driverMap.put("jdbc:dbcp:", "COM.FirstSQL.Dbcp.DbcpDriver");
121         
122         //IBM DB2 (DataDirect Connect for JDBC)
123
driverMap.put("jdbc:datadirect:db2:", "com.ddtek.jdbc.db2.DB2Driver");
124         //Informix Dynamic Server (DataDirect Connect for JDBC)
125
driverMap.put("jdbc:datadirect:informix:", "com.ddtek.jdbc.informix.InformixDriver");
126         //Oracle (DataDirect Connect for JDBC)
127
driverMap.put("jdbc:datadirect:oracle:", "com.ddtek.jdbc.oracle.OracleDriver");
128         //Microsoft SQL Server (DataDirect Connect for JDBC)
129
driverMap.put("jdbc:datadirect:sqlserver:", "com.ddtek.jdbc.sqlserver.SQLServerDriver");
130         //Sybase (DataDirect Connect for JDBC)
131
driverMap.put("jdbc:datadirect:sybase:", "com.ddtek.jdbc.sybase.SybaseDriver");
132         
133         //IDS Server
134
driverMap.put("jdbc:ids:", "ids.sql.IDSDriver");
135         //Informix Dynamic Server
136
driverMap.put("jdbc:informix-sqli:", "com.informix.jdbc.IfxDriver");
137         //InstantDB (v3.13 and earlier)
138
driverMap.put("jdbc:idb:", "jdbc.idbDriver");
139         //InstantDB (v3.14 and later)
140
driverMap.put("jdbc:idb:", "org.enhydra.instantdb.jdbc.idbDriver");
141         //Interbase (InterClient driver)
142
driverMap.put("jdbc:interbase:", "interbase.interclient.Driver");
143         //HSQLDB //(server)
144
driverMap.put("jdbc:hsqldb:hsql:", "org.hsqldb.jdbcDriver");
145         //HSQLDB //(webserver)
146
driverMap.put("jdbc:hsqldb:http:", "org.hsqldb.jdbcDriver");
147         //Hypersonic SQL (v1.2 and earlier)
148
driverMap.put("jdbc:HypersonicSQL:", "hSql.hDriver");
149         //Hypersonic SQL (v1.3 and later)
150
driverMap.put("jdbc:HypersonicSQL:", "org.hsql.jdbcDriver");
151         //jTDS
152
driverMap.put("jdbc:jtds:sqlserver:", "net.sourceforge.jtds.jdbc.Driver");
153         //jTDS
154
driverMap.put("jdbc:jtds:sybase:", "net.sourceforge.jtds.jdbc.Driver");
155         //Mckoi SQL Database //(server)
156
driverMap.put("jdbc:mckoi:", "com.mckoi.JDBCDriver");
157         //Mckoi SQL Database //(standalone)
158
driverMap.put("jdbc:mckoi:local:", "com.mckoi.JDBCDriver");
159         //Microsoft SQL Server (JTurbo driver)
160
driverMap.put("jdbc:JTurbo:", "com.ashna.jturbo.driver.Driver");
161         //Microsoft SQL Server (JTurbo driver 3.0)
162
//driverMap.put("jdbc:JTurbo:", "com.newatlanta.jturbo.driver.Driver");
163
//Microsoft SQL Server (Sprinta driver)
164
driverMap.put("jdbc:inetdae:", "com.inet.tds.TdsDriver");
165         //Microsoft SQL Server 2000 (Microsoft driver)
166
driverMap.put("jdbc:microsoft:sqlserver:", "com.microsoft.jdbc.sqlserver.SQLServerDriver");
167         driverMap.put("jdbc:sqlserver:", "com.microsoft.sqlserver.jdbc.SQLServerDriver"); //NOI18N
168
//MySQL (Connector/J driver)
169
driverMap.put("jdbc:mysql:", "com.mysql.jdbc.Driver");
170         //MySQL (MM.MySQL driver)
171
driverMap.put("jdbc:mysql:", "org.gjt.mm.mysql.Driver");
172         
173         //PostgreSQL (v6.5 and earlier)
174
//driverMap.put("jdbc:postgresql:", "postgresql.Driver");
175
//PostgreSQL (v7.0 and later)
176
driverMap.put("jdbc:postgresql:", "org.postgresql.Driver");
177         //Quadcap Embeddable Database
178
driverMap.put("jdbc:qed:", "com.quadcap.jdbc.JdbcDriver");
179         //Sybase (jConnect 4.2 and earlier)
180
//driverMap.put("jdbc:sybase:Tds:", "com.sybase.jdbc.SybDriver");
181
//Sybase (jConnect 5.2)
182
driverMap.put("jdbc:sybase:Tds:", "com.sybase.jdbc2.jdbc.SybDriver");
183         
184         // Following four entries for drivers to be included in Java Studio Enterprise 7 (Bow)
185
//Microsoft SQL Server Driver
186
driverMap.put("jdbc:sun:sqlserver:", "com.sun.sql.jdbc.sqlserver.SQLServerDriver");
187         //DB2 Driver
188
driverMap.put("jdbc:sun:db2:", "com.sun.sql.jdbc.db2.DB2Driver");
189         //Oracle Driver
190
driverMap.put("jdbc:sun:oracle:", "com.sun.sql.jdbc.oracle.OracleDriver");
191         //Sybase Driver
192
driverMap.put("jdbc:sun:sybase:", "com.sun.sql.jdbc.sybase.SybaseDriver");
193         
194     }
195
196     static {
197         dsClassMap = new HashMap JavaDoc();
198         
199         //IBM DB2
200
dsClassMap.put("jdbc:db2:", "com.ibm.db2.jcc.DB2DataSource");
201         //JDBC-ODBC Bridge
202
dsClassMap.put("jdbc:odbc:", "sun.jdbc.odbc.JdbcOdbcDriver");
203         //Microsoft SQL Server (Weblogic driver)
204
//dsClassMap.put("jdbc:weblogic:mssqlserver4:", "weblogic.jdbc.mssqlserver4.Driver");
205

206         //Oracle-thin
207
dsClassMap.put("jdbc:oracle:thin:", "oracle.jdbc.pool.OracleDataSource");
208         //Oracle //OCI 8i
209
dsClassMap.put("jdbc:oracle:oci8:", "oracle.jdbc.pool.OracleDataSource");
210         //Oracle //OCI 9i
211
dsClassMap.put("jdbc:oracle:oci:", "oracle.jdbc.pool.OracleDataSource");
212         
213         //PointBase
214
dsClassMap.put("jdbc:pointbase:", "com.pointbase.jdbc.jdbcDataSource");
215         //Cloudscape
216
dsClassMap.put("jdbc:cloudscape:", "com.cloudscape.core.BasicDataSource");
217         //Java DB (Net)
218
dsClassMap.put("jdbc:derby:", "org.apache.derby.jdbc.ClientDataSource");
219         //Firebird (JCA/JDBC driver)
220
//dsClassMap.put("jdbc:firebirdsql:", "org.firebirdsql.jdbc.FBDriver");
221
//FirstSQL/J //Enterprise Server Edition
222
//dsClassMap.put("jdbc:dbcp:", "COM.FirstSQL.Dbcp.DbcpDriver");
223
//FirstSQL/J //Professional Edition
224
//dsClassMap.put("jdbc:dbcp:", "COM.FirstSQL.Dbcp.DbcpDriver");
225

226         //IBM DB2 (DataDirect Connect for JDBC)
227
dsClassMap.put("jdbc:datadirect:db2:", "com.ddtek.jdbcx.db2.DB2DataSource");
228         //Informix Dynamic Server (DataDirect Connect for JDBC)
229
dsClassMap.put("jdbc:datadirect:informix:", "com.ddtek.jdbcx.informix.InformixDataSource");
230         //Oracle (DataDirect Connect for JDBC)
231
dsClassMap.put("jdbc:datadirect:oracle:", "com.ddtek.jdbcx.oracle.OracleDataSource");
232         //Microsoft SQL Server (DataDirect Connect for JDBC)
233
dsClassMap.put("jdbc:datadirect:sqlserver:", "com.ddtek.jdbcx.sqlserver.SQLServerDataSource");
234         //Sybase (DataDirect Connect for JDBC)
235
dsClassMap.put("jdbc:datadirect:sybase:", "com.ddtek.jdbcx.sybase.SybaseDataSource");
236         
237         //IDS Server
238
dsClassMap.put("jdbc:ids:", "ids.sql.IDSDriver");
239         //Informix Dynamic Server
240
dsClassMap.put("jdbc:informix-sqli:", "com.informix.jdbcx.IfxDataSource");
241         //InstantDB (v3.13 and earlier)
242
//dsClassMap.put("jdbc:idb:", "jdbc.idbDriver");
243
//InstantDB (v3.14 and later)
244
//dsClassMap.put("jdbc:idb:", "org.enhydra.instantdb.jdbc.idbDriver");
245
//Interbase (InterClient driver)
246
//dsClassMap.put("jdbc:interbase:", "interbase.interclient.Driver");
247
//HSQLDB //(server)
248
//dsClassMap.put("jdbc:hsqldb:hsql:", "org.hsqldb.jdbcDriver");
249
//HSQLDB //(webserver)
250
//dsClassMap.put("jdbc:hsqldb:http:", "org.hsqldb.jdbcDriver");
251
//Hypersonic SQL (v1.2 and earlier)
252
//dsClassMap.put("jdbc:HypersonicSQL:", "hSql.hDriver");
253
//Hypersonic SQL (v1.3 and later)
254
//dsClassMap.put("jdbc:HypersonicSQL:", "org.hsql.jdbcDriver");
255
//jTDS
256
dsClassMap.put("jdbc:jtds:sqlserver:", "net.sourceforge.jtds.jdbcx.JtdsDataSource");
257         //jTDS
258
dsClassMap.put("jdbc:jtds:sybase:", "net.sourceforge.jtds.jdbcx.JtdsDataSource");
259         //Mckoi SQL Database //(server)
260
//dsClassMap.put("jdbc:mckoi:", "com.mckoi.JDBCDriver");
261
//Mckoi SQL Database //(standalone)
262
//dsClassMap.put("jdbc:mckoi:local:", "com.mckoi.JDBCDriver");
263
//Microsoft SQL Server (JTurbo driver old version)
264
//dsClassMap.put("jdbc:JTurbo:", "com.ashna.jturbo.driver.DataSource");
265
//Microsoft SQL Server (JTurbo driver 3.0)
266
dsClassMap.put("jdbc:JTurbo:", "com.newatlanta.jturbo.driver.DataSource");
267         //Microsoft SQL Server (Sprinta driver)
268
dsClassMap.put("jdbc:inetdae:", "com.inet.tds.TdsDataSource");
269         //Microsoft SQL Server 2000 (Microsoft driver)
270
dsClassMap.put("jdbc:microsoft:sqlserver:", "com.microsoft.jdbc.sqlserver.SQLServerDataSource");
271         dsClassMap.put("jdbc:sqlserver:", "com.microsoft.sqlserver.jdbc.SQLServerDataSource"); //NOI18N
272
//MySQL (Connector/J driver)
273
//dsClassMap.put("jdbc:mysql:", "com.mysql.jdbc.Driver");
274
//MySQL (MM.MySQL driver)
275
dsClassMap.put("jdbc:mysql:", "com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource");
276         
277         //PostgreSQL (v6.5 and earlier)
278
//dsClassMap.put("jdbc:postgresql:", "postgresql.Driver");
279
//PostgreSQL (v7.0 and later)
280
dsClassMap.put("jdbc:postgresql:", "org.postgresql.ds.PGSimpleDataSource");
281         //Quadcap Embeddable Database
282
//dsClassMap.put("jdbc:qed:", "com.quadcap.jdbc.JdbcDriver");
283
//Sybase (jConnect 4.2 and earlier)
284
//dsClassMap.put("jdbc:sybase:Tds:", "com.sybase.jdbc.SybDriver");
285
//Sybase (jConnect 5.2)
286
dsClassMap.put("jdbc:sybase:Tds:", "com.sybase.jdbc2.jdbc.SybDataSource");
287         
288         // Following four entries for drivers to be included in Java Studio Enterprise 7 (Bow)
289
//Microsoft SQL Server Driver
290
dsClassMap.put("jdbc:sun:sqlserver:", "com.sun.sql.jdbcx.sqlserver.SQLServerDataSource");
291         //DB2 Driver
292
dsClassMap.put("jdbc:sun:db2:", "com.sun.sql.jdbcx.db2.DB2DataSource");
293         //Oracle Driver
294
dsClassMap.put("jdbc:sun:oracle:", "com.sun.sql.jdbcx.oracle.OracleDataSource");
295         //Sybase Driver
296
dsClassMap.put("jdbc:sun:sybase:", "com.sun.sql.jdbcx.sybase.SybaseDataSource");
297         
298     }
299 }
300
Popular Tags