use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testRemoveFromFrontAndCloseTransaction.
/**
* Create a test file, then continue removing the first entry until there
* are no features left.
*/
@Test
public void testRemoveFromFrontAndCloseTransaction() throws Throwable {
IndexedShapefileFeatureStore sds = createDataStore();
int idx = loadFeatures(sds).size();
while (idx > 0) {
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getName()));
writer.next();
writer.remove();
} finally {
if (writer != null) {
writer.close();
writer = null;
}
}
assertEquals(--idx, loadFeatures(sds).size());
}
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class Copy method insert.
private void insert(GenericName name, final Session sourceSS, final Session targetSS, Query query, final boolean erase, final boolean newVersion) throws DataStoreException {
FeatureType type = sourceSS.getFeatureStore().getFeatureType(name.toString());
// Change * to featureType default geometry name
if (query != null && query.getSelection() != null) {
final Filter newFilter = (Filter) new BBOXFilterVisitor(type).visit((Filter) query.getSelection());
final Query builder = new Query();
builder.copy(query);
builder.setSelection(newFilter);
query = builder;
}
final FeatureCollection collection = sourceSS.getFeatureCollection(query);
// get the real FeatureType of collection (in case of reprojection, CRS is different).
type = collection.getType();
if (targetSS.getFeatureStore().getNames().contains(name)) {
// ERASE
if (erase) {
targetSS.getFeatureStore().deleteFeatureType(name.toString());
targetSS.getFeatureStore().createFeatureType(type);
}
} else {
targetSS.getFeatureStore().createFeatureType(type);
}
// get the created name, namespace might change
name = targetSS.getFeatureStore().getFeatureType(type.getName().tip().toString()).getName();
if (targetSS.getFeatureStore().getQueryCapabilities().handleVersioning()) {
try {
targetSS.getFeatureStore().getVersioning(name.toString()).startVersioning();
} catch (VersioningException ex) {
throw new DataStoreException(ex.getLocalizedMessage(), ex);
}
}
// NEW VERSION (remove old features)
if (newVersion) {
targetSS.removeFeatures(name.toString(), Filter.include());
}
// Logger
final StringBuilder logMsg = new StringBuilder("Insert ");
logMsg.append(collection.size()).append(" features ");
logMsg.append("in type ").append(name.tip().toString());
logMsg.append(" [");
if (erase) {
logMsg.append("ERASE");
if (newVersion)
logMsg.append(", NEWVERSION");
}
if (newVersion)
logMsg.append("NEWVERSION");
logMsg.append("]");
LOGGER.log(Level.INFO, logMsg.toString());
// APPEND
targetSS.addFeatures(name.toString(), collection);
}
Aggregations