// Path: app/models/MongoEntity.java
// public static ObjectId toId(String x) {
//     ObjectId bubu = null;
//     try { bubu = new ObjectId(x);} catch (Exception e ) {};
//     return bubu;
// }


import models.*;
import play.Logger;
import play.Play;
import static models.MongoEntity.toId;
import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.google.code.morphia.Morphia;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import java.util.LinkedList;
import java.util.List;
import org.bson.types.ObjectId;

    public static DB getDB() {
        return db;
    }

    protected static Mongo getMongo() {
        return mongo;
    }

    public static void shutdown() {
        Logger.info("Mongo stopping");
    }

    public static Morphia getMorphia() {
        return morphia;
    }

    public static void save(MongoEntity m) {
         m.getCollection().insert(morphia.toDBObject(m));
    }

    public static void update(MongoEntity m) {
         m.getCollection().save(morphia.toDBObject(m));
    }

    public static void delete(MongoEntity m) {
         m.getCollection().remove(morphia.toDBObject(m));
    }

    public static <T> T load(String id, String col, Class<T> entityClass) {
// Path: app/models/MongoEntity.java
// public static ObjectId toId(String x) {
//     ObjectId bubu = null;
//     try { bubu = new ObjectId(x);} catch (Exception e ) {};
//     return bubu;
// }


// Path: app/plugins/MongoDB.java
import models.*;
import play.Logger;
import play.Play;
import static models.MongoEntity.toId;
import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.google.code.morphia.Morphia;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import java.util.LinkedList;
import java.util.List;
import org.bson.types.ObjectId;


    public static DB getDB() {
        return db;
    }

    protected static Mongo getMongo() {
        return mongo;
    }

    public static void shutdown() {
        Logger.info("Mongo stopping");
    }

    public static Morphia getMorphia() {
        return morphia;
    }

    public static void save(MongoEntity m) {
         m.getCollection().insert(morphia.toDBObject(m));
    }

    public static void update(MongoEntity m) {
         m.getCollection().save(morphia.toDBObject(m));
    }

    public static void delete(MongoEntity m) {
         m.getCollection().remove(morphia.toDBObject(m));
    }

    public static <T> T load(String id, String col, Class<T> entityClass) {
        return load(toId(id), col, entityClass);