DATADOC-88 added accessors for Mongo and database name to MongoDbFactory

This commit is contained in:
Thomas Risberg
2011-05-17 12:13:42 -04:00
parent 9641434090
commit 30e96f9c97
3 changed files with 15 additions and 3 deletions

View File

@@ -3,9 +3,14 @@ package org.springframework.data.document.mongodb;
import org.springframework.dao.DataAccessException;
import com.mongodb.DB;
import com.mongodb.Mongo;
public interface MongoDbFactory {
DB getDb() throws DataAccessException;
Mongo getMongo();
String getDatabaseName();
}

View File

@@ -100,6 +100,14 @@ public class MongoDbFactoryBean implements MongoDbFactory, FactoryBean<DB>, Init
return MongoDbUtils.getDB(mongo, databaseName, username, password == null ? null : password.toCharArray());
}
public Mongo getMongo() {
return this.mongo;
}
public String getDatabaseName() {
return this.databaseName;
}
public DB getObject() throws Exception {
return getDb();
}

View File

@@ -1122,9 +1122,8 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
}
private void initializeMappingMongoConverter(MappingMongoConverter converter) {
DB db = this.mongoDbFactory.getDb();
converter.setMongo(db.getMongo());
converter.setDefaultDatabase(db.getName());
converter.setMongo(this.mongoDbFactory.getMongo());
converter.setDefaultDatabase(this.mongoDbFactory.getDatabaseName());
}
/**