use of org.mongodb.morphia.Datastore in project morphia by mongodb.
the class ReferenceTest method testReferencesWithoutMapping.
@Test
public void testReferencesWithoutMapping() {
Child child1 = new Child();
getDs().save(child1);
Parent parent1 = new Parent();
parent1.children.add(child1);
getDs().save(parent1);
List<Parent> parentList = getDs().find(Parent.class).asList();
Assert.assertEquals(1, parentList.size());
// reset Datastore to reset internal Mapper cache, so Child class
// already cached by previous save is cleared
Datastore localDs = getMorphia().createDatastore(getMongoClient(), new Mapper(), getDb().getName());
parentList = localDs.find(Parent.class).asList();
Assert.assertEquals(1, parentList.size());
}
use of org.mongodb.morphia.Datastore in project morphia by mongodb.
the class TestMaxMin method testMaxCompoundIndex.
@Test
@SuppressWarnings("deprecation")
public void testMaxCompoundIndex() {
final IndexedEntity a1 = new IndexedEntity("a");
final IndexedEntity a2 = new IndexedEntity("a");
final IndexedEntity b1 = new IndexedEntity("b");
final IndexedEntity b2 = new IndexedEntity("b");
final IndexedEntity c1 = new IndexedEntity("c");
final IndexedEntity c2 = new IndexedEntity("c");
Datastore ds = getDs();
ds.save(a1);
ds.save(a2);
ds.save(b1);
ds.save(b2);
ds.save(c1);
ds.save(c2);
List<IndexedEntity> l = ds.find(IndexedEntity.class).order("testField, id").upperIndexBound(new BasicDBObject("testField", "b").append("_id", b2.id)).asList();
Assert.assertEquals("size", 3, l.size());
Assert.assertEquals("item", b1.id, l.get(2).id);
l = ds.find(IndexedEntity.class).order("testField, id").asList(new FindOptions().modifier("$max", new BasicDBObject("testField", "b").append("_id", b2.id)));
Assert.assertEquals("size", 3, l.size());
Assert.assertEquals("item", b1.id, l.get(2).id);
}
use of org.mongodb.morphia.Datastore in project morphia by mongodb.
the class MapObjectReference method syncKeys.
@SuppressWarnings("unchecked")
private void syncKeys() {
final Datastore ds = getDatastore();
keyMap.clear();
final Map<Object, Object> map = (Map) object;
for (final Map.Entry<Object, Object> e : map.entrySet()) {
keyMap.put(e.getKey(), ds.getKey(e.getValue()));
}
}
use of org.mongodb.morphia.Datastore in project morphia by mongodb.
the class TestMaxMin method testMinCompoundIndex.
@Test
@SuppressWarnings("deprecation")
public void testMinCompoundIndex() {
final IndexedEntity a1 = new IndexedEntity("a");
final IndexedEntity a2 = new IndexedEntity("a");
final IndexedEntity b1 = new IndexedEntity("b");
final IndexedEntity b2 = new IndexedEntity("b");
final IndexedEntity c1 = new IndexedEntity("c");
final IndexedEntity c2 = new IndexedEntity("c");
Datastore ds = getDs();
ds.save(a1);
ds.save(a2);
ds.save(b1);
ds.save(b2);
ds.save(c1);
ds.save(c2);
List<IndexedEntity> l = ds.find(IndexedEntity.class).order("testField, id").lowerIndexBound(new BasicDBObject("testField", "b").append("_id", b1.id)).asList();
Assert.assertEquals("size", 4, l.size());
Assert.assertEquals("item", b1.id, l.get(0).id);
l = ds.find(IndexedEntity.class).order("testField, id").asList(new FindOptions().modifier("$min", new BasicDBObject("testField", "b").append("_id", b1.id)));
Assert.assertEquals("size", 4, l.size());
Assert.assertEquals("item", b1.id, l.get(0).id);
}
use of org.mongodb.morphia.Datastore in project morphia by mongodb.
the class TestMaxMin method testMax.
@Test
@SuppressWarnings("deprecation")
public void testMax() {
final IndexedEntity a = new IndexedEntity("a");
final IndexedEntity b = new IndexedEntity("b");
final IndexedEntity c = new IndexedEntity("c");
Datastore ds = getDs();
ds.save(a);
ds.save(b);
ds.save(c);
Assert.assertEquals("last", b.id, ds.find(IndexedEntity.class).order("-id").upperIndexBound(new BasicDBObject("testField", "c")).get().id);
Assert.assertEquals("last", b.id, ds.find(IndexedEntity.class).order("-id").get(new FindOptions().modifier("$max", new BasicDBObject("testField", "c"))).id);
}
Aggregations