Package net.csdn.mongo.commands

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

package net.csdn.mongo.commands;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import net.csdn.mongo.Callbacks;
import net.csdn.mongo.Document;

import static net.csdn.common.reflect.ReflectHelper.staticMethod;

/**
* User: WilliamZhu
* Date: 12-10-17
* Time: 下午2:07
*/
public class Save {

    public static boolean execute(Document doc) {
        Document parent = doc._parent;
        if (parent != null) {
            Save.execute(parent);
        } else {
            doc.runCallbacks(Callbacks.Callback.before_save);
            //we cannot call doc.collection().remove() directly,because of the dam inheritance of static methods in java
            DBCollection collection = (DBCollection) staticMethod(doc.getClass(), "collection");
            collection.save(new BasicDBObject(doc.attributes()));
            doc.runCallbacks(Callbacks.Callback.after_save);
        }

        return true;
    }
}
TOP

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

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.