/** * Uses the current {@link JDBCDataStore} facilities to grab a connection, subclasses can * override to use other methods * * @param ds * @throws IOException */ protected Connection getDatabaseConnection(DataStore ds) throws IOException { if (ds instanceof JDBCDataStore) { return ((JDBCDataStore) ds).getConnection(Transaction.AUTO_COMMIT); } else { return null; } }
/** Gets a database connection for the specified feature store. */ protected final Connection getConnection(JDBCState state) throws IOException { return getConnection(state.getTransaction()); }
/** * Creates a new database index * * @param index * @throws IOException */ public void dropIndex(String typeName, String indexName) throws IOException { SimpleFeatureType schema = getSchema(typeName); Connection cx = null; try { cx = getConnection(Transaction.AUTO_COMMIT); dialect.dropIndex(cx, schema, databaseSchema, indexName); } catch (SQLException e) { throw new IOException("Failed to create index", e); } finally { closeSafe(cx); } }
/** * Lists all indexes associated to the given feature type * * @param typeName Name of the type for which indexes are searched. It's mandatory * @return */ public List<Index> getIndexes(String typeName) throws IOException { // just to ensure we have the type name specified getSchema(typeName); Connection cx = null; try { cx = getConnection(Transaction.AUTO_COMMIT); return dialect.getIndexes(cx, databaseSchema, typeName); } catch (SQLException e) { throw new IOException("Failed to create index", e); } finally { closeSafe(cx); } }
/** * Creates a new database index * * @param index * @throws IOException */ public void createIndex(Index index) throws IOException { SimpleFeatureType schema = getSchema(index.typeName); Connection cx = null; try { cx = getConnection(Transaction.AUTO_COMMIT); dialect.createIndex(cx, schema, databaseSchema, index); } catch (SQLException e) { throw new IOException("Failed to create index", e); } finally { closeSafe(cx); } }
Connection cx = dataStore.getConnection(Transaction.AUTO_COMMIT); try { dialect.unwrapConnection(cx);
@Override protected boolean handleVisitor(Query query, FeatureVisitor visitor) throws IOException { // special case for nearest visit, it's the sum of two other visits if (visitor instanceof NearestVisitor) { return handleNearestVisitor(query, visitor); } else { // grab connection using the current transaction Connection cx = getDataStore().getConnection(getState()); try { Object result = getDataStore().getAggregateValue(visitor, getSchema(), query, cx); return result != null; } finally { // release the connection - behaviour depends on Transaction.AUTO_COMMIT getDataStore().releaseConnection(cx, getState()); } } }
Connection cx = getDataStore().getConnection(getState().getTransaction());
Connection cx = getDataStore().getConnection(getState().getTransaction());
Transaction tx = getState().getTransaction(); try { cx = getDataStore().getConnection(tx);
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()); } } }
cx = getDataStore().getConnection(tx);
/** * Gets a database connection for the specified feature store. */ protected final Connection getConnection(JDBCState state) throws IOException { return getConnection(state.getTransaction()); }
Connection cx = getDataStore().getConnection(getState());
Connection cx = dataStore.getConnection(getState()); try { DefaultQuery q = new DefaultQuery(query);
Connection cx = getDataStore().getConnection(getState());
Connection cx = dataStore.getConnection(getState()); try { DefaultQuery q = new DefaultQuery(query);
Connection cx = getDataStore().getConnection(state);
@After public void resetCollectionLayer() throws IOException, SQLException { String s1 = "DELETE from \"collection_layer\""; String s2 = "INSERT into \"collection_layer\"\n" + "(\"cid\", \"workspace\", \"layer\", \"separateBands\", \"bands\", \"browseBands\", \"heterogeneousCRS\", \"mosaicCRS\")\n" + "VALUES(17, 'gs', 'sentinel2', true, 'B01,B02,B03,B04,B05,B06,B07,B08,B09,B10,B11,B12', 'B04,B03,B02', true, 'EPSG:4326')"; try (Connection conn = h2.getConnection(Transaction.AUTO_COMMIT); Statement st = conn.createStatement()) { st.execute(s1); st.execute(s2); } }
@Override protected boolean handleVisitor(Query query, FeatureVisitor visitor) throws IOException { // grab connection using the current transaction Connection cx = getDataStore().getConnection(getState()); try { Object result = getDataStore().getAggregateValue(visitor, getSchema(), query, cx); return result != null; } finally { // release the connection - behaviour depends on Transaction.AUTO_COMMIT getDataStore().releaseConnection(cx, getState()); } }