protected void initDS(final MongoClient mongoClient, final Morphia mor, final String db) { ds = (xyz.morphia.DatastoreImpl) mor.createDatastore(mongoClient, db); }
@Test public void testMorphiaDS() { new Morphia().createDatastore(getMongoClient(), "test"); }
protected TestBase(final MongoClient mongoClient) { this.mongoClient = mongoClient; this.db = getMongoClient().getDB(TEST_DB_NAME); this.database = getMongoClient().getDatabase(TEST_DB_NAME); this.ds = getMorphia().createDatastore(getMongoClient(), getDb().getName()); }
Mapper mapper = morphia.getMapper(); mapper.addMappedClass(Container.class); Datastore ds = morphia.createDatastore(getMongoClient(), "testDB");
@Test public void testReferencesWithoutMapping() { Child child1 = new Child(); getDs().save(child1); Parent parent1 = new Parent(); parent1.children.add(child1); getDs().save(parent1); List<Parent> parentList = toList(getDs().find(Parent.class).find()); Assert.assertEquals(1, parentList.size()); // reset Datastore to reset internal Mapper cache, so Child class // already cached by previous save is cleared Datastore localDs = getMorphia().createDatastore(getMongoClient(), new Mapper(), getDb().getName()); parentList = toList(localDs.find(Parent.class).find()); Assert.assertEquals(1, parentList.size()); }
@Test public void testMultipleDatabasesSingleThreaded() { getMorphia().map(FacebookUser.class); final Datastore ds1 = getMorphia().createDatastore(getMongoClient(), "db1"); final Datastore ds2 = getMorphia().createDatastore(getMongoClient(), "db2"); final FacebookUser db1Friend = new FacebookUser(3, "DB1 FaceBook Friend"); ds1.save(db1Friend); final FacebookUser db1User = new FacebookUser(1, "DB1 FaceBook User"); db1User.friends.add(db1Friend); ds1.save(db1User); final FacebookUser db2Friend = new FacebookUser(4, "DB2 FaceBook Friend"); ds2.save(db2Friend); final FacebookUser db2User = new FacebookUser(2, "DB2 FaceBook User"); db2User.friends.add(db2Friend); ds2.save(db2User); testFirstDatastore(ds1); testSecondDatastore(ds2); testFirstDatastore(ds1); testSecondDatastore(ds2); testFirstDatastore(ds1); testSecondDatastore(ds2); testFirstDatastore(ds1); testSecondDatastore(ds2); testStandardDatastore(); }
private void morphify() { String packageName = this.config.getString(MORPHIA_PACKAGE, DEFAULT_MORPHIA_PACKAGE); String dbName = this.config.getString(MONGODB_DBNAME, DEFAULT_MONGODB_NAME); this.morphia = new Morphia().mapPackage(packageName); this.datastore = this.morphia.createDatastore(this.mongoClient, dbName); LOG.info("Mapped Morphia models of package '" + packageName + "' and created Morphia Datastore with database '" + dbName + "'"); }