@Override public void close() { cursor.close(); } }
@Override public void close() { proxied.close(); }
private void discardCursor() { synchronized (cursorLock) { if (cursor != null) { cursor.close(); cursor = null; } } }
@Override public void close() { proxied.close(); }
@Override public void close() { cursor.close(); }
@Override public void close() { closed = true; if (cursor != null) { cursor.close(); cursor = null; setServerCursorOnFinalizer(null); } currentObject = null; }
@Override public T first() { final MongoCursor<T> iterator = iterator(); try { return iterator.tryNext(); } finally { iterator.close(); } }
@Override public void cancel() throws DataAccessResourceFailureException { synchronized (lifecycleMonitor) { if (State.RUNNING.equals(state) || State.STARTING.equals(state)) { this.state = State.CANCELLED; if (cursor != null) { cursor.close(); } } } }
static <TResult> void forEach(final MongoIterable<TResult> iterable, final Consumer<? super TResult> block) { MongoCursor<TResult> cursor = iterable.iterator(); try { while (cursor.hasNext()) { block.accept(cursor.next()); } } finally { cursor.close(); } }
@Override public T get(final FindOptions options) { final MongoCursor<T> it = find(options.copy().limit(1)); try { return it.tryNext(); } finally { it.close(); } }
@Override public Key<T> getKey(final FindOptions options) { final MongoCursor<Key<T>> it = keys(options.copy().limit(1)); try { return it.tryNext(); } finally { it.close(); } }
@Override public void forEach(final Block<? super TResult> block) { MongoCursor<TResult> cursor = iterator(); try { while (cursor.hasNext()) { block.apply(cursor.next()); } } finally { cursor.close(); } }
@Override public void forEach(final Block<? super T> block) { MongoCursor<T> cursor = iterator(); try { while (cursor.hasNext()) { block.apply(cursor.next()); } } finally { cursor.close(); } }
protected static <E> List<E> toList(final MongoCursor<E> cursor) { final List<E> results = new ArrayList<E>(); try { while (cursor.hasNext()) { results.add(cursor.next()); } } finally { cursor.close(); } return results; }
@Nullable @Override public TResult first() { MongoCursor<TResult> cursor = iterator(); try { if (!cursor.hasNext()) { return null; } return cursor.next(); } finally { cursor.close(); } }
@Override public void forEach(final Block<? super TResult> block) { MongoCursor<TResult> cursor = iterator(); try { while (cursor.hasNext()) { block.apply(cursor.next()); } } finally { cursor.close(); } }
private Document findOne(Document query, Document projection) { MongoCollection col = controllerService.getDatabase(databaseName).getCollection(collection); MongoCursor<Document> it = (projection != null ? col.find(query).projection(projection) : col.find(query)).iterator(); Document retVal = it.hasNext() ? it.next() : null; it.close(); return retVal; } }
@Test public void onException() throws Exception { when(cursor.hasNext()).thenReturn(true); when(cursor.next()).thenThrow(new IllegalStateException("boom")); try { repository.findAll().fetchAll().getUnchecked(); fail("Shouldn't get here"); } catch (Exception ignore) { // expected } verify(cursor, times(1)).close(); } }
@Test public void singleResult() throws Exception { when(cursor.hasNext()).thenReturn(true).thenReturn(false); when(cursor.next()).thenReturn(ImmutableEntity.of("foo")); check(repository.findAll().fetchAll().getUnchecked()).has(ImmutableEntity.of("foo")); verify(cursor, times(1)).close(); }
@Test public void emptyResult() throws Exception { when(cursor.hasNext()).thenReturn(false); check(repository.findAll().fetchAll().getUnchecked()).isEmpty(); verify(cursor, times(1)).close(); }