* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------
* SSDriver.java
* ---------------
* Author: Volker Berlin
*
*/
package smallsql.database;
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.sql.*;
import java.util.Properties;
public class SSDriver implements Driver {
static final String URL_PREFIX = "jdbc:smallsql";
static SSDriver drv;
static {
try{
drv = new SSDriver();
java.sql.DriverManager.registerDriver(drv);
}catch(Throwable e){}
}
public Connection connect(String url, Properties info) throws SQLException {
Properties props = (Properties)info.clone();
if(!acceptsURL(url)) return null;
int idx1 = url.indexOf( ':', 5); if(idx1 > 0){
int idx2 = url.indexOf('?', idx1+1);
String dbPath = (idx2 > 0) ? url.substring(idx1+1, idx2) : url.substring(idx1+1);
props.setProperty("dbpath", dbPath);
if(idx2 > 0){
String propsString = url.substring(idx2+1);
propsString = propsString.replace(';', '\n');
try {
Properties urlProps = new Properties(props);
urlProps.load(new StringBufferInputStream(propsString));
props = urlProps;
} catch (Exception e) {
e.printStackTrace();
}
}
}
return new SSConnection( props );
}
public boolean acceptsURL(String url) throws SQLException {
return url.startsWith(URL_PREFIX);
}
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
throw new java.lang.UnsupportedOperationException("Method getPropertyInfo() not yet implemented.");
}
public int getMajorVersion() {
return 0;
}
public int getMinorVersion() {
return 13;
}
public boolean jdbcCompliant() {
return true;
}
}