Moved QueryDslPredicateExecutor into Spring Data Commons.
This commit is contained in:
@@ -34,6 +34,7 @@ import org.springframework.data.document.mongodb.query.Index;
|
||||
import org.springframework.data.document.mongodb.query.Order;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mapping.model.MappingContext;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.querydsl.EntityPathResolver;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
import org.springframework.data.repository.support.EntityMetadata;
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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.document.mongodb.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.Predicate;
|
||||
|
||||
/**
|
||||
* Interface for query methods taking a QueryDsl {@link Predicate}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface QueryDslPredicateExecutor<T> {
|
||||
|
||||
/**
|
||||
* Returns a single entity matching the given {@link Predicate}.
|
||||
*
|
||||
* @param spec
|
||||
* @return
|
||||
*/
|
||||
T findOne(Predicate predicate);
|
||||
|
||||
/**
|
||||
* Returns all entities matching the given {@link Predicate}.
|
||||
*
|
||||
* @param spec
|
||||
* @return
|
||||
*/
|
||||
List<T> findAll(Predicate predicate);
|
||||
|
||||
/**
|
||||
* Returns all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s.
|
||||
*
|
||||
* @param predicate
|
||||
* @param orders
|
||||
* @return
|
||||
*/
|
||||
List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders);
|
||||
|
||||
/**
|
||||
* Returns a {@link Page} of entities matching the given {@link Predicate}.
|
||||
*
|
||||
* @param predicate
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Page<T> findAll(Predicate predicate, Pageable pageable);
|
||||
|
||||
/**
|
||||
* Returns the number of instances that the given {@link Predicate} will return.
|
||||
*
|
||||
* @param predicate
|
||||
* the {@link Predicate} to count instances for
|
||||
* @return the number of instances
|
||||
*/
|
||||
long count(Predicate predicate);
|
||||
}
|
||||
@@ -180,9 +180,9 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
@Test
|
||||
public void findsPeopleByQueryDslLastnameSpec() throws Exception {
|
||||
|
||||
List<Person> result = repository.findAll(person.lastname.eq("Matthews"));
|
||||
assertThat(result.size(), is(1));
|
||||
Iterable<Person> result = repository.findAll(person.lastname.eq("Matthews"));
|
||||
assertThat(result, hasItem(dave));
|
||||
assertThat(result, not(hasItems(carter, boyd, stefan, leroi, alicia)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,9 +192,9 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
dave.setAddress(address);
|
||||
repository.save(dave);
|
||||
|
||||
List<Person> result = repository.findAll(person.address.zipCode.eq("C0123"));
|
||||
assertThat(result.size(), is(1));
|
||||
Iterable<Person> result = repository.findAll(person.address.zipCode.eq("C0123"));
|
||||
assertThat(result, hasItem(dave));
|
||||
assertThat(result, not(hasItems(carter, boyd, stefan, leroi, alicia)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -54,6 +54,7 @@ public class MongoRepositoryFactoryUnitTests {
|
||||
MongoPersistentEntity entity;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void setUp() {
|
||||
when(template.getConverter()).thenReturn(converter);
|
||||
when(converter.getMappingContext()).thenReturn((MappingContext) mappingContext);
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.data.document.mongodb.geo.Point;
|
||||
import org.springframework.data.document.mongodb.repository.Person.Sex;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
|
||||
/**
|
||||
* Sample repository managing {@link Person} entities.
|
||||
|
||||
@@ -27,8 +27,9 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
||||
import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
||||
import org.springframework.data.document.mongodb.convert.MongoConverter;
|
||||
import org.springframework.data.document.mongodb.convert.SimpleMongoConverter;
|
||||
import org.springframework.data.document.mongodb.mapping.MongoMappingContext;
|
||||
import org.springframework.data.document.mongodb.query.BasicQuery;
|
||||
import org.springframework.data.document.mongodb.repository.MongoRepositoryFactoryBean.EntityInformationCreator;
|
||||
import org.springframework.data.repository.support.RepositoryMetadata;
|
||||
@@ -51,7 +52,7 @@ public class StringBasedMongoQueryUnitTests {
|
||||
@Mock
|
||||
EntityInformationCreator creator;
|
||||
|
||||
MongoConverter converter = new SimpleMongoConverter();
|
||||
MongoConverter converter = new MappingMongoConverter(new MongoMappingContext());
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -84,10 +85,11 @@ public class StringBasedMongoQueryUnitTests {
|
||||
|
||||
DBObject dbObject = new BasicDBObject();
|
||||
converter.write(address, dbObject);
|
||||
dbObject.removeField(MappingMongoConverter.CUSTOM_TYPE_KEY);
|
||||
|
||||
org.springframework.data.document.mongodb.query.Query query = mongoQuery.createQuery(accesor);
|
||||
org.springframework.data.document.mongodb.query.Query reference = new BasicQuery(new BasicDBObject("address",
|
||||
dbObject));
|
||||
BasicDBObject queryObject = new BasicDBObject("address", dbObject);
|
||||
org.springframework.data.document.mongodb.query.Query reference = new BasicQuery(queryObject);
|
||||
|
||||
assertThat(query.getQueryObject(), is(reference.getQueryObject()));
|
||||
}
|
||||
@@ -104,6 +106,7 @@ public class StringBasedMongoQueryUnitTests {
|
||||
|
||||
DBObject addressDbObject = new BasicDBObject();
|
||||
converter.write(address, addressDbObject);
|
||||
addressDbObject.removeField(MappingMongoConverter.CUSTOM_TYPE_KEY);
|
||||
|
||||
DBObject reference = new BasicDBObject("address", addressDbObject);
|
||||
reference.put("lastname", "Matthews");
|
||||
|
||||
Reference in New Issue
Block a user