KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sqlmagic > tinysql > tinySQLDriver


1 /*
2  * tinySQLDriver - the tinySQLDriver abstract class
3  *
4  * A lot of this code is based on or directly taken from
5  * George Reese's (borg@imaginary.com) mSQL driver.
6  *
7  * So, it's probably safe to say:
8  *
9  * Portions of this code Copyright (c) 1996 George Reese
10  *
11  * The rest of it:
12  *
13  * Copyright 1996, Brian C. Jepson
14  * (bjepson@ids.net)
15  * $Author: davis $
16  * $Date: 2004/12/18 21:27:06 $
17  * $Revision: 1.1 $
18  *
19  * This library is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU Lesser General Public
21  * License as published by the Free Software Foundation; either
22  * version 2.1 of the License, or (at your option) any later version.
23  *
24  * This library is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27  * Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public
30  * License along with this library; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32  */

33
34 package com.sqlmagic.tinysql;
35
36 import java.sql.Connection JavaDoc;
37 import java.sql.DriverPropertyInfo JavaDoc;
38 import java.sql.SQLException JavaDoc;
39 import java.sql.Driver JavaDoc;
40 import java.util.Properties JavaDoc;
41
42 public abstract class tinySQLDriver implements java.sql.Driver JavaDoc {
43
44   /**
45    *
46    * Constructs a new tinySQLDriver
47    *
48    */

49   public tinySQLDriver() {
50   }
51
52   /**
53    *
54    * Check the syntax of the URL.
55    * @see java.sql.Driver#connect
56    * @param url the URL for the database in question
57    * @param info the properties object
58    * @return null if the URL should be ignored, or a new Connection
59    * object if the URL is a valid tinySQL URL
60    *
61    */

62   public Connection JavaDoc connect(String JavaDoc url, Properties JavaDoc info)
63        throws SQLException JavaDoc {
64
65     if( !acceptsURL(url) ) {
66       return null;
67     }
68    
69     // if it was a valid URL, return the new Connection
70
//
71
return getConnection(info.getProperty("user"), url, this);
72   }
73
74   /**
75    *
76    * Check to see if the URL is a tinySQL URL. It should start
77    * with jdbc:tinySQL in order to qualify.
78    *
79    * @param url The URL of the database.
80    * @return True if this driver can connect to the given URL.
81    *
82    */

83   public boolean acceptsURL(String JavaDoc url) throws SQLException JavaDoc {
84
85     // make sure the length is at least twelve
86
// before bothering with the substring
87
// comparison.
88
//
89
if( url.length() < 12 ) {
90       return false;
91     }
92
93     // if everything after the jdbc: part is
94
// tinySQL, then return true.
95
//
96
return url.substring(5,12).equals("tinySQL");
97
98   }
99
100   /**
101    *
102    * The getPropertyInfo method is intended to allow a generic GUI tool to
103    * discover what properties it should prompt a human for in order to get
104    * enough information to connect to a database. Note that depending on
105    * the values the human has supplied so far, additional values may become
106    * necessary, so it may be necessary to iterate though several calls
107    * to getPropertyInfo.
108    *
109    * @param url The URL of the database to connect to.
110    * @param info A proposed list of tag/value pairs that will be sent on
111    * connect open.
112    * @return An array of DriverPropertyInfo objects describing possible
113    * properties. This array may be an empty array if no properties
114    * are required.
115    *
116    */

117   public DriverPropertyInfo JavaDoc[] getPropertyInfo(String JavaDoc url,
118                           java.util.Properties JavaDoc info)
119        throws SQLException JavaDoc {
120     return new DriverPropertyInfo JavaDoc[0];
121   }
122                 
123   /**
124    *
125    * Gets the driver's major version number.
126    * @see java.sql.Driver#getMajorVersion
127    * @return the major version
128    *
129    */

130   public int getMajorVersion() {
131     return 0;
132   }
133
134   /**
135    *
136    * Gets the driver's minor version
137    * @see java.sql.Driver#getMinorVersion
138    * @return the minor version
139    *
140    */

141   public int getMinorVersion() {
142     return 9;
143   }
144
145   /**
146    *
147    * Report whether the Driver is a genuine JDBC COMPLIANT (tm) driver.
148    * Unfortunately, the tinySQL is "sub-compliant" :-(
149    *
150    */

151   public boolean jdbcCompliant() {
152     return false;
153   }
154
155   /**
156    *
157    * Abstract method to return a tinySQLConnection object, typically
158    * a subclass of the abstract class tinySQLConnection.
159    *
160    */

161   public abstract tinySQLConnection getConnection
162                (String JavaDoc user, String JavaDoc url, Driver JavaDoc d)
163            throws SQLException JavaDoc;
164
165 }
166
Popular Tags