DATADOC-88 - Create MongoDbFactory to consolidate DB, Server location, and user credentials into one location

This commit is contained in:
Mark Pollack
2011-05-24 17:23:02 -04:00
parent 2284a5137e
commit 69b1b9b96b
3 changed files with 10 additions and 2 deletions

View File

@@ -9,6 +9,6 @@ public interface MongoDbFactory {
DB getDb() throws DataAccessException;
Mongo getMongo();
DB getDb(String dbName) throws DataAccessException;
}

View File

@@ -50,6 +50,14 @@ public class SimpleMongoDbFactory implements MongoDbFactory {
Assert.hasText(databaseName, "Database name must not be empty");
return MongoDbUtils.getDB(mongo, databaseName, username, password == null ? null : password.toCharArray());
}
public DB getDb(String dbName) throws DataAccessException {
Assert.notNull(mongo, "Mongo must not be null");
Assert.hasText(dbName, "Database name must not be empty");
return MongoDbUtils.getDB(mongo, dbName, username, password == null ? null : password.toCharArray());
}
public Mongo getMongo() {
return this.mongo;

View File

@@ -596,7 +596,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
}
String dbname = dbref.db();
DB db = StringUtils.hasText(dbname) ? mongoDbFactory.getMongo().getDB(dbname) : mongoDbFactory.getDb();
DB db = StringUtils.hasText(dbname) ? mongoDbFactory.getDb(dbname) : mongoDbFactory.getDb();
return new DBRef(db, collection, id);
}