this.grid.readUnLock();
cacheFeatureReader = new GridCacheFeatureReader(found, (GridSpatialIndex)grid.getIndex());
}else{
//need a write lock; release all read locks
for( Iterator<NodeIdentifier> iterator = found.iterator(); iterator.hasNext(); ) {
NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
nodeid.readUnLock();
}
this.grid.readUnLock();
this.grid.writeLock();
try{
//re-get read locks
acquireReadLocks(missing, found);
// acquire write locks
if (missing.size() > 0 && fs != null) {
acquireWriteLocks(missing, found);
}
// register working area
if (missing.size() > 0 && fs != null) {
this.grid.register(missing);
}
}finally{
this.grid.writeUnLock();
}
if (fs != null) {
// note that for performance reasons this query might actually return
// features from an area larger than we are interested in caching
DefaultQuery dq = new DefaultQuery(featureType.getName().getLocalPart(), this.createFilter(missing));
dq.setCoordinateSystem(featureType.getCoordinateReferenceSystem());
if (query != null) {
dq.setHints(query.getHints());
dq.setHandle(query.getHandle());
} else {
dq.setHints(new Hints(Hints.JTS_COORDINATE_SEQUENCE_FACTORY,new LiteCoordinateSequenceFactory()));
}
try{
sourceFeatureReader = ((DataStore) fs.getDataStore()).getFeatureReader(dq,Transaction.AUTO_COMMIT);
}catch (Exception ex){
//nothing to get
missing.clear();
sourceFeatureReader = null;
}
} else {
missing.clear(); // we didn't get anything so we don't want to register these as write locks
}
if (found.size() > 0) {
cacheFeatureReader = new GridCacheFeatureReader(found, (GridSpatialIndex) grid.getIndex());
}
}
boolean localcache = cacheFeatures;
if (query != null && query.getMaxFeatures() != Integer.MAX_VALUE){
localcache = false;
}
FeatureReader<SimpleFeatureType, SimpleFeature> fr = null;
if (sourceFeatureReader != null && cacheFeatureReader != null){
fr = new CombiningCachingFeatureReader(cacheFeatureReader, sourceFeatureReader, false, localcache, grid.getIndex(), this.postFilter);
}else if (sourceFeatureReader != null && cacheFeatureReader == null){
fr = new CombiningCachingFeatureReader(new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), sourceFeatureReader, false, localcache, grid.getIndex(), this.postFilter);
}else if (sourceFeatureReader == null && cacheFeatureReader != null){
fr = new CombiningCachingFeatureReader(cacheFeatureReader, new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), false, false, grid.getIndex(), this.postFilter);
}else{
fr = new CombiningCachingFeatureReader(new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), false, false, grid.getIndex(), this.postFilter);
}
it = new FeatureReaderFeatureIterator(wrapFeatureReader(fr), missing, found);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Failed to create feature collection iterator.", ex);
if (missing != null){
for( Iterator<NodeIdentifier> iterator = missing.iterator(); iterator.hasNext(); ) {
NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
nodeid.writeUnLock();
}
}
if (found != null){
for( Iterator<NodeIdentifier> iterator = found.iterator(); iterator.hasNext(); ) {
NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
nodeid.readUnLock();
}
}
if (missing != null){
this.grid.unregister(missing);
}