@Test public void testSPIRegistration() throws Exception { Connection connection = new TestConnection(); Connection wrapper = new WrapperConnection(connection); GenericUnWrapper.CONNECTION_METHODS.put( WrapperConnection.class, WrapperConnection.class.getMethod("getUnderlyingConnection", null)); UnWrapper uw = DataSourceFinder.getUnWrapper(wrapper); assertNotNull("registed and canUnwrap", uw); if (uw instanceof GenericUnWrapper) { assertSame("Generic unwrapper is working", connection, uw.unwrap(wrapper)); } } }
@Test public void testUnwrapConnection() throws SQLException, NoSuchMethodException, SecurityException { Connection connection = new TestConnection(); Connection wrapper = new WrapperConnection(connection); assertTrue(wrapper.isWrapperFor(Connection.class)); Connection unwrap = wrapper.unwrap(Connection.class); assertSame(connection, unwrap); UnWrapper unwrapper = new GenericUnWrapper(); assertFalse(unwrapper.canUnwrap(wrapper)); try { assertNull(unwrapper.unwrap(wrapper)); fail("Cannot unwrap yet"); } catch (Exception expected) { } GenericUnWrapper.CONNECTION_METHODS.put( WrapperConnection.class, WrapperConnection.class.getMethod("getUnderlyingConnection", null)); assertTrue(unwrapper.canUnwrap(wrapper)); assertSame(connection, unwrapper.unwrap(wrapper)); }
testCon = unwrapper.unwrap(testCon); if (testCon instanceof OracleConnection) { return (OracleConnection) testCon;
assertNotNull(uw); assertTrue(uw.canUnwrap(conn)); Connection unwrapped = uw.unwrap(conn); assertNotNull(unwrapped); assertTrue(unwrapped instanceof org.h2.jdbc.JdbcConnection); assertNotNull(uw); assertTrue(uw.canUnwrap(st)); Statement uwst = uw.unwrap(st); assertNotNull(uwst); assertTrue(uwst instanceof org.h2.jdbc.JdbcStatement); assertNotNull(uw); assertTrue(uw.canUnwrap(ps)); PreparedStatement uwps = (PreparedStatement) uw.unwrap(ps); assertNotNull(uwps); assertTrue(uwps instanceof org.h2.jdbc.JdbcPreparedStatement);
public OracleFeatureWriter(FeatureReader <SimpleFeatureType, SimpleFeature> fReader, QueryData queryData ) throws IOException { super(fReader, queryData); Connection conn = queryData.getConnection(); if(!(conn instanceof OracleConnection)) { UnWrapper uw = DataSourceFinder.getUnWrapper(conn); if(uw != null) conn = uw.unwrap(conn); } OracleConnection oracleConnection = (OracleConnection) conn; this.converter = new GeometryConverter(oracleConnection); }
/** * @see org.geotools.data.jdbc.fidmapper.FIDMapper#createID(java.sql.Connection, org.geotools.feature.Feature, Statement) */ public String createID(Connection conn, SimpleFeature feature, Statement statement) throws IOException { try { if(!(statement instanceof PGStatement)) { UnWrapper uw = DataSourceFinder.getUnWrapper(statement); if(uw != null) statement = uw.unwrap(statement); } PGStatement pgStatement = (PGStatement) statement; return String.valueOf(pgStatement.getLastOID()); } catch (SQLException e) { throw new DataSourceException("Problems occurred while getting last generate oid from Postgresql statement", e); } catch (ClassCastException e) { throw new DataSourceException("Statement is not a PGStatement. OIDFidMapper can be used only with Postgres!", e); } }
Object struct = results.getObject(1); UnWrapper unwrapper = DataSourceFinder.getUnWrapper(conn); OracleConnection oraConn = (OracleConnection) unwrapper.unwrap(conn); GeometryConverter converter = new GeometryConverter(oraConn, new GeometryFactory()); geom = converter.asGeometry( (STRUCT) struct );
UnWrapper uw = DataSourceFinder.getUnWrapper(conn); if(uw != null) conn = uw.unwrap(conn);