Browse Source

DATAMONGO-512 - Fixed broken handling of AND in query methods.

Apparently the fix fof DATAMONGO-469 was messed up later on.
1.0.x
Oliver Gierke 13 years ago
parent
commit
c1030abe96
  1. 9
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java
  2. 19
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
  3. 2
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java
  4. 2
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests.java
  5. 5
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryCreatorUnitTests.java

9
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java

@ -117,8 +117,11 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> { @@ -117,8 +117,11 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
}
PersistentPropertyPath<MongoPersistentProperty> path = context.getPersistentPropertyPath(part.getProperty());
return from(part.getType(), where(path.toDotPath(MongoPersistentProperty.PropertyToFieldNameConverter.INSTANCE)),
(PotentiallyConvertingIterator) iterator);
return new Criteria().andOperator(
base,
from(part.getType(), where(path.toDotPath(MongoPersistentProperty.PropertyToFieldNameConverter.INSTANCE)),
(PotentiallyConvertingIterator) iterator));
}
/*
@ -265,4 +268,4 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> { @@ -265,4 +268,4 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
return source.replaceAll("\\*", ".*");
}
}
}

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

@ -432,4 +432,21 @@ public abstract class AbstractPersonRepositoryIntegrationTests { @@ -432,4 +432,21 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
List<Person> result = repository.findByCreatedAtLessThanManually(boyd.createdAt);
assertThat(result.isEmpty(), is(false));
}
}
/**
* @see DATAMONGO-521
*/
@Test
public void executesAndQueryCorrectly() {
List<Person> result = repository.findByFirstnameAndLastname("Dave", "Matthews");
assertThat(result, hasSize(1));
assertThat(result, hasItem(dave));
result = repository.findByFirstnameAndLastname("Oliver August", "Matthews");
assertThat(result, hasSize(1));
assertThat(result, hasItem(oliver));
}
}

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

@ -106,6 +106,8 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query @@ -106,6 +106,8 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
*/
List<Person> findByFirstnameNotIn(Collection<String> firstnames);
List<Person> findByFirstnameAndLastname(String firstname, String lastname);
/**
* Returns all {@link Person}s with an age between the two given values.
*

2
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2010-2012 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.

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

@ -97,7 +97,8 @@ public class MongoQueryCreatorUnitTests { @@ -97,7 +97,8 @@ public class MongoQueryCreatorUnitTests {
getAccessor(converter, "Oliver", person), context);
Query query = creator.createQuery();
assertThat(query, is(query(where("firstName").is("Oliver").and("friend").is(person))));
Criteria criteria = new Criteria().andOperator(where("firstName").is("Oliver"), where("friend").is(person));
assertThat(query, is(query(criteria)));
}
@Test
@ -222,7 +223,7 @@ public class MongoQueryCreatorUnitTests { @@ -222,7 +223,7 @@ public class MongoQueryCreatorUnitTests {
}
/**
* @see DATAMONGO
* @see DATAMONGO-413
*/
@Test
public void createsOrQueryCorrectly() {

Loading…
Cancel
Save