public boolean hasNext() throws IOException { return delegate.hasNext(); }
/** * Query for more content. * * @see org.geotools.data.FeatureWriter#hasNext() */ public boolean hasNext() throws IOException { if (writer == null) { return false; } return writer.hasNext(); }
public boolean hasNext() throws IOException { live = null; return writer.hasNext(); }
@Override public boolean hasNext() throws IOException { return w.hasNext(); }
public boolean hasNext() throws IOException { return writer.hasNext(); }
/** 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; } }
/** * Utility method that ensures we are going to write only in append mode * * @return * @throws IOException */ private FeatureWriter<SimpleFeatureType, SimpleFeature> getWriterAppend() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = getWriter(Filter.INCLUDE, WRITER_ADD); while (writer.hasNext()) { writer.next(); } return writer; }
/** 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 testGetFeaturesWriterAdd() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); } assertFalse(writer.hasNext()); feature = (SimpleFeature) writer.next(); feature.setAttributes(newRoad.getAttributes()); writer.write(); assertFalse(writer.hasNext()); assertEquals(roadFeatures.length + 1, data.entry("road").getMemory().size()); }
public void testGetFeatureWriterRemove() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); SimpleFeature feature; while (writer.hasNext()) { feature = writer.next(); if (feature.getID().equals("road.rd1")) { writer.remove(); } } assertEquals(roadFeatures.length - 1, data.entry("road").getMemory().size()); }
public void testGetFeaturesWriterAdd() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(tname("road"), Transaction.AUTO_COMMIT)) { SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); } assertFalse(writer.hasNext()); feature = (SimpleFeature) writer.next(); feature.setAttributes(td.newRoad.getAttributes()); writer.write(); assertFalse(writer.hasNext()); assertEquals(td.roadFeatures.length + 1, count(tname("road"))); } }
public void testGetFeaturesWriterModify() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); SimpleFeature feature; while (writer.hasNext()) { feature = writer.next(); if (feature.getID().equals("road.rd1")) { feature.setAttribute("name", "changed"); writer.write(); } } feature = data.entry("road").getMemory().get("road.rd1"); assertEquals("changed", feature.getAttribute("name")); }
public void testGetFeatureWriter() throws NoSuchElementException, IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); assertEquals(roadFeatures.length, count(writer)); assertFalse(writer.hasNext()); try { writer.next(); fail("Should not be able to use a closed writer"); } catch (IOException expected) { } }
public void testGetFeatureWriterRemove() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = writer(tname("road"))) { SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); if (feature.getID().equals(td.roadFeatures[0].getID())) { writer.remove(); } } } assertEquals(td.roadFeatures.length - 1, count(tname("road"))); }
public void testGetFeatureWriterRemoveAll() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = writer(tname("road"))) { SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); writer.remove(); } } assertEquals(0, count(tname("road"))); }
public void testModifyFeatures() throws Exception { try (FeatureWriter<SimpleFeatureType, SimpleFeature> w = dataStore.getFeatureWriter(tname("guid"), Transaction.AUTO_COMMIT)) { w.hasNext(); SimpleFeature f = w.next(); f.setAttribute(aname("uuidProperty"), uuid2); assertEquals(uuid2, f.getAttribute(aname("uuidProperty"))); w.write(); } }
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 testGetFeaturesWriterModify() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = writer(tname("road"))) { while (writer.hasNext()) { SimpleFeature feature = (SimpleFeature) writer.next(); if (feature.getID().equals(td.roadFeatures[0].getID())) { feature.setAttribute(aname("name"), "changed"); writer.write(); } } } SimpleFeature feature = (SimpleFeature) feature(tname("road"), td.roadFeatures[0].getID()); assertNotNull(feature); assertEquals("changed", feature.getAttribute(aname("name"))); }
public void testWrite() throws Exception { int count = dataStore.getFeatureSource(tname("udt")).getCount(Query.ALL); try (FeatureWriter w = dataStore.getFeatureWriterAppend(tname("udt"), Transaction.AUTO_COMMIT)) { w.hasNext(); SimpleFeature f = (SimpleFeature) w.next(); f.setAttribute(aname("ut"), "abcd"); try { w.write(); fail("Write should have failed with UDT constraint failure"); } catch (Exception e) { } f.setAttribute(aname("ut"), "34cd"); w.write(); } assertEquals(count + 1, dataStore.getFeatureSource(tname("udt")).getCount(Query.ALL)); }
public void testGetFeatureWriterWithFilter() throws IOException { FilterFactory ff = dataStore.getFilterFactory(); Filter f = ff.equals(ff.property(aname("intProperty")), ff.literal(100)); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(f); assertEquals(0, features.size()); f = ff.equals(ff.property(aname("intProperty")), ff.literal(1)); try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(tname("ft1"), f, Transaction.AUTO_COMMIT)) { while (writer.hasNext()) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("intProperty"), Integer.valueOf(100)); writer.write(); } } f = ff.equals(ff.property(aname("intProperty")), ff.literal(100)); features = dataStore.getFeatureSource(tname("ft1")).getFeatures(f); assertEquals(1, features.size()); }