refactoring
This commit is contained in:
@@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user