/** * 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 GMLObject getObjectById( String id ) { return storedFeatures.getObjectById( id ); }
/** * 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 ); } }
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 ); }
GMLObject obj = sf.getObjectById( id.getRid() ); if ( obj != null ) { if ( obj instanceof Feature ) { Feature f = (Feature) obj; sf.removeFeature( f ); deleted++;
FeatureCollection fc = sf.getFeatures( ft ); int deleted = 0; if ( fc != null ) { sf.removeFeature( feature ); if ( lock != null ) { lock.release( feature.getId() );
@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; }
@Override public FeatureInputStream query( Query query ) throws FilterEvaluationException, FeatureStoreException { return storedFeatures.query( query ); }
@Override public void commit() throws FeatureStoreException { try { sf.rebuildIndexes(); } catch ( UnknownCRSException e ) { throw new FeatureStoreException( e.getMessage() ); } fs.releaseTransaction( this, sf ); }
sf.addFeature( feature );
FeatureCollection fc = sf.getFeatures( ft ); List<String> updatedFids = new ArrayList<String>(); if ( fc != null ) {
@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; }
@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; }
@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; }
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; }
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; }