diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java index b38b6e377..6c7b4eb92 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java @@ -48,7 +48,6 @@ import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.document.mongodb.convert.MappingMongoConverter; import org.springframework.data.document.mongodb.convert.MongoConverter; -import org.springframework.data.document.mongodb.convert.SimpleMongoConverter; import org.springframework.data.document.mongodb.index.IndexDefinition; import org.springframework.data.document.mongodb.mapping.MongoMappingContext; import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity; @@ -186,8 +185,8 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } private final MongoConverter getDefaultMongoConverter() { - - SimpleMongoConverter converter = new SimpleMongoConverter(); + //ToDo: maybe add some additional configurations to this very basic one + MappingMongoConverter converter = new MappingMongoConverter(new MongoMappingContext()); converter.afterPropertiesSet(); return converter; } @@ -286,71 +285,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } } - /** - * Central callback executing method to do queries against the datastore that requires reading a single object from a - * collection of objects. It will take the following steps - *
    - *
  1. Execute the given {@link ConnectionCallback} for a {@link DBObject}.
  2. - *
  3. Apply the given {@link DbObjectCallback} to each of the {@link DBObject}s to obtain the result.
  4. - *
      - * - * @param - * @param collectionCallback the callback to retrieve the {@link DBObject} with - * @param objectCallback the {@link DbObjectCallback} to transform {@link DBObject}s into the actual domain type - * @param collectionName the collection to be queried - * @return - */ - private T execute(CollectionCallback collectionCallback, DbObjectCallback objectCallback, - String collectionName) { - - try { - T result = objectCallback.doWith(collectionCallback.doInCollection(getCollection(collectionName))); - return result; - } catch (RuntimeException e) { - throw potentiallyConvertRuntimeException(e); - } - } - - /** - * Central callback executing method to do queries against the datastore that requires reading a collection of - * objects. It will take the following steps - *
        - *
      1. Execute the given {@link ConnectionCallback} for a {@link DBCursor}.
      2. - *
      3. Prepare that {@link DBCursor} with the given {@link CursorPreparer} (will be skipped if {@link CursorPreparer} - * is {@literal null}
      4. - *
      5. Iterate over the {@link DBCursor} and applies the given {@link DbObjectCallback} to each of the - * {@link DBObject}s collecting the actual result {@link List}.
      6. - *
          - * - * @param - * @param collectionCallback the callback to retrieve the {@link DBCursor} with - * @param preparer the {@link CursorPreparer} to potentially modify the {@link DBCursor} before ireating over it - * @param objectCallback the {@link DbObjectCallback} to transform {@link DBObject}s into the actual domain type - * @param collectionName the collection to be queried - * @return - */ - private List executeEach(CollectionCallback collectionCallback, CursorPreparer preparer, - DbObjectCallback objectCallback, String collectionName) { - - try { - DBCursor cursor = collectionCallback.doInCollection(getCollection(collectionName)); - - if (preparer != null) { - cursor = preparer.prepare(cursor); - } - - List result = new ArrayList(); - - for (DBObject object : cursor) { - result.add(objectCallback.doWith(object)); - } - - return result; - } catch (RuntimeException e) { - throw potentiallyConvertRuntimeException(e); - } - } - /* (non-Javadoc) * @see org.springframework.data.document.mongodb.MongoOperations#executeInSession(org.springframework.data.document.mongodb.DBCallback) */ diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateUnitTests.java index 3030cc133..c3d0ad03b 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateUnitTests.java @@ -27,7 +27,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.dao.DataAccessException; -import org.springframework.data.document.mongodb.convert.SimpleMongoConverter; +import org.springframework.data.document.mongodb.convert.MappingMongoConverter; import org.springframework.test.util.ReflectionTestUtils; /** @@ -70,9 +70,9 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests { } @Test - public void defaultsConverterToSimpleMongoConverter() throws Exception { + public void defaultsConverterToMappingMongoConverter() throws Exception { MongoTemplate template = new MongoTemplate(mongo, "database"); - assertTrue(ReflectionTestUtils.getField(template, "mongoConverter") instanceof SimpleMongoConverter); + assertTrue(ReflectionTestUtils.getField(template, "mongoConverter") instanceof MappingMongoConverter); } /**