Search in sources :

Example 26 with FeatureStoreRuntimeException

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

the class FishReader method next.

@Override
public Feature next() throws FeatureStoreRuntimeException {
    read();
    final Feature ob = current;
    current = null;
    if (ob == null) {
        throw new FeatureStoreRuntimeException("No more records.");
    }
    return ob;
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Feature(org.opengis.feature.Feature)

Example 27 with FeatureStoreRuntimeException

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

the class MIFWriter method write.

public void write() throws FeatureStoreRuntimeException {
    if (currentFeature == null) {
        throw new FeatureStoreRuntimeException("There's no feature to write (null value).");
    }
    if (reader == null) {
        throw new FeatureStoreRuntimeException("Writer has been closed");
    }
    try {
        final String mifGeom = MIFUtils.buildMIFGeometry(currentFeature);
        tmpMifWriter.write(mifGeom);
    } catch (Exception e) {
        throw new FeatureStoreRuntimeException("A problem occurred while building geometry.", e);
    }
    try {
        if (master.getBaseType() != null && master.getBaseType().getProperties(true).size() > 0) {
            final String midAttributes = master.buildMIDAttributes(currentFeature);
            tmpMidWriter.write(midAttributes);
        }
    } catch (Exception e) {
        throw new FeatureStoreRuntimeException("A problem occurred while building MID attributes.", e);
    }
    currentFeature = null;
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException)

Example 28 with FeatureStoreRuntimeException

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

the class MIFWriter method close.

@Override
public void close() throws FeatureStoreRuntimeException {
    if (reader == null) {
        throw new FeatureStoreRuntimeException("Writer has already been closed");
    }
    // make sure to write the last feature...
    if (currentFeature != null) {
        write();
    }
    reader.close();
    reader = null;
    try {
        tmpMidWriter.close();
        tmpMidWriter = null;
    } catch (Exception e) {
        MIFManager.LOGGER.log(Level.WARNING, "Temporary MIF data writer can't be closed", e);
    }
    try {
        tmpMifWriter.close();
        tmpMifWriter = null;
    } catch (Exception e) {
        MIFManager.LOGGER.log(Level.WARNING, "Temporary MIF data writer can't be closed", e);
    }
    try {
        master.flushData(tmpMifFile, tmpMidFile);
    } catch (Exception ex) {
        throw new FeatureStoreRuntimeException("Data flushing impossible, there's a possibility of data loss.");
    } finally {
        try {
            Files.delete(tmpMidFile);
            Files.delete(tmpMifFile);
        } catch (IOException ex) {
            MIFManager.LOGGER.log(Level.FINE, "Cannot delete temporary files", ex);
        }
    }
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException)

Example 29 with FeatureStoreRuntimeException

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

the class MIFReader method hasNext.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasNext() throws FeatureStoreRuntimeException {
    boolean midNext = false;
    boolean mifNext = false;
    try {
        checkScanners();
    } catch (IOException e) {
        // If we can't access source files, maybe we're in creation mode, so we just say we can't find next.
        return false;
    } catch (DataStoreException e) {
        throw new FeatureStoreRuntimeException(e);
    }
    if (readMif) {
        // Check the MapInfo geometry typename to see if there's some next in the file.
        mifNext = mifScanner.hasNext(GEOMETRY_ID_PATTERN);
    }
    // Once we know the number of the next geometry data, we can check if we can go as far in the mid file.
    if (readMid) {
        for (; midCounter < mifCounter; midCounter++) {
            if (midScanner.hasNextLine()) {
                midScanner.nextLine();
            } else {
                break;
            }
        }
        midNext = midScanner.hasNextLine();
    }
    if (readMid && !readMif) {
        return midNext;
    } else if (readMif && !readMid) {
        return mifNext;
    } else
        return (midNext && mifNext);
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException)

Example 30 with FeatureStoreRuntimeException

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

the class DefaultJDBCFeatureStore method handleUpdateWithFeatureWriter.

/**
 * Convinient method to handle adding features operation by using the
 * FeatureWriter.
 */
protected void handleUpdateWithFeatureWriter(final String groupName, final Filter filter, final Map<String, ? extends Object> values, Connection cnx) throws DataStoreException {
    try (FeatureWriter writer = getFeatureWriterInternal(groupName, filter, EditMode.UPDATE, cnx, null)) {
        while (writer.hasNext()) {
            final Feature f = writer.next();
            for (final Map.Entry<String, ? extends Object> entry : values.entrySet()) {
                f.setPropertyValue(entry.getKey(), entry.getValue());
            }
            writer.write();
        }
    } 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) Feature(org.opengis.feature.Feature) Map(java.util.Map)

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