Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89a7309707 | ||
|
|
55ec9c5e5b | ||
|
|
cbb4dcb025 | ||
|
|
a0bad13505 | ||
|
|
d13521ae5d | ||
|
|
51f1526214 | ||
|
|
d049d96952 | ||
|
|
885bf0eae9 | ||
|
|
2a8ffd53d8 | ||
|
|
d54ed61581 | ||
|
|
9e76da91a9 | ||
|
|
595fde7b04 | ||
|
|
01f4e73b48 | ||
|
|
2934c4886b | ||
|
|
080c798721 | ||
|
|
7cfb68e6be | ||
|
|
1e24abe8e5 | ||
|
|
a316d156dc | ||
|
|
6563b125eb |
10
Jenkinsfile
vendored
10
Jenkinsfile
vendored
@@ -3,7 +3,7 @@ pipeline {
|
||||
|
||||
triggers {
|
||||
pollSCM 'H/10 * * * *'
|
||||
upstream(upstreamProjects: "spring-data-commons/master", threshold: hudson.model.Result.SUCCESS)
|
||||
upstream(upstreamProjects: "spring-data-commons/2.4.x", threshold: hudson.model.Result.SUCCESS)
|
||||
}
|
||||
|
||||
options {
|
||||
@@ -68,7 +68,7 @@ pipeline {
|
||||
stage("test: baseline (jdk8)") {
|
||||
when {
|
||||
anyOf {
|
||||
branch 'master'
|
||||
branch '3.1.x'
|
||||
not { triggeredBy 'UpstreamCause' }
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ pipeline {
|
||||
stage("Test other configurations") {
|
||||
when {
|
||||
allOf {
|
||||
branch 'master'
|
||||
branch '3.1.x'
|
||||
not { triggeredBy 'UpstreamCause' }
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ pipeline {
|
||||
stage('Release to artifactory') {
|
||||
when {
|
||||
anyOf {
|
||||
branch 'master'
|
||||
branch '3.1.x'
|
||||
not { triggeredBy 'UpstreamCause' }
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ pipeline {
|
||||
|
||||
stage('Publish documentation') {
|
||||
when {
|
||||
branch 'master'
|
||||
branch '3.1.x'
|
||||
}
|
||||
agent {
|
||||
docker {
|
||||
|
||||
10
pom.xml
10
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>3.2.0-M1</version>
|
||||
<version>3.1.2</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Spring Data MongoDB</name>
|
||||
@@ -15,7 +15,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data.build</groupId>
|
||||
<artifactId>spring-data-parent</artifactId>
|
||||
<version>2.5.0-M1</version>
|
||||
<version>2.4.2</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
@@ -26,7 +26,7 @@
|
||||
<properties>
|
||||
<project.type>multi</project.type>
|
||||
<dist.id>spring-data-mongodb</dist.id>
|
||||
<springdata.commons>2.5.0-M1</springdata.commons>
|
||||
<springdata.commons>2.4.2</springdata.commons>
|
||||
<mongo>4.1.1</mongo>
|
||||
<mongo.reactivestreams>${mongo}</mongo.reactivestreams>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
@@ -134,8 +134,8 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-libs-milestone</id>
|
||||
<url>https://repo.spring.io/libs-milestone</url>
|
||||
<id>spring-libs-release</id>
|
||||
<url>https://repo.spring.io/libs-release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype-libs-snapshot</id>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>3.2.0-M1</version>
|
||||
<version>3.1.2</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>3.2.0-M1</version>
|
||||
<version>3.1.2</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>3.2.0-M1</version>
|
||||
<version>3.1.2</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -156,7 +156,6 @@ import com.mongodb.client.result.UpdateResult;
|
||||
* @author Michael J. Simons
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Yadhukrishna S Pai
|
||||
* @author Anton Barkan
|
||||
*/
|
||||
public class MongoTemplate implements MongoOperations, ApplicationContextAware, IndexOperationsProvider {
|
||||
|
||||
@@ -3290,10 +3289,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
cursorToUse = cursorToUse.batchSize(meta.getCursorBatchSize());
|
||||
}
|
||||
|
||||
if (meta.getAllowDiskUse() != null) {
|
||||
cursorToUse = cursorToUse.allowDiskUse(meta.getAllowDiskUse());
|
||||
}
|
||||
|
||||
for (Meta.CursorOption option : meta.getFlags()) {
|
||||
|
||||
switch (option) {
|
||||
|
||||
@@ -3329,10 +3329,6 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
if (meta.getCursorBatchSize() != null) {
|
||||
findPublisherToUse = findPublisherToUse.batchSize(meta.getCursorBatchSize());
|
||||
}
|
||||
|
||||
if (meta.getAllowDiskUse() != null) {
|
||||
findPublisherToUse = findPublisherToUse.allowDiskUse(meta.getAllowDiskUse());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
@@ -181,11 +181,7 @@ public class Meta {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables writing to temporary files for aggregation stages and queries. When set to {@literal true}, aggregation
|
||||
* stages can write data to the {@code _tmp} subdirectory in the {@code dbPath} directory.
|
||||
* <p>
|
||||
* Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a {@code usedDisk}
|
||||
* indicator if any aggregation stage wrote data to temporary files due to memory restrictions.
|
||||
* Set to {@literal true}, to allow aggregation stages to write data to disk.
|
||||
*
|
||||
* @param allowDiskUse use {@literal null} for server defaults.
|
||||
* @since 3.0
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.springframework.util.Assert;
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Anton Barkan
|
||||
*/
|
||||
public class Query {
|
||||
|
||||
@@ -373,24 +372,6 @@ public class Query {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables writing to temporary files for aggregation stages and queries. When set to {@literal true}, aggregation
|
||||
* stages can write data to the {@code _tmp} subdirectory in the {@code dbPath} directory.
|
||||
* <p>
|
||||
* Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a {@code usedDisk}
|
||||
* indicator if any aggregation stage wrote data to temporary files due to memory restrictions.
|
||||
*
|
||||
* @param allowDiskUse
|
||||
* @return this.
|
||||
* @see Meta#setAllowDiskUse(Boolean)
|
||||
* @since 3.2
|
||||
*/
|
||||
public Query allowDiskUse(boolean allowDiskUse) {
|
||||
|
||||
meta.setAllowDiskUse(allowDiskUse);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of documents to return in each response batch. <br />
|
||||
* Use {@literal 0 (zero)} for no limit. A <strong>negative limit</strong> closes the cursor after returning a single
|
||||
|
||||
@@ -64,4 +64,16 @@ public interface ReactiveMongoRepository<T, ID> extends ReactiveSortingRepositor
|
||||
*/
|
||||
<S extends T> Flux<S> insert(Publisher<S> entities);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
|
||||
*/
|
||||
<S extends T> Flux<S> findAll(Example<S> example);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
|
||||
*/
|
||||
<S extends T> Flux<S> findAll(Example<S> example, Sort sort);
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ import com.mongodb.client.result.DeleteResult;
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
* @author Mehran Behnam
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
|
||||
@@ -73,10 +72,6 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
this.mongoOperations = mongoOperations;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from CrudRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Object)
|
||||
@@ -140,27 +135,6 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Iterable<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Ids of entities not be null!");
|
||||
|
||||
return findAll(getIdQuery(ids));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#count()
|
||||
@@ -201,19 +175,6 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#deleteAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public void deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of ids must not be null!");
|
||||
|
||||
mongoOperations.remove(getIdQuery(ids), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable)
|
||||
@@ -221,7 +182,7 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
@Override
|
||||
public void deleteAll(Iterable<? extends T> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
Assert.notNull(entities, "The given Iterable of entities not be null!");
|
||||
|
||||
entities.forEach(this::delete);
|
||||
}
|
||||
@@ -235,9 +196,27 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
mongoOperations.remove(new Query(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from PagingAndSortingRepository
|
||||
// -------------------------------------------------------------------------
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Iterable<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Ids of entities not be null!");
|
||||
|
||||
return findAll(new Query(new Criteria(entityInformation.getIdAttribute())
|
||||
.in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()))));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -266,10 +245,6 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from MongoRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#insert(java.lang.Object)
|
||||
@@ -300,33 +275,23 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return new ArrayList<>(mongoOperations.insertAll(list));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from QueryByExampleExecutor
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example, org.springframework.data.domain.Pageable)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Optional<S> findOne(Example<S> example) {
|
||||
public <S extends T> Page<S> findAll(final Example<S> example, Pageable pageable) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(pageable, "Pageable must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
.collation(entityInformation.getCollation()).with(pageable); //
|
||||
|
||||
return Optional
|
||||
.ofNullable(mongoOperations.findOne(query, example.getProbeType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
List<S> list = mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> List<S> findAll(Example<S> example) {
|
||||
return findAll(example, Sort.unsorted());
|
||||
return PageableExecutionUtils.getPage(list, pageable,
|
||||
() -> mongoOperations.count(Query.of(query).limit(-1).skip(-1), example.getProbeType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -348,21 +313,27 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example, org.springframework.data.domain.Pageable)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
|
||||
public <S extends T> List<S> findAll(Example<S> example) {
|
||||
return findAll(example, Sort.unsorted());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Optional<S> findOne(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(pageable, "Pageable must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()).with(pageable); //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
List<S> list = mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
|
||||
return PageableExecutionUtils.getPage(list, pageable,
|
||||
() -> mongoOperations.count(Query.of(query).limit(-1).skip(-1), example.getProbeType(), entityInformation.getCollectionName()));
|
||||
return Optional
|
||||
.ofNullable(mongoOperations.findOne(query, example.getProbeType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -395,10 +366,6 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return mongoOperations.exists(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private Query getIdQuery(Object id) {
|
||||
return new Query(getIdCriteria(id));
|
||||
}
|
||||
@@ -407,11 +374,6 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return where(entityInformation.getIdAttribute()).is(id);
|
||||
}
|
||||
|
||||
private Query getIdQuery(Iterable<? extends ID> ids) {
|
||||
return new Query(new Criteria(entityInformation.getIdAttribute())
|
||||
.in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList())));
|
||||
}
|
||||
|
||||
private List<T> findAll(@Nullable Query query) {
|
||||
|
||||
if (query == null) {
|
||||
@@ -420,5 +382,4 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
|
||||
return mongoOperations.find(query, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,12 +21,10 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.data.domain.Example;
|
||||
@@ -49,7 +47,6 @@ import com.mongodb.client.result.DeleteResult;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Ruben J Garcia
|
||||
* @author Jens Schauder
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SimpleReactiveMongoRepository<T, ID extends Serializable> implements ReactiveMongoRepository<T, ID> {
|
||||
@@ -67,9 +64,232 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
this.mongoOperations = mongoOperations;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveCrudRepository
|
||||
// -------------------------------------------------------------------------
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(
|
||||
id -> mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> findOne(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.limit(2);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
|
||||
.map(vals -> {
|
||||
|
||||
if (vals.size() > 1) {
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
return vals.iterator().next();
|
||||
}).next();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName()));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#exists(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Boolean> exists(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.exists(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of Id's must not be null!");
|
||||
|
||||
return findAll(new Query(new Criteria(entityInformation.getIdAttribute())
|
||||
.in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()))));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Publisher<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Publisher of Id's must not be null!");
|
||||
|
||||
return Flux.from(ids).buffer().flatMap(this::findAllById);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll(org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll(Sort sort) {
|
||||
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example, Sort sort) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.with(sort);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Example must not be null!");
|
||||
|
||||
return findAll(example, Sort.unsorted());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#count()
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> count() {
|
||||
return mongoOperations.count(new Query(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#count(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Long> count(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.count(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> insert(S entity) {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
|
||||
return mongoOperations.insert(entity, entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Iterable<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
|
||||
List<S> source = Streamable.of(entities).stream().collect(StreamUtils.toUnmodifiableList());
|
||||
|
||||
return source.isEmpty() ? Flux.empty() : Flux.from(mongoOperations.insertAll(source));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Publisher<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Publisher of entities must not be null!");
|
||||
|
||||
return Flux.from(entities).flatMap(entity -> mongoOperations.insert(entity, entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -117,100 +337,6 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity)));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(
|
||||
id -> mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of Id's must not be null!");
|
||||
|
||||
return findAll(getIdQuery(ids));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Publisher<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Publisher of Id's must not be null!");
|
||||
|
||||
return Flux.from(ids).buffer().flatMap(this::findAllById);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#count()
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> count() {
|
||||
return mongoOperations.count(new Query(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteById(java.lang.Object)
|
||||
@@ -266,19 +392,6 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
return remove.then();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of Id's must not be null!");
|
||||
|
||||
return mongoOperations
|
||||
.remove(getIdQuery(ids), entityInformation.getJavaType(), entityInformation.getCollectionName()).then();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(java.lang.Iterable)
|
||||
@@ -288,14 +401,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
|
||||
Collection<?> idCollection = StreamUtils.createStreamFromIterator(entities.iterator()).map(entityInformation::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Criteria idsInCriteria = where(entityInformation.getIdAttribute()).in(idCollection);
|
||||
|
||||
return mongoOperations
|
||||
.remove(new Query(idsInCriteria), entityInformation.getJavaType(), entityInformation.getCollectionName())
|
||||
.then();
|
||||
return Flux.fromIterable(entities).flatMap(this::delete).then();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -322,151 +428,6 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
return mongoOperations.remove(new Query(), entityInformation.getCollectionName()).then(Mono.empty());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveSortingRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll(org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll(Sort sort) {
|
||||
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveMongoRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> insert(S entity) {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
|
||||
return mongoOperations.insert(entity, entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Iterable<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
|
||||
List<S> source = Streamable.of(entities).stream().collect(StreamUtils.toUnmodifiableList());
|
||||
|
||||
return source.isEmpty() ? Flux.empty() : Flux.from(mongoOperations.insertAll(source));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Publisher<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Publisher of entities must not be null!");
|
||||
|
||||
return Flux.from(entities).flatMap(entity -> mongoOperations.insert(entity, entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveMongoRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> findOne(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.limit(2);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
|
||||
.map(vals -> {
|
||||
|
||||
if (vals.size() > 1) {
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
return vals.iterator().next();
|
||||
}).next();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Example must not be null!");
|
||||
|
||||
return findAll(example, Sort.unsorted());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example, Sort sort) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.with(sort);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#count(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Long> count(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.count(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#exists(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Boolean> exists(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.exists(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
|
||||
private Query getIdQuery(Object id) {
|
||||
return new Query(getIdCriteria(id));
|
||||
}
|
||||
@@ -475,13 +436,6 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
return where(entityInformation.getIdAttribute()).is(id);
|
||||
}
|
||||
|
||||
private Query getIdQuery(Iterable<? extends ID> ids) {
|
||||
Collection<?> idCollection = StreamUtils.createStreamFromIterator(ids.iterator()).collect(Collectors.toList());
|
||||
Criteria idsInCriteria = where(entityInformation.getIdAttribute()).in(idCollection);
|
||||
|
||||
return new Query(idsInCriteria);
|
||||
}
|
||||
|
||||
private Flux<T> findAll(Query query) {
|
||||
|
||||
return mongoOperations.find(query, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
|
||||
@@ -45,7 +45,6 @@ import com.mongodb.client.FindIterable;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Anton Barkan
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@@ -62,7 +61,6 @@ class QueryCursorPreparerUnitTests {
|
||||
when(factory.getCodecRegistry()).thenReturn(MongoClientSettings.getDefaultCodecRegistry());
|
||||
when(cursor.batchSize(anyInt())).thenReturn(cursor);
|
||||
when(cursor.comment(anyString())).thenReturn(cursor);
|
||||
when(cursor.allowDiskUse(anyBoolean())).thenReturn(cursor);
|
||||
when(cursor.maxTime(anyLong(), any())).thenReturn(cursor);
|
||||
when(cursor.hint(any())).thenReturn(cursor);
|
||||
when(cursor.noCursorTimeout(anyBoolean())).thenReturn(cursor);
|
||||
@@ -96,6 +94,27 @@ class QueryCursorPreparerUnitTests {
|
||||
verify(cursor).hint(new Document("age", 1));
|
||||
}
|
||||
|
||||
// TODO
|
||||
// @Test // DATAMONGO-957
|
||||
// public void doesNotApplyMetaWhenEmpty() {
|
||||
//
|
||||
// Query query = query(where("foo").is("bar"));
|
||||
// query.setMeta(new Meta());
|
||||
//
|
||||
// prepare(query);
|
||||
//
|
||||
// verify(cursor, never()).modifiers(any(Document.class));
|
||||
// }
|
||||
|
||||
// @Test // DATAMONGO-957
|
||||
// public void appliesMaxScanCorrectly() {
|
||||
//
|
||||
// Query query = query(where("foo").is("bar")).maxScan(100);
|
||||
// prepare(query);
|
||||
//
|
||||
// verify(cursor).maxScan(100);
|
||||
// }
|
||||
|
||||
@Test // DATAMONGO-957
|
||||
void appliesMaxTimeCorrectly() {
|
||||
|
||||
@@ -114,14 +133,15 @@ class QueryCursorPreparerUnitTests {
|
||||
verify(cursor).comment("spring data");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2659
|
||||
void appliesAllowDiskUseCorrectly() {
|
||||
|
||||
Query query = query(where("foo").is("bar")).allowDiskUse(true);
|
||||
prepare(query);
|
||||
|
||||
verify(cursor).allowDiskUse(true);
|
||||
}
|
||||
// TODO
|
||||
// @Test // DATAMONGO-957
|
||||
// public void appliesSnapshotCorrectly() {
|
||||
//
|
||||
// Query query = query(where("foo").is("bar")).useSnapshot();
|
||||
// prepare(query);
|
||||
//
|
||||
// verify(cursor).snapshot(true);
|
||||
// }
|
||||
|
||||
@Test // DATAMONGO-1480
|
||||
void appliesNoCursorTimeoutCorrectly() {
|
||||
|
||||
@@ -180,7 +180,6 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
when(findPublisher.limit(anyInt())).thenReturn(findPublisher);
|
||||
when(findPublisher.collation(any())).thenReturn(findPublisher);
|
||||
when(findPublisher.first()).thenReturn(findPublisher);
|
||||
when(findPublisher.allowDiskUse(anyBoolean())).thenReturn(findPublisher);
|
||||
when(aggregatePublisher.allowDiskUse(anyBoolean())).thenReturn(aggregatePublisher);
|
||||
when(aggregatePublisher.collation(any())).thenReturn(aggregatePublisher);
|
||||
when(aggregatePublisher.maxTime(anyLong(), any())).thenReturn(aggregatePublisher);
|
||||
@@ -232,17 +231,6 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
verify(findPublisher).batchSize(1234);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2659
|
||||
void executeQueryShouldUseAllowDiskSizeWhenPresent() {
|
||||
|
||||
when(findPublisher.batchSize(anyInt())).thenReturn(findPublisher);
|
||||
|
||||
Query query = new Query().allowDiskUse(true);
|
||||
template.find(query, Person.class).subscribe();
|
||||
|
||||
verify(findPublisher).allowDiskUse(true);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1518
|
||||
void findShouldUseCollationWhenPresent() {
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ import org.springframework.data.mongodb.test.util.MongoClientExtension;
|
||||
import org.springframework.data.mongodb.test.util.MongoTestUtils;
|
||||
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
@@ -76,13 +77,11 @@ import com.mongodb.reactivestreams.client.MongoClient;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith({ MongoClientExtension.class, SpringExtension.class })
|
||||
class ReactiveMongoRepositoryTests {
|
||||
public class ReactiveMongoRepositoryTests {
|
||||
|
||||
private static final int PERSON_COUNT = 7;
|
||||
private static @Client MongoClient mongoClient;
|
||||
static @Client MongoClient mongoClient;
|
||||
|
||||
@Autowired ReactiveMongoTemplate template;
|
||||
|
||||
@@ -90,8 +89,8 @@ class ReactiveMongoRepositoryTests {
|
||||
@Autowired ReactiveContactRepository contactRepository;
|
||||
@Autowired ReactiveCappedCollectionRepository cappedRepository;
|
||||
|
||||
private Person dave, oliver, carter, boyd, stefan, leroi, alicia;
|
||||
private QPerson person = QPerson.person;
|
||||
Person dave, oliver, carter, boyd, stefan, leroi, alicia;
|
||||
QPerson person = QPerson.person;
|
||||
|
||||
@Configuration
|
||||
static class Config extends AbstractReactiveMongoConfiguration {
|
||||
@@ -141,14 +140,14 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
static void cleanDb() {
|
||||
public static void cleanDb() {
|
||||
|
||||
MongoTestUtils.createOrReplaceCollectionNow("reactive", "person", mongoClient);
|
||||
MongoTestUtils.createOrReplaceCollectionNow("reactive", "capped", mongoClient);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
public void setUp() throws Exception {
|
||||
|
||||
repository.deleteAll().as(StepVerifier::create).verifyComplete();
|
||||
|
||||
@@ -165,35 +164,35 @@ class ReactiveMongoRepositoryTests {
|
||||
alicia = new Person("Alicia", "Keys", 30, Sex.FEMALE);
|
||||
|
||||
repository.saveAll(Arrays.asList(oliver, carter, boyd, stefan, leroi, alicia, dave)).as(StepVerifier::create) //
|
||||
.expectNextCount(PERSON_COUNT) //
|
||||
.expectNextCount(7) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldFindByLastName() {
|
||||
public void shouldFindByLastName() {
|
||||
repository.findByLastname(dave.getLastname()).as(StepVerifier::create).expectNextCount(2).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldFindOneByLastName() {
|
||||
public void shouldFindOneByLastName() {
|
||||
repository.findOneByLastname(carter.getLastname()).as(StepVerifier::create).expectNext(carter).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldFindOneByPublisherOfLastName() {
|
||||
public void shouldFindOneByPublisherOfLastName() {
|
||||
repository.findByLastname(Mono.just(carter.getLastname())).as(StepVerifier::create).expectNext(carter)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldFindByPublisherOfLastNameIn() {
|
||||
public void shouldFindByPublisherOfLastNameIn() {
|
||||
repository.findByLastnameIn(Flux.just(carter.getLastname(), dave.getLastname())).as(StepVerifier::create) //
|
||||
.expectNextCount(3) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldFindByPublisherOfLastNameInAndAgeGreater() {
|
||||
public void shouldFindByPublisherOfLastNameInAndAgeGreater() {
|
||||
|
||||
repository.findByLastnameInAndAgeGreaterThan(Flux.just(carter.getLastname(), dave.getLastname()), 41)
|
||||
.as(StepVerifier::create) //
|
||||
@@ -202,7 +201,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldFindUsingPublishersInStringQuery() {
|
||||
public void shouldFindUsingPublishersInStringQuery() {
|
||||
|
||||
repository.findStringQuery(Flux.just("Beauford", "Matthews"), Mono.just(41)).as(StepVerifier::create) //
|
||||
.expectNextCount(2) //
|
||||
@@ -210,7 +209,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldFindByLastNameAndSort() {
|
||||
public void shouldFindByLastNameAndSort() {
|
||||
|
||||
repository.findByLastname("Matthews", Sort.by(ASC, "age")).as(StepVerifier::create) //
|
||||
.expectNext(oliver, dave) //
|
||||
@@ -222,7 +221,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldUseTailableCursor() throws Exception {
|
||||
public void shouldUseTailableCursor() throws Exception {
|
||||
|
||||
template.dropCollection(Capped.class) //
|
||||
.then(template.createCollection(Capped.class, //
|
||||
@@ -247,7 +246,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void shouldUseTailableCursorWithProjection() throws Exception {
|
||||
public void shouldUseTailableCursorWithProjection() throws Exception {
|
||||
|
||||
template.dropCollection(Capped.class) //
|
||||
.then(template.createCollection(Capped.class, //
|
||||
@@ -278,7 +277,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2080
|
||||
void shouldUseTailableCursorWithDtoProjection() {
|
||||
public void shouldUseTailableCursorWithDtoProjection() {
|
||||
|
||||
template.dropCollection(Capped.class) //
|
||||
.then(template.createCollection(Capped.class, //
|
||||
@@ -291,7 +290,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void findsPeopleByLocationWithinCircle() {
|
||||
public void findsPeopleByLocationWithinCircle() {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -303,7 +302,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void findsPeopleByPageableLocationWithinCircle() {
|
||||
public void findsPeopleByPageableLocationWithinCircle() {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -316,7 +315,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void findsPeopleGeoresultByLocationWithinBox() {
|
||||
public void findsPeopleGeoresultByLocationWithinBox() {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -331,7 +330,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void findsPeoplePageableGeoresultByLocationWithinBox() throws InterruptedException {
|
||||
public void findsPeoplePageableGeoresultByLocationWithinBox() throws InterruptedException {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -351,7 +350,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
void findsPeopleByLocationWithinBox() throws InterruptedException {
|
||||
public void findsPeopleByLocationWithinBox() throws InterruptedException {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -367,23 +366,23 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1865
|
||||
void shouldErrorOnFindOneWithNonUniqueResult() {
|
||||
public void shouldErrorOnFindOneWithNonUniqueResult() {
|
||||
repository.findOneByLastname(dave.getLastname()).as(StepVerifier::create)
|
||||
.expectError(IncorrectResultSizeDataAccessException.class).verify();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1865
|
||||
void shouldReturnFirstFindFirstWithMoreResults() {
|
||||
public void shouldReturnFirstFindFirstWithMoreResults() {
|
||||
repository.findFirstByLastname(dave.getLastname()).as(StepVerifier::create).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2030
|
||||
void shouldReturnExistsBy() {
|
||||
public void shouldReturnExistsBy() {
|
||||
repository.existsByLastname(dave.getLastname()).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1979
|
||||
void findAppliesAnnotatedSort() {
|
||||
public void findAppliesAnnotatedSort() {
|
||||
|
||||
repository.findByAgeGreaterThan(40).collectList().as(StepVerifier::create).consumeNextWith(result -> {
|
||||
assertThat(result).containsSequence(carter, boyd, dave, leroi);
|
||||
@@ -391,7 +390,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1979
|
||||
void findWithSortOverwritesAnnotatedSort() {
|
||||
public void findWithSortOverwritesAnnotatedSort() {
|
||||
|
||||
repository.findByAgeGreaterThan(40, Sort.by(Direction.ASC, "age")).collectList().as(StepVerifier::create)
|
||||
.consumeNextWith(result -> {
|
||||
@@ -400,7 +399,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2181
|
||||
void considersRepositoryCollectionName() {
|
||||
public void considersRepositoryCollectionName() {
|
||||
|
||||
repository.deleteAll() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -429,7 +428,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2182
|
||||
void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() {
|
||||
public void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() {
|
||||
|
||||
repository.findAll(person.id.in(Arrays.asList(dave.id, carter.id))) //
|
||||
.collectList() //
|
||||
@@ -440,19 +439,24 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void findListOfSingleValue() {
|
||||
public void findListOfSingleValue() {
|
||||
|
||||
repository.findAllLastnames() //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual)
|
||||
.contains("Lessard", "Keys", "Tinsley", "Beauford", "Moore", "Matthews");
|
||||
assertThat(actual) //
|
||||
.contains("Lessard") //
|
||||
.contains("Keys") //
|
||||
.contains("Tinsley") //
|
||||
.contains("Beauford") //
|
||||
.contains("Moore") //
|
||||
.contains("Matthews");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void annotatedAggregationWithPlaceholderValue() {
|
||||
public void annotatedAggregationWithPlaceholderValue() {
|
||||
|
||||
repository.groupByLastnameAnd("firstname") //
|
||||
.collectList() //
|
||||
@@ -469,7 +473,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void annotatedAggregationWithSort() {
|
||||
public void annotatedAggregationWithSort() {
|
||||
|
||||
repository.groupByLastnameAnd("firstname", Sort.by("lastname")) //
|
||||
.collectList() //
|
||||
@@ -488,7 +492,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void annotatedAggregationWithPageable() {
|
||||
public void annotatedAggregationWithPageable() {
|
||||
|
||||
repository.groupByLastnameAnd("firstname", PageRequest.of(1, 2, Sort.by("lastname"))) //
|
||||
.collectList() //
|
||||
@@ -503,7 +507,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void annotatedAggregationWithSingleSimpleResult() {
|
||||
public void annotatedAggregationWithSingleSimpleResult() {
|
||||
|
||||
repository.sumAge() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -512,7 +516,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void annotatedAggregationWithAggregationResultAsReturnType() {
|
||||
public void annotatedAggregationWithAggregationResultAsReturnType() {
|
||||
|
||||
repository.sumAgeAndReturnRawResult() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -521,7 +525,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void annotatedAggregationWithAggregationResultAsReturnTypeAndProjection() {
|
||||
public void annotatedAggregationWithAggregationResultAsReturnTypeAndProjection() {
|
||||
|
||||
repository.sumAgeAndReturnSumWrapper() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -530,7 +534,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2374
|
||||
void findsWithNativeProjection() {
|
||||
public void findsWithNativeProjection() {
|
||||
|
||||
repository.findDocumentById(dave.getId()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -540,7 +544,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
void annotatedAggregationWithAggregationResultAsMap() {
|
||||
public void annotatedAggregationWithAggregationResultAsMap() {
|
||||
|
||||
repository.sumAgeAndReturnSumAsMap() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -550,7 +554,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2403
|
||||
void annotatedAggregationExtractingSimpleValueIsEmptyForEmptyDocument() {
|
||||
public void annotatedAggregationExtractingSimpleValueIsEmptyForEmptyDocument() {
|
||||
|
||||
Person p = new Person("project-on-lastanme", null);
|
||||
repository.save(p).then().as(StepVerifier::create).verifyComplete();
|
||||
@@ -561,7 +565,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2403
|
||||
void annotatedAggregationSkipsEmptyDocumentsWhenExtractingSimpleValue() {
|
||||
public void annotatedAggregationSkipsEmptyDocumentsWhenExtractingSimpleValue() {
|
||||
|
||||
String firstname = "project-on-lastanme";
|
||||
|
||||
@@ -580,7 +584,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2406
|
||||
void deleteByShouldHandleVoidResultTypeCorrectly() {
|
||||
public void deleteByShouldHandleVoidResultTypeCorrectly() {
|
||||
|
||||
repository.deleteByLastname(dave.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -592,7 +596,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1997
|
||||
void deleteByShouldAllowDeletedCountAsResult() {
|
||||
public void deleteByShouldAllowDeletedCountAsResult() {
|
||||
|
||||
repository.deleteCountByLastname(dave.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -601,7 +605,7 @@ class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1997
|
||||
void deleteByShouldAllowSingleDocumentRemovalCorrectly() {
|
||||
public void deleteByShouldAllowSingleDocumentRemovalCorrectly() {
|
||||
|
||||
repository.deleteSinglePersonByLastname(carter.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -613,18 +617,6 @@ class ReactiveMongoRepositoryTests {
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2652
|
||||
void deleteAllById() {
|
||||
|
||||
repository.deleteAllById(Arrays.asList(carter.id, dave.id)) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
repository.count().as(StepVerifier::create) //
|
||||
.expectNext(PERSON_COUNT - 2L) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
interface ReactivePersonRepository
|
||||
extends ReactiveMongoRepository<Person, String>, ReactiveQuerydslPredicateExecutor<Person> {
|
||||
|
||||
@@ -725,7 +717,7 @@ class ReactiveMongoRepositoryTests {
|
||||
String key;
|
||||
double random;
|
||||
|
||||
Capped(String key, double random) {
|
||||
public Capped(String key, double random) {
|
||||
this.key = key;
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.support;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.ExampleMatcher.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -58,13 +58,12 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith({ MongoTemplateExtension.class, MongoServerCondition.class })
|
||||
class SimpleMongoRepositoryTests {
|
||||
public class SimpleMongoRepositoryTests {
|
||||
|
||||
@Template(initialEntitySet = Person.class) //
|
||||
private static MongoTestTemplate template;
|
||||
static MongoTestTemplate template;
|
||||
|
||||
private Person oliver, dave, carter, boyd, stefan, leroi, alicia;
|
||||
private List<Person> all;
|
||||
@@ -74,7 +73,7 @@ class SimpleMongoRepositoryTests {
|
||||
template);
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
public void setUp() {
|
||||
|
||||
repository.deleteAll();
|
||||
|
||||
@@ -86,21 +85,21 @@ class SimpleMongoRepositoryTests {
|
||||
leroi = new Person("Leroi", "Moore", 41);
|
||||
alicia = new Person("Alicia", "Keys", 30, Sex.FEMALE);
|
||||
|
||||
all = repository.saveAll(asList(oliver, dave, carter, boyd, stefan, leroi, alicia));
|
||||
all = repository.saveAll(Arrays.asList(oliver, dave, carter, boyd, stefan, leroi, alicia));
|
||||
}
|
||||
|
||||
@Test
|
||||
void findAllFromCustomCollectionName() {
|
||||
assertThat(repository.findAll()).hasSameSizeAs(all);
|
||||
public void findALlFromCustomCollectionName() {
|
||||
assertThat(repository.findAll()).hasSize(all.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findOneFromCustomCollectionName() {
|
||||
assertThat(repository.findById(dave.getId())).contains(dave);
|
||||
public void findOneFromCustomCollectionName() {
|
||||
assertThat(repository.findById(dave.getId()).get()).isEqualTo(dave);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteFromCustomCollectionName() {
|
||||
public void deleteFromCustomCollectionName() {
|
||||
|
||||
repository.delete(dave);
|
||||
|
||||
@@ -108,7 +107,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteByIdFromCustomCollectionName() {
|
||||
public void deleteByIdFromCustomCollectionName() {
|
||||
|
||||
repository.deleteById(dave.getId());
|
||||
|
||||
@@ -116,7 +115,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1054
|
||||
void shouldInsertSingle() {
|
||||
public void shouldInsertSingle() {
|
||||
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
|
||||
@@ -127,7 +126,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1054
|
||||
void shouldInsertMultipleFromList() {
|
||||
public void shouldInsertMultipleFromList() {
|
||||
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
Map<String, Person> idToPerson = new HashMap<String, Person>();
|
||||
@@ -141,12 +140,12 @@ class SimpleMongoRepositoryTests {
|
||||
|
||||
List<Person> saved = repository.insert(persons);
|
||||
|
||||
assertThat(saved).hasSameSizeAs(persons);
|
||||
assertThat(saved).hasSize(persons.size());
|
||||
assertThatAllReferencePersonsWereStoredCorrectly(idToPerson, saved);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1054
|
||||
void shouldInsertMutlipleFromSet() {
|
||||
public void shouldInsertMutlipleFromSet() {
|
||||
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
Map<String, Person> idToPerson = new HashMap<String, Person>();
|
||||
@@ -160,12 +159,12 @@ class SimpleMongoRepositoryTests {
|
||||
|
||||
List<Person> saved = repository.insert(persons);
|
||||
|
||||
assertThat(saved).hasSameSizeAs(persons);
|
||||
assertThat(saved).hasSize(persons.size());
|
||||
assertThatAllReferencePersonsWereStoredCorrectly(idToPerson, saved);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245, DATAMONGO-1464
|
||||
void findByExampleShouldLookUpEntriesCorrectly() {
|
||||
public void findByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -178,7 +177,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1464
|
||||
void findByExampleMultiplePagesShouldLookUpEntriesCorrectly() {
|
||||
public void findByExampleMultiplePagesShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -191,7 +190,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldLookUpEntriesCorrectly() {
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -201,7 +200,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObject() {
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObject() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -217,7 +216,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingPartialNestedObject() {
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingPartialNestedObject() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -233,7 +232,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldNotFindEntriesWhenUsingPartialNestedObjectInStrictMode() {
|
||||
public void findAllByExampleShouldNotFindEntriesWhenUsingPartialNestedObjectInStrictMode() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -248,7 +247,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObjectInStrictMode() {
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObjectInStrictMode() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -263,7 +262,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldRespectStringMatchMode() {
|
||||
public void findAllByExampleShouldRespectStringMatchMode() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Mat");
|
||||
@@ -275,7 +274,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldResolveDbRefCorrectly() {
|
||||
public void findAllByExampleShouldResolveDbRefCorrectly() {
|
||||
|
||||
User user = new User();
|
||||
user.setId("c0nf1ux");
|
||||
@@ -295,7 +294,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldResolveLegacyCoordinatesCorrectly() {
|
||||
public void findAllByExampleShouldResolveLegacyCoordinatesCorrectly() {
|
||||
|
||||
Person megan = new Person("megan", "tarash");
|
||||
megan.setLocation(new Point(41.85003D, -87.65005D));
|
||||
@@ -310,7 +309,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldResolveGeoJsonCoordinatesCorrectly() {
|
||||
public void findAllByExampleShouldResolveGeoJsonCoordinatesCorrectly() {
|
||||
|
||||
Person megan = new Person("megan", "tarash");
|
||||
megan.setLocation(new GeoJsonPoint(41.85003D, -87.65005D));
|
||||
@@ -325,7 +324,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findAllByExampleShouldProcessInheritanceCorrectly() {
|
||||
public void findAllByExampleShouldProcessInheritanceCorrectly() {
|
||||
|
||||
PersonExtended reference = new PersonExtended();
|
||||
reference.setLastname("Matthews");
|
||||
@@ -341,7 +340,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void findOneByExampleShouldLookUpEntriesCorrectly() {
|
||||
public void findOneByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setFirstname("Dave");
|
||||
@@ -352,7 +351,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void existsByExampleShouldLookUpEntriesCorrectly() {
|
||||
public void existsByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setFirstname("Dave");
|
||||
@@ -363,7 +362,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
void countByExampleShouldLookUpEntriesCorrectly() {
|
||||
public void countByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -373,7 +372,7 @@ class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1896
|
||||
void saveAllUsesEntityCollection() {
|
||||
public void saveAllUsesEntityCollection() {
|
||||
|
||||
Person first = new PersonExtended();
|
||||
first.setEmail("foo@bar.com");
|
||||
@@ -385,7 +384,7 @@ class SimpleMongoRepositoryTests {
|
||||
|
||||
repository.deleteAll();
|
||||
|
||||
repository.saveAll(asList(first, second));
|
||||
repository.saveAll(Arrays.asList(first, second));
|
||||
|
||||
assertThat(repository.findAll()).containsExactlyInAnyOrder(first, second);
|
||||
}
|
||||
@@ -393,7 +392,7 @@ class SimpleMongoRepositoryTests {
|
||||
@Test // DATAMONGO-2130
|
||||
@EnableIfReplicaSetAvailable
|
||||
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
|
||||
void countShouldBePossibleInTransaction() {
|
||||
public void countShouldBePossibleInTransaction() {
|
||||
|
||||
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
|
||||
TransactionTemplate tt = new TransactionTemplate(txmgr);
|
||||
@@ -417,7 +416,7 @@ class SimpleMongoRepositoryTests {
|
||||
@Test // DATAMONGO-2130
|
||||
@EnableIfReplicaSetAvailable
|
||||
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
|
||||
void existsShouldBePossibleInTransaction() {
|
||||
public void existsShouldBePossibleInTransaction() {
|
||||
|
||||
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
|
||||
TransactionTemplate tt = new TransactionTemplate(txmgr);
|
||||
@@ -436,15 +435,6 @@ class SimpleMongoRepositoryTests {
|
||||
assertThat(exists).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2652
|
||||
void deleteAllByIds() {
|
||||
|
||||
repository.deleteAllById(asList(dave.getId(), carter.getId()));
|
||||
|
||||
assertThat(repository.findAll()) //
|
||||
.hasSize(all.size() - 2).doesNotContain(dave, carter);
|
||||
}
|
||||
|
||||
private void assertThatAllReferencePersonsWereStoredCorrectly(Map<String, Person> references, List<Person> saved) {
|
||||
|
||||
for (Person person : saved) {
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
Spring Data MongoDB Changelog
|
||||
=============================
|
||||
|
||||
Changes in version 3.1.2 (2020-12-09)
|
||||
-------------------------------------
|
||||
* DATAMONGO-2663 - Document Spring Data to MongoDB compatibility.
|
||||
* DATAMONGO-2661 - Handle nullable types for KPropertyPath.
|
||||
* DATAMONGO-2653 - Release 3.1.2 (2020.0.2).
|
||||
|
||||
|
||||
Changes in version 3.2.0-M1 (2020-12-09)
|
||||
----------------------------------------
|
||||
* DATAMONGO-2663 - Document Spring Data to MongoDB compatibility.
|
||||
@@ -3252,5 +3259,6 @@ Repository
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Spring Data MongoDB 3.2 M1 (2021.0.0)
|
||||
Spring Data MongoDB 3.1.2 (2020.0.2)
|
||||
Copyright (c) [2010-2019] Pivotal Software, Inc.
|
||||
|
||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||
@@ -21,3 +21,4 @@ conditions of the subcomponent's license, as noted in the LICENSE file.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user