org.postgis
Class DriverWrapper

java.lang.Object
  extended by org.postgresql.Driver
      extended by org.postgis.DriverWrapper
All Implemented Interfaces:
java.sql.Driver
Direct Known Subclasses:
DriverWrapperAutoprobe, DriverWrapperLW

public class DriverWrapper
extends org.postgresql.Driver

DriverWrapper Wraps the PostGreSQL Driver to transparently add the PostGIS Object Classes. This avoids the need of explicit addDataType() calls from the driver users side. This method currently works with J2EE DataSource implementations, and with DriverManager framework. Simply replace the "jdbc:postgresql:" with a "jdbc:postgresql_postGIS:" in the jdbc URL. When using the drivermanager, you need to initialize DriverWrapper instead of (or in addition to) org.postgresql.Driver. When using a J2EE DataSource implementation, set the driver class property in the datasource config, the following works for jboss: <driver-class>org.postgis.DriverWrapper</driver-class> If you don't like or want to use the DriverWrapper, you have two alternatives, see the README file. Also note that the addDataType() methods known from earlier pgjdbc versions are deprecated in pgjdbc 8.0, see the commented code variants in the addGisTypes() method. This wrapper always uses EWKT as canonical text representation, and thus works against PostGIS 1.x servers as well as 0.x (tested with 0.8, 0.9 and 1.0).

Author:
Markus Schaber
See Also:
DriverWrapperLW, DriverWrapperAutoprobe

Nested Class Summary
protected static class DriverWrapper.TypesAdder
          Base class for the three typewrapper implementations
protected static class DriverWrapper.TypesAdder72
          addGISTypes for V7.2 pgjdbc
protected static class DriverWrapper.TypesAdder74
          addGISTypes for V7.3 and V7.4 pgjdbc
protected static class DriverWrapper.TypesAdder80
          addGISTypes for V8.0 (and hopefully newer) pgjdbc
 
Field Summary
protected static java.util.logging.Logger logger
           
static java.lang.String POSTGIS_PROTOCOL
           
static java.lang.String POSTGRES_PROTOCOL
           
static java.lang.String REVISION
           
protected static DriverWrapper.TypesAdder ta72
           
protected static DriverWrapper.TypesAdder ta74
           
protected static DriverWrapper.TypesAdder ta80
           
protected  DriverWrapper.TypesAdder typesAdder
           
 
Fields inherited from class org.postgresql.Driver
DEBUG, INFO, MAJORVERSION, MINORVERSION
 
Constructor Summary
DriverWrapper()
          Default constructor.
 
Method Summary
 boolean acceptsURL(java.lang.String url)
          Check whether the driver thinks he can handle the given URL.
static void addGISTypes(org.postgresql.PGConnection pgconn)
          adds the JTS/PostGIS Data types to a PG 7.3+ Connection.
static void addGISTypes72(org.postgresql.PGConnection pgconn)
          adds the JTS/PostGIS Data types to a PG 7.2 Connection.
static void addGISTypes80(org.postgresql.PGConnection pgconn)
          adds the JTS/PostGIS Data types to a PG 8.0+ Connection.
 java.sql.Connection connect(java.lang.String url, java.util.Properties info)
          Creates a postgresql connection, and then adds the PostGIS data types to it calling addpgtypes()
protected  java.lang.String getProtoString()
           
protected static DriverWrapper.TypesAdder getTypesAdder(org.postgresql.Driver d)
           
static java.lang.String getVersion()
          Returns our own CVS version plus postgres Version
protected  java.lang.String mangleURL(java.lang.String url)
          Mangles the PostGIS URL to return the original PostGreSQL URL
protected  boolean useLW(java.sql.Connection result)
          Do we have HexWKB as well known text representation - to be overridden by subclasses.
 
Methods inherited from class org.postgresql.Driver
getLogLevel, getMajorVersion, getMinorVersion, getPropertyInfo, jdbcCompliant, makeSSL, notImplemented, setLogLevel, sslEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final java.util.logging.Logger logger

POSTGRES_PROTOCOL

public static final java.lang.String POSTGRES_PROTOCOL
See Also:
Constant Field Values

POSTGIS_PROTOCOL

public static final java.lang.String POSTGIS_PROTOCOL
See Also:
Constant Field Values

REVISION

public static final java.lang.String REVISION
See Also:
Constant Field Values

ta72

protected static DriverWrapper.TypesAdder ta72

ta74

protected static DriverWrapper.TypesAdder ta74

ta80

protected static DriverWrapper.TypesAdder ta80

typesAdder

protected DriverWrapper.TypesAdder typesAdder
Constructor Detail

DriverWrapper

public DriverWrapper()
              throws java.sql.SQLException
Default constructor. This also loads the appropriate TypesAdder for our SQL Driver instance.

Throws:
java.sql.SQLException
Method Detail

getTypesAdder

protected static DriverWrapper.TypesAdder getTypesAdder(org.postgresql.Driver d)
                                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

connect

public java.sql.Connection connect(java.lang.String url,
                                   java.util.Properties info)
                            throws java.sql.SQLException
Creates a postgresql connection, and then adds the PostGIS data types to it calling addpgtypes()

Specified by:
connect in interface java.sql.Driver
Overrides:
connect in class org.postgresql.Driver
Parameters:
url - the URL of the database to connect to
info - a list of arbitrary tag/value pairs as connection arguments
Returns:
a connection to the URL or null if it isnt us
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
Driver.connect(java.lang.String, java.util.Properties), Driver

useLW

protected boolean useLW(java.sql.Connection result)
Do we have HexWKB as well known text representation - to be overridden by subclasses.


acceptsURL

public boolean acceptsURL(java.lang.String url)
                   throws java.sql.SQLException
Check whether the driver thinks he can handle the given URL.

Specified by:
acceptsURL in interface java.sql.Driver
Overrides:
acceptsURL in class org.postgresql.Driver
Parameters:
url - the URL of the driver
Returns:
true if this driver accepts the given URL
Throws:
java.sql.SQLException - Passed through from the underlying PostgreSQL driver, should not happen.
See Also:
Driver.acceptsURL(java.lang.String)

getVersion

public static java.lang.String getVersion()
Returns our own CVS version plus postgres Version


addGISTypes

public static void addGISTypes(org.postgresql.PGConnection pgconn)
                        throws java.sql.SQLException
adds the JTS/PostGIS Data types to a PG 7.3+ Connection. If you use PostgreSQL jdbc drivers V8.0 or newer, those methods are deprecated due to some class loader problems (but still work for now), and you may want to use the method below instead.

Throws:
java.sql.SQLException

addGISTypes80

public static void addGISTypes80(org.postgresql.PGConnection pgconn)
                          throws java.sql.SQLException
adds the JTS/PostGIS Data types to a PG 8.0+ Connection.

Throws:
java.sql.SQLException

addGISTypes72

public static void addGISTypes72(org.postgresql.PGConnection pgconn)
                          throws java.sql.SQLException
adds the JTS/PostGIS Data types to a PG 7.2 Connection.

Throws:
java.sql.SQLException

mangleURL

protected java.lang.String mangleURL(java.lang.String url)
                              throws java.sql.SQLException
Mangles the PostGIS URL to return the original PostGreSQL URL

Throws:
java.sql.SQLException

getProtoString

protected java.lang.String getProtoString()