Search in sources :

Example 21 with Datastore

use of org.mongodb.morphia.Datastore in project morphia by mongodb.

the class VersionTest method testVersionsWithFindAndModify.

@Test
public void testVersionsWithFindAndModify() {
    final ALongPrimitive initial = new ALongPrimitive();
    Datastore ds = getDs();
    ds.save(initial);
    Query<ALongPrimitive> query = ds.find(ALongPrimitive.class).field("id").equal(initial.getId());
    UpdateOperations<ALongPrimitive> update = ds.createUpdateOperations(ALongPrimitive.class).set("text", "some new value");
    ALongPrimitive postUpdate = ds.findAndModify(query, update);
    Assert.assertEquals(initial.version + 1, postUpdate.version);
}
Also used : Datastore(org.mongodb.morphia.Datastore) Test(org.junit.Test)

Aggregations

Datastore (org.mongodb.morphia.Datastore)21 Test (org.junit.Test)15 BasicDBObject (com.mongodb.BasicDBObject)5 DBObject (com.mongodb.DBObject)4 DBCollection (com.mongodb.DBCollection)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Key (org.mongodb.morphia.Key)2 City (org.mongodb.morphia.geo.City)2 UpdateResults (org.mongodb.morphia.query.UpdateResults)2 MongoClient (com.mongodb.MongoClient)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Morphia (org.mongodb.morphia.Morphia)1 IndexOnValue (org.mongodb.morphia.entities.IndexOnValue)1 NamedIndexOnValue (org.mongodb.morphia.entities.NamedIndexOnValue)1 UniqueIndexOnValue (org.mongodb.morphia.entities.UniqueIndexOnValue)1