DATAMONGO-1729 - Open projections don't get field restrictions applied.
We now only apply a field restriction if the projection used for a query is closed.
This commit is contained in:
@@ -100,7 +100,7 @@ public class PartTreeMongoQuery extends AbstractMongoQuery {
|
|||||||
|
|
||||||
ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
|
ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
|
||||||
|
|
||||||
if (returnedType.isProjecting()) {
|
if (returnedType.needsCustomConstruction()) {
|
||||||
|
|
||||||
Field fields = query.fields();
|
Field fields = query.fields();
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.junit.rules.ExpectedException;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.mongodb.MongoDbFactory;
|
import org.springframework.data.mongodb.MongoDbFactory;
|
||||||
import org.springframework.data.mongodb.core.MongoOperations;
|
import org.springframework.data.mongodb.core.MongoOperations;
|
||||||
import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
||||||
@@ -172,6 +173,14 @@ public class PartTreeMongoQueryUnitTests {
|
|||||||
assertThat(query.getFieldsObject().get("firstname"), is((Object) 1));
|
assertThat(query.getFieldsObject().get("firstname"), is((Object) 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATAMONGO-1729
|
||||||
|
public void doesNotCreateFieldsObjectForOpenProjection() {
|
||||||
|
|
||||||
|
org.springframework.data.mongodb.core.query.Query query = deriveQueryFromMethod("findAllBy");
|
||||||
|
|
||||||
|
assertThat(query.getFieldsObject(), is(nullValue()));
|
||||||
|
}
|
||||||
|
|
||||||
private org.springframework.data.mongodb.core.query.Query deriveQueryFromMethod(String method, Object... args) {
|
private org.springframework.data.mongodb.core.query.Query deriveQueryFromMethod(String method, Object... args) {
|
||||||
|
|
||||||
Class<?>[] types = new Class<?>[args.length];
|
Class<?>[] types = new Class<?>[args.length];
|
||||||
@@ -232,6 +241,8 @@ public class PartTreeMongoQueryUnitTests {
|
|||||||
|
|
||||||
@Query(fields = "{ 'firstname' : 1 }")
|
@Query(fields = "{ 'firstname' : 1 }")
|
||||||
List<Person> findBySex(Sex sex);
|
List<Person> findBySex(Sex sex);
|
||||||
|
|
||||||
|
OpenProjection findAllBy();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PersonProjection {
|
interface PersonProjection {
|
||||||
@@ -256,4 +267,12 @@ public class PartTreeMongoQueryUnitTests {
|
|||||||
this.lastname = lastname;
|
this.lastname = lastname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OpenProjection {
|
||||||
|
|
||||||
|
String getFirstname();
|
||||||
|
|
||||||
|
@Value("#{target.firstname + ' ' + target.lastname}")
|
||||||
|
String getFullname();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user