Browse Source

DATAMONGO-1030 - Projections now work on single-entity query method executions.

We now correctly forward the domain type collection to the query executing a query for a projection type.
1.5.x
Oliver Gierke 11 years ago
parent
commit
440d16ebc6
  1. 2
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java
  2. 14
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
  3. 5
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java
  4. 25
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonSummary.java

2
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java

@ -284,7 +284,7 @@ public abstract class AbstractMongoQuery implements RepositoryQuery { @@ -284,7 +284,7 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
MongoEntityMetadata<?> metadata = method.getEntityInformation();
return countProjection ? operations.count(query, metadata.getJavaType()) : operations.findOne(query,
metadata.getJavaType());
metadata.getJavaType(), metadata.getCollectionName());
}
}

14
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

@ -949,4 +949,18 @@ public abstract class AbstractPersonRepositoryIntegrationTests { @@ -949,4 +949,18 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
public void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() {
assertThat(repository.findAll(person.id.in(Arrays.asList(dave.id, carter.id))), containsInAnyOrder(dave, carter));
}
/**
* @see DATAMONGO-1030
*/
@Test
public void executesSingleEntityQueryWithProjectionCorrectly() {
PersonSummary result = repository.findSummaryByLastname("Beauford");
assertThat(result, is(notNullValue()));
assertThat(result.firstname, is("Carter"));
assertThat(result.lastname, is("Beauford"));
}
}

5
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java

@ -302,4 +302,9 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query @@ -302,4 +302,9 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
*/
@Query("{lastname:?0, address.street:{$in:?1}}")
Page<Person> findByCustomQueryLastnameAndAddressStreetInList(String lastname, List<String> streetNames, Pageable page);
/**
* @see DATAMONGO-1030
*/
PersonSummary findSummaryByLastname(String lastname);
}

25
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonSummary.java

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
/*
* Copyright 2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.repository;
/**
* @author Oliver Gierke
*/
public class PersonSummary {
String firstname;
String lastname;
}
Loading…
Cancel
Save