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.
This commit is contained in:
Oliver Gierke
2014-08-26 15:16:18 +02:00
parent 4eaef300cb
commit 7d69b840fe
4 changed files with 44 additions and 1 deletions

View File

@@ -317,7 +317,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());
}
}

View File

@@ -1011,4 +1011,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"));
}
}

View File

@@ -313,4 +313,8 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
*/
Page<Person> findTop3ByLastnameStartingWith(String lastname, Pageable pageRequest);
/**
* @see DATAMONGO-1030
*/
PersonSummary findSummaryByLastname(String lastname);
}

View File

@@ -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;
}