/** * Creates a new {@link InsertRowManager} instance. * * @param fs * feature store, must not be <code>null</code> * @param conn * connection, must not be <code>null</code> * @param idGenMode * feature id generation mode, must not be <code>null</code> */ public InsertRowManager( SQLFeatureStore fs, Connection conn, IDGenMode idGenMode ) { this.fs = fs; this.dialect = fs.getDialect(); this.conn = conn; this.idGenMode = idGenMode; this.tableDeps = fs.getSchema().getKeyDependencies(); }
@Override public Envelope calcEnvelope( QName ftName ) throws FeatureStoreException { Envelope env = null; Connection conn = null; try { conn = getConnection(); env = calcEnvelope( ftName, conn ); } catch ( SQLException e ) { throw new FeatureStoreException( e.getMessage() ); } finally { release( null, null, conn ); } return env; }
@Override public Feature buildFeature( ResultSet rs ) throws SQLException { Feature feature = null; try { String gmlId = rs.getString( 1 ); if ( fs.getCache() != null ) { feature = (Feature) fs.getCache().get( gmlId ); } if ( feature == null ) { LOG.debug( "Recreating object '" + gmlId + "' from db (BLOB/hybrid mode)." ); feature = (Feature) codec.decode( rs.getBinaryStream( 2 ), fs.getNamespaceContext(), fs.getSchema(), crs, fs.getResolver() ); if ( fs.getCache() != null ) { fs.getCache().add( feature ); } } else { LOG.debug( "Cache hit." ); } fs.checkIfFeatureTypIsRequested( typeNames, feature.getType() ); } catch ( Exception e ) { String msg = "Cannot recreate feature from result set: " + e.getMessage(); throw new SQLException( msg, e ); } return feature; }
@Override public GMLObject getObjectById( String id ) throws FeatureStoreException { GMLObject geomOrFeature = null; if ( getCache() != null ) { geomOrFeature = getCache().get( id ); } if ( geomOrFeature == null ) { if ( getSchema().getBlobMapping() != null ) { geomOrFeature = getObjectByIdBlob( id, getSchema().getBlobMapping() ); } else { geomOrFeature = getObjectByIdRelational( id ); } } return geomOrFeature; }
if ( getSchema().getBlobMapping() != null ) { return queryHitsByOperatorFilterBlob( query, ftName, filter ); FeatureType ft = getSchema().getFeatureType( ftName ); FeatureTypeMapping ftMapping = getMapping( ftName ); if ( ftMapping == null ) { String msg = "Cannot perform query on feature type '" + ftName + "'. Feature type is not mapped."; conn = getConnection(); AbstractWhereBuilder wb = getWhereBuilder( ft, filter, query.getSortProperties(), conn ); hits = queryByOperatorFilter( query, ftName, filter ).count(); } else { StringBuilder sql = new StringBuilder( "SELECT " ); throw new FeatureStoreException( msg, e ); } finally { release( rs, stmt, conn );
conn = getConnection(); BlobMapping blobMapping = getSchema().getBlobMapping(); wb = getWhereBuilderBlob( bboxFilter, conn ); LOG.debug( "WHERE clause: " + wb.getWhere() ); stmt.setShort( i++, getSchema().getFtId( ftName ) ); if ( wb != null ) { for ( SQLArgument o : wb.getWhere().getArguments() ) { throw new FeatureStoreException( msg, e ); } finally { release( rs, stmt, conn );
if ( getSchema().getBlobMapping() != null ) { return queryByOperatorFilterBlob( query, ftName, filter ); ResultSet rs = null; FeatureType ft = getSchema().getFeatureType( ftName ); FeatureTypeMapping ftMapping = getMapping( ftName ); if ( ftMapping == null ) { String msg = "Cannot perform query on feature type '" + ftName + "'. Feature type is not mapped."; conn = getConnection(); wb = getWhereBuilder( ft, filter, query.getSortProperties(), conn ); String ftTableAlias = wb.getAliasManager().getRootTableAlias(); LOG.debug( "WHERE clause: " + wb.getWhere() ); List<String> columns = builder.getInitialSelectList(); BlobMapping blobMapping = getSchema().getBlobMapping(); release( rs, stmt, conn ); String msg = "Error performing query by operator filter: " + e.getMessage(); LOG.error( msg, e ); throw e; } catch ( Exception e ) { release( rs, stmt, conn ); String msg = "Error performing query by operator filter: " + e.getMessage(); LOG.error( msg, e );
sql.append( "=?" ); conn = getConnection(); stmt = conn.prepareStatement( sql.toString() ); stmt.setFetchSize( fetchSize ); LOG.debug( "Recreating object '" + id + "' from bytea." ); BlobCodec codec = blobMapping.getCodec(); geomOrFeature = codec.decode( rs.getBinaryStream( 1 ), getNamespaceContext(), getSchema(), blobMapping.getCRS(), resolver ); if ( getCache() != null ) { getCache().add( geomOrFeature ); throw new FeatureStoreException( msg, e ); } finally { release( rs, stmt, conn );
try { for ( String fid : filter.getMatchingIds() ) { IdAnalysis analysis = getSchema().analyzeId( fid ); FeatureType ft = analysis.getFeatureType(); List<IdAnalysis> idKernels = ftNameToIdAnalysis.get( ft.getName() ); FeatureType ft = getSchema().getFeatureType( ftName ); checkIfFeatureTypIsRequested( typeNames, ft ); FeatureTypeMapping ftMapping = getSchema().getFtMapping( ftName ); FIDMapping fidMapping = ftMapping.getFidMapping(); List<IdAnalysis> idKernels = ftNameToIdAnalysis.get( ftName ); try { long begin = System.currentTimeMillis(); conn = getConnection(); result = new IteratorFeatureInputStream( new FeatureResultSetIterator( builder, rs, conn, stmt ) ); } catch ( Exception e ) { release( rs, stmt, conn ); String msg = "Error performing query by id filter (relational mode): " + e.getMessage(); LOG.error( msg, e );
if ( looseBBox != null ) { final OperatorFilter bboxFilter = new OperatorFilter( new BBOX( looseBBox ) ); blobWb = getWhereBuilderBlob( bboxFilter, conn ); conn = getConnection(); final short[] ftId = getQueriedFeatureTypeIds( queries ); final StringBuilder sql = new StringBuilder(); for ( int i = 0; i < ftId.length; i++ ) { result = new IteratorFeatureInputStream( new FeatureResultSetIterator( builder, rs, conn, stmt ) ); } catch ( Exception e ) { release( rs, stmt, conn ); String msg = "Error performing query: " + e.getMessage(); LOG.debug( msg );
MappedAppSchema getSchema() { return fs.getSchema(); }
@Override public FeatureInputStream query( Query query ) throws FeatureStoreException, FilterEvaluationException { if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) { String msg = "Join queries between multiple feature types are not by SQLFeatureStore (yet)."; throw new UnsupportedOperationException( msg ); } FeatureInputStream result = null; Filter filter = query.getFilter(); if ( query.getTypeNames().length == 1 && ( filter == null || filter instanceof OperatorFilter ) ) { QName ftName = query.getTypeNames()[0].getFeatureTypeName(); FeatureType ft = getSchema().getFeatureType( ftName ); if ( ft == null ) { String msg = "Feature store is not configured to serve feature type '" + ftName + "'."; throw new FeatureStoreException( msg ); } result = queryByOperatorFilter( query, ftName, (OperatorFilter) filter ); } else { // must be an id filter based query if ( query.getFilter() == null || !( query.getFilter() instanceof IdFilter ) ) { String msg = "Invalid query. If no type names are specified, it must contain an IdFilter."; throw new FilterEvaluationException( msg ); } result = queryByIdFilter( query.getTypeNames(), (IdFilter) filter, query.getSortProperties() ); } return result; }
@Override public int queryHits( Query query ) throws FeatureStoreException, FilterEvaluationException { if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) { String msg = "Join queries between multiple feature types are not supported by the SQLFeatureStore implementation (yet)."; throw new UnsupportedOperationException( msg ); } Filter filter = query.getFilter(); int hits = 0; if ( query.getTypeNames().length == 1 && ( filter == null || filter instanceof OperatorFilter ) ) { QName ftName = query.getTypeNames()[0].getFeatureTypeName(); FeatureType ft = getSchema().getFeatureType( ftName ); if ( ft == null ) { String msg = "Feature type '" + ftName + "' is not served by this feature store."; throw new FeatureStoreException( msg ); } hits = queryHitsByOperatorFilter( query, ftName, (OperatorFilter) filter ); } else { // must be an id filter based query if ( query.getFilter() == null || !( query.getFilter() instanceof IdFilter ) ) { String msg = "Invalid query. If no type names are specified, it must contain an IdFilter."; throw new FilterEvaluationException( msg ); } // should be no problem iterating over the features (id queries usually request only a few ids) hits = queryByIdFilter( query.getTypeNames(), (IdFilter) filter, query.getSortProperties() ).count(); } return hits; }
@Override public FeatureStoreTransaction acquireTransaction() throws FeatureStoreException { SQLFeatureStoreTransaction ta = null; try { final Connection conn = getConnection(); conn.setAutoCommit( false ); ta = new SQLFeatureStoreTransaction( this, conn, getSchema(), inspectors ); transaction.set( ta ); } catch ( SQLException e ) { throw new FeatureStoreException( "Unable to acquire JDBC connection for transaction: " + e.getMessage(), e ); } return ta; }
private byte[] encodeFeatureBlob( final Feature feature, ICRS crs ) throws FactoryConfigurationError, SQLException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { final BlobCodec codec = fs.getSchema().getBlobMapping().getCodec(); codec.encode( feature, fs.getNamespaceContext(), bos, crs ); } catch ( Exception e ) { String msg = "Error encoding feature for BLOB: " + e.getMessage(); LOG.error( msg ); LOG.trace( "Stack trace:", e ); throw new SQLException( msg, e ); } byte[] bytes = bos.toByteArray(); return bytes; }
private GMLObject getObjectByIdRelational( String id ) throws FeatureStoreException { GMLObject result = null; IdAnalysis idAnalysis = getSchema().analyzeId( id ); if ( !idAnalysis.isFid() ) { String msg = "Fetching of geometries by id (relational mode) is not implemented yet."; throw new UnsupportedOperationException( msg ); } FeatureInputStream rs = queryByIdFilterRelational( null, new IdFilter( id ), null ); try { Iterator<Feature> iter = rs.iterator(); if ( iter.hasNext() ) { result = iter.next(); } } finally { rs.close(); } return result; }
throws SQLException, FeatureStoreException { LOG.debug( "Inserting feature with id '" + feature.getId() + "' (BLOB)" ); if ( fs.getSchema().getFeatureType( feature.getName() ) == null ) { throw new FeatureStoreException( "Cannot insert feature '" + feature.getName() + "': feature type is not served by this feature store." ); stmt.setShort( 2, fs.getFtId( feature.getName() ) ); byte[] bytes = encodeFeatureBlob( feature, crs ); stmt.setBytes( 3, bytes );
if ( getSchema().getBlobMapping() != null && queries[0].getFilter() == null && queries[0].getSortProperties().length == 0 ) { wmsStyleQuery = true; return queryMultipleFts( queries, env );
ParticleConverter<?> converter = fs.getConverter( mapping ); if ( particle instanceof GenericXMLElement && fs.getSchema().getGeometryType( elName ) != null ) { particle = unwrapCustomGeometry( (GenericXMLElement) particle );
ResultSet rs = null; try { conn = getConnection(); result = new IteratorFeatureInputStream( new FeatureResultSetIterator( builder, rs, conn, stmt ) ); } catch ( Exception e ) { release( rs, stmt, conn ); String msg = "Error performing id query: " + e.getMessage(); LOG.debug( msg, e );