Class DriverWrapper

  • All Implemented Interfaces:
    java.sql.Driver

    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>io.github.sebasbaumh.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 <[email protected]>
    • Constructor Summary

      Constructors 
      Constructor Description
      DriverWrapper()
      Default constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean acceptsURL​(java.lang.String url)
      Check whether the driver thinks he can handle the given URL.
      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()
      java.util.logging.Logger getParentLogger()  
      static void registerDataTypes​(org.postgresql.PGConnection pgconn)
      Registers all datatypes on the given connection.
      • Methods inherited from class org.postgresql.Driver

        deregister, getMajorVersion, getMinorVersion, getPropertyInfo, getSharedTimer, getVersion, isRegistered, jdbcCompliant, notImplemented, parseURL, register
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DriverWrapper

        public DriverWrapper()
        Default constructor. This also loads the appropriate TypesAdder for our SQL Driver instance.
    • Method Detail

      • registerDataTypes

        public static void registerDataTypes​(@Nonnull
                                             org.postgresql.PGConnection pgconn)
                                      throws java.sql.SQLException
        Registers all datatypes on the given connection.
        Parameters:
        pgconn - Connection
        Throws:
        java.sql.SQLException
      • acceptsURL

        public boolean acceptsURL​(java.lang.String url)
        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
        See Also:
        Driver.acceptsURL(java.lang.String)
      • 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
      • getParentLogger

        public java.util.logging.Logger getParentLogger()
        Specified by:
        getParentLogger in interface java.sql.Driver
        Overrides:
        getParentLogger in class org.postgresql.Driver