use of org.polymap.recordstore.IRecordState 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.IRecordState 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.IRecordState 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.IRecordState 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);
}
}
use of org.polymap.recordstore.IRecordState in project polymap4-core by Polymap4.
the class AbstractRecordStoreTest method readRecords.
protected void readRecords(int loops) throws Exception {
final Timer timer = new Timer();
int found = 0;
for (int i = 0; i < loops; i++) {
IRecordState record = store.get(String.valueOf(start + i));
if (record != null) {
found++;
}
}
log.info("Records read: " + found + " in " + timer.elapsedTime() + "ms -> " + (double) timer.elapsedTime() / loops + "ms/loop");
}
Aggregations