com.foundationdb.sql.jdbc.Driver Maven / Gradle / Ivy
/*-------------------------------------------------------------------------
*
* Copyright (c) 2003-2011, PostgreSQL Global Development Group
*
*
*-------------------------------------------------------------------------
*/
package com.foundationdb.sql.jdbc;
import java.sql.*;
import java.util.*;
import com.foundationdb.sql.jdbc.util.PSQLState;
import com.foundationdb.sql.jdbc.util.PSQLDriverVersion;
import com.foundationdb.sql.jdbc.util.GT;
/**
* The Java SQL framework allows for multiple database drivers. Each
* driver should supply a class that implements the Driver interface
*
* The DriverManager will try to load as many drivers as it can find and
* then for any given connection request, it will ask each driver in turn
* to try to connect to the target URL.
*
*
It is strongly recommended that each Driver class should be small and
* stand alone so that the Driver class can be loaded and queried without
* bringing in vast quantities of supporting code.
*
*
When a Driver class is loaded, it should create an instance of itself
* and register it with the DriverManager. This means that a user can load
* and register a driver by doing Class.forName("foo.bah.Driver")
*
* @see com.foundationdb.sql.jdbc.PGConnection
* @see java.sql.Driver
*/
public class Driver extends com.foundationdb.sql.jdbc.DriverBase
{
static
{
try
{
// moved the registerDriver from the constructor to here
// because some clients call the driver themselves (I know, as
// my early jdbc work did - and that was based on other examples).
// Placing it here, means that the driver is registered once only.
java.sql.DriverManager.registerDriver(new Driver());
}
catch (SQLException e)
{
e.printStackTrace();
}
}
/**
* Create a connection from URL and properties. Always
* does the connection work in the current thread without
* enforcing a timeout, regardless of any timeout specified
* in the properties.
*
* @param url the original URL
* @param props the parsed/defaulted connection properties
* @return a new connection
* @throws SQLException if the connection could not be made
*/
protected Connection makeConnection(String url, Properties props) throws SQLException {
Properties p = new Properties (props);
p.setProperty("PROTOCOL", getProtocol());
p.setProperty("VERSION", getVersion());
p.setProperty("MAJORVERSION", Integer.toString(getMajorVersion()));
p.setProperty("MINORVERSION", Integer.toString(getMinorVersion()));
return new com.foundationdb.sql.jdbc.jdbc4.Jdbc4Connection(hostSpecs(p),
user(p), database(p),
p, url);
}
public static final int MAJORVERSION = 2;
/**
* Gets the drivers major version number
*
* @return the drivers major version number
*/
public int getMajorVersion()
{
return MAJORVERSION;
}
public static final int MINORVERSION = 0;
/**
* Get the drivers minor version number
*
* @return the drivers minor version number
*/
public int getMinorVersion()
{
return MINORVERSION;
}
/**
* Returns the server version series of this driver and the
* specific build number.
*/
public static String getVersion()
{
return "FoundationDB SQL layer 2.0 JDBC4.1 (build " + PSQLDriverVersion.buildNumber + ")";
}
public String getProtocol()
{
return "jdbc:fdbsql:";
}
protected String getName()
{
return "FoundationBD SQL layer";
}
protected String getResourcesName()
{
return "org/fdbsql/driverconfig.properties";
}
protected String getPortNumber()
{
return "15432";
}
/*
* This method was added in v6.5, and simply throws an SQLException
* for an unimplemented method. I decided to do it this way while
* implementing the JDBC2 extensions to JDBC, as it should help keep the
* overall driver size down.
* It now requires the call Class and the function name to help when the
* driver is used with closed software that don't report the stack trace
* @param callClass the call Class
* @param functionName the name of the unimplemented function with the type
* of its arguments
* @return PSQLException with a localized message giving the complete
* description of the unimplemented function
*/
public static java.sql.SQLFeatureNotSupportedException notImplemented(Class callClass, String functionName)
{
return new java.sql.SQLFeatureNotSupportedException(GT.tr("Method {0} is not yet implemented.", callClass.getName() + "." + functionName),
PSQLState.NOT_IMPLEMENTED.getState());
}
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
{
throw notImplemented(this.getClass(), "getParentLogger()");
}
}