use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestQueriesOnReferences method testQueryOverReference.
@Test
public void testQueryOverReference() {
final ContainsPic cpk = new ContainsPic();
final Pic p = new Pic();
getDs().save(p);
cpk.setPic(p);
getDs().save(cpk);
final Query<ContainsPic> query = getDs().find(ContainsPic.class);
final ContainsPic object = query.filter(eq("pic", p)).iterator(new FindOptions().limit(1)).tryNext();
assertNotNull(object);
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestQueriesOnReferences method testQueryOverLazyReference.
@Test
public void testQueryOverLazyReference() {
final ContainsPic cpk = new ContainsPic();
final Pic p = new Pic();
getDs().save(p);
final PicWithObjectId withObjectId = new PicWithObjectId();
getDs().save(withObjectId);
cpk.setLazyPic(p);
cpk.setLazyObjectIdPic(withObjectId);
getDs().save(cpk);
Query<ContainsPic> query = getDs().find(ContainsPic.class);
assertNotNull(query.filter(eq("lazyPic", p)).iterator(new FindOptions().limit(1)).tryNext());
query = getDs().find(ContainsPic.class);
assertNotNull(query.filter(eq("lazyObjectIdPic", withObjectId)).iterator(new FindOptions().limit(1)).tryNext());
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestTextSearching method testTextSearchWithMeta.
@Test
public void testTextSearchWithMeta() {
getMapper().map(Book.class);
getDs().ensureIndexes();
getDs().save(asList(new Book("The Banquet", "Dante"), new Book("Divine Comedy", "Dante"), new Book("Eclogues", "Dante"), new Book("The Odyssey", "Homer"), new Book("Iliad", "Homer")));
List<Book> books = getDs().find(Book.class).filter(text("Dante")).iterator(new FindOptions().sort(Meta.textScore("score"))).toList();
assertEquals(books.size(), 3);
for (Book book : books) {
assertEquals(book.author, "Dante");
}
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestLazyCircularReference method testCircularReferences.
public void testCircularReferences() {
RootEntity root = new RootEntity();
ReferencedEntity first = new ReferencedEntity();
ReferencedEntity second = new ReferencedEntity();
getDs().save(asList(root, first, second));
root.r = first;
root.secondReference = second;
first.parent = root;
second.parent = root;
getDs().save(asList(root, first, second));
RootEntity rootEntity = getDs().find(RootEntity.class).iterator(new FindOptions().limit(1)).tryNext();
assertEquals(first.getId(), rootEntity.getR().getId());
assertEquals(second.getId(), rootEntity.getSecondReference().getId());
assertEquals(root.getId(), rootEntity.getR().getParent().getId());
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestSingleToMultipleConversion method testBasicType.
@Test
public void testBasicType() {
getDs().find(HasSingleString.class).delete();
getDs().save(new HasSingleString());
Assert.assertNotNull(getDs().find(HasSingleString.class).iterator(new FindOptions().limit(1)).next());
Assert.assertEquals(getDs().find(HasSingleString.class).count(), 1);
final HasManyStringsArray hms = getDs().find(HasManyStringsArray.class).iterator(new FindOptions().limit(1)).next();
Assert.assertNotNull(hms);
Assert.assertNotNull(hms.strings);
Assert.assertEquals(hms.strings.length, 1);
final HasManyStringsList hms2 = getDs().find(HasManyStringsList.class).iterator(new FindOptions().limit(1)).next();
Assert.assertNotNull(hms2);
Assert.assertNotNull(hms2.strings);
Assert.assertEquals(hms2.strings.size(), 1);
}
Aggregations