Search in sources :

Example 6 with SimpleQuery

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;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) SimpleQuery(org.polymap.recordstore.SimpleQuery)

Example 7 with SimpleQuery

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();
    }
}
Also used : SimpleQuery(org.polymap.recordstore.SimpleQuery) Timer(org.polymap.core.runtime.Timer) IRecordStore(org.polymap.recordstore.IRecordStore) ResultSet(org.polymap.recordstore.ResultSet) IRecordState(org.polymap.recordstore.IRecordState) IOException(java.io.IOException)

Example 8 with SimpleQuery

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);
    }
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) SimpleQuery(org.polymap.recordstore.SimpleQuery) ResultSet(org.polymap.recordstore.ResultSet) IRecordState(org.polymap.recordstore.IRecordState) IOException(java.io.IOException) IOException(java.io.IOException)

Example 9 with SimpleQuery

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);
    }
}
Also used : SimpleQuery(org.polymap.recordstore.SimpleQuery) Updater(org.polymap.recordstore.IRecordStore.Updater) ResultSet(org.polymap.recordstore.ResultSet) IOException(java.io.IOException)

Example 10 with SimpleQuery

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();
}
Also used : Timer(org.polymap.core.runtime.Timer) SimpleQuery(org.polymap.recordstore.SimpleQuery) ResultSet(org.polymap.recordstore.ResultSet)

Aggregations

SimpleQuery (org.polymap.recordstore.SimpleQuery)10 ResultSet (org.polymap.recordstore.ResultSet)8 IOException (java.io.IOException)5 IRecordState (org.polymap.recordstore.IRecordState)5 FeatureType (org.opengis.feature.type.FeatureType)2 Timer (org.polymap.core.runtime.Timer)2 Updater (org.polymap.recordstore.IRecordStore.Updater)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 FeatureSource (org.geotools.data.FeatureSource)1 NameImpl (org.geotools.feature.NameImpl)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 Feature (org.opengis.feature.Feature)1 FeatureVisitor (org.opengis.feature.FeatureVisitor)1 Name (org.opengis.feature.type.Name)1 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)1 IRecordStore (org.polymap.recordstore.IRecordStore)1