Search in sources :

Example 31 with FeatureStoreRuntimeException

use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.

the class DefaultJDBCFeatureStore method handleRemoveWithFeatureWriter.

/**
 * Convenient method to handle adding features operation by using the
 * FeatureWriter.
 */
protected void handleRemoveWithFeatureWriter(final String groupName, final Filter filter, Connection cnx) throws DataStoreException {
    try (FeatureWriter writer = getFeatureWriterInternal(groupName, filter, EditMode.UPDATE, cnx, null)) {
        while (writer.hasNext()) {
            writer.next();
            writer.remove();
        }
    } catch (FeatureStoreRuntimeException | IOException ex) {
        throw new DataStoreException(ex);
    }
}
Also used : FeatureWriter(org.geotoolkit.storage.feature.FeatureWriter) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException)

Example 32 with FeatureStoreRuntimeException

use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.

the class ShapefileFeatureReader method close.

/**
 * {@inheritDoc }
 */
@Override
public void close() throws FeatureStoreRuntimeException {
    if (closed)
        return;
    closed = true;
    Exception ex = null;
    try {
        fidReader.close();
    } catch (DataStoreException e) {
        ex = e;
    }
    try {
        attributeReader.close();
    } catch (IOException e) {
        if (ex == null) {
            ex = e;
        } else {
        // we tryed to close both and both failed
        // return the first exception
        }
    }
    if (ex != null) {
        throw new FeatureStoreRuntimeException(ex);
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException) MismatchedFeatureException(org.opengis.feature.MismatchedFeatureException) IOException(java.io.IOException) PropertyNotFoundException(org.opengis.feature.PropertyNotFoundException) DataStoreException(org.apache.sis.storage.DataStoreException) NoSuchElementException(java.util.NoSuchElementException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException)

Example 33 with FeatureStoreRuntimeException

use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.

the class ShapefileFeatureWriter method doClose.

protected void doClose() throws FeatureStoreRuntimeException {
    // close reader, flush headers, and copy temp files, if any
    try {
        featureReader.close();
    } finally {
        try {
            flush();
        } catch (IOException ex) {
            throw new FeatureStoreRuntimeException(ex);
        } finally {
            try {
                shpWriter.close();
                dbfWriter.close();
            } catch (IOException ex) {
                throw new FeatureStoreRuntimeException(ex);
            }
        }
        featureReader = null;
        shpWriter = null;
        dbfWriter = null;
    }
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException)

Example 34 with FeatureStoreRuntimeException

use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.

the class IndexedShapefileFeatureWriter method next.

@Override
public Feature next() throws FeatureStoreRuntimeException {
    // closed already, error!
    if (featureReader == null) {
        throw new FeatureStoreRuntimeException("Writer closed");
    }
    // we have to write the current feature back into the stream
    if (currentFeature != null) {
        write();
    }
    final long next;
    try {
        next = fidWriter.next();
    } catch (IOException ex) {
        throw new FeatureStoreRuntimeException(ex);
    }
    currentFid = getFeatureType().getName().tip() + "." + next;
    Feature feature = super.next();
    return feature;
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException) Feature(org.opengis.feature.Feature)

Example 35 with FeatureStoreRuntimeException

use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.

the class IndexedFidReader method hasNext.

@Override
public boolean hasNext() throws FeatureStoreRuntimeException {
    if (done) {
        return false;
    }
    if (((Buffer) buffer).position() == ((Buffer) buffer).limit()) {
        ((Buffer) buffer).position(0);
        final FileChannel fc = (FileChannel) readChannel;
        final int read;
        try {
            bufferStart = fc.position();
            read = ShapefileReader.fill(buffer, readChannel);
        } catch (IOException ex) {
            throw new FeatureStoreRuntimeException(ex);
        }
        if (read != 0) {
            ((Buffer) buffer).position(0);
        }
    }
    return buffer.remaining() != 0;
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(java.nio.Buffer) FileChannel(java.nio.channels.FileChannel) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException)

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