use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class Cache304 method get.
/**
* @param request
* @param layers
* @param props The processor properties for this layer.
* @return The cached tile or null.
*/
public CachedTile get(PipelineProcessorSite site, GetMapRequest request) {
try {
// keep store and queue stable; prevent race between removing
// Command from queue and writing to store
lock.readLock().lock();
// search the store
RecordQuery query = buildQuery(site, request);
query.setMaxResults(2);
ResultSet resultSet = store.find(query);
if (resultSet.count() > 1) {
log.warn("More than one tile for query: " + request);
}
List<CachedTile> result = new ArrayList();
for (IRecordState state : resultSet) {
result.add(new CachedTile(state, dataDir));
}
// search the queue
updateQueue.adaptCacheResult(result, query);
if (result.size() > 1) {
log.warn("More than one tile in result: " + result.size());
}
if (!result.isEmpty()) {
CachedTile cachedTile = result.get(0);
long now = System.currentTimeMillis();
if (!cachedTile.dataExists()) {
log.warn("Tile data file lost for: " + cachedTile.filename.get());
return null;
}
// done in the last accessTimeRasterMillis
if ((cachedTile.lastAccessed.get() + accessTimeRasterMillis) < now) {
cachedTile.lastAccessed.put(now);
updateQueue.push(new CacheUpdateQueue.TouchCommand(cachedTile));
updater.reSchedule();
}
statistics.incLayerCounter(site.layerId.get(), false);
return cachedTile;
} else {
statistics.incLayerCounter(site.layerId.get(), true);
return null;
}
} catch (Exception e) {
log.error("", e);
return null;
} finally {
lock.readLock().unlock();
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class Cache304 method updateLayer.
public void updateLayer(String layer, Geometry changed) {
// flush queue
if (!updateQueue.isEmpty()) {
log.warn("Queue is not empty before updateLayer()!");
}
// remove all tiles for layer
IRecordStore.Updater tx = null;
try {
lock.writeLock().tryLock(3, TimeUnit.SECONDS);
SimpleQuery query = new SimpleQuery();
query.eq(CachedTile.TYPE.layerId.name(), layer);
query.setMaxResults(1000000);
ResultSet resultSet = store.find(query);
log.debug("Removing tiles: " + resultSet.count());
Timer timer = new Timer();
tx = store.prepareUpdate();
for (IRecordState record : resultSet) {
deleteTile(record, tx);
}
tx.apply(true);
log.debug("done. (" + timer.elapsedTime() + "ms)");
} catch (Exception e) {
if (tx != null) {
tx.discard();
}
} finally {
lock.writeLock().unlock();
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class LuceneQueryDialect method getFeatureStates.
@Override
public PostProcessResultSet getFeatureStates(RFeatureStore fs, final Query query) throws IOException {
try {
Timer timer = new Timer();
// transform query
final Transformer transformer = new Transformer();
RecordQuery rsQuery = transformer.transform(fs, query);
// field selector
final String[] propNames = query.getPropertyNames();
if (propNames != null) {
rsQuery.setFieldSelector(new IRecordFieldSelector() {
private Map<String, Boolean> keys = new HashMap(64);
@Override
public boolean test(String key) {
Boolean accepted = keys.get(key);
if (accepted == null) {
keys.put(key, accepted = Boolean.FALSE);
for (String propName : propNames) {
// XXX real field names and additional fields are not known here
if (key.startsWith(propName)) {
keys.put(key, accepted = Boolean.TRUE);
break;
}
}
}
return accepted;
}
});
}
final ResultSet results = rs(fs).find(rsQuery);
log.debug(" non-processed results: " + results.count() + " ( " + timer.elapsedTime() + "ms)");
return new PostProcessResultSet() {
private boolean hasProcessing = !transformer.postProcess.isEmpty();
private Filter filter = query.getFilter();
@Override
public Iterator<IRecordState> iterator() {
return results.iterator();
}
@Override
public boolean hasPostProcessing() {
return hasProcessing;
}
@Override
public boolean postProcess(Feature feature) {
return hasProcessing ? filter.evaluate(feature) : true;
}
@Override
public int size() {
return results.count();
}
};
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class LuceneQueryDialect method getBounds.
@Override
public ReferencedEnvelope getBounds(RFeatureStore fs, Query query) throws IOException {
Timer timer = new Timer();
FeatureType schema = fs.getSchema();
assert schema.getGeometryDescriptor() != null : "Schema has no Geometry: " + schema;
String geomName = schema.getGeometryDescriptor().getLocalName();
// type/name query
// XXX handle postProcess
Transformer transformer = new Transformer();
RecordQuery rsQuery = transformer.transform(fs, query);
rsQuery.setMaxResults(1);
try {
// MinX
String fieldName = geomName + GeometryValueCoder.FIELD_MINX;
rsQuery.sort(fieldName, RecordQuery.ASC, Double.class);
ResultSet resultSet = rs(fs).find(rsQuery);
if (resultSet.count() == 0) {
return ReferencedEnvelope.EVERYTHING;
}
IRecordState record = resultSet.get(0);
double minX = record.get(fieldName);
// MaxX
fieldName = geomName + GeometryValueCoder.FIELD_MAXX;
rsQuery.sort(fieldName, RecordQuery.DESC, Double.class);
resultSet = rs(fs).find(rsQuery);
double maxX = resultSet.get(0).get(fieldName);
// MinY
fieldName = geomName + GeometryValueCoder.FIELD_MINY;
rsQuery.sort(fieldName, RecordQuery.ASC, Double.class);
resultSet = rs(fs).find(rsQuery);
double minY = resultSet.get(0).get(fieldName);
// MaxX
fieldName = geomName + GeometryValueCoder.FIELD_MAXY;
rsQuery.sort(fieldName, RecordQuery.DESC, Double.class);
resultSet = rs(fs).find(rsQuery);
double maxY = resultSet.get(0).get(fieldName);
log.info("Bounds: ... (" + timer.elapsedTime() + "ms)");
return new ReferencedEnvelope(minX, maxX, minY, maxY, schema.getCoordinateReferenceSystem());
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class RDataStore method loadSchema.
protected Optional<FeatureType> loadSchema(Name name) throws IOException {
// name
assert name != null : "Name must not be null.";
try {
// query the store
assert name.getLocalPart() != null;
SimpleQuery query = new SimpleQuery().setMaxResults(1).eq("type", "FeatureType").eq("name", name.getLocalPart());
if (name.getNamespaceURI() != null) {
query.eq("namespace", name.getNamespaceURI());
}
ResultSet rs = store.find(query);
int rsCount = rs.count();
if (rsCount > 1) {
throw new RuntimeException("Illegal size of result set: " + rsCount);
} else if (rsCount == 0) {
return Optional.empty();
} else {
IRecordState entry = rs.iterator().next();
FeatureType schema = schemaCoder.decode((String) entry.get("content"));
log.debug("Decoded schema: " + schema);
return Optional.of(schema);
}
} catch (IOException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
Aggregations