diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DbRefResolver.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DbRefResolver.java
index a43b742c6..8efedbee5 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DbRefResolver.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DbRefResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2015 the original author or authors.
+ * Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.springframework.data.mongodb.core.convert;
+import java.util.List;
+
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
@@ -64,4 +66,14 @@ public interface DbRefResolver {
* @since 1.7
*/
DBObject fetch(DBRef dbRef);
+
+ /**
+ * Loads a given {@link List} of {@link DBRef}s from the datasource in one batch.
+ * The {@link DBRef} elements in the list must not reference different collections.
+ *
+ * @param dbRefs must not be {@literal null}.
+ * @return never {@literal null}.
+ * @since 1.10
+ */
+ List bulkFetch(List dbRefs);
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java
index cbffcf1f5..850a8c7ba 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java
@@ -22,6 +22,10 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
@@ -31,6 +35,7 @@ import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.Factory;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.dao.DataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.mongodb.LazyLoadingException;
import org.springframework.data.mongodb.MongoDbFactory;
@@ -40,6 +45,9 @@ import org.springframework.objenesis.ObjenesisStd;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
+import com.mongodb.BasicDBObject;
+import com.mongodb.BasicDBObjectBuilder;
+import com.mongodb.DB;
import com.mongodb.DBObject;
import com.mongodb.DBRef;
@@ -109,6 +117,40 @@ public class DefaultDbRefResolver implements DbRefResolver {
return ReflectiveDBRefResolver.fetch(mongoDbFactory, dbRef);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.mongodb.core.convert.DbRefResolver#bulkFetch(java.util.List)
+ */
+ @Override
+ public List bulkFetch(List refs) {
+
+ Assert.notNull(mongoDbFactory, "Factory must not be null!");
+ Assert.notNull(refs, "DBRef to fetch must not be null!");
+
+ if (refs.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ String collection = refs.iterator().next().getCollectionName();
+
+ List