Package net.csdn.mongo.commands

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

package net.csdn.mongo.commands;

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

/**
* User: WilliamZhu
* Date: 12-11-6
* Time: 下午2:34
*/
public class Insert {
    public static boolean execute(Document doc, boolean validate) {
        Document parent = doc._parent;
        if (parent != null) {
            Insert.execute(parent, validate);
        } 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) ReflectHelper.staticMethod(doc.getClass(), "collection");
            collection.insert(new BasicDBObject(doc.attributes()));
            doc.runCallbacks(Callbacks.Callback.after_save);
        }

        return true;
    }
}
TOP

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

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.