| | |
| | | |
| | | 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; |
| | |
| | | * |
| | | * @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(); |
| | | } |
| | | } |
| | |
| | | * @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); |
| | |
| | | * @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); |
| | |
| | | |
| | | /** |
| | | * 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); |
| | | } |
| | | } |
| | |
| | | * 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); |
| | |
| | | * @return the drivers major version number |
| | | */ |
| | | |
| | | public int getMajorVersion() |
| | | { |
| | | public int getMajorVersion() { |
| | | return super.getMajorVersion(); |
| | | } |
| | | |
| | |
| | | * |
| | | * @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."); |
| | | } |
| | | } |