use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestUriMapping method testURIField.
@Test
public void testURIField() throws URISyntaxException {
final ContainsURI entity = new ContainsURI();
final URI testURI = new URI("http://lamest.local/test.html");
entity.uri = testURI;
getDs().save(entity);
final ContainsURI loaded = getDs().find(ContainsURI.class).iterator(new FindOptions().limit(1)).tryNext();
assertNotNull(loaded.uri);
assertEquals(testURI, loaded.uri);
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestUriMapping method testURIMap.
@Test
public void testURIMap() throws URISyntaxException {
final ContainsURIKeyedMap entity = new ContainsURIKeyedMap();
final URI testURI = new URI("http://lamest.local/test.html");
entity.uris.put(testURI, "first");
getDs().save(entity);
final ContainsURIKeyedMap loaded = getDs().find(ContainsURIKeyedMap.class).iterator(new FindOptions().limit(1)).tryNext();
assertNotNull(loaded.uris);
assertEquals(loaded.uris.size(), 1);
assertEquals(testURI, loaded.uris.keySet().iterator().next());
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestQuery method testAliasedFieldSort.
@Test
public void testAliasedFieldSort() {
getDs().save(asList(new Rectangle(1, 10), new Rectangle(3, 8), new Rectangle(6, 10), new Rectangle(10, 10), new Rectangle(10, 1)));
Rectangle r1 = getDs().find(Rectangle.class).iterator(new FindOptions().sort(ascending("w")).limit(1)).tryNext();
assertNotNull(r1);
assertEquals(r1.getWidth(), 1, 0);
r1 = getDs().find(Rectangle.class).iterator(new FindOptions().sort(descending("w")).limit(1)).tryNext();
assertNotNull(r1);
assertEquals(r1.getWidth(), 10, 0);
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestQuery method testReturnOnlyIndexedFields.
@Test
public void testReturnOnlyIndexedFields() {
getMapper().map(Pic.class);
getDs().ensureIndexes(Pic.class);
getDs().save(asList(new Pic("pic1"), new Pic("pic2"), new Pic("pic3"), new Pic("pic4")));
Pic foundItem = getDs().find(Pic.class).filter(eq("name", "pic2")).first(new FindOptions().limit(1).returnKey(true));
assertNotNull(foundItem);
assertThat("Name should be populated", foundItem.getName(), is("pic2"));
assertNull(foundItem.getId(), "ID should not be populated");
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestQuery method testProjectArrayField.
@Test
public void testProjectArrayField() {
int[] ints = { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 };
IntVector vector = new IntVector(ints);
getDs().save(vector);
assertEquals(copy(ints, 0, 4), getDs().find(IntVector.class).iterator(new FindOptions().projection().project("scalars", new ArraySlice(4)).limit(1)).next().scalars);
assertEquals(copy(ints, 5, 4), getDs().find(IntVector.class).iterator(new FindOptions().projection().project("scalars", new ArraySlice(5, 4)).limit(1)).next().scalars);
assertEquals(copy(ints, ints.length - 10, 6), getDs().find(IntVector.class).iterator(new FindOptions().projection().project("scalars", new ArraySlice(-10, 6)).limit(1)).next().scalars);
assertEquals(copy(ints, ints.length - 12, 12), getDs().find(IntVector.class).iterator(new FindOptions().projection().project("scalars", new ArraySlice(-12)).limit(1)).next().scalars);
}
Aggregations