]> granicus.if.org Git - postgis/commitdiff
Now compiles against 7.2 with some magic trickery instead of patching.
authorMarkus Schaber <markus@schabi.de>
Mon, 14 Feb 2005 11:49:19 +0000 (11:49 +0000)
committerMarkus Schaber <markus@schabi.de>
Mon, 14 Feb 2005 11:49:19 +0000 (11:49 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1395 b70326c6-7e19-0410-871a-916f4a2858ee

jdbc2/.cvsignore
jdbc2/Makefile
jdbc2/README
jdbc2/src/examples/TestServer.java
jdbc2/src/org/postgis/DriverWrapper.java
jdbc2/stubs/LICENSE [new file with mode: 0644]
jdbc2/stubs/org/postgresql/Connection.java [new file with mode: 0644]
jdbc2/stubs/org/postgresql/PGConnection.java [new file with mode: 0644]
jdbc2/woody.patch [deleted file]

index 8613f1eb3fe7f0f10f700c79038f2782ad57f339..b02641c40571cc762c5d6a32dee7a1c644211f2c 100644 (file)
@@ -2,3 +2,5 @@ bin
 compile
 postgis.jar
 postgis_debug.jar
+stubbin
+stubcompile
index 57c321dab4a6f164eda2a12a71b1201537c9a169..ebfe7c9c23d609b5392124c0a1ea86443a8f22e5 100644 (file)
@@ -30,7 +30,7 @@ CP=$(CLASSPATH):src/
 
 SRCDIR=src
 EXAMPLES=examples
-BUILD=bin/make
+BUILD=bin
 PGHOST?=localhost
 PGPORT?=5432
 PGDATABASE?=jdbc_test
@@ -58,6 +58,11 @@ SRC= $(SRCDIR)/examples/Test.java \
                $(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
@@ -72,9 +77,15 @@ jar: compile
 $(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
@@ -107,7 +118,7 @@ onlinetests: boxtest ptest jtest autoregistertest
 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
index 2ed1c2ccb29703485fc61a7cc8896c7dd062d8d4..ecfd7c03077d08fbf251466e57f17cf0bcdb0a5c 100644 (file)
@@ -10,7 +10,7 @@ world, JDBC allows java applications to transparently use different
 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,
@@ -66,9 +66,16 @@ link against those.
 
 * 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.
@@ -83,23 +90,6 @@ A "make jar" then compiles the code and creates two jar files. The
 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
index cef15ba3375e6ea31d501855c8b5717956d2cd07..106dc9a63493ee4cf1322e9f9898f6bbcd836b41 100644 (file)
@@ -63,8 +63,18 @@ public class TestServer {
             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
index e0e997ec670a840b0e58353d65a408ef9fddd221..8b5af581026daf0311e2161c7211389ae38122ff 100644 (file)
@@ -67,9 +67,43 @@ public class DriverWrapper extends Driver {
     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 {
@@ -96,39 +130,10 @@ public class DriverWrapper extends Driver {
     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.
      * 
@@ -148,28 +153,84 @@ public class DriverWrapper extends Driver {
     }
 
     /**
-     * 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
diff --git a/jdbc2/stubs/LICENSE b/jdbc2/stubs/LICENSE
new file mode 100644 (file)
index 0000000..d11155c
--- /dev/null
@@ -0,0 +1,26 @@
+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.
diff --git a/jdbc2/stubs/org/postgresql/Connection.java b/jdbc2/stubs/org/postgresql/Connection.java
new file mode 100644 (file)
index 0000000..26c12a6
--- /dev/null
@@ -0,0 +1,20 @@
+/*-------------------------------------------------------------------------
+ * 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
diff --git a/jdbc2/stubs/org/postgresql/PGConnection.java b/jdbc2/stubs/org/postgresql/PGConnection.java
new file mode 100644 (file)
index 0000000..1a5ab6f
--- /dev/null
@@ -0,0 +1,25 @@
+/*-------------------------------------------------------------------------
+ * 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;
+}
+
diff --git a/jdbc2/woody.patch b/jdbc2/woody.patch
deleted file mode 100644 (file)
index 1cbd729..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-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");