public void close() throws IOException { delegate.close(); delegate = null; builder = null; }
@Override public void close() throws IOException { w.close(); } };
public void close() { if (writer != null) { try { writer.close(); } catch (IOException e) { // sorry but iterators die quitely in the night } writer = null; } } }
public void close() throws IOException { if (writer != null) { writer.close(); writer = null; } if (filter != null) { filter = null; } current = null; next = null; } }
public void close() throws IOException { live = null; if (writer != null) writer.close(); } };
/** * This method only needs package visability as only AbstractFeatureCollection is trusted enough * to call it. */ void close() { if (writer != null) { try { writer.close(); } catch (IOException e) { // sorry but iterators die quitely in the night } writer = null; } } }
/** * Adds a collection of features to the store. * * <p>This method operates by getting an appending feature writer and writing all the features * in <tt>collection</tt> to it. Directly after a feature is written its id is obtained and * added to the returned set. */ public List<FeatureId> addFeatures(Collection collection) throws IOException { // gather up id's List<FeatureId> ids = new ArrayList<FeatureId>(collection.size()); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = getWriterAppend(); try { for (Iterator f = collection.iterator(); f.hasNext(); ) { FeatureId id = addFeature((SimpleFeature) f.next(), writer); ids.add(id); } } finally { writer.close(); } return ids; }
/** Counts the number of Features in the specified writer. This method will close the writer. */ protected int count(FeatureWriter<SimpleFeatureType, SimpleFeature> writer) throws NoSuchElementException, IOException { int count = 0; try { while (writer.hasNext()) { writer.next(); count++; } } finally { writer.close(); } return count; } }
/** * Clean up resources associated with this writer. * * <p>Diff is not clear()ed as it is assumed that it belongs to a Transaction.State object and * may yet be written out. * * @see org.geotools.data.FeatureWriter#close() */ public void close() throws IOException { Transaction t = state.getTransaction(); if (t != Transaction.AUTO_COMMIT) { t.removeState(this); } if (writer != null) { writer.close(); writer = null; } feature = null; } /**
public void close() throws IOException { FeatureWriter w = writer; while (w instanceof DelegatingFeatureWriter) { if (w instanceof JDBCFeatureReader) { break; } w = ((DelegatingFeatureWriter) w).getDelegate(); } if (w instanceof JDBCFeatureReader) { JDBCFeatureReader jdbcReader = (JDBCFeatureReader) w; JDBCFeatureSource fs = jdbcReader.featureSource; Connection cx = jdbcReader.cx; try { writer.close(); } finally { fs.getDataStore().releaseConnection(cx, fs.getState()); } } } }
/** Counts the number of Features in the specified writer. This method will close the writer. */ protected int count(FeatureWriter<SimpleFeatureType, SimpleFeature> writer) throws NoSuchElementException, IOException, IllegalAttributeException { int count = 0; try { while (writer.hasNext()) { writer.next(); count++; } } finally { writer.close(); } return count; }
public void nextWriter() throws IOException { // close the old shapefile this.writer.close(); this.dstore.dispose(); // prepare the new one currentFileId++; SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(schema); tb.setName(schema.getTypeName() + String.valueOf(currentFileId)); SimpleFeatureType ft = tb.buildFeatureType(); // set it up at the current store and writer createStoreAndWriter(ft); } }
public void testGetFeatureWriterTypeNameTransaction() throws NoSuchElementException, IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer; writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); assertEquals(roadFeatures.length, count(writer)); writer.close(); }
public void testGetFeatureWriterAppendTypeNameTransaction() throws Exception { FeatureWriter<SimpleFeatureType, SimpleFeature> writer; writer = data.getFeatureWriterAppend("road", Transaction.AUTO_COMMIT); assertEquals(0, count(writer)); writer.close(); }
/** @see FeatureStore#removeFeatures(Filter) */ public void removeFeatures(final Filter filter) throws IOException { final Transaction currTransaction = getTransaction(); final String typeName = typeInfo.getFeatureTypeName(); // short circuit cut if needed to remove all features // if (Filter.INCLUDE == filter) { // truncate(typeName, connection); // return; // } final FeatureWriter<SimpleFeatureType, SimpleFeature> writer; writer = dataStore.getFeatureWriter(typeName, filter, currTransaction); try { while (writer.hasNext()) { writer.next(); writer.remove(); } } finally { writer.close(); } }
public void modifyFeatures(final Name[] attributes, final Object[] values, final Filter filter) throws IOException { final ISession session = getSession(); try { final String typeName = typeInfo.getFeatureTypeName(); final Transaction currTransaction = getTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer; writer = dataStore.getFeatureWriter(typeName, filter, currTransaction); try { SimpleFeature feature; while (writer.hasNext()) { feature = writer.next(); for (int i = 0; i < values.length; i++) { feature.setAttribute(attributes[i].getLocalPart(), values[i]); } writer.write(); } } finally { writer.close(); } } finally { session.dispose(); } }
public void testCommit() throws IOException { // JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1")); try (Transaction tx = new DefaultTransaction(); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), tx)) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("intProperty"), Integer.valueOf(100)); writer.write(); writer.close(); tx.commit(); } SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures(); assertEquals(4, fc.size()); }
public void testGetFeatureWriterClose() throws Exception { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter( tname("road"), Filter.INCLUDE, Transaction.AUTO_COMMIT)) { writer.close(); try { assertFalse(writer.hasNext()); fail("Should not be able to use a closed writer"); } catch (Exception expected) { } try { assertNull(writer.next()); fail("Should not be able to use a closed writer"); } catch (Exception expected) { } } }
public void testConcurrentTransactions() throws IOException { try (Transaction tx1 = new DefaultTransaction(); Transaction tx2 = new DefaultTransaction(); FeatureWriter<SimpleFeatureType, SimpleFeature> w1 = dataStore.getFeatureWriterAppend(tname("ft1"), tx1); FeatureWriter<SimpleFeatureType, SimpleFeature> w2 = dataStore.getFeatureWriterAppend(tname("ft1"), tx2)) { SimpleFeature f1 = w1.next(); SimpleFeature f2 = w2.next(); f1.setAttribute(aname("intProperty"), Integer.valueOf(100)); f2.setAttribute(aname("intProperty"), Integer.valueOf(101)); w1.write(); w2.write(); w1.close(); w2.close(); tx1.commit(); tx2.commit(); } SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures(); assertEquals(5, fc.size()); }
private void testInsertEmptyGeometry(String type) throws Exception { WKTReader reader = new WKTReader(); Geometry emptyGeometry = reader.read(type.toUpperCase() + " EMPTY"); try (Transaction tx = new DefaultTransaction(); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("empty"), tx)) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("id"), Integer.valueOf(100)); feature.setAttribute(aname("geom_" + type.toLowerCase()), emptyGeometry); feature.setAttribute(aname("name"), new String("empty " + type)); writer.write(); writer.close(); tx.commit(); } SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("empty")).getFeatures(); assertEquals(1, fc.size()); try (SimpleFeatureIterator fi = fc.features()) { SimpleFeature nf = fi.next(); Geometry geometry = (Geometry) nf.getDefaultGeometry(); // either null or empty, we don't really care assertTrue(geometry == null || geometry.isEmpty()); } } }