DATADOC-88 - Create MongoDbFactory to consolidate DB, Server location, and user credentials into one location
This commit is contained in:
@@ -9,6 +9,6 @@ public interface MongoDbFactory {
|
||||
|
||||
DB getDb() throws DataAccessException;
|
||||
|
||||
Mongo getMongo();
|
||||
DB getDb(String dbName) throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user