Examples of UpdateResults


Examples of org.mongodb.morphia.query.UpdateResults

        dbObj.put(versionKeyName, newVersion);
        mfVersion.setFieldValue(entity, newVersion);

        if (idValue != null && newVersion != 1) {
            final UpdateResults res = update(find(dbColl.getName(), entity.getClass()).filter(Mapper.ID_KEY, idValue)
                                                                                      .filter(versionKeyName, oldVersion),
                                             dbObj,
                                             false,
                                             false,
                                             wc
                                            );

            wr = res.getWriteResult();

            if (res.getUpdatedCount() != 1) {
                throw new ConcurrentModificationException(format("Entity of class %s (id='%s',version='%d') was concurrently updated.",
                                                                 entity.getClass().getName(), idValue, oldVersion));
            }
        } else {
            if (wc == null) {
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

    public <T> UpdateResults updateFirst(final Query<T> query, final T entity, final boolean createIfMissing) {
        final LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>();
        final DBObject dbObj = mapper.toDBObject(entity, involvedObjects);

        final UpdateResults res = update(query, dbObj, createIfMissing, false, getWriteConcern(entity));

        //update _id field
        if (res.getInsertedCount() > 0) {
            dbObj.put(Mapper.ID_KEY, res.getNewId());
        }

        postSaveOperations(involvedObjects);
        return res;
    }
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

        if (wr == null) {
            final Query<T> query = (Query<T>) createQuery(unwrapped.getClass()).filter(Mapper.ID_KEY, id);
            wr = update(query, new BasicDBObject("$set", dbObj), false, false, wc).getWriteResult();
        }

        final UpdateResults res = new UpdateResults(wr);

        if (res.getUpdatedCount() == 0) {
            throw new UpdateException("Nothing updated");
        }

        postSaveOperations(involvedObjects);
        return key;
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

            wr = dbColl.update(q, u, createIfMissing, multi);
        } else {
            wr = dbColl.update(q, u, createIfMissing, multi, wc);
        }

        return new UpdateResults(wr);
    }
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

        final Employee boss = getDs().find(Employee.class).field("manager").equal(null).get(); // get an employee without a manager
        Assert.assertNotNull(boss);
        final Key<Employee> key = getDs().save(new Employee("Scott", "Hernandez", getDs().getKey(boss), 150 * 1000));
        Assert.assertNotNull(key);

        final UpdateResults res = getDs().update(boss, getDs().createUpdateOperations(Employee.class)
                                                                     .add("underlings", key)); //add Scott as an employee of his manager
        Assert.assertNotNull(res);
        Assert.assertTrue("Should update existing document", res.getUpdatedExisting());
        Assert.assertEquals("Should update one document", 1, res.getUpdatedCount());

        final Employee scottsBoss = getDs().find(Employee.class).filter("underlings", key).get(); // get Scott's boss
        Assert.assertNotNull(scottsBoss);
        Assert.assertEquals(boss.id, scottsBoss.id);

View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

        final Query<Rectangle> q2 = getDs().find(Rectangle.class, "height", 2D);

        assertEquals(3, getDs().getCount(q1));
        assertEquals(0, getDs().getCount(q2));

        final UpdateResults results = getDs().update(q1, getDs().createUpdateOperations(Rectangle.class).inc("height"));
        assertUpdated(results, 3);

        assertEquals(0, getDs().getCount(q1));
        assertEquals(3, getDs().getCount(q2));
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

        assertNotNull(getDs().find(Rectangle.class, "width", 2D).get());
    }

    @Test
    public void testInsertUpdate() throws Exception {
        final UpdateResults res = getDs().update(getDs().createQuery(Circle.class).field("radius").equal(0),
                                                 getDs().createUpdateOperations(Circle.class).inc("radius", 1D), true);
        assertInserted(res);
    }
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

    @Test
    public void testSetUnset() throws Exception {
        final Key<Circle> key = getDs().save(new Circle(1));

        UpdateResults res = getDs().updateFirst(getDs().find(Circle.class, "radius", 1D),
                                                getDs().createUpdateOperations(Circle.class).set("radius", 2D));

        assertUpdated(res, 1);

        final Circle c = getDs().getByKey(Circle.class, key);
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

    @Test
    public void testSetOnInsertWhenInserting() throws Exception {
        checkMinServerVersion(2.4);
        ObjectId id = new ObjectId();
        UpdateResults res = getDs().updateFirst(getDs().createQuery(Circle.class).field("id").equal(id),
                                                getDs().createUpdateOperations(Circle.class).setOnInsert("radius", 2D), true);

        assertInserted(res);

        final Circle c = getDs().get(Circle.class, id);
View Full Code Here

Examples of org.mongodb.morphia.query.UpdateResults

    @Test
    public void testSetOnInsertWhenUpdating() throws Exception {
        checkMinServerVersion(2.4);
        ObjectId id = new ObjectId();
        UpdateResults res = getDs().updateFirst(getDs().createQuery(Circle.class).field("id").equal(id),
                                                getDs().createUpdateOperations(Circle.class).setOnInsert("radius", 1D), true);

        assertInserted(res);

        res = getDs().updateFirst(getDs().createQuery(Circle.class).field("id").equal(id),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.