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;
}
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;
}
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);
}
}
}
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);
}
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);
}
}
Aggregations