Package net.postgis.jdbc

# Class DriverWrapper

java.lang.Object
org.postgresql.Driver
net.postgis.jdbc.DriverWrapper

All Implemented Interfaces:
  `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>net.postgis.jdbc.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 <markus.schaber@logix-tt.com>
See Also:
  - `DriverWrapperLW`
  - `DriverWrapperAutoprobe`

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected static class`
`DriverWrapper.TypesAdder`
Base class for the three typewrapper implementations
`protected static class`
`DriverWrapper.TypesAdder72`
addGISTypes for V7.2 pgjdbc
`protected static final 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

Fields
Modifier and Type
Field
Description
`protected static final Logger`
`logger`
The static logger instance.
`static final String`
`POSTGIS_PROTOCOL`
`static final String`
`POSTGRES_PROTOCOL`
`static final String`
`REVISION`
`protected static DriverWrapper.TypesAdder`
`ta72`
`protected static DriverWrapper.TypesAdder`
`ta74`
`protected static DriverWrapper.TypesAdder`
`ta80`
`protected DriverWrapper.TypesAdder`
`typesAdder`

## Constructor Summary

Constructors
Constructor
Description
`DriverWrapper()`
Default constructor.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`acceptsURL(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.
`Connection`
`connect(String url, Properties info)`
Creates a postgresql connection, and then adds the PostGIS data types to it calling addpgtypes().
`Logger`
`getParentLogger()`
`protected String`
`getProtoString()`
`protected static DriverWrapper.TypesAdder`
`getTypesAdder(org.postgresql.Driver d)`
`static String`
`getVersion()`
Returns our own CVS version plus postgres Version
`protected String`
`mangleURL(String url)`
Mangles the PostGIS URL to return the original PostGreSQL URL
`protected boolean`
`useLW(Connection result)`
Do we have HexWKB as well known text representation - to be overridden by subclasses.

### Methods inherited from class org.postgresql.Driver

`deregister, getMajorVersion, getMinorVersion, getPropertyInfo, getSharedTimer, isRegistered, jdbcCompliant, notImplemented, parseURL, register`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### logger

protected static final Logger logger
The static logger instance.

### POSTGRES_PROTOCOL

public static final String POSTGRES_PROTOCOL

See Also:
  - Constant Field Values

### POSTGIS_PROTOCOL

public static final String POSTGIS_PROTOCOL

See Also:
  - Constant Field Values

### REVISION

public static final 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 Details

### DriverWrapper

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

Throws:
  `SQLException` - when a SQLException occurs

## Method Details

### getTypesAdder

protected static DriverWrapper.TypesAdder getTypesAdder(org.postgresql.Driver d) throws SQLException

Throws:
  `SQLException`

### connect

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

Specified by:
  `connect` in interface `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 the driver does not support the subprotocol specified in the URL
Throws:
  `SQLException` - if a database access error occurs
See Also:
  - `Driver.connect(java.lang.String, java.util.Properties)`
  - `Driver`

### useLW

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

Parameters:
  `result` - Connection to check
Returns:
  true if using EWKB, false otherwise

### acceptsURL

public boolean acceptsURL(String url)
Check whether the driver thinks he can handle the given URL.

Specified by:
  `acceptsURL` in interface `Driver`
Overrides:
  `acceptsURL` in class `org.postgresql.Driver`
Parameters:
  `url` - the URL of the driver
Returns:
  true if this driver accepts the given URL
See Also:
  - `Driver.acceptsURL(java.lang.String)`

### getVersion

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

Returns:
  String value reprenstation of the version

### addGISTypes

public static void addGISTypes(org.postgresql.PGConnection pgconn) throws 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.

Parameters:
  `pgconn` - The PGConnection object to add the types to
Throws:
  `SQLException` - when a SQLException occurs

### addGISTypes80

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

Parameters:
  `pgconn` - The PGConnection object to add the types to
Throws:
  `SQLException` - when a SQLException occurs

### addGISTypes72

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

Parameters:
  `pgconn` - The PGConnection object to add the types to
Throws:
  `SQLException` - when a SQLException occurs

### mangleURL

protected String mangleURL(String url)
Mangles the PostGIS URL to return the original PostGreSQL URL

Parameters:
  `url` - String containing the url to be "mangled"
Returns:
  "mangled" string or null if the URL is unsupported

### getProtoString

protected String getProtoString()

### getParentLogger

public Logger getParentLogger()

Specified by:
  `getParentLogger` in interface `Driver`
Overrides:
  `getParentLogger` in class `org.postgresql.Driver`