public DatastoreImpl( Morphia morphia, Mongo mongo, String dbName, String username, char[] password) { // this.morphia = morphia; this.mapr = morphia.getMapper(); this.mongo = mongo; this.db = mongo.getDB(dbName); if (username != null) if (!this.db.authenticate(username, password)) throw new AuthenticationException( "User '" + username + "' cannot be authenticated with the given password for database '" + dbName + "'"); // VERY discussable DatastoreHolder.getInstance().set(this); }
static { mor = new Morphia(); ds = mor.createDatastore("test"); }
@SuppressWarnings("unchecked") public static void mapClass(Class c) { mor.map(c); }
public static void mapPackage(String pkg) { mor.mapPackage(pkg, true); }
public static void setDatabase(String dbName) { if (!((DatastoreImpl) ds).getDB().getName().equals(dbName)) ds = mor.createDatastore(dbName); }