compile
postgis.jar
postgis_debug.jar
+stubbin
+stubcompile
SRCDIR=src
EXAMPLES=examples
-BUILD=bin/make
+BUILD=bin
PGHOST?=localhost
PGPORT?=5432
PGDATABASE?=jdbc_test
$(SRCDIR)/org/postgis/Point.java \
$(SRCDIR)/org/postgis/Polygon.java
+STUBDIR=stubs
+STUBBUILD=stubbin/
+STUBSRC= $(STUBDIR)/org/postgresql/Connection.java \
+ $(STUBDIR)/org/postgresql/PGConnection.java
+
all: jar \
offlinetests
$(BUILD):
$(MKDIR) $(BUILD)
+$(STUBBUILD):
+ $(MKDIR) $(STUBBUILD)
+
+stubcompile: $(STUBBUILD)
+ $(JAVAC) -d $(STUBBUILD) $(STUBSRC)
+ touch stubcompile
-compile: $(BUILD) $(SRC)
- $(JAVAC) -classpath "$(CP)" -d $(BUILD) $(SRC)
+compile: stubcompile $(BUILD) $(SRC)
+ $(JAVAC) -classpath "$(STUBBUILD):$(CP)" -d $(BUILD) $(SRC)
touch compile
test: compile
alltests: onlinetests test
clean:
- $(DELETE) $(BUILD) bin postgis.jar postgis_debug.jar compile
+ $(DELETE) $(BUILD) bin stubbin postgis.jar postgis_debug.jar compile stubcompile
# pgjdbc 7.2 special treating (needed e. G. for woody backport)
# Calling this rules multiple times does not really hurt, but litter
JDBC compliant databases without any source code changes. PostgreSQL,
the database PostGIS is written for, comes with a driver that
follows this specification. For downloads and more info, see:
-http://gborg.postgresql.org/project/pgjdbc/projdisplay.php
+http://jdbc.postgresql.org/download.html
The purpose of the JDBC Driver extension is to give the PostgreSQL
JDBC driver some understanding of the PostGIS data types (Geometry,
* How do I build it? *
-You need a recent pgjdbc driver jar, see the gborg.postgresql link
-above. It is currently tested with 7.3, 7.4 and 8.0 pgjdbc releases.
-(7.2 users see below.) Note that this does not constrain the PostgreSQL
+You need a recent pgjdbc driver jar, see the download link from above.
+It is currently tested and supported with 7.2, 7.3, 7.4 and 8.0 pgjdbc
+releases. Those are exactly the releases that are currently supported by
+PostgreSQL server guys.
+
+The current PostGIS jdbc release is also reported to run (but not compile)
+against the postgresql jdbc7.1-1.2.jar, but this is not supported, as well as
+PostGIS itsself does not support 7.1 any more.
+
+Note that your pgjdbc driver version does not constrain the PostgreSQL
server version. As the JDBC drivers are downwards compatible against older
servers, and PostgreSQL servers typically accept older clients, you can
easily use e. G. a pgjdbc 8.0 against a PostgreSQL 7.3 server.
debugging purposes.
-* What about pgjdbc 7.2? *
-
-Between pgjdbc 7.2 and 7.3, the PostgreSQL guys changed some interfaces.
-While this change improved some things, it also introduced some minor
-source level incompatibilities. If you want to use V7.2, you can apply the
-provided patch file "woody.patch", this makes the source compile and work
-fine with pg72jdbc2.jar.
-
-However, the resulting postgis.jar will only work with pgjdbc7.2, while a
-postgis.jar compiled using 7.3, 7.4 or 8.0 will be compatible to either
-of those newer release. So you may consider updating your pgjdbc version
-instead (remember that you can use a pgjdbc7.3 against a 7.2 server).
-
-For applying and reversing the patch, you can use the convenience make
-targets "woodypatch" and "woodyunpatch".
-
-
* How do I use it? *
To use the PostGIS types, you need the postgis.jar and the pgjdbc
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(dburl, dbuser, dbpass);
System.out.println("Adding geometric type entries...");
- ((org.postgresql.PGConnection) conn).addDataType("geometry", "org.postgis.PGgeometry");
- ((org.postgresql.PGConnection) conn).addDataType("box3d", "org.postgis.PGbox3d");
+ // magic trickery to be pgjdbc 7.2 compatible
+ // This works due to the late binding of data types in most java VMs. As
+ // this is more a demo source than a real-world app, we can risk this
+ // problem.
+ if (conn.getClass().getName().equals("org.postgresql.jdbc2.Connection")) {
+ ((org.postgresql.Connection) conn).addDataType("geometry", "org.postgis.PGgeometry");
+ ((org.postgresql.Connection) conn).addDataType("box3d", "org.postgis.PGbox3d");
+ } else {
+ ((org.postgresql.PGConnection) conn).addDataType("geometry",
+ "org.postgis.PGgeometry");
+ ((org.postgresql.PGConnection) conn).addDataType("box3d", "org.postgis.PGbox3d");
+ }
Statement s = conn.createStatement();
System.out.println("Creating table with geometric types...");
//table might not yet exist
private static final String POSTGRES_PROTOCOL = "jdbc:postgresql:";
private static final String POSTGIS_PROTOCOL = "jdbc:postgresql_postGIS:";
public static final String REVISION = "$Revision$";
+ public final TypesAdder typesAdder;
- public DriverWrapper() {
+ /**
+ * Default constructor.
+ *
+ * This also loads the appropriate TypesAdder for our SQL Driver instance.
+ *
+ * @throws SQLException
+ */
+ public DriverWrapper() throws SQLException {
super();
+ typesAdder = getTypesAdder(this);
+ // The debug method is @since 7.2
+ if (super.getMajorVersion() > 8 || super.getMinorVersion() > 1) {
+ super.debug("DriverWrapper loaded TypesAdder: " + typesAdder.getClass().getName());
+ }
+ }
+
+ protected static TypesAdder getTypesAdder(Driver d) throws SQLException {
+ if (d.getMajorVersion() == 7) {
+ if (d.getMinorVersion() >= 3) {
+ return loadTypesAdder(74);
+ } else {
+ return loadTypesAdder(72);
+ }
+ } else {
+ return loadTypesAdder(80);
+ }
+ }
+
+ private static TypesAdder loadTypesAdder(int i) throws SQLException {
+ try {
+ Class klass = Class.forName("org.postgis.DriverWrapper$TypesAdder" + i);
+ return (TypesAdder) klass.newInstance();
+ } catch (Exception e) {
+ throw new SQLException("Cannot create TypesAdder instance! " + e.getMessage());
+ }
}
static {
public java.sql.Connection connect(String url, Properties info) throws SQLException {
url = mangleURL(url);
Connection result = super.connect(url, info);
- addGISTypes((PGConnection) result);
+ typesAdder.addGT(result);
return result;
}
- /**
- * adds the JTS/PostGIS Data types to a PG Connection.
- */
- public static void addGISTypes(PGConnection pgconn) {
- // This is correct for PostgreSQL jdbc drivers up to V7.4
- pgconn.addDataType("geometry", "org.postgis.PGgeometry");
- pgconn.addDataType("box3d", "org.postgis.PGbox3d");
- pgconn.addDataType("box2d", "org.postgis.PGbox2d");
-
- // If you use PostgreSQL jdbc drivers V8.0 or newer, the above
- // methods are deprecated (but still work for now), and you
- // may want to use the two lines below instead.
-
- //pgconn.addDataType("geometry", org.postgis.PGgeometry.class);
- //pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
- //pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
- }
-
- /**
- * Mangles the PostGIS URL to return the original PostGreSQL URL
- */
- public static String mangleURL(String url) throws SQLException {
- if (url.startsWith(POSTGIS_PROTOCOL)) {
- return POSTGRES_PROTOCOL + url.substring(POSTGIS_PROTOCOL.length());
- } else {
- throw new SQLException("Unknown protocol or subprotocol in url " + url);
- }
- }
-
/**
* Check whether the driver thinks he can handle the given URL.
*
}
/**
- * Gets the underlying drivers major version number
- *
- * @return the drivers major version number
+ * Returns our own CVS version plus postgres Version
+ */
+ public static String getVersion() {
+ return "PostGisWrapper " + REVISION + ", wrapping " + Driver.getVersion();
+ }
+
+ /*
+ * Here follows the addGISTypes() stuff. This is a little tricky because the
+ * pgjdbc people had several, partially incompatible API changes during 7.2
+ * and 8.0. We still want to support all those releases, however.
+ *
+ */
+ /**
+ * 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.
+ *
*/
+ public static void addGISTypes(PGConnection pgconn) {
+ pgconn.addDataType("geometry", "org.postgis.PGgeometry");
+ pgconn.addDataType("box3d", "org.postgis.PGbox3d");
+ pgconn.addDataType("box2d", "org.postgis.PGbox2d");
+ }
- public int getMajorVersion() {
- return super.getMajorVersion();
+ /**
+ * adds the JTS/PostGIS Data types to a PG 8.0+ Connection.
+ */
+ public static void addGISTypes80(PGConnection pgconn) throws SQLException {
+ pgconn.addDataType("geometry", org.postgis.PGgeometry.class);
+ pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
+ pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
}
/**
- * Get the underlying drivers minor version number
- *
- * @return the drivers minor version number
+ * adds the JTS/PostGIS Data types to a PG 7.2 Connection.
*/
- public int getMinorVersion() {
- return super.getMinorVersion();
+ public static void addGISTypes72(org.postgresql.Connection pgconn) {
+ pgconn.addDataType("geometry", "org.postgis.PGgeometry");
+ pgconn.addDataType("box3d", "org.postgis.PGbox3d");
+ pgconn.addDataType("box2d", "org.postgis.PGbox2d");
}
/**
- * Returns our own CVS version plus postgres Version
+ * Mangles the PostGIS URL to return the original PostGreSQL URL
*/
- public static String getVersion() {
- return "PostGisWrapper " + REVISION + ", wrapping " + Driver.getVersion();
+ public static String mangleURL(String url) throws SQLException {
+ if (url.startsWith(POSTGIS_PROTOCOL)) {
+ return POSTGRES_PROTOCOL + url.substring(POSTGIS_PROTOCOL.length());
+ } else {
+ throw new SQLException("Unknown protocol or subprotocol in url " + url);
+ }
+ }
+
+ /** Base class for the three typewrapper implementations */
+ protected static abstract class TypesAdder {
+ public abstract void addGT(java.sql.Connection conn) throws SQLException;
+ }
+
+ /** addGISTypes for V7.3 and V7.4 pgjdbc */
+ protected static final class TypesAdder74 extends TypesAdder {
+ public void addGT(java.sql.Connection conn) {
+ addGISTypes((PGConnection) conn);
+ }
+ }
+
+ /** addGISTypes for V7.2 pgjdbc */
+ protected static class TypesAdder72 extends TypesAdder {
+ public void addGT(java.sql.Connection conn) {
+ addGISTypes72((org.postgresql.Connection) conn);
+
+ }
+ }
+
+ /** addGISTypes for V8.0 (and hopefully newer) pgjdbc */
+ protected static class TypesAdder80 extends TypesAdder {
+ public void addGT(java.sql.Connection conn) throws SQLException {
+ addGISTypes80((PGConnection) conn);
+ }
}
}
\ No newline at end of file
--- /dev/null
+Copyright (c) 1997-2005, PostgreSQL Global Development Group
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+3. Neither the name of the PostgreSQL Global Development Group nor the names
+ of its contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
--- /dev/null
+/*-------------------------------------------------------------------------
+ * Derived from org.postgresql.PGConnection Source from jdbc8.0 as well as
+ * the pgjdbc 7.2 binary jar which both are licensed under BSD license.
+ *
+ * Copyright (c) 2003-2005, PostgreSQL Global Development Group
+ * Copyright (c) 2005 Markus Schaber <schabios@logi-track.com>
+ *
+ * IDENTIFICATION
+ * $PostgreSQL: pgjdbc/org/postgresql/PGConnection.java,v 1.13 2005/01/17 09:51:40 jurka Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+package org.postgresql;
+
+/**
+ * Stub to compile postgis jdbc against
+ */
+public abstract class Connection {
+ public abstract void addDataType(String type, String name);
+}
\ No newline at end of file
--- /dev/null
+/*-------------------------------------------------------------------------
+ * Derived from org.postgresql.PGConnection from jdbc8.0 which is licensed
+ * under BSD license.
+ *
+ * Copyright (c) 2003-2005, PostgreSQL Global Development Group
+ * Copyright (c) 2005 Markus Schaber <schabios@logi-track.com>
+ *
+ * IDENTIFICATION
+ * $PostgreSQL: pgjdbc/org/postgresql/PGConnection.java,v 1.13 2005/01/17 09:51:40 jurka Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+package org.postgresql;
+
+import java.sql.SQLException;
+
+/**
+ * Stub to compile postgis jdbc against
+ */
+public interface PGConnection {
+ public void addDataType(String type, String name);
+
+ public void addDataType(String type, Class klass) throws SQLException;
+}
+
+++ /dev/null
-Index: src/examples/TestServer.java
-===================================================================
-RCS file: /home/cvs/postgis/postgis/jdbc2/src/examples/TestServer.java,v
-retrieving revision 1.3
-diff -U2 -r1.3 TestServer.java
---- src/examples/TestServer.java 4 Feb 2005 09:05:24 -0000 1.3
-+++ src/examples/TestServer.java 8 Feb 2005 16:50:15 -0000
-@@ -64,6 +64,6 @@
- conn = DriverManager.getConnection(dburl, dbuser, dbpass);
- System.out.println("Adding geometric type entries...");
-- ((org.postgresql.PGConnection) conn).addDataType("geometry", "org.postgis.PGgeometry");
-- ((org.postgresql.PGConnection) conn).addDataType("box3d", "org.postgis.PGbox3d");
-+ ((org.postgresql.Connection) conn).addDataType("geometry", "org.postgis.PGgeometry");
-+ ((org.postgresql.Connection) conn).addDataType("box3d", "org.postgis.PGbox3d");
- Statement s = conn.createStatement();
- System.out.println("Creating table with geometric types...");
-Index: src/org/postgis/DriverWrapper.java
-===================================================================
-RCS file: /home/cvs/postgis/postgis/jdbc2/src/org/postgis/DriverWrapper.java,v
-retrieving revision 1.5
-diff -U2 -r1.5 DriverWrapper.java
---- src/org/postgis/DriverWrapper.java 4 Feb 2005 09:05:24 -0000 1.5
-+++ src/org/postgis/DriverWrapper.java 8 Feb 2005 16:50:15 -0000
-@@ -26,5 +26,4 @@
-
- import org.postgresql.Driver;
--import org.postgresql.PGConnection;
-
- import java.sql.Connection;
-@@ -69,5 +68,5 @@
- public static final String REVISION = "$Revision: 1.5 $";
-
-- public DriverWrapper() {
-+ public DriverWrapper() throws java.sql.SQLException {
- super();
- }
-@@ -97,5 +96,5 @@
- url = mangleURL(url);
- Connection result = super.connect(url, info);
-- addGISTypes((PGConnection) result);
-+ addGISTypes((org.postgresql.Connection) result);
- return result;
- }
-@@ -104,5 +103,5 @@
- * adds the JTS/PostGIS Data types to a PG Connection.
- */
-- public static void addGISTypes(PGConnection pgconn) {
-+ public static void addGISTypes(org.postgresql.Connection pgconn) {
- // This is correct for PostgreSQL jdbc drivers up to V7.4
- pgconn.addDataType("geometry", "org.postgis.PGgeometry");