iterator.close();
private List<SegmentIdWithShardSpec> getPendingSegmentsForIntervalWithHandle( final Handle handle, final String dataSource, final Interval interval ) throws IOException { final List<SegmentIdWithShardSpec> identifiers = new ArrayList<>(); final ResultIterator<byte[]> dbSegments = handle.createQuery( StringUtils.format( "SELECT payload FROM %1$s WHERE dataSource = :dataSource AND start <= :end and %2$send%2$s >= :start", dbTables.getPendingSegmentsTable(), connector.getQuoteString() ) ) .bind("dataSource", dataSource) .bind("start", interval.getStart().toString()) .bind("end", interval.getEnd().toString()) .map(ByteArrayMapper.FIRST) .iterator(); while (dbSegments.hasNext()) { final byte[] payload = dbSegments.next(); final SegmentIdWithShardSpec identifier = jsonMapper.readValue(payload, SegmentIdWithShardSpec.class); if (interval.overlaps(identifier.getInterval())) { identifiers.add(identifier); } } dbSegments.close(); return identifiers; }
@Override public synchronized void close() { if (!closed) { closed = true; iterator.close(); } } }
@Override public synchronized void close() { if (!closed) { closed = true; iterator.close(); } } }
public void close() { itty.close(); }
@Override public void close() { if (!closed) { closed = true; try { itty.close(); } finally { baton.release("iterator"); } } }
@Override public Void withHandle(final Handle handle) throws Exception { final ResultIterator<Map<String, Object>> iterator = handle.createQuery(queryBuilder.toString()) .bind("accountRecordId", context.getAccountRecordId()) .bind("tenantRecordId", context.getTenantRecordId()) .iterator(); try { while (iterator.hasNext()) { final Map<String, Object> row = iterator.next(); out.write(row); } } finally { iterator.close(); } return null; } });
@Test public void testIteratorPrepatureClose() throws Exception { HandleTrackerDBI dbi = new HandleTrackerDBI(ds); Spiffy spiffy = SqlObjectBuilder.onDemand(dbi, Spiffy.class); spiffy.insert(1, "Tom"); ResultIterator<Something> all = spiffy.findAll(); all.close(); assertFalse( dbi.hasOpenedHandle() ); }
@Test public void testIteratorPrepatureClose() throws Exception { HandleTrackerDBI dbi = new HandleTrackerDBI(ds); Spiffy spiffy = SqlObjectBuilder.onDemand(dbi, Spiffy.class); spiffy.insert(1, "Tom"); ResultIterator<Something> all = spiffy.findAll(); all.close(); assertFalse( dbi.hasOpenedHandle() ); }
@Test public void testLessLeakingJustNext() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); h.createStatement("insert into something (id, name) values (2, 'brian')").execute(); final ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); try { final Map<String, Object> result = it.next(); assertEquals(1, result.get("id")); assertEquals("eric", result.get("name")); assertFalse(h.isClosed()); } finally { it.close(); } } }
@Test public void testLessLeakingJustNext() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); h.createStatement("insert into something (id, name) values (2, 'brian')").execute(); final ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); try { final Map<String, Object> result = it.next(); assertEquals(1, result.get("id")); assertEquals("eric", result.get("name")); assertFalse(h.isClosed()); } finally { it.close(); } } }
@Test public void testBasicCleanupHalfwayIterator() throws Exception { final Handle handle = dbi.open(); final Query<Integer> q = handle.createQuery("SELECT id FROM something") .cleanupHandle() .mapTo(Integer.class); final ResultIterator<Integer> it = q.iterator(); for (int i = 0; i < COUNT / 2; i++) { assertTrue(it.hasNext()); it.next(); } assertTrue(it.hasNext()); assertFalse(handle.getConnection().isClosed()); it.close(); assertTrue(handle.getConnection().isClosed()); }
@Test public void testIteratorBehavior2() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); ResultIterator<Something> i = h.createQuery("select * from something order by id") .map(Something.class) .iterator(); Something first = i.next(); assertEquals("eric", first.getName()); Something second = i.next(); assertEquals(2, second.getId()); assertFalse(i.hasNext()); i.close(); }
@Test public void testIteratorBehavior2() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); ResultIterator<Something> i = h.createQuery("select * from something order by id") .map(Something.class) .iterator(); Something first = i.next(); assertEquals("eric", first.getName()); Something second = i.next(); assertEquals(2, second.getId()); assertFalse(i.hasNext()); i.close(); }
@Test public void testIteratedResult() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); ResultIterator<Something> i = h.createQuery("select * from something order by id") .map(Something.class) .iterator(); assertTrue(i.hasNext()); Something first = i.next(); assertEquals("eric", first.getName()); assertTrue(i.hasNext()); Something second = i.next(); assertEquals(2, second.getId()); assertFalse(i.hasNext()); i.close(); }
@Test public void testIteratedResult() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); ResultIterator<Something> i = h.createQuery("select * from something order by id") .map(Something.class) .iterator(); assertTrue(i.hasNext()); Something first = i.next(); assertEquals("eric", first.getName()); assertTrue(i.hasNext()); Something second = i.next(); assertEquals(2, second.getId()); assertFalse(i.hasNext()); i.close(); }
@Test public void testIteratorBehavior() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); ResultIterator<Something> i = h.createQuery("select * from something order by id") .map(Something.class) .iterator(); assertTrue(i.hasNext()); assertTrue(i.hasNext()); Something first = i.next(); assertEquals("eric", first.getName()); assertTrue(i.hasNext()); Something second = i.next(); assertEquals(2, second.getId()); assertFalse(i.hasNext()); i.close(); }
@Test public void testIteratorBehavior() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); ResultIterator<Something> i = h.createQuery("select * from something order by id") .map(Something.class) .iterator(); assertTrue(i.hasNext()); assertTrue(i.hasNext()); Something first = i.next(); assertEquals("eric", first.getName()); assertTrue(i.hasNext()); Something second = i.next(); assertEquals(2, second.getId()); assertFalse(i.hasNext()); i.close(); }
@Test public void testIteratorClose() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); h.createStatement("insert into something (id, name) values (2, 'brian')").execute(); h.createStatement("insert into something (id, name) values (3, 'john')").execute(); ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); assertTrue(it.hasNext()); assertFalse(h.isClosed()); it.next(); assertTrue(it.hasNext()); assertFalse(h.isClosed()); it.close(); assertFalse(it.hasNext()); assertTrue(h.isClosed()); } }
@Test public void testIteratorClose() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); h.createStatement("insert into something (id, name) values (2, 'brian')").execute(); h.createStatement("insert into something (id, name) values (3, 'john')").execute(); ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); assertTrue(it.hasNext()); assertFalse(h.isClosed()); it.next(); assertTrue(it.hasNext()); assertFalse(h.isClosed()); it.close(); assertFalse(it.hasNext()); assertTrue(h.isClosed()); } }