forked from geodmms/xdgnjobs

Dennis Kao
2014-01-15 94ae08701bbd7585a0b7e5a92d1975965a503c03
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGisWrapper.java
@@ -27,7 +27,9 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;
import org.postgresql.Driver;
import org.postgresql.PGConnection;
@@ -45,26 +47,21 @@
 *
 * @author markus.schaber@logix-tt.com
 */
public class JtsGisWrapper extends Driver
{
public class JtsGisWrapper extends Driver {
    private static final String POSTGRES_PROTOCOL = "jdbc:postgresql:";
    private static final String POSTGIS_PROTOCOL = "jdbc:postgresql_JTS:";
    public static final String REVISION = "$Revision: 1977 $";
    public JtsGisWrapper()
    {
    public JtsGisWrapper() {
        super();
    }
    static
    {
        try
        {
    static {
        try {
            // Analogy to org.postgresql.Driver
            java.sql.DriverManager.registerDriver(new JtsGisWrapper());
        } catch (SQLException e)
        {
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
@@ -80,8 +77,7 @@
     * @see java.sql.Driver#connect
     * @see org.postgresql.Driver
     */
    public java.sql.Connection connect(String url, Properties info) throws SQLException
    {
    public java.sql.Connection connect(String url, Properties info) throws SQLException {
        url = mangleURL(url);
        Connection result = super.connect(url, info);
        addGISTypes((PGConnection) result);
@@ -94,8 +90,7 @@
     * @param pgconn
     * @throws SQLException
     */
    public static void addGISTypes(PGConnection pgconn) throws SQLException
    {
    public static void addGISTypes(PGConnection pgconn) throws SQLException {
        pgconn.addDataType("geometry", JtsGeometry.class);
        pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
        pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
@@ -103,17 +98,15 @@
    /**
     * Mangles the PostGIS URL to return the original PostGreSQL URL
     *
     * @param url url
     * @return string
     * @throws java.sql.SQLException error
     */
    public static String mangleURL(String url) throws SQLException
    {
        if (url.startsWith(POSTGIS_PROTOCOL))
        {
    public static String mangleURL(String url) throws SQLException {
        if (url.startsWith(POSTGIS_PROTOCOL)) {
            return POSTGRES_PROTOCOL + url.substring(POSTGIS_PROTOCOL.length());
        } else
        {
        } else {
            throw new SQLException("Unknown protocol or subprotocol in url " + url);
        }
    }
@@ -130,13 +123,10 @@
     *                      it would *shrug*)
     * @see java.sql.Driver#acceptsURL
     */
    public boolean acceptsURL(String url) throws SQLException
    {
        try
        {
    public boolean acceptsURL(String url) throws SQLException {
        try {
            url = mangleURL(url);
        } catch (SQLException e)
        {
        } catch (SQLException e) {
            return false;
        }
        return super.acceptsURL(url);
@@ -148,8 +138,7 @@
     * @return the drivers major version number
     */
    public int getMajorVersion()
    {
    public int getMajorVersion() {
        return super.getMajorVersion();
    }
@@ -158,16 +147,18 @@
     *
     * @return the drivers minor version number
     */
    public int getMinorVersion()
    {
    public int getMinorVersion() {
        return super.getMinorVersion();
    }
    /**
     * Returns our own CVS version plus postgres Version
     */
    public static String getVersion()
    {
    public static String getVersion() {
        return "JtsGisWrapper " + REVISION + ", wrapping " + Driver.getVersion();
    }
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}