KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nilostep > xlsql > jdbc > xlDriver


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

26 package com.nilostep.xlsql.jdbc;
27
28
29 import java.io.*;
30
31 import java.sql.*;
32
33 import java.util.*;
34 import java.util.logging.*;
35
36
37 /**
38  * DOCUMENT ME!
39  *
40  * @version $Revision: 1.5 $
41  * @author $author$
42  */

43 public class xlDriver implements Driver, Constants {
44     /** DOCUMENT ME! */
45     public static final Logger logger = Logger.getAnonymousLogger();
46
47     static {
48         try {
49             try {
50                 Class.forName("com.mysql.jdbc.Driver");
51             } catch (Exception JavaDoc e2) {
52                 ;
53             }
54
55             try {
56                 Class.forName("com.mckoi.JDBCDriver");
57             } catch (Exception JavaDoc e3) {
58                 ;
59             }
60
61             Class.forName("org.hsqldb.jdbcDriver");
62             DriverManager.registerDriver(new xlDriver());
63         } catch (Exception JavaDoc e1) {
64             e1.printStackTrace();
65         }
66     }
67
68     // ··········································
69
xlConnection c;
70     Properties xlsqlproperties;
71
72     /**
73      * DOCUMENT ME!
74      *
75      * @param url DOCUMENT ME!
76      *
77      * @return DOCUMENT ME!
78      *
79      * @throws SQLException DOCUMENT ME!
80      */

81     public boolean acceptsURL(String JavaDoc url) throws SQLException {
82         return (url.startsWith(URL_PFX_XLS) || url.startsWith(URL_PFX_CSV));
83     }
84
85     /**
86      * DOCUMENT ME!
87      *
88      * @param url DOCUMENT ME!
89      * @param info DOCUMENT ME!
90      *
91      * @return DOCUMENT ME!
92      *
93      * @throws SQLException DOCUMENT ME!
94      */

95     public Connection connect(String JavaDoc url, Properties info)
96                        throws SQLException {
97         try {
98             Properties p = new Properties();
99             p.load(new FileInputStream(
100                            new File(System.getProperty("user.dir") + File.separator +
101                                             "xlsql.properties")));
102             xlsqlproperties = p;
103         } catch (IOException ioe) {
104             xlsqlproperties = info;
105         }
106
107         c = xlConnection.factory(url, xlsqlproperties);
108
109         Runtime.getRuntime().addShutdownHook(new Thread JavaDoc() {
110             public void run() {
111                 try {
112                     if (c != null) {
113                         if (c.closed) {
114                             c = null;
115                         }
116                     }
117                 } catch (Exception JavaDoc e) {
118                     e.printStackTrace();
119                 }
120             }
121         });
122         logger.info("Connection to " +
123                     c.dbCon.getMetaData().getDatabaseProductName() +
124                     " established.");
125
126         return c;
127     }
128
129     /**
130      * DOCUMENT ME!
131      *
132      * @return DOCUMENT ME!
133      */

134     public int getMajorVersion() {
135         return MAJOR_VERSION;
136     }
137
138     /**
139      * DOCUMENT ME!
140      *
141      * @return DOCUMENT ME!
142      */

143     public int getMinorVersion() {
144         return MINOR_VERSION;
145     }
146
147     /**
148      * DOCUMENT ME!
149      *
150      * @param url DOCUMENT ME!
151      * @param info DOCUMENT ME!
152      *
153      * @return DOCUMENT ME!
154      */

155     public DriverPropertyInfo[] getPropertyInfo(String JavaDoc url, Properties info) {
156         //NiLOSTEP
157
//... I doubt if any generic GUI reads this repeatedly, if so
158
// initially only sql.url should be returned here...
159
// Don't understand this: when setting p.value Squirrel SQL (...)
160
// crashes.
161
//End
162
DriverPropertyInfo[] pinfo = new DriverPropertyInfo[4];
163         DriverPropertyInfo p;
164
165         p = new DriverPropertyInfo("sql.url", null);
166         p.description = "jdbc url of SQL engine";
167
168
169         //p.value = xlsqlproperties.getProperty("sql.url");
170
p.required = false;
171         pinfo[0] = p;
172
173         p = new DriverPropertyInfo("sql.database", null);
174         p.description = "intial context of SQL engine";
175
176
177         //p.value = xlsqlproperties.getProperty("sql.database");
178
p.required = false;
179         pinfo[1] = p;
180
181         p = new DriverPropertyInfo("sql.user", null);
182         p.description = "db user engine";
183
184
185         //p.value = xlsqlproperties.getProperty("sql.user");
186
p.required = false;
187         pinfo[2] = p;
188
189         p = new DriverPropertyInfo("sql.password", null);
190         p.description = "db password engine";
191
192
193         //p.value = xlsqlproperties.getProperty("sql.password");
194
p.required = false;
195         pinfo[3] = p;
196
197         return pinfo;
198     }
199
200     /**
201      * DOCUMENT ME!
202      *
203      * @return DOCUMENT ME!
204      */

205     public boolean jdbcCompliant() {
206         return JDBC_COMPLIANT;
207     }
208 }
Popular Tags