Search in sources :

Example 16 with FeatureStoreRuntimeException

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;
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException)

Example 17 with FeatureStoreRuntimeException

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);
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Feature(org.opengis.feature.Feature)

Example 18 with FeatureStoreRuntimeException

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) DataStoreException(org.apache.sis.storage.DataStoreException) XMLStreamException(javax.xml.stream.XMLStreamException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException) JAXPStreamFeatureWriter(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter) Feature(org.opengis.feature.Feature)

Example 19 with FeatureStoreRuntimeException

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;
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Feature(org.opengis.feature.Feature)

Example 20 with FeatureStoreRuntimeException

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);
        }
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException)

Aggregations

FeatureStoreRuntimeException (org.geotoolkit.storage.feature.FeatureStoreRuntimeException)35 DataStoreException (org.apache.sis.storage.DataStoreException)21 IOException (java.io.IOException)17 Feature (org.opengis.feature.Feature)16 HashMap (java.util.HashMap)8 FeatureType (org.opengis.feature.FeatureType)8 PropertyNotFoundException (org.opengis.feature.PropertyNotFoundException)5 PropertyType (org.opengis.feature.PropertyType)5 Path (java.nio.file.Path)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 FeatureSet (org.apache.sis.storage.FeatureSet)4 JAXPStreamFeatureWriter (org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter)4 Query (org.geotoolkit.storage.feature.query.Query)4 AttributeType (org.opengis.feature.AttributeType)4 ResourceId (org.opengis.filter.ResourceId)4 Date (java.util.Date)3 JAXBException (javax.xml.bind.JAXBException)3 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)3 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)3 GeoJSONStreamWriter (org.geotoolkit.storage.geojson.GeoJSONStreamWriter)3