diff --git a/pom.xml b/pom.xml index 001acbdaa..9541b9f08 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ multi spring-data-mongodb - 1.6.4.RELEASE + 1.6.5.BUILD-SNAPSHOT 2.10.1 @@ -113,8 +113,8 @@ - spring-lib-release - http://repo.spring.io/libs-release + spring-lib-snapshot + http://repo.spring.io/libs-snapshot diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java index 88e4dc3cb..e6eb23759 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2010-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. @@ -79,22 +79,24 @@ public abstract class AbstractMongoQuery implements RepositoryQuery { MongoParameterAccessor accessor = new MongoParametersParameterAccessor(method, parameters); Query query = createQuery(new ConvertingParameterAccessor(operations.getConverter(), accessor)); + Object result = null; + if (method.isGeoNearQuery() && method.isPageQuery()) { MongoParameterAccessor countAccessor = new MongoParametersParameterAccessor(method, parameters); Query countQuery = createCountQuery(new ConvertingParameterAccessor(operations.getConverter(), countAccessor)); - return new GeoNearExecution(accessor).execute(query, countQuery); + result = new GeoNearExecution(accessor).execute(query, countQuery); } else if (method.isGeoNearQuery()) { return new GeoNearExecution(accessor).execute(query); } else if (method.isCollectionQuery()) { - return new CollectionExecution(accessor.getPageable()).execute(query); + result = new CollectionExecution(accessor.getPageable()).execute(query); } else if (method.isPageQuery()) { - return new PagedExecution(accessor.getPageable()).execute(query); + result = new PagedExecution(accessor.getPageable()).execute(query); + } else { + result = new SingleEntityExecution(isCountQuery()).execute(query); } - Object result = new SingleEntityExecution(isCountQuery()).execute(query); - if (result == null) { return result; } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java index b5b445f91..58dc8d95b 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-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. @@ -680,4 +680,16 @@ public abstract class AbstractPersonRepositoryIntegrationTests { assertThat(results.isLastPage(), is(true)); assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS)); } + + /** + * @see DATAMONGO-871 + */ + @Test + public void findsPersonsByFirstnameAsArray() { + + Person[] result = repository.findByThePersonsFirstnameAsArray("Leroi"); + + assertThat(result, is(arrayWithSize(1))); + assertThat(result, is(arrayContaining(leroi))); + } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java index df79b1b8a..4d10dbd21 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2010-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. @@ -69,6 +69,12 @@ public interface PersonRepository extends MongoRepository, Query @Query(value = "{ 'firstname' : ?0 }", fields = "{ 'firstname': 1, 'lastname': 1}") List findByThePersonsFirstname(String firstname); + /** + * @see DATAMONGO-871 + */ + @Query(value = "{ 'firstname' : ?0 }") + Person[] findByThePersonsFirstnameAsArray(String firstname); + /** * Returns all {@link Person}s with a firstname matching the given one (*-wildcard supported). *