DATAMONGO-1668 - Polishing.
Replace new Sort(…) with Sort.by(…) and new PageRequest(…) with PageRequest.of(…).
This commit is contained in:
@@ -348,7 +348,7 @@ public class Aggregation {
|
||||
* @return
|
||||
*/
|
||||
public static SortOperation sort(Direction direction, String... fields) {
|
||||
return new SortOperation(new Sort(direction, fields));
|
||||
return new SortOperation(Sort.by(direction, fields));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,7 +585,7 @@ public class Aggregation {
|
||||
return command;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/sort/">MongoDB Aggregation Framework: $sort</a>
|
||||
*/
|
||||
@@ -40,7 +41,7 @@ public class SortOperation implements AggregationOperation {
|
||||
|
||||
/**
|
||||
* Creates a new {@link SortOperation} for the given {@link Sort} instance.
|
||||
*
|
||||
*
|
||||
* @param sort must not be {@literal null}.
|
||||
*/
|
||||
public SortOperation(Sort sort) {
|
||||
@@ -50,14 +51,14 @@ public class SortOperation implements AggregationOperation {
|
||||
}
|
||||
|
||||
public SortOperation and(Direction direction, String... fields) {
|
||||
return and(new Sort(direction, fields));
|
||||
return and(Sort.by(direction, fields));
|
||||
}
|
||||
|
||||
public SortOperation and(Sort sort) {
|
||||
return new SortOperation(this.sort.and(sort));
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
|
||||
@@ -57,7 +57,6 @@ import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
@@ -1122,7 +1121,7 @@ public class MongoTemplateTests {
|
||||
|
||||
// test query with a sort
|
||||
Query q2 = new Query(Criteria.where("age").gt(10));
|
||||
q2.with(new Sort(Direction.DESC, "age"));
|
||||
q2.with(Sort.by(Direction.DESC, "age"));
|
||||
PersonWithAList p5 = template.findOne(q2, PersonWithAList.class);
|
||||
assertThat(p5.getFirstName(), is("Mark"));
|
||||
}
|
||||
@@ -2064,8 +2063,8 @@ public class MongoTemplateTests {
|
||||
|
||||
assertThat(template.count(query, Sample.class), is(1L));
|
||||
|
||||
query.with(new PageRequest(0, 10));
|
||||
query.with(new Sort("field"));
|
||||
query.with(PageRequest.of(0, 10));
|
||||
query.with(Sort.by("field"));
|
||||
|
||||
assertThat(template.find(query, Sample.class), is(not(empty())));
|
||||
}
|
||||
@@ -2696,7 +2695,7 @@ public class MongoTemplateTests {
|
||||
template.save(one);
|
||||
template.save(two);
|
||||
|
||||
Query query = query(where("_id").in("1", "2")).with(new Sort(Direction.DESC, "someIdKey"));
|
||||
Query query = query(where("_id").in("1", "2")).with(Sort.by(Direction.DESC, "someIdKey"));
|
||||
assertThat(template.find(query, DoucmentWithNamedIdField.class), contains(two, one));
|
||||
}
|
||||
|
||||
@@ -2714,7 +2713,7 @@ public class MongoTemplateTests {
|
||||
template.save(one);
|
||||
template.save(two);
|
||||
|
||||
Query query = query(where("_id").in("1", "2")).with(new Sort(Direction.DESC, "value"));
|
||||
Query query = query(where("_id").in("1", "2")).with(Sort.by(Direction.DESC, "value"));
|
||||
assertThat(template.find(query, DoucmentWithNamedIdField.class), contains(two, one));
|
||||
}
|
||||
|
||||
@@ -2819,7 +2818,7 @@ public class MongoTemplateTests {
|
||||
template.insertAll(Arrays.asList(oldestPerson, youngestPerson));
|
||||
|
||||
Query q = new Query();
|
||||
q.with(new Sort(Direction.ASC, "age"));
|
||||
q.with(Sort.by(Direction.ASC, "age"));
|
||||
CloseableIterator<Person> stream = template.stream(q, Person.class);
|
||||
|
||||
assertThat(stream.next().getAge(), is(youngestPerson.getAge()));
|
||||
@@ -2835,7 +2834,7 @@ public class MongoTemplateTests {
|
||||
template.insertAll(Arrays.asList(oldestPerson, youngestPerson));
|
||||
|
||||
Query q = new Query();
|
||||
q.with(new PageRequest(0, 1, new Sort(Direction.ASC, "age")));
|
||||
q.with(PageRequest.of(0, 1, Sort.by(Direction.ASC, "age")));
|
||||
CloseableIterator<Person> stream = template.stream(q, Person.class);
|
||||
|
||||
assertThat(stream.next().getAge(), is(youngestPerson.getAge()));
|
||||
|
||||
@@ -87,6 +87,7 @@ import com.mongodb.client.result.UpdateResult;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@@ -321,7 +322,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Test // DATAMONGO-948
|
||||
public void sortShouldBeTakenAsIsWhenExecutingQueryWithoutSpecificTypeInformation() {
|
||||
|
||||
Query query = Query.query(Criteria.where("foo").is("bar")).with(new Sort("foo"));
|
||||
Query query = Query.query(Criteria.where("foo").is("bar")).with(Sort.by("foo"));
|
||||
template.executeQuery(query, "collection1", new DocumentCallbackHandler() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,15 +26,16 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SortOperation}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SortOperationUnitTests {
|
||||
|
||||
@Test
|
||||
public void createsDocumentForAscendingSortCorrectly() {
|
||||
|
||||
SortOperation operation = new SortOperation(new Sort(Direction.ASC, "foobar"));
|
||||
SortOperation operation = new SortOperation(Sort.by(Direction.ASC, "foobar"));
|
||||
Document result = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
Document sortValue = getAsDocument(result, "$sort");
|
||||
@@ -45,7 +46,7 @@ public class SortOperationUnitTests {
|
||||
@Test
|
||||
public void createsDocumentForDescendingSortCorrectly() {
|
||||
|
||||
SortOperation operation = new SortOperation(new Sort(Direction.DESC, "foobar"));
|
||||
SortOperation operation = new SortOperation(Sort.by(Direction.DESC, "foobar"));
|
||||
Document result = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
Document sortValue = getAsDocument(result, "$sort");
|
||||
|
||||
@@ -64,7 +64,7 @@ import com.mongodb.QueryBuilder;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QueryMapper}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Patryk Wasik
|
||||
* @author Thomas Darimont
|
||||
@@ -565,7 +565,7 @@ public class QueryMapperUnitTests {
|
||||
@Test // DATAMONGO-647
|
||||
public void customizedFieldNameShouldBeMappedCorrectlyWhenApplyingSort() {
|
||||
|
||||
Query query = query(where("field").is("bar")).with(new Sort(Direction.DESC, "field"));
|
||||
Query query = query(where("field").is("bar")).with(Sort.by(Direction.DESC, "field"));
|
||||
org.bson.Document document = mapper.getMappedObject(query.getSortObject(),
|
||||
context.getPersistentEntity(CustomizedField.class));
|
||||
assertThat(document, equalTo(new org.bson.Document().append("foo", -1)));
|
||||
@@ -597,7 +597,7 @@ public class QueryMapperUnitTests {
|
||||
@Test // DATAMONGO-973
|
||||
public void getMappedSortAppendsTextScoreProperlyWhenSortedByScore() {
|
||||
|
||||
Query query = new Query().with(new Sort("textScore"));
|
||||
Query query = new Query().with(Sort.by("textScore"));
|
||||
|
||||
org.bson.Document document = mapper.getMappedSort(query.getSortObject(),
|
||||
context.getPersistentEntity(WithTextScoreProperty.class));
|
||||
@@ -608,7 +608,7 @@ public class QueryMapperUnitTests {
|
||||
@Test // DATAMONGO-973
|
||||
public void getMappedSortIgnoresTextScoreWhenNotSortedByScore() {
|
||||
|
||||
Query query = new Query().with(new Sort("id"));
|
||||
Query query = new Query().with(Sort.by("id"));
|
||||
|
||||
org.bson.Document document = mapper.getMappedSort(query.getSortObject(),
|
||||
context.getPersistentEntity(WithTextScoreProperty.class));
|
||||
@@ -643,7 +643,7 @@ public class QueryMapperUnitTests {
|
||||
@Test // DATAMONGO-1050
|
||||
public void shouldUseExplicitlySetFieldnameForIdPropertyCandidatesUsedInSortClause() {
|
||||
|
||||
Query query = new Query().with(new Sort("nested.id"));
|
||||
Query query = new Query().with(Sort.by("nested.id"));
|
||||
|
||||
org.bson.Document document = mapper.getMappedSort(query.getSortObject(),
|
||||
context.getPersistentEntity(RootForClassWithExplicitlyRenamedIdField.class));
|
||||
|
||||
@@ -379,7 +379,7 @@ public class UpdateMapperUnitTests {
|
||||
public void updatePushEachWithDocumentSortShouldRenderCorrectly() {
|
||||
|
||||
Update update = new Update().push("list")
|
||||
.sort(new Sort(new Order(Direction.ASC, "value"), new Order(Direction.ASC, "field")))
|
||||
.sort(Sort.by(new Order(Direction.ASC, "value"), new Order(Direction.ASC, "field")))
|
||||
.each(Collections.emptyList());
|
||||
|
||||
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(),
|
||||
@@ -397,7 +397,7 @@ public class UpdateMapperUnitTests {
|
||||
public void updatePushEachWithSortShouldRenderCorrectlyWhenUsingMultiplePush() {
|
||||
|
||||
Update update = new Update().push("authors").sort(Direction.ASC).each("Harry").push("chapters")
|
||||
.sort(new Sort(Direction.ASC, "order")).each(Collections.emptyList());
|
||||
.sort(Sort.by(Direction.ASC, "order")).each(Collections.emptyList());
|
||||
|
||||
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Object.class));
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import com.mongodb.client.MongoCollection;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class MappingTests extends AbstractIntegrationTests {
|
||||
|
||||
@@ -427,7 +428,7 @@ public class MappingTests extends AbstractIntegrationTests {
|
||||
template.insert(p4);
|
||||
|
||||
Query q = query(where("id").in("1", "2"));
|
||||
q.with(new Sort(Direction.ASC, "id"));
|
||||
q.with(Sort.by(Direction.ASC, "id"));
|
||||
List<PersonPojoStringId> people = template.find(q, PersonPojoStringId.class);
|
||||
assertEquals(2, people.size());
|
||||
|
||||
|
||||
@@ -29,10 +29,11 @@ import org.springframework.data.mongodb.core.DocumentTestUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link NearQuery}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class NearQueryUnitTests {
|
||||
|
||||
@@ -86,7 +87,7 @@ public class NearQueryUnitTests {
|
||||
@Test // DATAMONGO-445
|
||||
public void shouldTakeSkipAndLimitSettingsFromGivenPageable() {
|
||||
|
||||
Pageable pageable = new PageRequest(3, 5);
|
||||
Pageable pageable = PageRequest.of(3, 5);
|
||||
NearQuery query = NearQuery.near(new Point(1, 1)).with(pageable);
|
||||
|
||||
assertThat(query.getSkip(), is((long)pageable.getPageNumber() * pageable.getPageSize()));
|
||||
@@ -110,7 +111,7 @@ public class NearQueryUnitTests {
|
||||
|
||||
int limit = 10;
|
||||
int skip = 5;
|
||||
Pageable pageable = new PageRequest(3, 5);
|
||||
Pageable pageable = PageRequest.of(3, 5);
|
||||
NearQuery query = NearQuery.near(new Point(1, 1))
|
||||
.query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip)).with(pageable);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.data.mongodb.core.SpecialDoc;
|
||||
* @author Patryk Wasik
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class QueryTests {
|
||||
|
||||
@@ -190,7 +191,7 @@ public class QueryTests {
|
||||
@Test // DATAMONGO-538
|
||||
public void addsSortCorrectly() {
|
||||
|
||||
Query query = new Query().with(new Sort(Direction.DESC, "foo"));
|
||||
Query query = new Query().with(Sort.by(Direction.DESC, "foo"));
|
||||
assertThat(query.getSortObject(), is(Document.parse("{ \"foo\" : -1}")));
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ public class QueryTests {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("foo");
|
||||
|
||||
new Query().with(new Sort(new Sort.Order("foo").ignoreCase()));
|
||||
new Query().with(Sort.by(new Sort.Order("foo").ignoreCase()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-709
|
||||
|
||||
@@ -25,27 +25,30 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
* Unit tests for sorting.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SortTests {
|
||||
|
||||
@Test
|
||||
public void testWithSortAscending() {
|
||||
Query s = new Query().with(new Sort(Direction.ASC, "name"));
|
||||
|
||||
Query s = new Query().with(Sort.by(Direction.ASC, "name"));
|
||||
assertEquals(Document.parse("{ \"name\" : 1}"), s.getSortObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSortDescending() {
|
||||
Query s = new Query().with(new Sort(Direction.DESC, "name"));
|
||||
|
||||
Query s = new Query().with(Sort.by(Direction.DESC, "name"));
|
||||
assertEquals(Document.parse("{ \"name\" : -1}"), s.getSortObject());
|
||||
}
|
||||
|
||||
@Test // DATADOC-177
|
||||
public void preservesOrderKeysOnMultipleSorts() {
|
||||
|
||||
Query sort = new Query().with(new Sort(Direction.DESC, "foo").and(new Sort(Direction.DESC, "bar")));
|
||||
Query sort = new Query().with(Sort.by(Direction.DESC, "foo").and(Sort.by(Direction.DESC, "bar")));
|
||||
assertThat(sort.getSortObject(), is(Document.parse("{ \"foo\" : -1 , \"bar\" : -1}")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.springframework.data.util.Version;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class TextQueryTests extends AbstractIntegrationTests {
|
||||
|
||||
@@ -207,12 +208,12 @@ public class TextQueryTests extends AbstractIntegrationTests {
|
||||
|
||||
// page 1
|
||||
List<FullTextDoc> result = template
|
||||
.find(new TextQuery("bake coffee cake").sortByScore().with(new PageRequest(0, 2)), FullTextDoc.class);
|
||||
.find(new TextQuery("bake coffee cake").sortByScore().with(PageRequest.of(0, 2)), FullTextDoc.class);
|
||||
assertThat(result, hasSize(2));
|
||||
assertThat(result, contains(BAKE, COFFEE));
|
||||
|
||||
// page 2
|
||||
result = template.find(new TextQuery("bake coffee cake").sortByScore().with(new PageRequest(1, 2)),
|
||||
result = template.find(new TextQuery("bake coffee cake").sortByScore().with(PageRequest.of(1, 2)),
|
||||
FullTextDoc.class);
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, contains(CAKE));
|
||||
|
||||
@@ -24,8 +24,9 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link TextQuery}.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class TextQueryUnitTests {
|
||||
|
||||
@@ -65,7 +66,7 @@ public class TextQueryUnitTests {
|
||||
public void shouldNotOverrideExistingSort() {
|
||||
|
||||
TextQuery query = new TextQuery(QUERY);
|
||||
query.with(new Sort(Direction.DESC, "foo"));
|
||||
query.with(Sort.by(Direction.DESC, "foo"));
|
||||
query.sortByScore();
|
||||
|
||||
assertThat(query,
|
||||
|
||||
@@ -45,7 +45,7 @@ import com.mongodb.gridfs.GridFSFile;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link GridFsTemplate}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Philipp Schneider
|
||||
* @author Thomas Darimont
|
||||
@@ -151,7 +151,7 @@ public class GridFsTemplateIntegrationTests {
|
||||
ObjectId third = operations.store(resource.getInputStream(), "foobar.xml");
|
||||
ObjectId first = operations.store(resource.getInputStream(), "bar.xml");
|
||||
|
||||
Query query = new Query().with(new Sort(Direction.ASC, "filename"));
|
||||
Query query = new Query().with(Sort.by(Direction.ASC, "filename"));
|
||||
|
||||
List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<com.mongodb.client.gridfs.model.GridFSFile>();
|
||||
GridFSFindIterable result = operations.find(query);
|
||||
|
||||
@@ -63,7 +63,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* Base class for tests for {@link PersonRepository}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
@@ -187,7 +187,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
@Test
|
||||
public void findsPagedPersons() throws Exception {
|
||||
|
||||
Page<Person> result = repository.findAll(new PageRequest(1, 2, Direction.ASC, "lastname", "firstname"));
|
||||
Page<Person> result = repository.findAll(PageRequest.of(1, 2, Direction.ASC, "lastname", "firstname"));
|
||||
assertThat(result.isFirst(), is(false));
|
||||
assertThat(result.isLast(), is(false));
|
||||
assertThat(result, hasItems(dave, stefan));
|
||||
@@ -197,7 +197,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
public void executesPagedFinderCorrectly() throws Exception {
|
||||
|
||||
Page<Person> page = repository.findByLastnameLike("*a*",
|
||||
new PageRequest(0, 2, Direction.ASC, "lastname", "firstname"));
|
||||
PageRequest.of(0, 2, Direction.ASC, "lastname", "firstname"));
|
||||
assertThat(page.isFirst(), is(true));
|
||||
assertThat(page.isLast(), is(false));
|
||||
assertThat(page.getNumberOfElements(), is(2));
|
||||
@@ -208,7 +208,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
public void executesPagedFinderWithAnnotatedQueryCorrectly() throws Exception {
|
||||
|
||||
Page<Person> page = repository.findByLastnameLikeWithPageable(".*a.*",
|
||||
new PageRequest(0, 2, Direction.ASC, "lastname", "firstname"));
|
||||
PageRequest.of(0, 2, Direction.ASC, "lastname", "firstname"));
|
||||
assertThat(page.isFirst(), is(true));
|
||||
assertThat(page.isLast(), is(false));
|
||||
assertThat(page.getNumberOfElements(), is(2));
|
||||
@@ -345,7 +345,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
public void findsPagedPeopleByPredicate() throws Exception {
|
||||
|
||||
Page<Person> page = repository.findAll(person.lastname.contains("a"),
|
||||
new PageRequest(0, 2, Direction.ASC, "lastname"));
|
||||
PageRequest.of(0, 2, Direction.ASC, "lastname"));
|
||||
assertThat(page.isFirst(), is(true));
|
||||
assertThat(page.isLast(), is(false));
|
||||
assertThat(page.getNumberOfElements(), is(2));
|
||||
@@ -364,7 +364,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
@Test // DATAMONGO-446
|
||||
public void findsPeopleBySexPaginated() {
|
||||
|
||||
List<Person> males = repository.findBySex(Sex.MALE, new PageRequest(0, 2));
|
||||
List<Person> males = repository.findBySex(Sex.MALE, PageRequest.of(0, 2));
|
||||
assertThat(males.size(), is(2));
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
|
||||
@Test // DATADOC-236
|
||||
public void appliesStaticAndDynamicSorting() {
|
||||
List<Person> result = repository.findByFirstnameLikeOrderByLastnameAsc("*e*", new Sort("age"));
|
||||
List<Person> result = repository.findByFirstnameLikeOrderByLastnameAsc("*e*", Sort.by("age"));
|
||||
assertThat(result.size(), is(5));
|
||||
assertThat(result.get(0), is(carter));
|
||||
assertThat(result.get(1), is(stefan));
|
||||
@@ -430,7 +430,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(dave);
|
||||
|
||||
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
|
||||
new Distance(2000, Metrics.KILOMETERS), new PageRequest(0, 20));
|
||||
new Distance(2000, Metrics.KILOMETERS), PageRequest.of(0, 20));
|
||||
assertThat(results.getContent().isEmpty(), is(false));
|
||||
|
||||
// DATAMONGO-607
|
||||
@@ -440,7 +440,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
@Test // DATAMONGO-323
|
||||
public void considersSortForAnnotatedQuery() {
|
||||
|
||||
List<Person> result = repository.findByAgeLessThan(60, new Sort("firstname"));
|
||||
List<Person> result = repository.findByAgeLessThan(60, Sort.by("firstname"));
|
||||
|
||||
assertThat(result.size(), is(7));
|
||||
assertThat(result.get(0), is(alicia));
|
||||
@@ -605,7 +605,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(Arrays.asList(dave, oliver, carter, boyd, leroi));
|
||||
|
||||
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
|
||||
new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
|
||||
new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
|
||||
|
||||
assertThat(results.getContent().isEmpty(), is(false));
|
||||
assertThat(results.getNumberOfElements(), is(2));
|
||||
@@ -627,7 +627,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(Arrays.asList(dave, oliver, carter));
|
||||
|
||||
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
|
||||
new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
|
||||
new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
|
||||
assertThat(results.getContent().isEmpty(), is(false));
|
||||
assertThat(results.getNumberOfElements(), is(1));
|
||||
assertThat(results.isFirst(), is(false));
|
||||
@@ -643,7 +643,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(dave);
|
||||
|
||||
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
|
||||
new Distance(2000, Metrics.KILOMETERS), new PageRequest(0, 2));
|
||||
new Distance(2000, Metrics.KILOMETERS), PageRequest.of(0, 2));
|
||||
|
||||
assertThat(results.getContent().isEmpty(), is(false));
|
||||
assertThat(results.getNumberOfElements(), is(1));
|
||||
@@ -659,7 +659,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(dave);
|
||||
|
||||
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
|
||||
new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
|
||||
new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
|
||||
|
||||
assertThat(results.getContent().isEmpty(), is(true));
|
||||
assertThat(results.getNumberOfElements(), is(0));
|
||||
@@ -722,7 +722,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
@Test // DATAMONGO-870
|
||||
public void findsSliceOfPersons() {
|
||||
|
||||
Slice<Person> result = repository.findByAgeGreaterThan(40, new PageRequest(0, 2, Direction.DESC, "firstname"));
|
||||
Slice<Person> result = repository.findByAgeGreaterThan(40, PageRequest.of(0, 2, Direction.DESC, "firstname"));
|
||||
|
||||
assertThat(result.hasNext(), is(true));
|
||||
}
|
||||
@@ -748,7 +748,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
alicia.creator = user;
|
||||
repository.save(alicia);
|
||||
|
||||
Page<Person> result = repository.findByHavingCreator(new PageRequest(0, 100));
|
||||
Page<Person> result = repository.findByHavingCreator(PageRequest.of(0, 100));
|
||||
|
||||
assertThat(result.getNumberOfElements(), is(1));
|
||||
assertThat(result.getContent().get(0), is(alicia));
|
||||
@@ -817,7 +817,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
|
||||
repository.save(p);
|
||||
|
||||
Page<Person> result = repository.findByAddressIn(Arrays.asList(adr), new PageRequest(0, 10));
|
||||
Page<Person> result = repository.findByAddressIn(Arrays.asList(adr), PageRequest.of(0, 10));
|
||||
|
||||
assertThat(result.getContent(), hasSize(1));
|
||||
}
|
||||
@@ -831,7 +831,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(new Person("notfound", "bar"));
|
||||
|
||||
Page<Person> result = repository.findByCustomQueryFirstnamesAndLastname(Arrays.asList("bar", "foo", "fuu"), "bar",
|
||||
new PageRequest(0, 2));
|
||||
PageRequest.of(0, 2));
|
||||
|
||||
assertThat(result.getContent(), hasSize(2));
|
||||
assertThat(result.getTotalPages(), is(2));
|
||||
@@ -847,7 +847,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(new Person("notfound", "notfound"));
|
||||
|
||||
Page<Person> result = repository.findByCustomQueryLastnameAndAddressStreetInList("bar",
|
||||
Arrays.asList("street1", "street2"), new PageRequest(0, 2));
|
||||
Arrays.asList("street1", "street2"), PageRequest.of(0, 2));
|
||||
|
||||
assertThat(result.getContent(), hasSize(2));
|
||||
assertThat(result.getTotalPages(), is(2));
|
||||
@@ -869,7 +869,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
|
||||
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
|
||||
new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
|
||||
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(0, 2));
|
||||
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", PageRequest.of(0, 2));
|
||||
assertThat(result.getContent().size(), is(2));
|
||||
assertThat(result.getTotalElements(), is(3L));
|
||||
}
|
||||
@@ -879,7 +879,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
|
||||
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
|
||||
new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
|
||||
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(1, 2));
|
||||
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", PageRequest.of(1, 2));
|
||||
assertThat(result.getContent().size(), is(1));
|
||||
}
|
||||
|
||||
@@ -888,7 +888,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
|
||||
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
|
||||
new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
|
||||
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(100, 2));
|
||||
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", PageRequest.of(100, 2));
|
||||
assertThat(result.getContent().size(), is(0));
|
||||
assertThat(result.getTotalElements(), is(3L));
|
||||
}
|
||||
@@ -896,7 +896,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
@Test // DATAMONGO-996, DATAMONGO-950, DATAMONGO-1464
|
||||
public void gettingNonFirstPageWorksWithoutLimitBeingSet() {
|
||||
|
||||
Page<Person> slice = repository.findByLastnameLike("Matthews", new PageRequest(1, 1));
|
||||
Page<Person> slice = repository.findByLastnameLike("Matthews", PageRequest.of(1, 1));
|
||||
|
||||
assertThat(slice.getContent(), hasSize(1));
|
||||
assertThat(slice.hasPrevious(), is(true));
|
||||
@@ -948,7 +948,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
|
||||
repository.save(persons);
|
||||
|
||||
Slice<Person> slice = repository.findByAgeGreaterThan(50, new PageRequest(0, 20, Direction.ASC, "firstname"));
|
||||
Slice<Person> slice = repository.findByAgeGreaterThan(50, PageRequest.of(0, 20, Direction.ASC, "firstname"));
|
||||
assertThat(slice, contains(persons.subList(0, 20).toArray()));
|
||||
|
||||
slice = repository.findByAgeGreaterThan(50, slice.nextPageable());
|
||||
@@ -1010,7 +1010,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
|
||||
repository.save(persons);
|
||||
|
||||
PageRequest pageRequest = new PageRequest(0, 2, new QSort(person.address.street.desc()));
|
||||
PageRequest pageRequest = PageRequest.of(0, 2, new QSort(person.address.street.desc()));
|
||||
Iterable<Person> result = repository.findAll(pageRequest);
|
||||
|
||||
assertThat(result, is(Matchers.<Person> iterableWithSize(2)));
|
||||
@@ -1102,7 +1102,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
ReflectionTestUtils.setField(sample, "createdAt", null);
|
||||
ReflectionTestUtils.setField(sample, "email", null);
|
||||
|
||||
Page<Person> result = repository.findAll(Example.of(sample), new PageRequest(0, 10));
|
||||
Page<Person> result = repository.findAll(Example.of(sample), PageRequest.of(0, 10));
|
||||
assertThat(result.getNumberOfElements(), is(2));
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ import com.mongodb.MongoClient;
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@@ -122,7 +123,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
|
||||
|
||||
initRepoWithDefaultDocuments();
|
||||
|
||||
Page<FullTextDocument> page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("film"), new PageRequest(1,
|
||||
Page<FullTextDocument> page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("film"), PageRequest.of(1,
|
||||
1, Direction.ASC, "id"));
|
||||
|
||||
assertThat(page.hasNext(), is(true));
|
||||
@@ -138,7 +139,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
|
||||
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
|
||||
repo.save(snipes);
|
||||
|
||||
List<FullTextDocument> result = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), new Sort(
|
||||
List<FullTextDocument> result = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), Sort.by(
|
||||
"score"));
|
||||
|
||||
assertThat(result.size(), is(4));
|
||||
@@ -152,7 +153,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
|
||||
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
|
||||
repo.save(snipes);
|
||||
|
||||
Page<FullTextDocument> page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), new PageRequest(
|
||||
Page<FullTextDocument> page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), PageRequest.of(
|
||||
0, 10, Direction.ASC, "score"));
|
||||
|
||||
assertThat(page.getTotalElements(), is(4L));
|
||||
@@ -166,7 +167,7 @@ public class MongoRepositoryTextSearchIntegrationTests {
|
||||
FullTextDocument snipes = new FullTextDocument("4", "Snipes", "Wesley Trent Snipes is an actor and film producer.");
|
||||
repo.save(snipes);
|
||||
|
||||
Page<FullTextDocument> page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), new PageRequest(
|
||||
Page<FullTextDocument> page = repo.findAllBy(TextCriteria.forDefaultLanguage().matching("snipes"), PageRequest.of(
|
||||
0, 10, Direction.ASC, "id"));
|
||||
|
||||
assertThat(page.getTotalElements(), is(4L));
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ContextConfiguration("config/MongoNamespaceIntegrationTests-context.xml")
|
||||
public class RedeclaringRepositoryMethodsTests extends AbstractPersonRepositoryIntegrationTests {
|
||||
@@ -37,7 +38,7 @@ public class RedeclaringRepositoryMethodsTests extends AbstractPersonRepositoryI
|
||||
@Test // DATAMONGO-760
|
||||
public void adjustedWellKnownPagedFindAllMethodShouldReturnOnlyTheUserWithFirstnameOliverAugust() {
|
||||
|
||||
Page<Person> page = repository.findAll(new PageRequest(0, 2));
|
||||
Page<Person> page = repository.findAll(PageRequest.of(0, 2));
|
||||
|
||||
assertThat(page.getNumberOfElements(), is(1));
|
||||
assertThat(page.getContent().get(0).getFirstname(), is(oliver.getFirstname()));
|
||||
|
||||
@@ -163,7 +163,7 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
|
||||
@Test // DATAMONGO-1444
|
||||
public void findAllWithSortShouldReturnResults() {
|
||||
|
||||
StepVerifier.create(repository.findAll(new Sort(new Order(Direction.ASC, "age")))) //
|
||||
StepVerifier.create(repository.findAll(Sort.by(new Order(Direction.ASC, "age")))) //
|
||||
.expectNextCount(7) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ import com.mongodb.client.result.DeleteResult;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractMongoQuery}.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
@@ -152,7 +152,7 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void metadataShouldBeAddedToQueryCorrectly() {
|
||||
|
||||
MongoQueryFake query = createQueryForMethod("findByFirstname", String.class, Pageable.class);
|
||||
query.execute(new Object[] { "fake", new PageRequest(0, 10) });
|
||||
query.execute(new Object[] { "fake", PageRequest.of(0, 10) });
|
||||
|
||||
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
|
||||
|
||||
@@ -164,7 +164,7 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void metadataShouldBeAddedToCountQueryCorrectly() {
|
||||
|
||||
MongoQueryFake query = createQueryForMethod("findByFirstname", String.class, Pageable.class);
|
||||
query.execute(new Object[] { "fake", new PageRequest(1, 10) });
|
||||
query.execute(new Object[] { "fake", PageRequest.of(1, 10) });
|
||||
|
||||
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
|
||||
|
||||
@@ -176,7 +176,7 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void metadataShouldBeAddedToStringBasedQueryCorrectly() {
|
||||
|
||||
MongoQueryFake query = createQueryForMethod("findByAnnotatedQuery", String.class, Pageable.class);
|
||||
query.execute(new Object[] { "fake", new PageRequest(0, 10) });
|
||||
query.execute(new Object[] { "fake", PageRequest.of(0, 10) });
|
||||
|
||||
ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
|
||||
|
||||
@@ -188,7 +188,7 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void slicedExecutionShouldRetainNrOfElementsToSkip() {
|
||||
|
||||
MongoQueryFake query = createQueryForMethod("findByLastname", String.class, Pageable.class);
|
||||
Pageable page1 = new PageRequest(0, 10);
|
||||
Pageable page1 = PageRequest.of(0, 10);
|
||||
Pageable page2 = page1.next();
|
||||
|
||||
query.execute(new Object[] { "fake", page1 });
|
||||
@@ -206,7 +206,7 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void slicedExecutionShouldIncrementLimitByOne() {
|
||||
|
||||
MongoQueryFake query = createQueryForMethod("findByLastname", String.class, Pageable.class);
|
||||
Pageable page1 = new PageRequest(0, 10);
|
||||
Pageable page1 = PageRequest.of(0, 10);
|
||||
Pageable page2 = page1.next();
|
||||
|
||||
query.execute(new Object[] { "fake", page1 });
|
||||
@@ -224,7 +224,7 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void slicedExecutionShouldRetainSort() {
|
||||
|
||||
MongoQueryFake query = createQueryForMethod("findByLastname", String.class, Pageable.class);
|
||||
Pageable page1 = new PageRequest(0, 10, Sort.Direction.DESC, "bar");
|
||||
Pageable page1 = PageRequest.of(0, 10, Sort.Direction.DESC, "bar");
|
||||
Pageable page2 = page1.next();
|
||||
|
||||
query.execute(new Object[] { "fake", page1 });
|
||||
|
||||
@@ -55,7 +55,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MongoQueryExecution}.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @soundtrack U Can't Touch This - MC Hammer
|
||||
*/
|
||||
@@ -88,7 +88,7 @@ public class MongoQueryExecutionUnitTests {
|
||||
when(mongoOperationsMock.find(any(Query.class), eq(Person.class), eq("person")))
|
||||
.thenReturn(Collections.<Person> emptyList());
|
||||
|
||||
PagedExecution execution = new PagedExecution(mongoOperationsMock, new PageRequest(0, 10));
|
||||
PagedExecution execution = new PagedExecution(mongoOperationsMock, PageRequest.of(0, 10));
|
||||
execution.execute(new Query(), Person.class, "person");
|
||||
|
||||
verify(mongoOperationsMock).find(any(Query.class), eq(Person.class), eq("person"));
|
||||
@@ -101,7 +101,7 @@ public class MongoQueryExecutionUnitTests {
|
||||
when(mongoOperationsMock.find(any(Query.class), eq(Person.class), eq("person")))
|
||||
.thenReturn(Arrays.asList(new Person(), new Person(), new Person(), new Person()));
|
||||
|
||||
PagedExecution execution = new PagedExecution(mongoOperationsMock, new PageRequest(0, 10));
|
||||
PagedExecution execution = new PagedExecution(mongoOperationsMock, PageRequest.of(0, 10));
|
||||
execution.execute(new Query(), Person.class, "person");
|
||||
|
||||
verify(mongoOperationsMock).find(any(Query.class), eq(Person.class), eq("person"));
|
||||
@@ -114,7 +114,7 @@ public class MongoQueryExecutionUnitTests {
|
||||
when(mongoOperationsMock.find(any(Query.class), eq(Person.class), eq("person")))
|
||||
.thenReturn(Collections.<Person> emptyList());
|
||||
|
||||
PagedExecution execution = new PagedExecution(mongoOperationsMock, new PageRequest(2, 10));
|
||||
PagedExecution execution = new PagedExecution(mongoOperationsMock, PageRequest.of(2, 10));
|
||||
execution.execute(new Query(), Person.class, "person");
|
||||
|
||||
verify(mongoOperationsMock).find(any(Query.class), eq(Person.class), eq("person"));
|
||||
@@ -125,7 +125,7 @@ public class MongoQueryExecutionUnitTests {
|
||||
public void pagingGeoExecutionShouldUseCountFromResultWithOffsetAndResultsWithinPageSize() throws Exception {
|
||||
|
||||
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod,
|
||||
new Object[] { POINT, DISTANCE, new PageRequest(0, 10) });
|
||||
new Object[] { POINT, DISTANCE, PageRequest.of(0, 10) });
|
||||
|
||||
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock);
|
||||
GeoResult<Person> result = new GeoResult<Person>(new Person(), DISTANCE);
|
||||
@@ -145,7 +145,7 @@ public class MongoQueryExecutionUnitTests {
|
||||
public void pagingGeoExecutionRetrievesObjectsForPageableOutOfRange() throws Exception {
|
||||
|
||||
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod,
|
||||
new Object[] { POINT, DISTANCE, new PageRequest(2, 10) });
|
||||
new Object[] { POINT, DISTANCE, PageRequest.of(2, 10) });
|
||||
|
||||
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ReactiveMongoQueryExecutionUnitTests {
|
||||
Query query = new Query();
|
||||
when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
|
||||
when(parameterAccessor.getDistanceRange()).thenReturn(new Range<>(new Distance(10), new Distance(15)));
|
||||
when(parameterAccessor.getPageable()).thenReturn(new PageRequest(1, 10));
|
||||
when(parameterAccessor.getPageable()).thenReturn(PageRequest.of(1, 10));
|
||||
|
||||
new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query,
|
||||
Person.class, "person");
|
||||
|
||||
@@ -38,8 +38,9 @@ import com.querydsl.core.types.Predicate;
|
||||
|
||||
/**
|
||||
* Integration test for {@link QueryDslMongoRepository}.
|
||||
*
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ContextConfiguration(
|
||||
locations = "/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml")
|
||||
@@ -81,7 +82,7 @@ public class QueryDslMongoRepositoryIntegrationTests {
|
||||
@Test // DATAMONGO-1167
|
||||
public void shouldSupportFindAllWithPredicateAndSort() {
|
||||
|
||||
List<Person> users = repository.findAll(person.lastname.isNotNull(), new Sort(Direction.ASC, "firstname"));
|
||||
List<Person> users = repository.findAll(person.lastname.isNotNull(), Sort.by(Direction.ASC, "firstname"));
|
||||
|
||||
assertThat(users, hasSize(3));
|
||||
assertThat(users.get(0).getFirstname(), is(carter.getFirstname()));
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:kowsercse@gmail.com">A. B. M. Kowser</a>
|
||||
* @author A. B. M. Kowser
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
@@ -172,7 +172,7 @@ public class SimpleMongoRepositoryTests {
|
||||
sample.setLastname("Matthews");
|
||||
trimDomainType(sample, "id", "createdAt", "email");
|
||||
|
||||
Page<Person> result = repository.findAll(Example.of(sample), new PageRequest(0, 10));
|
||||
Page<Person> result = repository.findAll(Example.of(sample), PageRequest.of(0, 10));
|
||||
|
||||
assertThat(result.getContent(), hasItems(dave, oliver));
|
||||
assertThat(result.getContent(), hasSize(2));
|
||||
@@ -186,7 +186,7 @@ public class SimpleMongoRepositoryTests {
|
||||
sample.setLastname("Matthews");
|
||||
trimDomainType(sample, "id", "createdAt", "email");
|
||||
|
||||
Page<Person> result = repository.findAll(Example.of(sample), new PageRequest(0, 1));
|
||||
Page<Person> result = repository.findAll(Example.of(sample), PageRequest.of(0, 1));
|
||||
|
||||
assertThat(result.getContent(), hasSize(1));
|
||||
assertThat(result.getTotalPages(), is(2));
|
||||
|
||||
@@ -114,7 +114,7 @@ public class PersonRepositoryTests {
|
||||
@Test
|
||||
public void readsFirstPageCorrectly() {
|
||||
|
||||
Page<Person> persons = repository.findAll(new PageRequest(0, 10));
|
||||
Page<Person> persons = repository.findAll(PageRequest.of(0, 10));
|
||||
assertThat(persons.isFirstPage(), is(true));
|
||||
}
|
||||
}
|
||||
@@ -463,7 +463,7 @@ QPerson person = new QPerson("person");
|
||||
List<Person> result = repository.findAll(person.address.zipCode.eq("C0123"));
|
||||
|
||||
Page<Person> page = repository.findAll(person.lastname.contains("a"),
|
||||
new PageRequest(0, 2, Direction.ASC, "lastname"));
|
||||
PageRequest.of(0, 2, Direction.ASC, "lastname"));
|
||||
----
|
||||
|
||||
`QPerson` is a class that is generated (via the Java annotation post processing tool) which is a `Predicate` that allows you to write type safe queries. Notice that there are no strings in the query other than the value "C0123".
|
||||
@@ -528,12 +528,12 @@ interface FullTextRepository extends Repository<FullTextDocument, String> {
|
||||
}
|
||||
|
||||
|
||||
Sort sort = new Sort("score");
|
||||
Sort sort = Sort.by("score");
|
||||
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("spring", "data");
|
||||
List<FullTextDocument> result = repository.findAllBy(criteria, sort);
|
||||
|
||||
criteria = TextCriteria.forDefaultLanguage().matching("film");
|
||||
Page<FullTextDocument> page = repository.findAllBy(criteria, new PageRequest(1, 1, sort));
|
||||
Page<FullTextDocument> page = repository.findAllBy(criteria, PageRequest.of(1, 1, sort));
|
||||
List<FullTextDocument> result = repository.findByTitleOrderByScoreDesc("mongodb", criteria);
|
||||
----
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public class PersonRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void sortsElementsCorrectly() {
|
||||
Flux<Person> persons = repository.findAll(new Sort(new Order(ASC, "lastname")));
|
||||
Flux<Person> persons = repository.findAll(Sort.by(new Order(ASC, "lastname")));
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Reference in New Issue
Block a user