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 87b7239e5..520fa0da3 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 @@ -534,9 +534,9 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } protected void doInsertList(List listToSave, MongoWriter writer) { - Map> objs = new HashMap>(); + Map> objs = new HashMap>(); - for (Object o : listToSave) { + for (T o : listToSave) { MongoPersistentEntity entity = mappingContext.getPersistentEntity(o.getClass()); if (entity == null) { @@ -545,17 +545,17 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } String collection = entity.getCollection(); - List objList = objs.get(collection); + List objList = objs.get(collection); if (null == objList) { - objList = new ArrayList(); + objList = new ArrayList(); objs.put(collection, objList); } objList.add(o); } - for (Map.Entry> entry : objs.entrySet()) { - insertList(entry.getKey(), entry.getValue()); + for (Map.Entry> entry : objs.entrySet()) { + doInsertList(entry.getKey(), entry.getValue(), this.mongoConverter); } } @@ -744,7 +744,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher return doUpdate(collectionName, query, update, null, false, true); } - private WriteResult doUpdate(final String collectionName, + protected WriteResult doUpdate(final String collectionName, final Query query, final Update update, final Class entityClass, @@ -812,10 +812,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher remove(determineCollectionName(targetClass), query, targetClass); } - private PersistentEntity getPersistentEntity(Class type) { - return type == null ? null : mappingContext.getPersistentEntity(type); - } - public void remove(String collectionName, final Query query, Class targetClass) { if (query == null) { throw new InvalidDataAccessApiUsageException("Query passed in to remove can't be null"); @@ -1056,10 +1052,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } } - private PersistentProperty getIdPropertyFor(Class type) { - return mappingContext.getPersistentEntity(type).getIdProperty(); - } - /** * Substitutes the id key if it is found in he query. Any 'id' keys will be replaced with '_id' and the value converted * to an ObjectId if possible. This conversion should match the way that the id fields are converted during read @@ -1141,6 +1133,14 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } } + private PersistentEntity getPersistentEntity(Class type) { + return type == null ? null : mappingContext.getPersistentEntity(type); + } + + private PersistentProperty getIdPropertyFor(Class type) { + return mappingContext.getPersistentEntity(type).getIdProperty(); + } + private ObjectId convertIdValue(MongoConverter converter, Object value) { ObjectId newValue = null; try {