refactoring

This commit is contained in:
Thomas Risberg
2010-08-27 17:59:27 -04:00
parent 7f05a7e212
commit 307481edb4

View File

@@ -89,12 +89,10 @@ public class MongoTemplate extends AbstractDocumentStoreTemplate<DB> {
public void save(String collectionName, DocumentSource<DBObject> documentSource) { public void save(String collectionName, DocumentSource<DBObject> documentSource) {
DBObject dbDoc = documentSource.getDocument(); DBObject dbDoc = documentSource.getDocument();
DB db = getDocumentStoreConnectionFactory().getConnection();
WriteResult wr = null; WriteResult wr = null;
try { try {
wr = getDocumentStoreConnectionFactory() wr = db.getCollection(collectionName).save(dbDoc);
.getConnection()
.getCollection(collectionName)
.save(dbDoc);
} catch (MongoException e) { } catch (MongoException e) {
throw new DataRetrievalFailureException(wr.getLastError().getErrorMessage(), e); throw new DataRetrievalFailureException(wr.getLastError().getErrorMessage(), e);
} }
@@ -107,9 +105,8 @@ public class MongoTemplate extends AbstractDocumentStoreTemplate<DB> {
public <T> List<T> queryForCollection(String collectionName, DocumentMapper<DBObject, T> mapper) { public <T> List<T> queryForCollection(String collectionName, DocumentMapper<DBObject, T> mapper) {
List<T> results = new ArrayList<T>(); List<T> results = new ArrayList<T>();
DBCollection collection = getDocumentStoreConnectionFactory() DB db = getDocumentStoreConnectionFactory().getConnection();
.getConnection() DBCollection collection = db.getCollection(collectionName);
.getCollection(collectionName);
for (DBObject dbo : collection.find()) { for (DBObject dbo : collection.find()) {
results.add(mapper.mapDocument(dbo)); results.add(mapper.mapDocument(dbo));
} }