protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException { JDBCDataStore dataStore = getDataStore(); Filter[] split = splitFilter(query.getFilter()); Filter preFilter = split[0]; Filter postFilter = split[1]; || (query.getMaxFeatures() < Integer.MAX_VALUE && !canLimit()) || (query.getStartIndex() != null && query.getStartIndex() > 0 && !canOffset())) { getDataStore().getLogger().fine("Calculating bounds manually"); CRS.getHorizontalCRS(getSchema().getCoordinateReferenceSystem()); ReferencedEnvelope bounds = new ReferencedEnvelope(flatCRS); FeatureReader<SimpleFeatureType, SimpleFeature> i = getReader(q); try { if (i.hasNext()) { Connection cx = dataStore.getConnection(getState()); try { DefaultQuery q = new DefaultQuery(query); q.setFilter(preFilter); return dataStore.getBounds(getSchema(), q, cx); } finally { getDataStore().releaseConnection(cx, getState());
public boolean isValid(String fid) { PrimaryKey key = featureSource.getPrimaryKey(); try { featureSource.getDataStore().decodeFID(key, fid, true); return true; } catch (Exception e) { return false; } } }
@Override protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException { return delegate.getReaderInternal(query); }
@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()); } } }
public void close() throws IOException { FeatureReader r = reader; while (r instanceof DelegatingFeatureReader) { if (r instanceof JDBCFeatureReader) { break; } r = ((DelegatingFeatureReader) r).getDelegate(); } if (r instanceof JDBCFeatureReader) { JDBCFeatureReader jdbcReader = (JDBCFeatureReader) r; JDBCFeatureSource fs = jdbcReader.featureSource; Connection cx = jdbcReader.cx; try { reader.close(); } finally { fs.getDataStore().releaseConnection(cx, fs.getState()); } } } }
Filter[] split = splitFilter(query.getFilter()); Filter preFilter = split[0]; Filter postFilter = split[1]; buildQueryAndReturnFeatureTypes(getSchema(), query.getPropertyNames(), postFilter); SimpleFeatureType querySchema = types[0]; SimpleFeatureType returnedSchema = types[1]; Connection cx = getDataStore().getConnection(getState()); SQLDialect dialect = getDataStore().getSQLDialect(); if (getState().getTransaction() == Transaction.AUTO_COMMIT) { cx.setAutoCommit(dialect.isAutoCommitQuery()); PreparedStatement ps = getDataStore().selectSQLPS(querySchema, preQuery, cx); reader = new JDBCFeatureReader(ps, cx, this, querySchema, query); } else { String sql = getDataStore().selectSQL(querySchema, preQuery); getDataStore().getLogger().fine(sql); getDataStore().selectJoinSQLPS(querySchema, join, preQuery, cx); reader = new JDBCJoiningFeatureReader(ps, cx, this, querySchema, join, query); } else { String sql = getDataStore().selectJoinSQL(querySchema, join, preQuery); getDataStore().getLogger().fine(sql);
@Override public JDBCDataStore getDataStore() { return delegate.getDataStore(); }
Filter[] splitFilter(Filter original, FeatureSource source) { JDBCFeatureSource featureSource = null; if (source instanceof JDBCFeatureSource) { featureSource = (JDBCFeatureSource) source; } else { featureSource = ((JDBCFeatureStore) source).getFeatureSource(); } Filter[] split = new Filter[2]; if (original != null) { split = getDataStore().getSQLDialect().splitFilter(original, featureSource.getSchema()); } // handle three-valued logic differences by adding "is not null" checks in the filter, // the simplifying filter visitor will take care of them if they are redundant NullHandlingVisitor nhv = new NullHandlingVisitor(source.getSchema()); split[0] = (Filter) split[0].accept(nhv, null); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setFIDValidator(new PrimaryKeyFIDValidator(featureSource)); visitor.setFeatureType(getSchema()); split[0] = (Filter) split[0].accept(visitor, null); split[1] = (Filter) split[1].accept(visitor, null); return split; }
this.dataStore = featureSource.getDataStore(); this.featureType = featureType; this.tx = featureSource.getTransaction(); this.query = query; this.hints = query != null ? query.getHints() : null; if (ff == null) ff = featureSource.getDataStore().getFeatureFactory(); builder = new SimpleFeatureBuilder(featureType, ff);
/** * Consults the fid mapper for the feature source, if the null feature map reliable fids not * supported. */ @Override public boolean isReliableFIDSupported() { return !(source.getPrimaryKey() instanceof NullPrimaryKey); }
PrimaryKey pkey = getDataStore().getPrimaryKey(entry); VirtualTable virtualTable = getDataStore().getVirtualTables().get(entry.getTypeName()); tb.setNamespaceURI(getDataStore().getNamespaceURI()); JDBCState state = getState(); String databaseSchema = getDataStore().getDatabaseSchema(); Connection cx = getDataStore().getConnection(state); SQLDialect dialect = getDataStore().getSQLDialect(); columns = getColumnMetadata(cx, virtualTable, dialect, getDataStore()); } else { columns = getColumnMetadata(cx, databaseSchema, tableName, dialect); if (getDataStore().isAssociations()) { getDataStore().ensureAssociationTablesExist(cx); if (getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect) { st = getDataStore().selectRelationshipSQLPS(tableName, name, cx); relationships = ((PreparedStatement) st).executeQuery(); } else { String sql = getDataStore().selectRelationshipSQL(tableName, name); getDataStore().getLogger().fine(sql); getDataStore().closeSafe(relationships); getDataStore().closeSafe(st);
@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()); } }
AttributeDescriptor descriptor = getSchema().getDescriptor(attribute); if (descriptor == null) { return false; // optimization restricted to column evaulation FilterFactory ff = getDataStore().getFilterFactory(); Query qBelow = new Query(query); Filter lessFilter = ff.lessOrEqual(ff.property(attribute), ff.literal(targetValue)); qBelow.setFilter(ff.and(query.getFilter(), lessFilter)); MaxVisitor max = new MaxVisitor(attribute); handleVisitor(qBelow, max); Comparable maxBelow = (Comparable) max.getResult().getValue(); if (maxBelow != null && maxBelow.equals(targetValue)) { qAbove.setFilter(ff.and(query.getFilter(), aboveFilter)); MinVisitor min = new MinVisitor(attribute); handleVisitor(qAbove, min); Comparable minAbove = (Comparable) min.getResult().getValue(); nearest.setValue(maxBelow, minAbove);
/** * Creates a new instance of {@link JDBCFeatureStore}. * * @see ContentDataStore#createFeatureSource(ContentEntry) */ protected ContentFeatureSource createFeatureSource(ContentEntry entry) throws IOException { // grab the schema, it carries a flag telling us if the feature type is read only SimpleFeatureType schema = entry.getState(Transaction.AUTO_COMMIT).getFeatureType(); if (schema == null) { // if the schema still haven't been computed, force its computation so // that we can decide if the feature type is read only schema = new JDBCFeatureSource(entry, null).buildFeatureType(); entry.getState(Transaction.AUTO_COMMIT).setFeatureType(schema); } Object readOnlyMarker = schema.getUserData().get(JDBC_READ_ONLY); if (Boolean.TRUE.equals(readOnlyMarker)) { return new JDBCFeatureSource(entry, null); } return new JDBCFeatureStore(entry, null); }
@Override protected boolean canSort() { return delegate.canSort(); }
@Override protected boolean canOffset() { return delegate.canOffset(); }
@Override protected SimpleFeatureType buildFeatureType() throws IOException { return delegate.buildFeatureType(); }
@Override protected boolean canLimit() { return delegate.canLimit(); }
@Override protected boolean canFilter() { return delegate.canFilter(); }
@Override protected boolean canRetype() { return delegate.canRetype(); }