1 /* Copyrights and Licenses
2 *
3 * This product includes Hypersonic SQL.
4 * Originally developed by Thomas Mueller and the Hypersonic SQL Group.
5 *
6 * Copyright (c) 1995-2000 by the Hypersonic SQL Group. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice, this list of conditions
10 * and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice, this list of
12 * conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * - All advertising materials mentioning features or use of this software must display the
15 * following acknowledgment: "This product includes Hypersonic SQL."
16 * - Products derived from this software may not be called "Hypersonic SQL" nor may
17 * "Hypersonic SQL" appear in their names without prior written permission of the
18 * Hypersonic SQL Group.
19 * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
20 * product includes Hypersonic SQL."
21 * This software is provided "as is" and any expressed or implied warranties, including, but
22 * not limited to, the implied warranties of merchantability and fitness for a particular purpose are
23 * disclaimed. In no event shall the Hypersonic SQL Group or its contributors be liable for any
24 * direct, indirect, incidental, special, exemplary, or consequential damages (including, but
25 * not limited to, procurement of substitute goods or services; loss of use, data, or profits;
26 * or business interruption). However caused any on any theory of liability, whether in contract,
27 * strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
28 * software, even if advised of the possibility of such damage.
29 * This software consists of voluntary contributions made by many individuals on behalf of the
30 * Hypersonic SQL Group.
31 *
32 *
33 * For work added by the HSQL Development Group:
34 *
35 * Copyright (c) 2001-2002, The HSQL Development Group
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions are met:
40 *
41 * Redistributions of source code must retain the above copyright notice, this
42 * list of conditions and the following disclaimer, including earlier
43 * license statements (above) and comply with all above license conditions.
44 *
45 * Redistributions in binary form must reproduce the above copyright notice,
46 * this list of conditions and the following disclaimer in the documentation
47 * and/or other materials provided with the distribution, including earlier
48 * license statements (above) and comply with all above license conditions.
49 *
50 * Neither the name of the HSQL Development Group nor the names of its
51 * contributors may be used to endorse or promote products derived from this
52 * software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
58 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
59 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
60 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
61 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
62 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 */
66
67
68 package org.hsqldb;
69
70 import java.sql.Connection;
71 import java.sql.Driver;
72 import java.sql.DriverManager;
73 import java.sql.DriverPropertyInfo;
74 import java.sql.SQLException;
75 import java.util.Properties;
76
77 // fredt@users 20020320 - patch 1.7.0 - JDBC 2 support and error trapping
78 // JDBC 2 methods can now be called from jdk 1.1.x - see javadoc comments
79
80 /**
81 * Each JDBC driver must supply a class that implements the Driver
82 * interface. <p>
83 *
84 * The Java SQL framework allows for multiple database drivers. <p>
85 *
86 * The DriverManager will try to load as many drivers as it can find and
87 * then for any given connection request, it will ask each driver in turn
88 * to try to connect to the target URL. <p>
89 *
90 * <font color="#009900"> The application developer will normally not need
91 * to call any function of the Driver directly. All required calls are made
92 * by the DriverManager. <p>
93 *
94 * When the HSQL Database Engine Driver class is loaded, it creates an
95 * instance of itself and register it with the DriverManager. This means
96 * that a user can load and register the HSQL Database Engine driver by
97 * calling <pre>
98 * <code>Class.forName("org.hsqldb.jdbcDriver")</code> </pre> For more
99 * information about how to connect to a HSQL Database Engine database,
100 * please see jdbcConnection. </font><p>
101 *
102 * <font color="#009900"> As of version 1.7.0 all JDBC 2 methods can be
103 * called with jdk 1.1.x. Some of these method calls require int values
104 * that are defined in JDBC 2 version of ResultSet. These values are
105 * defined in the jdbcResultSet class when it is compiled with jdk 1.1.x.
106 * When using the JDBC 2 methods that require those values as parameters or
107 * return one of those values, refer to them as follows: (The code will not
108 * be compatible with other JDBC 2 driver, which require ResultSet to be
109 * used instead of jdbcResultSet) (fredt@users)</font> <p>
110 * <font color="#009900">
111 * jdbcResultSet.FETCH_FORWARD<br>
112 * jdbcResultSet.TYPE_FORWARD_ONLY<br>
113 * jdbcResultSet TYPE_SCROLL_INSENSITIVE<br>
114 * jdbcResultSet.CONCUR_READ_ONLY</font><p>
115 *
116 *
117 * @see jdbcConnection
118 */
119 // fredt@users 20011220 - patch 1.7.0 by fredt
120 // new version numbering scheme
121 public class jdbcDriver implements Driver {
122
123 static final String sStartURL = "jdbc:hsqldb:";
124 static final int MAJOR = 1,
125 MINOR = 7,
126 REVISION = 1;
127 static final String VERSION = "1.7.1";
128 static final String PRODUCT = "HSQL Database Engine";
129
130 /**
131 * Attempts to make a database connection to the given URL. The driver
132 * returns "null" if it realizes it is the wrong kind of driver to
133 * connect to the given URL. This will be common, as when the JDBC
134 * driver manager is asked to connect to a given URL it passes the URL
135 * to each loaded driver in turn. <p>
136 *
137 * The driver raises a SQLException if it is the right driver to
138 * connect to the given URL, but has trouble connecting to the
139 * database. <p>
140 *
141 * The java.util.Properties argument can be used to passed arbitrary
142 * string tag/value pairs as connection arguments. <p>
143 *
144 * <font color="#009900"> For HSQL Database Engine, at least "user" and
145 * "password" properties must be included in the Properties. </font>
146 * <p>
147 *
148 *
149 *
150 * @param url the URL of the database to which to connect
151 * @param info a list of arbitrary string tag/value pairs as connection
152 * arguments. Normally at least a "user" and "password" property
153 * should be included.
154 * @return a <code>Connection</code> object that represents a
155 * connection to the URL
156 * @exception SQLException if a database access error occurs
157 */
158 public Connection connect(String url,
159 Properties info) throws SQLException {
160
161 if (!acceptsURL(url)) {
162 return null;
163 }
164
165 String s = url.substring(sStartURL.length());
166
167 return new jdbcConnection(s, info);
168 }
169
170 /**
171 * Returns true if the driver thinks that it can open a connection to
172 * the given URL. Typically drivers will return true if they understand
173 * the subprotocol specified in the URL and false if they don't.
174 *
175 * @param url the URL of the database
176 * @return true if this driver can connect to the given URL
177 */
178
179 // fredt@users - patch 1.70 - allow mixedcase url's when called externally
180 public boolean acceptsURL(String url) {
181
182 if (Trace.TRACE) {
183 Trace.trace(url);
184 }
185
186 return url.toLowerCase().startsWith(sStartURL);
187 }
188
189 /**
190 * Gets information about the possible properties for this driver. <p>
191 *
192 * The getPropertyInfo method is intended to allow a generic GUI tool
193 * to discover what properties it should prompt a human for in order to
194 * get enough information to connect to a database. Note that depending
195 * on the values the human has supplied so far, additional values may
196 * become necessary, so it may be necessary to iterate though several
197 * calls to getPropertyInfo.
198 * <!-- start release-specific documentation -->
199 * <span class="ReleaseSpecificDocumentation">
200 * <b>HSQLDB-Specific Information:</b> <p>
201 *
202 * HSQLDB 1.7.1 uses the values submitted in info to set the value for
203 * each DriverPropertyInfo object returned. It does not use the default
204 * value that it would use for the property if the value is null.
205 *
206 * </span> <!-- end release-specific documentation -->
207 *
208 * @param url the URL of the database to which to connect
209 * @param info a proposed list of tag/value pairs that will be sent on
210 * connect open
211 * @return an array of DriverPropertyInfo objects describing possible
212 * properties. This array may be an empty array if no properties
213 * are required.
214 */
215 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
216
217 if (Trace.TRACE) {
218 Trace.trace();
219 }
220
221 String[] choices = new String[] {
222 "true", "false"
223 };
224 DriverPropertyInfo pinfo[] = new DriverPropertyInfo[2];
225 DriverPropertyInfo p;
226
227 p = new DriverPropertyInfo("user", null);
228 p.value = info.getProperty("user");
229 p.required = true;
230 pinfo[0] = p;
231 p = new DriverPropertyInfo("password", null);
232 p.value = info.getProperty("password");
233 p.required = true;
234 pinfo[1] = p;
235 p = new DriverPropertyInfo("strict_md", null);
236 p.value = info.getProperty("strict_md");
237 p.required = false;
238 p.choices = choices;
239 pinfo[1] = p;
240 p = new DriverPropertyInfo("get_column_name", null);
241 p.value = info.getProperty("get_column_name");
242 p.required = false;
243 p.choices = choices;
244 pinfo[1] = p;
245
246 return pinfo;
247 }
248
249 /**
250 * Gets the driver's major version number.
251 *
252 * @return this driver's major version number
253 */
254 public int getMajorVersion() {
255
256 if (Trace.TRACE) {
257 Trace.trace();
258 }
259
260 return MAJOR;
261 }
262
263 /**
264 * Gets the driver's minor version number.
265 *
266 * @return this driver's minor version number
267 */
268 public int getMinorVersion() {
269
270 if (Trace.TRACE) {
271 Trace.trace();
272 }
273
274 return MINOR;
275 }
276
277 /**
278 * Reports whether this driver is a genuine JDBC COMPLIANT<sup><font
279 * size=-2>TM</font> </sup> driver. A driver may only report true here
280 * if it passes the JDBC compliance tests; otherwise it is required to
281 * return false. JDBC compliance requires full support for the JDBC API
282 * and full support for SQL 92 Entry Level. It is expected that JDBC
283 * compliant drivers will be available for all the major commercial
284 * databases. <p>
285 *
286 * <font color="#009900"> HSQL Database Engine currently does not yet
287 * support all required SQL 92 Entry Level functionality and thus
288 * returns false. The features that are missing are currently 'HAVING'
289 * and views. It looks like other drivers return true but do not
290 * support all features. </font> <p>
291 *
292 * This method is not intended to encourage the development of non-JDBC
293 * compliant drivers, but is a recognition of the fact that some
294 * vendors are interested in using the JDBC API and framework for
295 * lightweight databases that do not support full database
296 * functionality, or for special databases such as document information
297 * retrieval where a SQL implementation may not be feasible.
298 *
299 * @return Description of the Return Value
300 */
301 public boolean jdbcCompliant() {
302
303 if (Trace.TRACE) {
304 Trace.trace();
305
306 // todo: not all required features are implemented yet
307 }
308
309 return false;
310 }
311
312 static {
313 try {
314 DriverManager.registerDriver(new jdbcDriver());
315
316 if (Trace.TRACE) {
317 Trace.trace(PRODUCT + " " + VERSION);
318 }
319 } catch (Exception e) {
320 if (Trace.TRACE) {
321 Trace.trace(e.getMessage());
322 }
323 }
324 }
325 }