001: /*
002: * tinySQLDriver - the tinySQLDriver abstract class
003: *
004: * A lot of this code is based on or directly taken from
005: * George Reese's (borg@imaginary.com) mSQL driver.
006: *
007: * So, it's probably safe to say:
008: *
009: * Portions of this code Copyright (c) 1996 George Reese
010: *
011: * The rest of it:
012: *
013: * Copyright 1996, Brian C. Jepson
014: * (bjepson@ids.net)
015: * $Author: davis $
016: * $Date: 2004/12/18 21:27:06 $
017: * $Revision: 1.1 $
018: *
019: * This library is free software; you can redistribute it and/or
020: * modify it under the terms of the GNU Lesser General Public
021: * License as published by the Free Software Foundation; either
022: * version 2.1 of the License, or (at your option) any later version.
023: *
024: * This library is distributed in the hope that it will be useful,
025: * but WITHOUT ANY WARRANTY; without even the implied warranty of
026: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
027: * Lesser General Public License for more details.
028: *
029: * You should have received a copy of the GNU Lesser General Public
030: * License along with this library; if not, write to the Free Software
031: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
032: */
033:
034: package com.sqlmagic.tinysql;
035:
036: import java.sql.Connection;
037: import java.sql.DriverPropertyInfo;
038: import java.sql.SQLException;
039: import java.sql.Driver;
040: import java.util.Properties;
041:
042: public abstract class tinySQLDriver implements java.sql.Driver {
043:
044: /**
045: *
046: * Constructs a new tinySQLDriver
047: *
048: */
049: public tinySQLDriver() {
050: }
051:
052: /**
053: *
054: * Check the syntax of the URL.
055: * @see java.sql.Driver#connect
056: * @param url the URL for the database in question
057: * @param info the properties object
058: * @return null if the URL should be ignored, or a new Connection
059: * object if the URL is a valid tinySQL URL
060: *
061: */
062: public Connection connect(String url, Properties info)
063: throws SQLException {
064:
065: if (!acceptsURL(url)) {
066: return null;
067: }
068:
069: // if it was a valid URL, return the new Connection
070: //
071: return getConnection(info.getProperty("user"), url, this );
072: }
073:
074: /**
075: *
076: * Check to see if the URL is a tinySQL URL. It should start
077: * with jdbc:tinySQL in order to qualify.
078: *
079: * @param url The URL of the database.
080: * @return True if this driver can connect to the given URL.
081: *
082: */
083: public boolean acceptsURL(String url) throws SQLException {
084:
085: // make sure the length is at least twelve
086: // before bothering with the substring
087: // comparison.
088: //
089: if (url.length() < 12) {
090: return false;
091: }
092:
093: // if everything after the jdbc: part is
094: // tinySQL, then return true.
095: //
096: return url.substring(5, 12).equals("tinySQL");
097:
098: }
099:
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[] getPropertyInfo(String url,
118: java.util.Properties info) throws SQLException {
119: return new DriverPropertyInfo[0];
120: }
121:
122: /**
123: *
124: * Gets the driver's major version number.
125: * @see java.sql.Driver#getMajorVersion
126: * @return the major version
127: *
128: */
129: public int getMajorVersion() {
130: return 0;
131: }
132:
133: /**
134: *
135: * Gets the driver's minor version
136: * @see java.sql.Driver#getMinorVersion
137: * @return the minor version
138: *
139: */
140: public int getMinorVersion() {
141: return 9;
142: }
143:
144: /**
145: *
146: * Report whether the Driver is a genuine JDBC COMPLIANT (tm) driver.
147: * Unfortunately, the tinySQL is "sub-compliant" :-(
148: *
149: */
150: public boolean jdbcCompliant() {
151: return false;
152: }
153:
154: /**
155: *
156: * Abstract method to return a tinySQLConnection object, typically
157: * a subclass of the abstract class tinySQLConnection.
158: *
159: */
160: public abstract tinySQLConnection getConnection(String user,
161: String url, Driver d) throws SQLException;
162:
163: }
|