Search in sources :

Example 6 with IRecordState

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();
    }
}
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 7 with IRecordState

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);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) IRecordFieldSelector(org.polymap.recordstore.IRecordFieldSelector) Feature(org.opengis.feature.Feature) RFeature(org.polymap.core.data.rs.RFeature) IOException(java.io.IOException) Timer(org.polymap.core.runtime.Timer) IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) ResultSet(org.polymap.recordstore.ResultSet) IRecordState(org.polymap.recordstore.IRecordState) RecordQuery(org.polymap.recordstore.RecordQuery) LuceneRecordQuery(org.polymap.recordstore.lucene.LuceneRecordQuery)

Example 8 with IRecordState

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);
    }
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Timer(org.polymap.core.runtime.Timer) ResultSet(org.polymap.recordstore.ResultSet) IRecordState(org.polymap.recordstore.IRecordState) IOException(java.io.IOException) RecordQuery(org.polymap.recordstore.RecordQuery) LuceneRecordQuery(org.polymap.recordstore.lucene.LuceneRecordQuery) IOException(java.io.IOException)

Example 9 with IRecordState

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);
    }
}
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 10 with IRecordState

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

Aggregations

IRecordState (org.polymap.recordstore.IRecordState)10 IOException (java.io.IOException)8 ResultSet (org.polymap.recordstore.ResultSet)8 SimpleQuery (org.polymap.recordstore.SimpleQuery)5 Timer (org.polymap.core.runtime.Timer)4 FeatureType (org.opengis.feature.type.FeatureType)3 RecordQuery (org.polymap.recordstore.RecordQuery)3 ArrayList (java.util.ArrayList)2 Feature (org.opengis.feature.Feature)2 Updater (org.polymap.recordstore.IRecordStore.Updater)2 LuceneRecordQuery (org.polymap.recordstore.lucene.LuceneRecordQuery)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 FeatureSource (org.geotools.data.FeatureSource)1 NameImpl (org.geotools.feature.NameImpl)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 FeatureVisitor (org.opengis.feature.FeatureVisitor)1 Name (org.opengis.feature.type.Name)1 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)1 ExcludeFilter (org.opengis.filter.ExcludeFilter)1