@Override public void rollback() throws FeatureStoreException { fs.releaseTransaction( this, null ); } }
@Override public int[] queryHits( Query[] queries ) throws FeatureStoreException, FilterEvaluationException { int[] hits = new int[queries.length]; for ( int i = 0; i < queries.length; i++ ) { hits[i] = queryHits( queries[i] ); } return hits; }
@Override public FeatureInputStream query( Query query ) throws FilterEvaluationException, FeatureStoreException { return storedFeatures.query( query ); }
void rebuildIndexes() throws UnknownCRSException { long begin = System.currentTimeMillis(); rebuildFeatureCollectionEnvelopes(); long elapsed = System.currentTimeMillis() - begin; LOG.debug( "Recalculating bounding boxes took {} [ms]", elapsed ); begin = System.currentTimeMillis(); rebuildRtrees(); elapsed = System.currentTimeMillis() - begin; LOG.debug( "Building spatial indexes took {} [ms]", elapsed ); begin = System.currentTimeMillis(); rebuildIdToObjectMap(); elapsed = System.currentTimeMillis() - begin; LOG.debug( "Building id lookup table took {} [ms]", elapsed ); }
private String getGeometryId( Geometry geometry, IDGenMode mode ) { String gid = geometry.getId(); switch ( mode ) { case GENERATE_NEW: { gid = "GEOMETRY_" + generateNewId(); break; } case REPLACE_DUPLICATE: { if ( gid == null || sf.getObjectById( gid ) != null ) { gid = "FEATURE_" + generateNewId(); } } case USE_EXISTING: { if ( gid == null ) { gid = "GEOMETRY_" + generateNewId(); } break; } } return gid; }
@Override public synchronized FeatureStoreTransaction acquireTransaction() throws FeatureStoreException { while ( this.activeTransaction != null ) { Thread holder = this.transactionHolder; // check if transaction holder variable has (just) been cleared or if the other thread // has been killed (avoid deadlocks) if ( holder == null || !holder.isAlive() ) { this.activeTransaction = null; this.transactionHolder = null; break; } try { // wait until the transaction holder wakes us, but not longer than 5000 // milliseconds (as the transaction holder may very rarely get killed without // signalling us) wait( 5000 ); } catch ( InterruptedException e ) { // nothing to do } } StoredFeatures workingCopy = new StoredFeatures( schema, storageCRS, storedFeatures ); this.activeTransaction = new MemoryFeatureStoreTransaction( this, workingCopy, lockManager ); this.transactionHolder = Thread.currentThread(); return this.activeTransaction; }
@Override public void commit() throws FeatureStoreException { try { sf.rebuildIndexes(); } catch ( UnknownCRSException e ) { throw new FeatureStoreException( e.getMessage() ); } fs.releaseTransaction( this, sf ); }
private FeatureCollection transformGeometries( FeatureCollection fc ) throws IllegalArgumentException, UnknownCRSException, TransformationException { FeatureCollection transformedFc = new GenericFeatureCollection(); GeometryTransformer transformer = new GeometryTransformer( fs.getStorageCRS() ); for ( Feature feature : fc ) { transformedFc.add( transformGeometries( feature, transformer ) ); } return transformedFc; }
/** * Creates a new {@link StoredFeatures} instance. * * @param schema * application schema, must not be <code>null</code> * @param storageCRS * target CRS for stored geometries, can be <code>null</code> (no CRS normalization) * @param former * stored features to copy from, can be <code>null</code> (new instance will be empty) * @throws FeatureStoreException */ StoredFeatures( AppSchema schema, ICRS storageCRS, StoredFeatures former ) throws FeatureStoreException { this.schema = schema; this.storageCRS = storageCRS; initFtToFeaturesMap( schema, former ); try { rebuildIndexes(); } catch ( UnknownCRSException e ) { throw new FeatureStoreException( e.getMessage(), e ); } }
@Override public GMLObject getObjectById( String id ) { return storedFeatures.getObjectById( id ); }
@Override public ResourceMetadata<FeatureStore> createFromLocation( Workspace workspace, ResourceLocation<FeatureStore> location ) { return new MemoryFeatureStoreMetadata( workspace, location, this ); }
@Override public Envelope getEnvelope( QName ftName ) throws FeatureStoreException { return calcEnvelope( ftName ); }
/** * Creates a new {@link MemoryFeatureStore} instance for the given {@link AppSchema}. * * @param schema * application schema, must not be <code>null</code> * @param storageCRS * crs used for stored geometries, may be <code>null</code> (no transformation on inserts) * @param metadata * @throws FeatureStoreException */ MemoryFeatureStore( AppSchema schema, ICRS storageCRS, MemoryFeatureStoreMetadata metadata, ConnectionProvider lockConnection ) throws FeatureStoreException { this.schema = schema; this.storageCRS = storageCRS; this.metadata = metadata; this.storedFeatures = new StoredFeatures( schema, storageCRS, null ); // TODO lockManager = new DefaultLockManager( this, lockConnection ); }
@Override public int queryHits( org.deegree.feature.persistence.query.Query query ) throws FilterEvaluationException, FeatureStoreException { return query( query ).toCollection().size(); }
@Override public Envelope calcEnvelope( QName ftName ) { Envelope ftEnv = null; FeatureType ft = schema.getFeatureType( ftName ); if ( ft != null ) { FeatureCollection fc = storedFeatures.getFeatures( ft ); if ( fc != null ) { ftEnv = fc.getEnvelope(); } } return ftEnv; }
/** * Returns the transaction to the datastore. This makes the transaction available to other clients again (via * {@link #acquireTransaction()}. * <p> * The transaction should be terminated, i.e. commit() or rollback() must have been called before. * </p> * * @param ta * the transaction to be released, must not be <code>null</code> * @param newFeatures * @throws FeatureStoreException */ void releaseTransaction( MemoryFeatureStoreTransaction ta, StoredFeatures newFeatures ) throws FeatureStoreException { if ( ta.getStore() != this ) { String msg = Messages.getMessage( "TA_NOT_OWNER" ); throw new FeatureStoreException( msg ); } if ( ta != this.activeTransaction ) { String msg = Messages.getMessage( "TA_NOT_ACTIVE" ); throw new FeatureStoreException( msg ); } if ( newFeatures != null ) { storedFeatures = newFeatures; } this.activeTransaction = null; this.transactionHolder = null; // notifyAll(); }
private String getFeatureId( Feature feature, IDGenMode mode ) { String fid = feature.getId(); switch ( mode ) { case GENERATE_NEW: { fid = "FEATURE_" + generateNewId(); break; } case REPLACE_DUPLICATE: { if ( fid == null || sf.getObjectById( fid ) != null ) { fid = "FEATURE_" + generateNewId(); } } case USE_EXISTING: { if ( fid == null ) { fid = "FEATURE_" + generateNewId(); } break; } } return fid; }
@SuppressWarnings("synthetic-access") @Override public boolean visitGeometry( Geometry geom ) { String id = getGeometryId( geom, mode ); if ( sf.getObjectById( id ) != null ) { String msg = "Cannot insert geometry '" + id + "'. This geometry already exists in the feature store."; throw new IllegalArgumentException( msg ); } geom.setId( id ); return true; }
@SuppressWarnings("synthetic-access") @Override public boolean visitFeature( Feature feature ) { String id = getFeatureId( feature, mode ); if ( sf.getObjectById( id ) != null ) { String msg = "Cannot insert feature '" + id + "'. This feature already exists in the feature store."; throw new IllegalArgumentException( msg ); } if ( feature != fc ) { feature.setId( id ); features.add( feature ); } return true; }