use of org.polymap.recordstore.SimpleQuery in project polymap4-core by Polymap4.
the class Cache304 method buildQuery.
protected RecordQuery buildQuery(PipelineProcessorSite site, GetMapRequest request) {
SimpleQuery query = new SimpleQuery();
if (request.getWidth() != -1) {
query.eq(CachedTile.TYPE.width.name(), request.getWidth());
}
if (request.getHeight() != -1) {
query.eq(CachedTile.TYPE.height.name(), request.getHeight());
}
if (request.getBoundingBox() != null) {
ReferencedEnvelope bbox = request.getBoundingBox();
query.eq(CachedTile.TYPE.maxx.name(), bbox.getMaxX());
query.eq(CachedTile.TYPE.minx.name(), bbox.getMinX());
query.eq(CachedTile.TYPE.maxy.name(), bbox.getMaxY());
query.eq(CachedTile.TYPE.miny.name(), bbox.getMinY());
// // maxx > bbox.getMinX
// query.greater( CachedTile.TYPE.maxx.name(), bbox.getMinX() );
// // minx < bbox.getMaxX
// query.less( CachedTile.TYPE.minx.name(), bbox.getMaxX() );
// // maxy > bbox.getMinY
// query.greater( CachedTile.TYPE.maxy.name(), bbox.getMinY() );
// // miny < bbox.getMaxY
// query.less( CachedTile.TYPE.miny.name(), bbox.getMaxY() );
}
// layerId
query.eq(CachedTile.TYPE.layerId.name(), site.layerId.get());
// style
String styleHash = StringUtils.defaultString(request.getStyles().get(0), "_");
query.eq(CachedTile.TYPE.style.name(), styleHash);
// format
query.eq(CachedTile.TYPE.format.name(), request.getFormat());
// not expired
query.greater(CachedTile.TYPE.expires.name(), System.currentTimeMillis());
return query;
}
use of org.polymap.recordstore.SimpleQuery 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.SimpleQuery 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.SimpleQuery in project polymap4-core by Polymap4.
the class RDataStore method deleteSchema.
public void deleteSchema(FeatureType schema, IProgressMonitor monitor) {
// remove features
try {
RFeatureStore fs = (RFeatureStore) getFeatureSource(schema.getName());
fs.removeFeatures(Filter.INCLUDE);
} catch (Exception e) {
log.debug("", e);
throw new RuntimeException(e);
}
// remove schema
Updater tx = store.prepareUpdate();
try {
ResultSet rs = store.find(new SimpleQuery().setMaxResults(1).eq("type", "FeatureType").eq("name", schema.getName().getLocalPart()).eq("namespace", schema.getName().getNamespaceURI()));
assert rs.count() == 1 : "Illegal number of schemas found: " + rs.count();
tx.remove(rs.get(0));
tx.apply();
} catch (Throwable e) {
log.debug("", e);
tx.discard();
throw new RuntimeException(e);
}
}
use of org.polymap.recordstore.SimpleQuery in project polymap4-core by Polymap4.
the class AbstractRecordStoreTest method queryRecords.
protected void queryRecords(int loops) throws Exception {
final Timer timer = new Timer();
int found = 0;
for (int i = 0; i < loops; i++) {
// RecordQuery query = new SimpleQuery()
// .eq( TestRecord.TYPE.count.name(), String.valueOf( i ) )
// .eq( TestRecord.TYPE.type.name(), "2" )
// .setMaxResults( 1 );
SimpleQuery query = new SimpleQuery().setMaxResults(1);
TestRecord template = new TestRecord(query);
template.count.put(i);
template.type.put("2");
ResultSet result = store.find(query);
// assertTrue( result.count() == 0);
if (result.count() > 0) {
found++;
}
// TestRecord record = new TestRecord( result.get( 0 ) );
// dummy = record.type.get();
}
log.info("Records queried: " + found + " in " + timer.elapsedTime() + "ms -> " + (double) timer.elapsedTime() / loops + "ms/loop");
store.close();
}
Aggregations