use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class CSVWriter method close.
@Override
public void close() {
if (closed)
return;
try {
writer.flush();
writer.close();
} catch (IOException ex) {
throw new FeatureStoreRuntimeException(ex);
}
// close read iterator
super.close();
// flip files
fileLock.writeLock().lock();
tempLock.writeLock().lock();
try {
Files.move(writeFile, store.getFile(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ex) {
throw new FeatureStoreRuntimeException(ex);
} finally {
fileLock.writeLock().unlock();
tempLock.writeLock().unlock();
}
// Fire content change events only if we succeed replacing original file.
store.fireDataChangeEvents(addedIds, updatedIds, deletedIds);
closed = true;
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class GMLSparseStore method replaceIf.
@Override
public void replaceIf(Predicate<? super Feature> filter, UnaryOperator<Feature> updater) throws DataStoreException {
try (WriterIterator writer = new WriterIterator(featureType, file)) {
while (writer.hasNext()) {
final Feature f = writer.next();
if (filter.test(f)) {
Feature nw = updater.apply(f);
FeatureExt.copy(nw, f, false);
writer.write();
}
}
} catch (FeatureStoreRuntimeException ex) {
throw new DataStoreException(ex);
}
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class GMLSparseStore method add.
@Override
public void add(Iterator<? extends Feature> features) throws DataStoreException {
while (features.hasNext()) {
final Feature feature = features.next();
final Path currentFile = file.resolve(FeatureExt.getId(feature).getIdentifier() + ".gml");
// write feature
final JAXPStreamFeatureWriter writer = new JAXPStreamFeatureWriter(gmlVersion, "2.0.0", schemaLocations);
try {
writer.write(feature, currentFile);
} catch (IOException | XMLStreamException | DataStoreException ex) {
throw new FeatureStoreRuntimeException(ex.getMessage(), ex);
} finally {
try {
writer.dispose();
} catch (IOException | XMLStreamException ex) {
throw new FeatureStoreRuntimeException(ex.getMessage(), ex);
}
}
}
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class GMLSparseStore method removeIf.
@Override
public boolean removeIf(Predicate<? super Feature> filter) throws DataStoreException {
boolean changed = false;
try (WriterIterator writer = new WriterIterator(featureType, file)) {
while (writer.hasNext()) {
final Feature f = writer.next();
if (filter.test(f)) {
changed = true;
writer.remove();
}
}
} catch (FeatureStoreRuntimeException ex) {
throw new DataStoreException(ex);
}
return changed;
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class JDBCFeatureWriterInsert method write.
@Override
public void write() throws FeatureStoreRuntimeException {
if (batchInsert) {
toAdd.add(last);
last = type.newInstance();
if (toAdd.size() > 1000) {
try {
store.insert(toAdd, type, cx);
} catch (DataStoreException e) {
throw new FeatureStoreRuntimeException(e);
}
toAdd.clear();
}
} else {
try {
store.insert(last, type, cx);
// the featurestore sets as userData, grab it and update the fid
// TODO
// final String id = (String) last.getUserData().get("fid");
// if (id != null) {
// last.setIdentifier(new DefaultFeatureId(id));
// }
} catch (DataStoreException e) {
throw new FeatureStoreRuntimeException(e);
}
}
}
Aggregations