use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class CacheStatistics method layerStoreSize.
public long layerStoreSize(String layer) {
try {
SimpleQuery query = new SimpleQuery();
query.setMaxResults(Integer.MAX_VALUE);
query.eq(CachedTile.TYPE.layerId.name(), layer);
long result = 0;
try (ResultSet resultSet = cache.store.find(query)) {
for (IRecordState state : resultSet) {
result += new CachedTile(state, null).filesize.get();
}
}
return result;
} catch (Exception e) {
return -1;
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class CacheStatistics method layerTileCount.
public int layerTileCount(String layer) {
try {
SimpleQuery query = new SimpleQuery();
query.setMaxResults(Integer.MAX_VALUE);
query.eq(CachedTile.TYPE.layerId.name(), layer);
try (ResultSet resultSet = cache.store.find(query)) {
return resultSet.count();
}
} catch (Exception e) {
return -1;
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class RDataStore method updateSchema.
@Override
public void updateSchema(Name name, final FeatureType newSchema) throws IOException {
assert name != null && newSchema != null;
final Updater tx = store.prepareUpdate();
try {
// check modified property names
boolean namesModified = false;
for (PropertyDescriptor desc : newSchema.getDescriptors()) {
// set by FeatureTypeEditor/AttributeCellModifier
String origName = (String) desc.getUserData().get(ORIG_NAME_KEY);
if (origName != null) {
namesModified = true;
}
}
// find deleted properties
// XXX check complex schemas
FeatureType schema = getSchema(name);
final List<PropertyDescriptor> deleted = new ArrayList();
for (PropertyDescriptor desc : schema.getDescriptors()) {
if (newSchema.getDescriptor(desc.getName()) == null) {
deleted.add(desc);
}
}
// schema name changed or prop deleted? -> update features
final String newName = newSchema.getName().getLocalPart();
if (!name.getLocalPart().equals(newSchema.getName().getLocalPart()) || !deleted.isEmpty() || namesModified) {
FeatureSource fs = getFeatureSource(name);
fs.getFeatures().accepts(new FeatureVisitor() {
public void visit(Feature feature) {
try {
// typeName
((RFeature) feature).state.put(RFeature.TYPE_KEY, newName);
// List<Name> origModifiedNames = new ArrayList();
for (PropertyDescriptor desc : newSchema.getDescriptors()) {
// set by FeatureTypeEditor/AttributeCellModifier
String origName = (String) desc.getUserData().get(ORIG_NAME_KEY);
if (origName != null) {
RAttribute prop = (RAttribute) feature.getProperty(origName);
if (prop != null) {
if (prop.getValue() != null) {
((RFeature) feature).state.put(desc.getName().getLocalPart(), prop.getValue());
}
((RFeature) feature).state.remove(prop.key.toString());
}
}
}
// deleted attributes
for (PropertyDescriptor desc : deleted) {
// XXX check complex schemas
RProperty prop = (RProperty) feature.getProperty(desc.getName());
((RFeature) feature).state.remove(prop.key.toString());
}
tx.store(((RFeature) feature).state);
} catch (Exception e) {
// Designing a visitor interface without Exception is not a good idea!
throw new RuntimeException("", e);
}
}
}, null);
}
// update schema record
ResultSet rs = store.find(new SimpleQuery().setMaxResults(1).eq("type", "FeatureType").eq("name", name.getLocalPart()));
IRecordState record = rs.get(0);
String schemaContent = schemaCoder.encode(newSchema);
record.put("content", schemaContent);
record.put("name", newName);
tx.store(record);
log.debug("Current schema: " + schemaCoder.encode(schema));
log.debug("Updated schema: " + schemaContent);
tx.apply();
} catch (Throwable e) {
log.debug("", e);
tx.discard();
throw new RuntimeException(e);
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class RDataStore method getNames.
@Override
public List<Name> getNames() throws IOException {
// see #loadSchema()
try {
ResultSet rs = RDataStore.this.store.find(new SimpleQuery().setMaxResults(1000).eq("type", "FeatureType"));
HashSet result = new HashSet(rs.count() * 2);
for (IRecordState entry : rs) {
String namespace = entry.get("namespace");
String localpart = entry.get("name");
Name name = namespace == null ? new NameImpl(namespace, localpart) : new NameImpl(localpart);
if (!result.add(name)) {
throw new IllegalStateException("Name already loaded: " + name);
}
}
return ImmutableList.copyOf(result);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.polymap.recordstore.ResultSet in project polymap4-core by Polymap4.
the class LuceneQueryDialect method getCount.
@Override
public int getCount(RFeatureStore fs, Query query) throws IOException {
// XXX handle postProcess
Transformer transformer = new Transformer();
RecordQuery rsQuery = transformer.transform(fs, query);
try {
ResultSet resultSet = rs(fs).find(rsQuery);
return resultSet.count();
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
Aggregations