Package net.csdn.mongo.commands

Source Code of net.csdn.mongo.commands.Update

package net.csdn.mongo.commands;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import net.csdn.common.reflect.ReflectHelper;
import net.csdn.mongo.Callbacks;
import net.csdn.mongo.Document;

/**
* User: WilliamZhu
* Date: 12-11-6
* Time: 下午2:38
*/
public class Update {
    public static boolean execute(Document doc, boolean validate) {
        Document parent = doc._parent;
        if (parent != null) {
            Update.execute(parent, validate);
        } else {
            doc.runCallbacks(Callbacks.Callback.before_update);
            //we cannot call doc.collection().remove() directly,because of the dam inheritance of static methods in java
            if (doc.id() == null) return false;
            DBCollection collection = (DBCollection) ReflectHelper.staticMethod(doc.getClass(), "collection");
            DBObject query = new BasicDBObject("_id", doc.id());
            collection.update(query,new BasicDBObject( doc.attributes()));
            doc.runCallbacks(Callbacks.Callback.after_update);
        }

        return true;
    }
}
TOP

Related Classes of net.csdn.mongo.commands.Update

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.