]> granicus.if.org Git - postgis/commitdiff
Removed use of jdk1.4 only features to allow jdbc2 to be
authorMarkus Schaber <markus@schabi.de>
Tue, 8 Feb 2005 14:53:29 +0000 (14:53 +0000)
committerMarkus Schaber <markus@schabi.de>
Tue, 8 Feb 2005 14:53:29 +0000 (14:53 +0000)
build with older jdk releases (tested with 1.3)

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

jdbc2/src/examples/TestAutoregister.java
jdbc2/src/examples/TestBoxes.java
jdbc2/src/examples/TestParser.java
jdbc2/src/org/postgis/PGboxbase.java
jdbc2/src/org/postgis/PGgeometry.java
jdbc2/src/org/postgis/Point.java

index 42dccc92a9168a43a9581a9c619c432044785118..e48702c885624623e6ee81163eb2a8f7d7b4e171 100644 (file)
@@ -59,11 +59,11 @@ public class TestAutoregister {
             System.err.println("Usage: java examples/TestParser dburl user pass");
             System.exit(1);
             // Signal the compiler that code flow ends here.
-            throw new AssertionError();
+            return;
         }
 
         System.out.println("Driver version: " + Driver.getVersion());
-        int major = Integer.parseInt(Driver.getVersion().trim().split(" ")[1].split("\\.")[0]);
+        int major = Integer.parseInt(PGgeometry.splitAtFirst(PGgeometry.splitAtFirst(Driver.getVersion().trim(),' ')[1],'.')[0]);
         if (major < 8) {
             System.out.println("Your pgdjbc " + major
                     + ".X is too old, it does not support autoregistration!");
index 7893643e5f5536e2532e642cef6e72c7758fe8ab..220079c4b3e4497de7b6f121197c4f9fb8930068 100644 (file)
@@ -29,6 +29,7 @@ package examples;
 import org.postgis.PGbox2d;
 import org.postgis.PGbox3d;
 import org.postgresql.util.PGobject;
+import org.postgresql.util.PGtokenizer;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -157,16 +158,17 @@ public class TestBoxes {
 
     /** Our apps entry point */
     public static void main(String[] args) throws SQLException, ClassNotFoundException {
-        String[] dburls;
+        PGtokenizer dburls;
         String dbuser = null;
         String dbpass = null;
 
         if (args.length == 1 && args[0].equalsIgnoreCase("offline")) {
             System.out.println("Performing only offline tests");
-            dburls = new String[0];
+            dburls = new PGtokenizer("", ';');
         } else if (args.length == 3) {
             System.out.println("Performing offline and online tests");
-            dburls = args[0].split(";");
+
+            dburls = new PGtokenizer(args[0], ';');
             dbuser = args[1];
             dbpass = args[2];
         } else {
@@ -178,14 +180,14 @@ public class TestBoxes {
             System.err.println("tablename is 'jdbc_test' by default.");
             System.exit(1);
             // Signal the compiler that code flow ends here.
-            throw new AssertionError();
+            return;
         }
 
         Connection[] conns;
-        conns = new Connection[dburls.length];
-        for (int i = 0; i < dburls.length; i++) {
-            System.out.println("Creating JDBC connection to " + dburls[i]);
-            conns[i] = connect(dburls[i], dbuser, dbpass);
+        conns = new Connection[dburls.getSize()];
+        for (int i = 0; i < dburls.getSize(); i++) {
+            System.out.println("Creating JDBC connection to " + dburls.getToken(i));
+            conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
         }
 
         System.out.println("Performing tests...");
index 3f1bab1084eb35efba44c48c597b866311144154..8cc87adfe73b3974a78d6191c811f8d876b06c8d 100644 (file)
@@ -28,6 +28,7 @@ package examples;
 
 import org.postgis.Geometry;
 import org.postgis.PGgeometry;
+import org.postgresql.util.PGtokenizer;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -159,16 +160,17 @@ public class TestParser {
 
     /** Our apps entry point */
     public static void main(String[] args) throws SQLException, ClassNotFoundException {
-        String[] dburls;
+        PGtokenizer dburls;
         String dbuser = null;
         String dbpass = null;
 
         if (args.length == 1 && args[0].equalsIgnoreCase("offline")) {
             System.out.println("Performing only offline tests");
-            dburls = new String[0];
+            dburls = new PGtokenizer("",';');
         } else if (args.length == 3) {
             System.out.println("Performing offline and online tests");
-            dburls = args[0].split(";");
+            dburls = new PGtokenizer(args[0],';');
+            
             dbuser = args[1];
             dbpass = args[2];
         } else {
@@ -180,14 +182,14 @@ public class TestParser {
             System.err.println("tablename is 'jdbc_test' by default.");
             System.exit(1);
             // Signal the compiler that code flow ends here.
-            throw new AssertionError();
+            return;
         }
 
         Connection[] conns;
-        conns = new Connection[dburls.length];
-        for (int i = 0; i < dburls.length; i++) {
-            System.out.println("Creating JDBC connection to " + dburls[i]);
-            conns[i] = connect(dburls[i], dbuser, dbpass);
+        conns = new Connection[dburls.getSize()];
+        for (int i = 0; i < dburls.getSize(); i++) {
+            System.out.println("Creating JDBC connection to " + dburls.getToken(i));
+            conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
         }
 
         System.out.println("Performing tests...");
index 0c2c8a6ff004b7338f06e939dfd9fca958bb07ce..89d054d149b96b610c148740a8def8ea519340cd 100644 (file)
@@ -82,7 +82,7 @@ public abstract class PGboxbase extends PGobject {
         int srid = -1;
         value = value.trim();
         if (value.startsWith("SRID=")) {
-            String[] temp = value.split(";", 2);
+            String[] temp = PGgeometry.splitAtFirst(value,';');
             value = temp[1].trim();
             srid = Integer.parseInt(temp[0].substring(5));
         }
index f1120a9c06bad81dc469ab4e5b7323ae1c5040d0..8ad3dace7668d300875845640399ca279ed89835 100644 (file)
@@ -28,7 +28,6 @@ package org.postgis;
 
 import org.postgis.binary.BinaryParser;
 import org.postgresql.util.PGobject;
-import org.postgresql.util.PGtokenizer;
 
 import java.sql.SQLException;
 
@@ -68,12 +67,12 @@ public class PGgeometry extends PGobject {
         value = value.trim();
 
         int srid = -1;
+
         if (value.startsWith("SRID")) {
             //break up geometry into srid and wkt
-            PGtokenizer t = new PGtokenizer(value, ';');
-            value = t.getToken(1).trim();
-
-            srid = Integer.parseInt(t.getToken(0).split("=")[1]);
+            String[] parts = PGgeometry.splitAtFirst(value, ';');
+            value = parts[1];
+            srid = Integer.parseInt(PGgeometry.splitAtFirst(parts[0], '=')[1]);
         }
 
         Geometry result;
@@ -130,4 +129,23 @@ public class PGgeometry extends PGobject {
         return obj;
     }
 
+    /**
+     * Splits a String at the first occurrence of border charachter.
+     * 
+     * Poor man's String.split() replacement, as String.split() was invented at
+     * jdk1.4, and the Debian PostGIS Maintainer had problems building the woody
+     * backport of his package using DFSG-free compilers. In all the cases we
+     * used split() in the org.postgis package, we only needed to split at the
+     * first occurence, and thus this code could even be faster.
+     */
+    public static String[] splitAtFirst(String whole, char border) {
+        int index = whole.indexOf(border);
+        if (index == -1) {
+            return new String[]{whole};
+        } else {
+            return new String[]{
+                whole.substring(0, index),
+                whole.substring(index + 1)};
+        }
+    }
 }
\ No newline at end of file
index f47cbc2db5a2ce4666e4ecad0b5163e90f71cad9..152bb9155da4dd4330f31dea269bd97216ba4305 100644 (file)
@@ -226,7 +226,7 @@ public class Point extends Geometry {
             tz = this.z - other.z;
             return Math.sqrt(tx * tx + ty * ty + tz * tz);
         default :
-            throw new AssertionError("Illegal dimension of Point" + this.dimension);
+            throw new IllegalArgumentException("Illegal dimension of Point" + this.dimension);
         }
     }
 }
\ No newline at end of file