/** * Creates the new feature store. * * @param entry The datastore entry. * @param query The defining query. */ @SuppressWarnings("unchecked") public JDBCFeatureStore(ContentEntry entry, Query query) throws IOException { super(entry, query); delegate = new JDBCFeatureSource(entry, query) { @Override public void setTransaction(Transaction transaction) { super.setTransaction(transaction); // keep this feature store in sync JDBCFeatureStore.this.setTransaction(transaction); } }; Set<Hints.Key> jdbcHints = new HashSet<Hints.Key>(); jdbcHints.addAll((Set<Hints.Key>) (Set<?>) delegate.getSupportedHints()); getDataStore().getSQLDialect().addSupportedHints(jdbcHints); hints = Collections.unmodifiableSet(jdbcHints); }
private static FilterCapabilities getFilterCapabilities(FeatureSource mappedSource) throws IllegalArgumentException { FilterCapabilities capabilities = null; if (mappedSource instanceof JDBCFeatureSource) { capabilities = ((JDBCFeatureSource) mappedSource).getDataStore().getFilterCapabilities(); } else if (mappedSource instanceof JDBCFeatureStore) { capabilities = ((JDBCFeatureStore) mappedSource).getDataStore().getFilterCapabilities(); } else { throw new IllegalArgumentException( "Joining queries are only supported on JDBC data stores"); } return capabilities; } }
Connection cx = getDataStore().getConnection(getState()); Query queryNone = new Query(query); queryNone.setFilter(Filter.EXCLUDE); if (getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect) { PreparedStatement ps = getDataStore().selectSQLPS(getSchema(), queryNone, cx); return new JDBCInsertFeatureWriter(ps, cx, delegate, query); } else { String sql = getDataStore().selectSQL(getSchema(), queryNone); getDataStore().getLogger().fine(sql); if (getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect) { PreparedStatement ps = getDataStore().selectSQLPS(getSchema(), preQuery, cx); if ((flags | WRITER_UPDATE) == WRITER_UPDATE) { writer = new JDBCUpdateFeatureWriter(ps, cx, delegate, query); String sql = getDataStore().selectSQL(getSchema(), preQuery); getDataStore().getLogger().fine(sql); getDataStore().closeSafe(cx);
cx = getDataStore().getConnection(tx); getDataStore() .ensureAuthorization(featureType, preFilter, getTransaction(), cx); } catch (SQLException e) { getDataStore().delete(featureType, preFilter, cx); if (state.hasListener()) { getDataStore().closeSafe(cx);
Transaction tx = getState().getTransaction(); try { cx = getDataStore().getConnection(tx); getDataStore() .ensureAuthorization(featureType, preFilter, getTransaction(), cx); } catch (SQLException e) { getDataStore().update(getSchema(), innerTypes, values, preFilter, cx); } catch (SQLException e) { throw (IOException) (new IOException(e.getMessage()).initCause(e)); getDataStore().closeSafe(cx);
public void testAcceptsVisitor() throws Exception { class TotalVisitor implements FeatureVisitor { int total = 0; public void visit(Feature feature) { total++; } } TotalVisitor visitor = new TotalVisitor(); // initial test on Transaction.AUTO_COMMIT int count = featureSource.getCount(Query.ALL); featureSource.accepts(Query.ALL, visitor, null); assertEquals(count, visitor.total); visitor.total = 0; // reset // test on a transaction JDBCFeatureStore ft1 = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1")); try (Transaction transaction = new DefaultTransaction()) { ft1.setTransaction(transaction); Connection connection = ft1.getDataStore().getConnection(ft1.getState()); assertFalse("connection established", connection.isClosed()); ft1.accepts(Query.ALL, visitor, null); assertFalse("connection maintained", connection.isClosed()); } } }
private static FilterCapabilities getFilterCapabilities(FeatureSource mappedSource) throws IllegalArgumentException { FilterCapabilities capabilities = null; if (mappedSource instanceof JDBCFeatureSource) { capabilities = ((JDBCFeatureSource) mappedSource).getDataStore() .getFilterCapabilities(); } else if (mappedSource instanceof JDBCFeatureStore) { capabilities = ((JDBCFeatureStore) mappedSource).getDataStore().getFilterCapabilities(); } else { throw new IllegalArgumentException( "Joining queries are only supported on JDBC data stores"); } return capabilities; }
/** * Creates the new feature store. * @param entry The datastore entry. * @param query The defining query. */ public JDBCFeatureStore(ContentEntry entry,Query query) throws IOException { super(entry,query); delegate = new JDBCFeatureSource( entry, query ) { @Override public void setTransaction(Transaction transaction) { super.setTransaction(transaction); //keep this feature store in sync JDBCFeatureStore.this.setTransaction(transaction); } }; Set<Hints.Key> jdbcHints = new HashSet<Hints.Key>(); jdbcHints.addAll(delegate.getSupportedHints()); getDataStore().getSQLDialect().addSupportedHints(jdbcHints); hints=Collections.unmodifiableSet(jdbcHints); }
@Override public void removeFeatures(Filter filter) throws IOException { Filter[] splitted = delegate.splitFilter(filter); Filter preFilter = splitted[0]; Filter postFilter = splitted[1]; if(postFilter != null && !Filter.INCLUDE.equals(postFilter)) { // we don't have a fast way to perform this delete, let's do it the // feature by feature way then super.removeFeatures(filter); } else { // let's grab the connection Connection cx = getDataStore().getConnection(getState()); // we want to support a "batch" delete, but we need to be weary of locks SimpleFeatureType featureType = getSchema(); try { getDataStore().ensureAuthorization(featureType, preFilter, getTransaction(), cx); } catch (SQLException e) { throw (IOException) new IOException().initCause( e ); } getDataStore().delete(featureType, preFilter, cx); } } }
} else { Connection cx = getDataStore().getConnection(getState()); getDataStore().ensureAuthorization(featureType, preFilter, getTransaction(), cx); getDataStore().update(getSchema(), innerTypes, values, preFilter, cx);
Connection cx = getDataStore().getConnection(getState()); DefaultQuery queryNone = new DefaultQuery(query); queryNone.setFilter(Filter.EXCLUDE); if ( getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect ) { PreparedStatement ps = getDataStore().selectSQLPS(getSchema(), queryNone, cx); return new JDBCInsertFeatureWriter( ps, cx, delegate, query.getHints() ); String sql = getDataStore().selectSQL(getSchema(), queryNone); getDataStore().getLogger().fine(sql); if(getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect) { PreparedStatement ps = getDataStore().selectSQLPS(getSchema(), preQuery, cx); if ( (flags | WRITER_UPDATE) == WRITER_UPDATE ) { writer = new JDBCUpdateFeatureWriter(ps, cx, delegate, query.getHints() ); String sql = getDataStore().selectSQL(getSchema(), preQuery); getDataStore().getLogger().fine(sql); getDataStore().closeSafe(cx);
Connection cx = getDataStore().getConnection(getState()); DefaultQuery queryNone = new DefaultQuery(query); queryNone.setFilter(Filter.EXCLUDE); if ( getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect ) { PreparedStatement ps = getDataStore().selectSQLPS(getSchema(), queryNone, cx); return new JDBCInsertFeatureWriter( ps, cx, delegate, query.getHints() ); String sql = getDataStore().selectSQL(getSchema(), queryNone); getDataStore().getLogger().fine(sql); if(getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect) { PreparedStatement ps = getDataStore().selectSQLPS(getSchema(), preQuery, cx); if ( (flags | WRITER_UPDATE) == WRITER_UPDATE ) { writer = new JDBCUpdateFeatureWriter(ps, cx, delegate, query.getHints() ); String sql = getDataStore().selectSQL(getSchema(), preQuery); getDataStore().getLogger().fine(sql); getDataStore().closeSafe(cx);
cx = getDataStore().getConnection(tx); getDataStore().ensureAuthorization(featureType, preFilter, getTransaction(), cx); getDataStore().delete(featureType, preFilter, cx); if( state.hasListener() ){ getDataStore().closeSafe(cx);
Transaction tx = getState().getTransaction(); try { cx = getDataStore().getConnection(tx); getDataStore().ensureAuthorization(featureType, preFilter, getTransaction(), cx); getDataStore().update(getSchema(), innerTypes, values, preFilter, cx); } catch(SQLException e) { throw (IOException) (new IOException(e.getMessage()).initCause(e)); getDataStore().closeSafe(cx);