Package mungbean.rhino

Source Code of mungbean.rhino.RhinoDBCollection

package mungbean.rhino;

import mungbean.AbstractDBCollection;
import mungbean.DBOperationExecutor;
import mungbean.ObjectId;
import mungbean.protocol.bson.BSONCoder;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class RhinoDBCollection extends AbstractDBCollection<ScriptableObject> {

    public RhinoDBCollection(DBOperationExecutor executor, String dbName, String collectionName, Scriptable scriptable, Context context) {
        super(executor, dbName, collectionName, new RhinoBSONCoders(context, scriptable), new RhinoBSONCoders(context, scriptable));
    }

    @Override
    protected BSONCoder<ScriptableObject> defaultEncoder() {
        return new RhinoBSONMap();
    }

    @Override
    protected ScriptableObject injectId(ScriptableObject doc) {
        if (!NativeObject.hasProperty(doc, "_id")) {
            NativeObject.putProperty(doc, "_id", new ObjectId());
        }
        return doc;
    }
}
TOP

Related Classes of mungbean.rhino.RhinoDBCollection

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.