]> granicus.if.org Git - postgis/commitdiff
Update Java components to support SRID<=0 as unknown SRID (#1221)
authorSandro Santilli <strk@keybit.net>
Mon, 9 Jan 2012 11:01:44 +0000 (11:01 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 9 Jan 2012 11:01:44 +0000 (11:01 +0000)
This is first patch by Maria Arias de Reyna taking on maintainance
of the Java components. It includes tweaks in README file and
a new maven based build system. It also includes some indenting
changes.

git-svn-id: http://svn.osgeo.org/postgis/trunk@8710 b70326c6-7e19-0410-871a-916f4a2858ee

12 files changed:
java/jdbc/README
java/jdbc/jtssrc/org/postgis/jts/JtsBinaryParser.java
java/jdbc/jtssrc/pom.xml [new file with mode: 0644]
java/jdbc/pom.xml [new file with mode: 0644]
java/jdbc/src/examples/TestServer.java
java/jdbc/src/org/postgis/DriverWrapper.java
java/jdbc/src/org/postgis/Geometry.java
java/jdbc/src/org/postgis/Version.java
java/jdbc/src/org/postgis/binary/BinaryParser.java
java/jdbc/src/org/postgis/java2d/ShapeBinaryParser.java
java/jdbc/src/org/postgis/version.properties [new file with mode: 0644]
java/jdbc/todo.txt

index fab1e73b14f539dae846d57855ca80fb18b21cff..100a78735ccb99afc50e0678059d58695eac9a28 100644 (file)
@@ -68,17 +68,18 @@ link against those.
 
 * How do I build it? *
 
-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, 8.0 and 8.1 pgjdbc
-releases. Those are the same PostgreSQL releases that are supported by the
-PostGIS server-side C code, and apart from 7.2, the same as currently 
-supported by PostgreSQL server developers.
+There are older make files with which you can try to build, but maven is recommended, 
+as it handles dependencies on a better and cleaner way.
 
-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 
-current PostGIS backend itsself does not support 7.1 servers any more.
+You have to install maven on your computer to build it. To install maven you can try 
+to search on your software repositories or read the documentation:
+http://maven.apache.org/download.html
 
-Note that your pgjdbc driver version does not constrain the PostgreSQL 
+To compile your postgis driver, go to the jdbc folder and execute the console
+command "mvn package". This should create a postgis jar on the target folder 
+inside the jdbc folder.
+
+Note that your postgis 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. To benefit
@@ -86,16 +87,6 @@ from optimizations and bugfixes, it is generally suggested to use the
 newest stable pgjdbc build that is documented to work against your 
 server release.
 
-Make shure the pgjdbc driver is available in your Java CLASSPATH,
-either by setting the environment variable, or by editing the
-Makefile.
-
-A "make jar" then compiles the code and creates two jar files. The
-"postgis.jar" is for normal usage and deployment, the
-"postgis_debug.jar" additionally includes the source code, for
-debugging purposes.
-
-
 * It is called jdbc2 - does it work with jdbc3, too? *
 
 To make it short: The naming does not refer to SUN jdbc standard releases 
index 5718d9ec928e16eb0e400facd2d94807f397dac4..85095c103528e6ec61b3124dd14dba56790e2534 100644 (file)
@@ -102,14 +102,14 @@ public class JtsBinaryParser {
         boolean haveS = (typeword & 0x20000000) != 0;
 
         if (haveS) {
-            int newsrid = Geometry.parseSRID(data.getInt());
+            int newsrid = org.postgis.Geometry.parseSRID(data.getInt());
             if (inheritSrid && newsrid != srid) {
                 throw new IllegalArgumentException("Inconsistent srids in complex geometry: " + srid + ", " + newsrid);
             } else {
                 srid = newsrid;
             }
         } else if (!inheritSrid) {
-            srid = Geometry.UNKNOWN_SRID;
+            srid = org.postgis.Geometry.UNKNOWN_SRID;
         }
        
         Geometry result;
diff --git a/java/jdbc/jtssrc/pom.xml b/java/jdbc/jtssrc/pom.xml
new file mode 100644 (file)
index 0000000..c5c6254
--- /dev/null
@@ -0,0 +1,165 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+\r
+       <modelVersion>4.0.0</modelVersion>\r
+\r
+       <groupId>org.postgis</groupId>\r
+       <artifactId>postgis-jdbc-jtsparser</artifactId>\r
+       <version>2.0.0</version>\r
+       <packaging>jar</packaging>\r
+\r
+       <name>Postgis JDBC Driver JTS Parser</name>\r
+       <url>http://www.postgis.org</url>\r
+       <description>Parser between JTS and PostGIS geometry formats.</description>\r
+\r
+       <licenses>\r
+               <license>\r
+                       <name>GNU Lesser General Public License</name>\r
+                       <url>http://www.gnu.org/licenses/lgpl-2.1.txt</url>\r
+                       <distribution>repo</distribution>\r
+               </license>\r
+       </licenses>\r
+\r
+       <developers>\r
+               <developer>\r
+                       <name>Postgis Development Team</name>\r
+               </developer>\r
+               <developer>\r
+                       <name>MarĂ­a Arias de Reyna</name>\r
+                       <email>delawen en gmail.com</email>\r
+               </developer>\r
+       </developers>\r
+       <contributors>\r
+               <contributor>\r
+                       <name>Hakan Tandogan</name>\r
+                       <email>hakan@gurkensalat.com</email>\r
+                       <url>http://www.gurkensalat.com/</url>\r
+                       <roles>\r
+                               <role>Maven Packager</role>\r
+                       </roles>\r
+               </contributor>\r
+       </contributors>\r
+       <mailingLists>\r
+               <mailingList>\r
+                       <name>User List</name>\r
+                       <subscribe>postgis-users-subscribe@postgis.refractions.net</subscribe>\r
+                       <unsubscribe>postgis-users-unsubscribe@postgis.refractions.net</unsubscribe>\r
+                       <post>postgis-users@postgis.refractions.net</post>\r
+                       <archive>http://postgis.refractions.net/pipermail/postgis-users/</archive>\r
+               </mailingList>\r
+               <mailingList>\r
+                       <name>Developer List</name>\r
+                       <subscribe>postgis-devel-subscribe@postgis.refractions.net</subscribe>\r
+                       <unsubscribe>postgis-devel-unsubscribe@postgis.refractions.net</unsubscribe>\r
+                       <post>postgis-devel@postgis.refractions.net</post>\r
+                       <archive>http://postgis.refractions.net/pipermail/postgis-devel/</archive>\r
+               </mailingList>\r
+       </mailingLists>\r
+       <issueManagement>\r
+               <system>Trac</system>\r
+               <url>http://trac.osgeo.org/postgis/</url>\r
+       </issueManagement>\r
+       <scm>\r
+               <url>http://trac.osgeo.org/postgis/browser/tags/2.0.0</url>\r
+               <connection>scm:svn:http://svn.osgeo.org/postgis/tags/2.0.0/</connection>\r
+               <developerConnection>scm:svn:http://svn.osgeo.org/postgis/tags/2.0.0/</developerConnection>\r
+       </scm>\r
+\r
+       <build>\r
+               <sourceDirectory>${basedir}/org</sourceDirectory>\r
+               <plugins>\r
+\r
+                       <plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-source-plugin</artifactId>\r
+                               <executions>\r
+                                       <execution>\r
+                                               <id>attach-sources</id>\r
+                                               <phase>verify</phase>\r
+                                               <goals>\r
+                                                       <goal>jar</goal>\r
+                                               </goals>\r
+                                       </execution>\r
+                               </executions>\r
+                       </plugin>\r
+\r
+                       <plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-javadoc-plugin</artifactId>\r
+                               <executions>\r
+                                       <execution>\r
+                                               <id>attach-javadocs</id>\r
+                                               <phase>verify</phase>\r
+                                               <goals>\r
+                                                       <goal>jar</goal>\r
+                                               </goals>\r
+                                       </execution>\r
+                               </executions>\r
+                       </plugin>\r
+               </plugins>\r
+\r
+       </build>\r
+\r
+       <dependencies>\r
+               <dependency>\r
+                       <groupId>org.postgis</groupId>\r
+                       <artifactId>postgis-jdbc</artifactId>\r
+                       <version>2.0.0</version>\r
+               </dependency>\r
+               <dependency>\r
+                       <groupId>com.vividsolutions</groupId>\r
+                       <artifactId>jts</artifactId>\r
+                       <version>1.12</version>\r
+               </dependency>\r
+\r
+       </dependencies>\r
+       <reporting>\r
+               <plugins>\r
+                       <plugin>\r
+                               <artifactId>maven-javadoc-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <artifactId>maven-dependency-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <artifactId>maven-project-info-reports-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <artifactId>maven-surefire-report-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>findbugs-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>javancss-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>jdepend-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>jxr-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>taglist-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>versions-maven-plugin</artifactId>\r
+                       </plugin>\r
+               </plugins>\r
+       </reporting>\r
+\r
+\r
+       <distributionManagement>\r
+               <repository>\r
+                       <id>sonatype-postgis-releases</id>\r
+                       <name>Sonatype Postgis Releases Repo</name>\r
+                       <url>http://oss.sonatype.org/content/repositories/postgis-releases</url>\r
+               </repository>\r
+       </distributionManagement>\r
+</project>\r
diff --git a/java/jdbc/pom.xml b/java/jdbc/pom.xml
new file mode 100644 (file)
index 0000000..5315dc1
--- /dev/null
@@ -0,0 +1,182 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+\r
+       <modelVersion>4.0.0</modelVersion>\r
+\r
+       <groupId>org.postgis</groupId>\r
+       <artifactId>postgis-jdbc</artifactId>\r
+       <version>${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}</version>\r
+       <packaging>jar</packaging>\r
+\r
+       <name>Postgis JDBC Driver</name>\r
+       <url>http://www.postgis.org</url>\r
+       <description>PostGIS adds support for geographic objects to the PostgreSQL object-relational database.</description>\r
+\r
+       <licenses>\r
+               <license>\r
+                       <name>GNU Lesser General Public License</name>\r
+                       <url>http://www.gnu.org/licenses/lgpl-2.1.txt</url>\r
+                       <distribution>repo</distribution>\r
+               </license>\r
+       </licenses>\r
+\r
+       <developers>\r
+               <developer>\r
+                       <name>Postgis Development Team</name>\r
+               </developer>\r
+               <developer>\r
+                       <name>MarĂ­a Arias de Reyna</name>\r
+                       <email>delawen en gmail.com</email>\r
+               </developer>\r
+       </developers>\r
+       <contributors>\r
+               <contributor>\r
+                       <name>Hakan Tandogan</name>\r
+                       <email>hakan@gurkensalat.com</email>\r
+                       <url>http://www.gurkensalat.com/</url>\r
+                       <roles>\r
+                               <role>Maven Packager</role>\r
+                       </roles>\r
+               </contributor>\r
+       </contributors>\r
+       <mailingLists>\r
+               <mailingList>\r
+                       <name>User List</name>\r
+                       <subscribe>postgis-users-subscribe@postgis.refractions.net</subscribe>\r
+                       <unsubscribe>postgis-users-unsubscribe@postgis.refractions.net</unsubscribe>\r
+                       <post>postgis-users@postgis.refractions.net</post>\r
+                       <archive>http://postgis.refractions.net/pipermail/postgis-users/</archive>\r
+               </mailingList>\r
+               <mailingList>\r
+                       <name>Developer List</name>\r
+                       <subscribe>postgis-devel-subscribe@postgis.refractions.net</subscribe>\r
+                       <unsubscribe>postgis-devel-unsubscribe@postgis.refractions.net</unsubscribe>\r
+                       <post>postgis-devel@postgis.refractions.net</post>\r
+                       <archive>http://postgis.refractions.net/pipermail/postgis-devel/</archive>\r
+               </mailingList>\r
+       </mailingLists>\r
+       <issueManagement>\r
+               <system>Trac</system>\r
+               <url>http://trac.osgeo.org/postgis/</url>\r
+       </issueManagement>\r
+       <scm>\r
+               <url>http://trac.osgeo.org/postgis/browser/tags/2.0.0</url>\r
+               <connection>scm:svn:http://svn.osgeo.org/postgis/tags/2.0.0/</connection>\r
+               <developerConnection>scm:svn:http://svn.osgeo.org/postgis/tags/2.0.0/</developerConnection>\r
+       </scm>\r
+\r
+       <build>\r
+\r
+               <sourceDirectory>${basedir}/src</sourceDirectory>\r
+               <!-- For the driverconfig property file -->\r
+               <resources>\r
+                       <resource>\r
+                               <directory>src</directory>\r
+                               <filtering>true</filtering>\r
+                               <includes>\r
+                                       <include>**/*.properties</include>\r
+                               </includes>\r
+                               <excludes>\r
+                                       <exclude>**/*.java</exclude>\r
+                               </excludes>\r
+                       </resource>\r
+               </resources>\r
+\r
+               <plugins><!--\r
+\r
+                       <plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-source-plugin</artifactId>\r
+                               <executions>\r
+                                       <execution>\r
+                                               <id>attach-sources</id>\r
+                                               <phase>verify</phase>\r
+                                               <goals>\r
+                                                       <goal>jar</goal>\r
+                                               </goals>\r
+                                       </execution>\r
+                               </executions>\r
+                       </plugin><plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-javadoc-plugin</artifactId>\r
+                               <executions>\r
+                                       <execution>\r
+                                               <id>attach-javadocs</id>\r
+                                               <phase>verify</phase>\r
+                                               <goals>\r
+                                                       <goal>jar</goal>\r
+                                               </goals>\r
+                                       </execution>\r
+                               </executions>\r
+                       </plugin>\r
+\r
+                       -->\r
+               </plugins>\r
+\r
+       </build>\r
+\r
+       <dependencies>\r
+               <dependency>\r
+                       <groupId>postgresql</groupId>\r
+                       <artifactId>postgresql</artifactId>\r
+                       <version>9.1-901.jdbc3</version>\r
+               </dependency>\r
+       </dependencies>\r
+       <reporting>\r
+               <plugins>\r
+                       <plugin>\r
+                               <artifactId>maven-javadoc-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <artifactId>maven-dependency-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <artifactId>maven-project-info-reports-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <artifactId>maven-surefire-report-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>findbugs-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>javancss-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>jdepend-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>jxr-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>taglist-maven-plugin</artifactId>\r
+                       </plugin>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>versions-maven-plugin</artifactId>\r
+                       </plugin>\r
+               </plugins>\r
+       </reporting>\r
+\r
+\r
+       <distributionManagement>\r
+               <repository>\r
+                       <id>sonatype-postgis-releases</id>\r
+                       <name>Sonatype Postgis Releases Repo</name>\r
+                       <url>http://oss.sonatype.org/content/repositories/postgis-releases</url>\r
+               </repository>\r
+       </distributionManagement>\r
+       \r
+       \r
+  <properties>\r
+    <POSTGIS_MAJOR_VERSION>2</POSTGIS_MAJOR_VERSION>\r
+    <POSTGIS_MINOR_VERSION>0</POSTGIS_MINOR_VERSION>\r
+    <POSTGIS_MICRO_VERSION>0</POSTGIS_MICRO_VERSION>\r
+  </properties>\r
+       \r
+</project>\r
index 61eef9d192f49e1c942ca1ffea0d80d41d71cc01..bb36e7bc752322ad4edda2e1283e23ee9391f4de 100644 (file)
@@ -33,84 +33,76 @@ import java.sql.Statement;
 
 public class TestServer {
 
-    public static void main(String[] args) {
-        if (args.length != 4 && args.length != 3) {
-            System.err.println("Usage: java examples/TestServer dburl user pass [tablename]");
-            System.err.println();
-            System.err.println("dburl has the following format:");
-            System.err.println("jdbc:postgresql://HOST:PORT/DATABASENAME");
-            System.err.println("tablename is 'jdbc_test' by default.");
-            System.exit(1);
-        }
+       public static void main(String[] args) {
+               if (args.length != 4 && args.length != 3) {
+                       System.err
+                                       .println("Usage: java examples/TestServer dburl user pass [tablename]");
+                       System.err.println();
+                       System.err.println("dburl has the following format:");
+                       System.err.println("jdbc:postgresql://HOST:PORT/DATABASENAME");
+                       System.err.println("tablename is 'jdbc_test' by default.");
+                       System.exit(1);
+               }
 
-        Connection conn;
+               Connection conn;
 
-        String dburl = args[0];
-        String dbuser = args[1];
-        String dbpass = args[2];
+               String dburl = args[0];
+               String dbuser = args[1];
+               String dbpass = args[2];
 
-        String dbtable = "jdbc_test";
+               String dbtable = "jdbc_test";
 
-        String dropSQL = "drop table " + dbtable;
-        String createSQL = "create table " + dbtable + " (geom geometry, id int4)";
-        String insertPointSQL = "insert into " + dbtable + " values ('POINT (10 10 10)',1)";
-        String insertPolygonSQL = "insert into " + dbtable
-                + " values ('POLYGON ((0 0 0,0 10 0,10 10 0,10 0 0,0 0 0))',2)";
+               String dropSQL = "drop table " + dbtable;
+               String createSQL = "create table " + dbtable
+                               + " (geom geometry, id int4)";
+               String insertPointSQL = "insert into " + dbtable
+                               + " values ('POINT (10 10 10)',1)";
+               String insertPolygonSQL = "insert into " + dbtable
+                               + " values ('POLYGON ((0 0 0,0 10 0,10 10 0,10 0 0,0 0 0))',2)";
 
-        try {
+               try {
 
-            System.out.println("Creating JDBC connection...");
-            Class.forName("org.postgresql.Driver");
-            conn = DriverManager.getConnection(dburl, dbuser, dbpass);
-            System.out.println("Adding geometric type entries...");
-            /*
-             * 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 breaking on exotic VMs here. Real-world apps usually do not
-             * suffer from this problem as they do not have to support such a
-             * wide range of different pgjdbc releases, or they can use the
-             * approach from org.postgis.DriverWrapper (which we do not use here
-             * intentionally to have a test for the other ways to do it).
-             */
-            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
-            try {
-                s.execute(dropSQL);
-            } catch (Exception e) {
-                System.out.println("Error dropping old table: " + e.getMessage());
-            }
-            s.execute(createSQL);
-            System.out.println("Inserting point...");
-            s.execute(insertPointSQL);
-            System.out.println("Inserting polygon...");
-            s.execute(insertPolygonSQL);
-            System.out.println("Done.");
-            s = conn.createStatement();
-            System.out.println("Querying table...");
-            ResultSet r = s.executeQuery("select asText(geom),id from " + dbtable);
-            while (r.next()) {
-                Object obj = r.getObject(1);
-                int id = r.getInt(2);
-                System.out.println("Row " + id + ":");
-                System.out.println(obj.toString());
-            }
-            s.close();
-            conn.close();
-        } catch (Exception e) {
-            System.err.println("Aborted due to error:");
-            e.printStackTrace();
-            System.exit(1);
-        }
-    }
+                       System.out.println("Creating JDBC connection...");
+                       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.class);
+                       ((org.postgresql.PGConnection) conn).addDataType("box3d",
+                                       org.postgis.PGbox3d.class);
+
+                       Statement s = conn.createStatement();
+                       System.out.println("Creating table with geometric types...");
+                       // table might not yet exist
+                       try {
+                               s.execute(dropSQL);
+                       } catch (Exception e) {
+                               System.out.println("Error dropping old table: "
+                                               + e.getMessage());
+                       }
+                       s.execute(createSQL);
+                       System.out.println("Inserting point...");
+                       s.execute(insertPointSQL);
+                       System.out.println("Inserting polygon...");
+                       s.execute(insertPolygonSQL);
+                       System.out.println("Done.");
+                       s = conn.createStatement();
+                       System.out.println("Querying table...");
+                       ResultSet r = s.executeQuery("select asText(geom),id from "
+                                       + dbtable);
+                       while (r.next()) {
+                               Object obj = r.getObject(1);
+                               int id = r.getInt(2);
+                               System.out.println("Row " + id + ":");
+                               System.out.println(obj.toString());
+                       }
+                       s.close();
+                       conn.close();
+               } catch (Exception e) {
+                       System.err.println("Aborted due to error:");
+                       e.printStackTrace();
+                       System.exit(1);
+               }
+       }
 }
index 8351d20b05566613c3ad2efee6bc921cd78caabf..1743ddb05ad696761536148dc7a6d1a1a8a924e5 100644 (file)
@@ -224,7 +224,7 @@ public class DriverWrapper extends Driver {
      * 
      * @throws SQLException
      */
-    public static void addGISTypes72(org.postgresql.Connection pgconn) throws SQLException {
+    public static void addGISTypes72(org.postgresql.PGConnection pgconn) throws SQLException {
         loadTypesAdder("72").addGT((Connection) pgconn, false);
     }
 
@@ -264,39 +264,39 @@ public class DriverWrapper extends Driver {
 
     /** addGISTypes for V7.3 and V7.4 pgjdbc */
     protected static final class TypesAdder74 extends TypesAdder {
-        public void addGeometries(Connection conn) {
+        public void addGeometries(Connection conn) throws SQLException {
             PGConnection pgconn = (PGConnection) conn;
-            pgconn.addDataType("geometry", "org.postgis.PGgeometry");
+            pgconn.addDataType("geometry", org.postgis.PGgeometry.class);
         }
 
-        public void addBoxen(Connection conn) {
+        public void addBoxen(Connection conn) throws SQLException {
             PGConnection pgconn = (PGConnection) conn;
-            pgconn.addDataType("box3d", "org.postgis.PGbox3d");
-            pgconn.addDataType("box2d", "org.postgis.PGbox2d");
+            pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
+            pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
         }
 
-        public void addBinaryGeometries(Connection conn) {
+        public void addBinaryGeometries(Connection conn) throws SQLException {
             PGConnection pgconn = (PGConnection) conn;
-            pgconn.addDataType("geometry", "org.postgis.PGgeometryLW");
+            pgconn.addDataType("geometry", org.postgis.PGgeometryLW.class);
         }
     }
 
     /** addGISTypes for V7.2 pgjdbc */
     protected static class TypesAdder72 extends TypesAdder {
-        public void addGeometries(Connection conn) {
-            org.postgresql.Connection pgconn = (org.postgresql.Connection) conn;
-            pgconn.addDataType("geometry", "org.postgis.PGgeometry");
+        public void addGeometries(Connection conn) throws SQLException {
+            org.postgresql.PGConnection pgconn = (org.postgresql.PGConnection) conn;
+            pgconn.addDataType("geometry", org.postgis.PGgeometry.class);
         }
 
-        public void addBoxen(Connection conn) {
-            org.postgresql.Connection pgconn = (org.postgresql.Connection) conn;
-            pgconn.addDataType("box3d", "org.postgis.PGbox3d");
-            pgconn.addDataType("box2d", "org.postgis.PGbox2d");
+               public void addBoxen(Connection conn) throws SQLException {
+            org.postgresql.PGConnection pgconn = (org.postgresql.PGConnection) conn;
+            pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
+            pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
         }
 
-        public void addBinaryGeometries(Connection conn) {
-            org.postgresql.Connection pgconn = (org.postgresql.Connection) conn;
-            pgconn.addDataType("geometry", "org.postgis.PGgeometryLW");
+        public void addBinaryGeometries(Connection conn) throws SQLException {
+            org.postgresql.PGConnection pgconn = (org.postgresql.PGConnection) conn;
+            pgconn.addDataType("geometry", org.postgis.PGgeometryLW.class);
         }
     }
 
index 098062a0985a2daad4875baf818ed39f86e60e00..b3fa48fb6724535d298624ba83c715246760e939 100644 (file)
@@ -30,310 +30,307 @@ import java.io.Serializable;
 
 /** The base class of all geometries */
 public abstract class Geometry implements Serializable {
-    /* JDK 1.5 Serialization */
-    private static final long serialVersionUID = 0x100;
-
-    // OpenGIS Geometry types as defined in the OGC WKB Spec
-    // (May we replace this with an ENUM as soon as JDK 1.5
-    // has gained widespread usage?)
-
-    /** Fake type for linear ring */
-    public static final int LINEARRING = 0;
-    /**
-     * The OGIS geometry type number for points.
-     */
-    public static final int POINT = 1;
-
-    /**
-     * The OGIS geometry type number for lines.
-     */
-    public static final int LINESTRING = 2;
-
-    /**
-     * The OGIS geometry type number for polygons.
-     */
-    public static final int POLYGON = 3;
-
-    /**
-     * The OGIS geometry type number for aggregate points.
-     */
-    public static final int MULTIPOINT = 4;
-
-    /**
-     * The OGIS geometry type number for aggregate lines.
-     */
-    public static final int MULTILINESTRING = 5;
-
-    /**
-     * The OGIS geometry type number for aggregate polygons.
-     */
-    public static final int MULTIPOLYGON = 6;
-
-    /**
-     * The OGIS geometry type number for feature collections.
-     */
-    public static final int GEOMETRYCOLLECTION = 7;
-
-    public static final String[] ALLTYPES = new String[]{
-        "", // internally used LinearRing does not have any text in front of it
-        "POINT",
-        "LINESTRING",
-        "POLYGON",
-        "MULTIPOINT",
-        "MULTILINESTRING",
-        "MULTIPOLYGON",
-        "GEOMETRYCOLLECTION"};
-
-    /**
-     * The Text representations of the geometry types
-     */
-    public static String getTypeString(int type) {
-        if (type >= 0 && type <= 7) {
-            return ALLTYPES[type];
-        } else {
-            throw new IllegalArgumentException("Unknown Geometry type" + type);
-        }
-    }
-
-    // Properties common to all geometries
-    /**
-     * The dimensionality of this feature (2,3)
-     */
-    public int dimension;
-
-    /**
-     * Do we have a measure (4th dimension)
-     */
-    public boolean haveMeasure = false;
-
-    /**
-     * The OGIS geometry type of this feature. this is final as it never
-     * changes, it is bound to the subclass of the instance.
-     */
-    public final int type;
-
-    /**
-     * Official UNKNOWN srid value 
-     */
-    public final int UNKNOWN_SRID = 0;
-
-    /**
-     * The spacial reference system id of this geometry, default is no srid 
-     */
-    public int srid = UNKNOWN_SRID;
-
-    /**
-     * Parse a SRID value, anything <= 0 is unknown
-     */
-    public static int parseSRID(int srid) {
-        if ( srid < 0 ) {
-            /* TODO: raise a warning ? */
-            srid = 0;
-        }
-        return srid;
-    }
-
-    /**
-     * Constructor for subclasses
-     * 
-     * @param type has to be given by all subclasses.
-     */
-    protected Geometry(int type) {
-        this.type = type;
-    }
-
-    /**
-     * java.lang.Object hashCode implementation
-     */
-    public int hashCode() {
-        return dimension | (type * 4) | (srid * 32);
-    }
-
-    /**
-     * java.lang.Object equals implementation
-     */
-    public boolean equals(Object other) {
-        return (other != null) && (other instanceof Geometry) && equals((Geometry) other);
-    }
-
-    /**
-     * geometry specific equals implementation - only defined for non-null
-     * values
-     */
-    public boolean equals(Geometry other) {
-        return (other != null) 
-                && (this.dimension == other.dimension)
-                && (this.type == other.type)
-                && (this.srid == other.srid) 
-                && (this.haveMeasure == other.haveMeasure) 
-                && other.getClass().equals(this.getClass()) 
-                && this.equalsintern(other);
-    }
-
-    /**
-     * Whether test coordinates for geometry - subclass specific code
-     * 
-     * Implementors can assume that dimensin, type, srid and haveMeasure are
-     * equal, other != null and other is the same subclass.
-     */
-    protected abstract boolean equalsintern(Geometry other);
-
-    /**
-     * Return the number of Points of the geometry
-     */
-    public abstract int numPoints();
-
-    /**
-     * Get the nth Point of the geometry
-     * 
-     * @param n the index of the point, from 0 to numPoints()-1;
-     * @throws ArrayIndexOutOfBoundsException in case of an emtpy geometry or
-     *             bad index.
-     */
-    public abstract Point getPoint(int n);
-
-    /**
-     * Same as getPoint(0);
-     */
-    public abstract Point getFirstPoint();
-
-    /**
-     * Same as getPoint(numPoints()-1);
-     */
-    public abstract Point getLastPoint();
-
-    /**
-     * The OGIS geometry type number of this geometry.
-     */
-    public int getType() {
-        return this.type;
-    }
-
-    /**
-     * Return the Type as String
-     */
-    public String getTypeString() {
-        return getTypeString(this.type);
-    }
-
-    /** Returns whether we have a measure */
-    public boolean isMeasured() {
-        return haveMeasure;
-    }
-
-    /**
-     * Queries the number of geometric dimensions of this geometry. This does
-     * not include measures, as opposed to the server.
-     * 
-     * @return The dimensionality (eg, 2D or 3D) of this geometry.
-     */
-    public int getDimension() {
-        return this.dimension;
-    }
-
-    /**
-     * The OGIS geometry type number of this geometry.
-     */
-    public int getSrid() {
-        return this.srid;
-    }
-
-    /**
-     * Recursively sets the srid on this geometry and all contained
-     * subgeometries
-     */
-    public void setSrid(int srid) {
-        this.srid = srid;
-    }
-
-    public String toString() {
-        StringBuffer sb = new StringBuffer();
-        if (srid != UNKNOWN_SRID) {
-            sb.append("SRID=");
-            sb.append(srid);
-            sb.append(';');
-        }
-        outerWKT(sb, true);
-        return sb.toString();
-    }
-
-    /**
-     * Render the WKT version of this Geometry (without SRID) into the given
-     * StringBuffer.
-     */
-    public void outerWKT(StringBuffer sb, boolean putM) {
-        sb.append(getTypeString());
-        if (putM && haveMeasure && dimension == 2) {
-            sb.append('M');
-        }
-        mediumWKT(sb);
-    }
-
-    public final void outerWKT(StringBuffer sb) {
-        outerWKT(sb, true);
-    }
-
-    /**
-     * Render the WKT without the type name, but including the brackets into the
-     * StringBuffer
-     */
-    protected void mediumWKT(StringBuffer sb) {
-        sb.append('(');
-        innerWKT(sb);
-        sb.append(')');
-    }
-
-    /**
-     * Render the "inner" part of the WKT (inside the brackets) into the
-     * StringBuffer.
-     */
-    protected abstract void innerWKT(StringBuffer SB);
-
-    /**
-     * backwards compatibility method
-     */
-    public String getValue() {
-        StringBuffer sb = new StringBuffer();
-        mediumWKT(sb);
-        return sb.toString();
-    }
-
-    /**
-     * Do some internal consistency checks on the geometry.
-     * 
-     * Currently, all Geometries must have a valid dimension (2 or 3) and a
-     * valid type. 2-dimensional Points must have Z=0.0, as well as non-measured
-     * Points must have m=0.0. Composed geometries must have all equal SRID,
-     * dimensionality and measures, as well as that they do not contain NULL or
-     * inconsistent subgeometries.
-     * 
-     * BinaryParser and WKTParser should only generate consistent geometries.
-     * BinaryWriter may produce invalid results on inconsistent geometries.
-     * 
-     * @return true if all checks are passed.
-     */
-    public boolean checkConsistency() {
-        return (dimension >= 2 && dimension <= 3) && (type >= 0 && type <= 7);
-    }
-
-    /**
-     * Splits the SRID=4711; part of a EWKT rep if present and sets the srid.
-     * 
-     * @return value without the SRID=4711; part
-     */
-    protected String initSRID(String value) {
-        value = value.trim();
-        if (value.startsWith("SRID=")) {
-            int index = value.indexOf(';', 5); // sridprefix length is 5
-            if (index == -1) {
-                throw new IllegalArgumentException(
-                        "Error parsing Geometry - SRID not delimited with ';' ");
-            } else {
-                this.srid = Integer.parseInt(value.substring(5, index));
-                return value.substring(index + 1).trim();
-            }
-        } else {
-            return value;
-        }
-    }
+       /* JDK 1.5 Serialization */
+       private static final long serialVersionUID = 0x100;
+
+       // OpenGIS Geometry types as defined in the OGC WKB Spec
+       // (May we replace this with an ENUM as soon as JDK 1.5
+       // has gained widespread usage?)
+
+       /** Fake type for linear ring */
+       public static final int LINEARRING = 0;
+       /**
+        * The OGIS geometry type number for points.
+        */
+       public static final int POINT = 1;
+
+       /**
+        * The OGIS geometry type number for lines.
+        */
+       public static final int LINESTRING = 2;
+
+       /**
+        * The OGIS geometry type number for polygons.
+        */
+       public static final int POLYGON = 3;
+
+       /**
+        * The OGIS geometry type number for aggregate points.
+        */
+       public static final int MULTIPOINT = 4;
+
+       /**
+        * The OGIS geometry type number for aggregate lines.
+        */
+       public static final int MULTILINESTRING = 5;
+
+       /**
+        * The OGIS geometry type number for aggregate polygons.
+        */
+       public static final int MULTIPOLYGON = 6;
+
+       /**
+        * The OGIS geometry type number for feature collections.
+        */
+       public static final int GEOMETRYCOLLECTION = 7;
+
+       public static final String[] ALLTYPES = new String[] {
+                       "", // internally used LinearRing does not have any text in front of
+                               // it
+                       "POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING",
+                       "MULTIPOLYGON", "GEOMETRYCOLLECTION" };
+
+       /**
+        * The Text representations of the geometry types
+        */
+       public static String getTypeString(int type) {
+               if (type >= 0 && type <= 7) {
+                       return ALLTYPES[type];
+               } else {
+                       throw new IllegalArgumentException("Unknown Geometry type" + type);
+               }
+       }
+
+       // Properties common to all geometries
+       /**
+        * The dimensionality of this feature (2,3)
+        */
+       public int dimension;
+
+       /**
+        * Do we have a measure (4th dimension)
+        */
+       public boolean haveMeasure = false;
+
+       /**
+        * The OGIS geometry type of this feature. this is final as it never
+        * changes, it is bound to the subclass of the instance.
+        */
+       public final int type;
+
+       /**
+        * Official UNKNOWN srid value
+        */
+       public final static int UNKNOWN_SRID = 0;
+
+       /**
+        * The spacial reference system id of this geometry, default is no srid
+        */
+       public int srid = UNKNOWN_SRID;
+
+       /**
+        * Parse a SRID value, anything <= 0 is unknown
+        */
+       public static int parseSRID(int srid) {
+               if (srid < 0) {
+                       /* TODO: raise a warning ? */
+                       srid = 0;
+               }
+               return srid;
+       }
+
+       /**
+        * Constructor for subclasses
+        * 
+        * @param type
+        *            has to be given by all subclasses.
+        */
+       protected Geometry(int type) {
+               this.type = type;
+       }
+
+       /**
+        * java.lang.Object hashCode implementation
+        */
+       public int hashCode() {
+               return dimension | (type * 4) | (srid * 32);
+       }
+
+       /**
+        * java.lang.Object equals implementation
+        */
+       public boolean equals(Object other) {
+               return (other != null) && (other instanceof Geometry)
+                               && equals((Geometry) other);
+       }
+
+       /**
+        * geometry specific equals implementation - only defined for non-null
+        * values
+        */
+       public boolean equals(Geometry other) {
+               return (other != null) && (this.dimension == other.dimension)
+                               && (this.type == other.type) && (this.srid == other.srid)
+                               && (this.haveMeasure == other.haveMeasure)
+                               && other.getClass().equals(this.getClass())
+                               && this.equalsintern(other);
+       }
+
+       /**
+        * Whether test coordinates for geometry - subclass specific code
+        * 
+        * Implementors can assume that dimensin, type, srid and haveMeasure are
+        * equal, other != null and other is the same subclass.
+        */
+       protected abstract boolean equalsintern(Geometry other);
+
+       /**
+        * Return the number of Points of the geometry
+        */
+       public abstract int numPoints();
+
+       /**
+        * Get the nth Point of the geometry
+        * 
+        * @param n
+        *            the index of the point, from 0 to numPoints()-1;
+        * @throws ArrayIndexOutOfBoundsException
+        *             in case of an emtpy geometry or bad index.
+        */
+       public abstract Point getPoint(int n);
+
+       /**
+        * Same as getPoint(0);
+        */
+       public abstract Point getFirstPoint();
+
+       /**
+        * Same as getPoint(numPoints()-1);
+        */
+       public abstract Point getLastPoint();
+
+       /**
+        * The OGIS geometry type number of this geometry.
+        */
+       public int getType() {
+               return this.type;
+       }
+
+       /**
+        * Return the Type as String
+        */
+       public String getTypeString() {
+               return getTypeString(this.type);
+       }
+
+       /** Returns whether we have a measure */
+       public boolean isMeasured() {
+               return haveMeasure;
+       }
+
+       /**
+        * Queries the number of geometric dimensions of this geometry. This does
+        * not include measures, as opposed to the server.
+        * 
+        * @return The dimensionality (eg, 2D or 3D) of this geometry.
+        */
+       public int getDimension() {
+               return this.dimension;
+       }
+
+       /**
+        * The OGIS geometry type number of this geometry.
+        */
+       public int getSrid() {
+               return this.srid;
+       }
+
+       /**
+        * Recursively sets the srid on this geometry and all contained
+        * subgeometries
+        */
+       public void setSrid(int srid) {
+               this.srid = srid;
+       }
+
+       public String toString() {
+               StringBuffer sb = new StringBuffer();
+               if (srid != UNKNOWN_SRID) {
+                       sb.append("SRID=");
+                       sb.append(srid);
+                       sb.append(';');
+               }
+               outerWKT(sb, true);
+               return sb.toString();
+       }
+
+       /**
+        * Render the WKT version of this Geometry (without SRID) into the given
+        * StringBuffer.
+        */
+       public void outerWKT(StringBuffer sb, boolean putM) {
+               sb.append(getTypeString());
+               if (putM && haveMeasure && dimension == 2) {
+                       sb.append('M');
+               }
+               mediumWKT(sb);
+       }
+
+       public final void outerWKT(StringBuffer sb) {
+               outerWKT(sb, true);
+       }
+
+       /**
+        * Render the WKT without the type name, but including the brackets into the
+        * StringBuffer
+        */
+       protected void mediumWKT(StringBuffer sb) {
+               sb.append('(');
+               innerWKT(sb);
+               sb.append(')');
+       }
+
+       /**
+        * Render the "inner" part of the WKT (inside the brackets) into the
+        * StringBuffer.
+        */
+       protected abstract void innerWKT(StringBuffer SB);
+
+       /**
+        * backwards compatibility method
+        */
+       public String getValue() {
+               StringBuffer sb = new StringBuffer();
+               mediumWKT(sb);
+               return sb.toString();
+       }
+
+       /**
+        * Do some internal consistency checks on the geometry.
+        * 
+        * Currently, all Geometries must have a valid dimension (2 or 3) and a
+        * valid type. 2-dimensional Points must have Z=0.0, as well as non-measured
+        * Points must have m=0.0. Composed geometries must have all equal SRID,
+        * dimensionality and measures, as well as that they do not contain NULL or
+        * inconsistent subgeometries.
+        * 
+        * BinaryParser and WKTParser should only generate consistent geometries.
+        * BinaryWriter may produce invalid results on inconsistent geometries.
+        * 
+        * @return true if all checks are passed.
+        */
+       public boolean checkConsistency() {
+               return (dimension >= 2 && dimension <= 3) && (type >= 0 && type <= 7);
+       }
+
+       /**
+        * Splits the SRID=4711; part of a EWKT rep if present and sets the srid.
+        * 
+        * @return value without the SRID=4711; part
+        */
+       protected String initSRID(String value) {
+               value = value.trim();
+               if (value.startsWith("SRID=")) {
+                       int index = value.indexOf(';', 5); // sridprefix length is 5
+                       if (index == -1) {
+                               throw new IllegalArgumentException(
+                                               "Error parsing Geometry - SRID not delimited with ';' ");
+                       } else {
+                               this.srid = Integer.parseInt(value.substring(5, index));
+                               return value.substring(index + 1).trim();
+                       }
+               } else {
+                       return value;
+               }
+       }
 }
index 21d53839efb24c465119ed92eee0e04ca5080a93..2e0f817a28605e3b82ac661fda9bd73ae402d0f9 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Properties;
 
 /** Corresponds to the appropriate PostGIS that carried this source */
 public class Version {
-    /** We read our version information from this ressource... */
+    /** We read our version information from this resource... */
     private static final String RESSOURCENAME = "org/postgis/version.properties";
 
     /** The major version */
index 255e1a9b445e7c42b16a5fdabfdc21961dfd2586..a3ba524c737120f6aaf1d28a30ef9b4a3b04ad43 100644 (file)
@@ -138,7 +138,7 @@ public class BinaryParser {
 
         Geometry result = result1;
 
-        if (srid != Geometry.UNKONWN_SRID) {
+        if (srid != Geometry.UNKNOWN_SRID) {
             result.setSrid(srid);
         }
         return result;
index 73c8979652349fad6bf1ad8ac9b93a835998843f..3125bb3c2b3156a2b59049ac5c462f44e0f323e9 100644 (file)
@@ -25,6 +25,7 @@ package org.postgis.java2d;
 
 import java.awt.geom.GeneralPath;
 
+import org.postgis.Geometry;
 import org.postgis.binary.ByteGetter;
 import org.postgis.binary.ValueGetter;
 import org.postgis.binary.ByteGetter.BinaryByteGetter;
diff --git a/java/jdbc/src/org/postgis/version.properties b/java/jdbc/src/org/postgis/version.properties
new file mode 100644 (file)
index 0000000..3528898
--- /dev/null
@@ -0,0 +1,3 @@
+REL_MAJOR_VERSION=2
+REL_MINOR_VERSION=0
+REL_MICRO_VERSION=0
\ No newline at end of file
index bce33ddfb9f7e6e177e403d86c918190516b0b96..d824d9fd33ad2d17a2b7f56a11bd003f0bc46485 100644 (file)
@@ -3,6 +3,10 @@ $Id$
 
 - even more Testing, especialy against different postgis, 
   pgjdbc and postgresql releases.
+  
+- Use JUnit for testing (maven)
+
+- Unify the build of app java projects -> maven
 
 - Handling of length() - esp. with modifying the geometries
 
@@ -22,5 +26,3 @@ $Id$
 
 - Rework the BinaryParser/BinaryWriter to work on SQLInput/SQLOutput 
   instances, as well as reworking ValueGetter/ValueSetter to implment those interfaces.
-
-- Unify the build of app java projects