@Override public boolean hasNext() { return proxied.hasNext(); }
@Override public boolean hasNext() { return cursor.hasNext(); }
@Override public boolean hasNext() { MongoCursor<Document> cursor = this.cursor; if (cursor == null) { return false; } try { return cursor.hasNext(); } catch (RuntimeException ex) { throw potentiallyConvertRuntimeException(ex, exceptionTranslator); } }
private Set<String> getTableMetadataNames(String schemaName) throws TableNotFoundException { MongoDatabase db = client.getDatabase(schemaName); MongoCursor<Document> cursor = db.getCollection(schemaCollection) .find().projection(new Document(TABLE_NAME_KEY, true)).iterator(); HashSet<String> names = new HashSet<>(); while (cursor.hasNext()) { names.add((cursor.next()).getString(TABLE_NAME_KEY)); } return names; }
/** * Perform the given operation on each of the values in the iterable container. * * @param iterable the iterable collection obtained from a MongoDB client; may not be null * @param operation the operation to perform; may not be null */ public static <T> void forEach(MongoIterable<T> iterable, Consumer<T> operation) { try (MongoCursor<T> cursor = iterable.iterator()) { while (cursor.hasNext()) { operation.accept(cursor.next()); } } }
private List<IndexInfo> getIndexData(MongoCursor<Document> cursor) { List<IndexInfo> indexInfoList = new ArrayList<IndexInfo>(); while (cursor.hasNext()) { Document ix = cursor.next(); IndexInfo indexInfo = IndexConverters.documentToIndexInfoConverter().convert(ix); indexInfoList.add(indexInfo); } return indexInfoList; } });
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 Page getNextPage() { verify(pageBuilder.isEmpty()); count = 0; for (int i = 0; i < ROWS_PER_REQUEST; i++) { if (!cursor.hasNext()) { finished = true; break; } currentDoc = cursor.next(); count++; pageBuilder.declarePosition(); for (int column = 0; column < columnTypes.size(); column++) { BlockBuilder output = pageBuilder.getBlockBuilder(column); appendTo(columnTypes.get(column), currentDoc.get(columnNames.get(column)), output); } } Page page = pageBuilder.build(); pageBuilder.reset(); return page; }
@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 emptyResult() throws Exception { when(cursor.hasNext()).thenReturn(false); check(repository.findAll().fetchAll().getUnchecked()).isEmpty(); 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 testAddEmpty() { Query<Data> query = getDs().find(Data.class); List<ObjectId> memberships = new ArrayList<ObjectId>(); query.or( query.criteria("id").hasAnyOf(memberships), query.criteria("otherIds").hasAnyOf(memberships) ); Assert.assertFalse(query.find().hasNext()); }
@Test public void testFetchKeys() { List<Complex> list = asList(new Complex(new ChildId("Turk", 27), "Turk"), new Complex(new ChildId("JD", 26), "Dorian"), new Complex(new ChildId("Carla", 29), "Espinosa")); getDs().save(list); MongoCursor<Key<Complex>> keys = getDs().find(Complex.class).keys(); assertTrue(keys.hasNext()); assertEquals(list.get(0).getId(), keys.next().getId()); assertEquals(list.get(1).getId(), keys.next().getId()); assertEquals(list.get(2).getId(), keys.next().getId()); assertFalse(keys.hasNext()); }
@Test public void testFetchKeys() { PhotoWithKeywords pwk1 = new PhotoWithKeywords("california", "nevada", "arizona"); PhotoWithKeywords pwk2 = new PhotoWithKeywords("Joe", "Sarah"); PhotoWithKeywords pwk3 = new PhotoWithKeywords("MongoDB", "World"); getDs().save(asList(pwk1, pwk2, pwk3)); MongoCursor<Key<PhotoWithKeywords>> keys = getDs().find(PhotoWithKeywords.class).keys(); assertTrue(keys.hasNext()); assertEquals(pwk1.id, keys.next().getId()); assertEquals(pwk2.id, keys.next().getId()); assertEquals(pwk3.id, keys.next().getId()); }