Compare commits
97 Commits
3.0.0.RC1
...
3.0.4.RELE
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56115a263c | ||
|
|
66b809318a | ||
|
|
bfff60d915 | ||
|
|
051e973226 | ||
|
|
eb61629f10 | ||
|
|
85783e5354 | ||
|
|
433b012b91 | ||
|
|
8dca0049ca | ||
|
|
635f3b82be | ||
|
|
e69c7e1134 | ||
|
|
1f94e74b75 | ||
|
|
98858e0f5f | ||
|
|
90f311de51 | ||
|
|
7f7015fd86 | ||
|
|
ab9c5d73a0 | ||
|
|
13caa162db | ||
|
|
d5d620d777 | ||
|
|
21d50f2a72 | ||
|
|
4912d62be6 | ||
|
|
2bf6f226d6 | ||
|
|
1a6f7e371a | ||
|
|
2ef5d795ce | ||
|
|
e3d2f16202 | ||
|
|
c44232ff39 | ||
|
|
385e911708 | ||
|
|
171d8b2b1e | ||
|
|
7ac7eefad6 | ||
|
|
7a39e94e4b | ||
|
|
25733664b3 | ||
|
|
81da10f499 | ||
|
|
bde114ed19 | ||
|
|
a2403f58ec | ||
|
|
875b8eda9f | ||
|
|
fc0a021937 | ||
|
|
a6aa174ff5 | ||
|
|
8b36617752 | ||
|
|
56e8799c22 | ||
|
|
88e60070d6 | ||
|
|
6c7039580f | ||
|
|
fba003f215 | ||
|
|
1a3239554c | ||
|
|
37b541931d | ||
|
|
9038280f68 | ||
|
|
75935a2bdb | ||
|
|
d9ca3d7eb3 | ||
|
|
04e77ad5ab | ||
|
|
0ab39a17a7 | ||
|
|
49a6f13797 | ||
|
|
b0fd6f691b | ||
|
|
b5778772d9 | ||
|
|
0f55fb305d | ||
|
|
5ae7547465 | ||
|
|
cf4e04a30e | ||
|
|
89c1dc77d9 | ||
|
|
a2c842b59b | ||
|
|
0cd0be9478 | ||
|
|
f88d1de068 | ||
|
|
62bfde2b6b | ||
|
|
93a27f80a3 | ||
|
|
c2b0090ff1 | ||
|
|
0345abb5f8 | ||
|
|
35196e3129 | ||
|
|
37d99c4948 | ||
|
|
288e04b2d3 | ||
|
|
689c1480bd | ||
|
|
09fbe6060e | ||
|
|
d5cf3dfc22 | ||
|
|
0f987f44ef | ||
|
|
5df22233d8 | ||
|
|
9751c6bc8b | ||
|
|
7dc509953a | ||
|
|
2f4f1e524d | ||
|
|
26ddf9d59f | ||
|
|
96ff4e1d14 | ||
|
|
2af13c27a7 | ||
|
|
f4d2fc6231 | ||
|
|
3ab679bcc7 | ||
|
|
318d552797 | ||
|
|
8cfbd39c7e | ||
|
|
3a14af5485 | ||
|
|
00034d899a | ||
|
|
fba6d7d8be | ||
|
|
95c4707902 | ||
|
|
32f3e60c9f | ||
|
|
b57e571033 | ||
|
|
6604c507dd | ||
|
|
e1df28797a | ||
|
|
c6630aa279 | ||
|
|
bf921cdbd7 | ||
|
|
a1b4e6df59 | ||
|
|
4b3312998a | ||
|
|
c5501db577 | ||
|
|
936a0d35f7 | ||
|
|
5dd91d0b6d | ||
|
|
28510de6c8 | ||
|
|
4bbf4cd5cf | ||
|
|
90bd3f0f18 |
40
.travis.yml
40
.travis.yml
@@ -1,40 +0,0 @@
|
||||
language: java
|
||||
|
||||
before_install:
|
||||
- mkdir -p downloads
|
||||
- mkdir -p var/db var/log
|
||||
- if [[ ! -d downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION} ]] ; then cd downloads && wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}.tgz && tar xzf mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}.tgz && cd ..; fi
|
||||
- downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}/bin/mongod --version
|
||||
- downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}/bin/mongod --dbpath var/db --replSet rs0 --fork --logpath var/log/mongod.log
|
||||
- sleep 10
|
||||
- |-
|
||||
downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}/bin/mongo --eval "rs.initiate({_id: 'rs0', members:[{_id: 0, host: '127.0.0.1:27017'}]});"
|
||||
sleep 15
|
||||
|
||||
jdk:
|
||||
- openjdk13
|
||||
- openjdk-ea
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- jdk: openjdk-ea
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- MONGO_VERSION=4.2.0
|
||||
- MONGO_VERSION=4.0.14
|
||||
- MONGO_VERSION=3.6.16
|
||||
global:
|
||||
- PROFILE=ci
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.m2
|
||||
- downloads
|
||||
|
||||
install: true
|
||||
|
||||
script:
|
||||
- "./mvnw clean dependency:list test -Pjava11 -Dsort -U"
|
||||
20
Jenkinsfile
vendored
20
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.3.x", threshold: hudson.model.Result.SUCCESS)
|
||||
}
|
||||
|
||||
options {
|
||||
@@ -46,16 +46,16 @@ pipeline {
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Publish JDK 13 + MongoDB 4.2') {
|
||||
stage('Publish JDK 14 + MongoDB 4.2') {
|
||||
when {
|
||||
changeset "ci/openjdk13-mongodb-4.2/**"
|
||||
changeset "ci/openjdk14-mongodb-4.2/**"
|
||||
}
|
||||
agent { label 'data' }
|
||||
options { timeout(time: 30, unit: 'MINUTES') }
|
||||
|
||||
steps {
|
||||
script {
|
||||
def image = docker.build("springci/spring-data-openjdk13-with-mongodb-4.2.0", "ci/openjdk13-mongodb-4.2/")
|
||||
def image = docker.build("springci/spring-data-openjdk14-with-mongodb-4.2.0", "ci/openjdk14-mongodb-4.2/")
|
||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||
image.push()
|
||||
}
|
||||
@@ -68,7 +68,7 @@ pipeline {
|
||||
stage("test: baseline (jdk8)") {
|
||||
when {
|
||||
anyOf {
|
||||
branch 'master'
|
||||
branch '3.0.x'
|
||||
not { triggeredBy 'UpstreamCause' }
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ pipeline {
|
||||
stage("Test other configurations") {
|
||||
when {
|
||||
anyOf {
|
||||
branch 'master'
|
||||
branch '3.0.x'
|
||||
not { triggeredBy 'UpstreamCause' }
|
||||
}
|
||||
}
|
||||
@@ -139,10 +139,10 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage("test: baseline (jdk13)") {
|
||||
stage("test: baseline (jdk14)") {
|
||||
agent {
|
||||
docker {
|
||||
image 'springci/spring-data-openjdk13-with-mongodb-4.2.0:latest'
|
||||
image 'springci/spring-data-openjdk14-with-mongodb-4.2.0:latest'
|
||||
label 'data'
|
||||
args '-v $HOME:/tmp/jenkins-home'
|
||||
}
|
||||
@@ -164,7 +164,7 @@ pipeline {
|
||||
stage('Release to artifactory') {
|
||||
when {
|
||||
anyOf {
|
||||
branch 'master'
|
||||
branch '3.0.x'
|
||||
not { triggeredBy 'UpstreamCause' }
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ pipeline {
|
||||
|
||||
stage('Publish documentation') {
|
||||
when {
|
||||
branch 'master'
|
||||
branch '3.0.x'
|
||||
}
|
||||
agent {
|
||||
docker {
|
||||
|
||||
@@ -52,11 +52,6 @@ public class MyService {
|
||||
@EnableMongoRepositories
|
||||
class ApplicationConfig extends AbstractMongoClientConfiguration {
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
return MongoClients.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDatabaseName() {
|
||||
return "springdata";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM adoptopenjdk/openjdk13:latest
|
||||
FROM adoptopenjdk/openjdk14:latest
|
||||
|
||||
ENV TZ=Etc/UTC
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
12
pom.xml
12
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>3.0.0.RC1</version>
|
||||
<version>3.0.4.RELEASE</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.3.0.RC1</version>
|
||||
<version>2.3.4.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
@@ -26,8 +26,8 @@
|
||||
<properties>
|
||||
<project.type>multi</project.type>
|
||||
<dist.id>spring-data-mongodb</dist.id>
|
||||
<springdata.commons>2.3.0.RC1</springdata.commons>
|
||||
<mongo>4.0.1</mongo>
|
||||
<springdata.commons>2.3.4.RELEASE</springdata.commons>
|
||||
<mongo>4.0.5</mongo>
|
||||
<mongo.reactivestreams>${mongo}</mongo.reactivestreams>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
</properties>
|
||||
@@ -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.0.0.RC1</version>
|
||||
<version>3.0.4.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>3.0.0.RC1</version>
|
||||
<version>3.0.4.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>3.0.0.RC1</version>
|
||||
<version>3.0.4.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -25,8 +25,10 @@ public class LazyLoadingException extends UncategorizedDataAccessException {
|
||||
private static final long serialVersionUID = -7089224903873220037L;
|
||||
|
||||
/**
|
||||
* @param msg
|
||||
* @param cause
|
||||
* Constructor for LazyLoadingException.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the exception thrown by underlying data access API.
|
||||
*/
|
||||
public LazyLoadingException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface MongoDatabaseFactory extends CodecRegistryProvider, MongoSessio
|
||||
/**
|
||||
* Obtain a {@link MongoDatabase} instance to access the database with the given name.
|
||||
*
|
||||
* @param dbName
|
||||
* @param dbName must not be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
|
||||
@@ -79,7 +79,7 @@ public class MongoDatabaseUtils {
|
||||
* @param factory the {@link MongoDatabaseFactory} to get the {@link MongoDatabase} from.
|
||||
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
||||
*/
|
||||
public static MongoDatabase getDatabase(String dbName, MongoDatabaseFactory factory) {
|
||||
public static MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory) {
|
||||
return doGetMongoDatabase(dbName, factory, SessionSynchronization.ON_ACTUAL_TRANSACTION);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class MongoDatabaseUtils {
|
||||
* @param sessionSynchronization the synchronization to use. Must not be {@literal null}.
|
||||
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
||||
*/
|
||||
public static MongoDatabase getDatabase(String dbName, MongoDatabaseFactory factory,
|
||||
public static MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory,
|
||||
SessionSynchronization sessionSynchronization) {
|
||||
return doGetMongoDatabase(dbName, factory, sessionSynchronization);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface MongoDbFactory extends MongoDatabaseFactory {
|
||||
/**
|
||||
* Creates a default {@link MongoDatabase} instance.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @throws DataAccessException
|
||||
* @deprecated since 3.0. Use {@link #getMongoDatabase()} instead.
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ public interface MongoDbFactory extends MongoDatabaseFactory {
|
||||
* Obtain a {@link MongoDatabase} instance to access the database with the given name.
|
||||
*
|
||||
* @param dbName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @throws DataAccessException
|
||||
* @deprecated since 3.0. Use {@link #getMongoDatabase(String)} instead.
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.mongodb.reactivestreams.client.MongoDatabase;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Mathieu Ouellet
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface ReactiveMongoDatabaseFactory extends CodecRegistryProvider {
|
||||
@@ -38,19 +39,19 @@ public interface ReactiveMongoDatabaseFactory extends CodecRegistryProvider {
|
||||
/**
|
||||
* Creates a default {@link MongoDatabase} instance.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
MongoDatabase getMongoDatabase() throws DataAccessException;
|
||||
Mono<MongoDatabase> getMongoDatabase() throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Obtain a {@link MongoDatabase} instance to access the database with the given name.
|
||||
*
|
||||
* @param dbName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
MongoDatabase getMongoDatabase(String dbName) throws DataAccessException;
|
||||
Mono<MongoDatabase> getMongoDatabase(String dbName) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Exposes a shared {@link MongoExceptionTranslator}.
|
||||
@@ -64,10 +65,7 @@ public interface ReactiveMongoDatabaseFactory extends CodecRegistryProvider {
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
@Override
|
||||
default CodecRegistry getCodecRegistry() {
|
||||
return getMongoDatabase().getCodecRegistry();
|
||||
}
|
||||
CodecRegistry getCodecRegistry();
|
||||
|
||||
/**
|
||||
* Obtain a {@link Mono} emitting a {@link ClientSession} for given {@link ClientSessionOptions options}.
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.mongodb.reactivestreams.client.MongoDatabase;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Mathieu Ouellet
|
||||
* @since 2.2
|
||||
*/
|
||||
public class ReactiveMongoDatabaseUtils {
|
||||
@@ -142,14 +143,13 @@ public class ReactiveMongoDatabaseUtils {
|
||||
.flatMap(synchronizationManager -> {
|
||||
|
||||
return doGetSession(synchronizationManager, factory, sessionSynchronization) //
|
||||
.map(it -> getMongoDatabaseOrDefault(dbName, factory.withSession(it)));
|
||||
})
|
||||
.onErrorResume(NoTransactionException.class,
|
||||
e -> Mono.fromSupplier(() -> getMongoDatabaseOrDefault(dbName, factory)))
|
||||
.defaultIfEmpty(getMongoDatabaseOrDefault(dbName, factory));
|
||||
.flatMap(it -> getMongoDatabaseOrDefault(dbName, factory.withSession(it)));
|
||||
}) //
|
||||
.onErrorResume(NoTransactionException.class, e -> getMongoDatabaseOrDefault(dbName, factory))
|
||||
.switchIfEmpty(getMongoDatabaseOrDefault(dbName, factory));
|
||||
}
|
||||
|
||||
private static MongoDatabase getMongoDatabaseOrDefault(@Nullable String dbName,
|
||||
private static Mono<MongoDatabase> getMongoDatabaseOrDefault(@Nullable String dbName,
|
||||
ReactiveMongoDatabaseFactory factory) {
|
||||
return StringUtils.hasText(dbName) ? factory.getMongoDatabase(dbName) : factory.getMongoDatabase();
|
||||
}
|
||||
|
||||
@@ -42,21 +42,21 @@ public @interface EnableMongoAuditing {
|
||||
/**
|
||||
* Configures the {@link AuditorAware} bean to be used to lookup the current principal.
|
||||
*
|
||||
* @return
|
||||
* @return empty {@link String} by default.
|
||||
*/
|
||||
String auditorAwareRef() default "";
|
||||
|
||||
/**
|
||||
* Configures whether the creation and modification dates are set. Defaults to {@literal true}.
|
||||
*
|
||||
* @return
|
||||
* @return {@literal true} by default.
|
||||
*/
|
||||
boolean setDates() default true;
|
||||
|
||||
/**
|
||||
* Configures whether the entity shall be marked as modified on creation. Defaults to {@literal true}.
|
||||
*
|
||||
* @return
|
||||
* @return {@literal true} by default.
|
||||
*/
|
||||
boolean modifyOnCreate() default true;
|
||||
|
||||
@@ -64,7 +64,7 @@ public @interface EnableMongoAuditing {
|
||||
* Configures a {@link DateTimeProvider} bean name that allows customizing the {@link org.joda.time.DateTime} to be
|
||||
* used for setting creation and modification dates.
|
||||
*
|
||||
* @return
|
||||
* @return empty {@link String} by default.
|
||||
*/
|
||||
String dateTimeProviderRef() default "";
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public abstract class MongoConfigurationSupport {
|
||||
/**
|
||||
* Register custom {@link Converter}s in a {@link CustomConversions} object if required. These
|
||||
* {@link CustomConversions} will be registered with the
|
||||
* {@link org.springframework.data.mongodb.core.convert.MappingMongoConverter} and {@link #mongoMappingContext()}.
|
||||
* {@link org.springframework.data.mongodb.core.convert.MappingMongoConverter} and {@link MongoMappingContext}.
|
||||
* Returns an empty {@link MongoCustomConversions} instance by default.
|
||||
* <p>
|
||||
* <strong>NOTE:</strong> Use {@link #configureConverters(MongoConverterConfigurationAdapter)} to configure MongoDB
|
||||
@@ -217,6 +217,7 @@ public abstract class MongoConfigurationSupport {
|
||||
protected MongoClientSettings mongoClientSettings() {
|
||||
|
||||
MongoClientSettings.Builder builder = MongoClientSettings.builder();
|
||||
builder.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
|
||||
configureClientSettings(builder);
|
||||
return builder.build();
|
||||
}
|
||||
@@ -228,6 +229,6 @@ public abstract class MongoConfigurationSupport {
|
||||
* @since 3.0
|
||||
*/
|
||||
protected void configureClientSettings(MongoClientSettings.Builder builder) {
|
||||
builder.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
|
||||
// customization hook
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,6 @@ public interface BulkOperations {
|
||||
* Add a list of updates to the bulk operation. For each update request, all matching documents are updated.
|
||||
*
|
||||
* @param updates Update operations to perform.
|
||||
* @return The bulk operation.
|
||||
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
||||
*/
|
||||
BulkOperations updateMulti(List<Pair<Query, Update>> updates);
|
||||
@@ -105,7 +104,6 @@ public interface BulkOperations {
|
||||
*
|
||||
* @param query Update criteria.
|
||||
* @param update Update operation to perform.
|
||||
* @return The bulk operation.
|
||||
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
||||
*/
|
||||
BulkOperations upsert(Query query, Update update);
|
||||
@@ -115,7 +113,6 @@ public interface BulkOperations {
|
||||
* else an insert.
|
||||
*
|
||||
* @param updates Updates/insert operations to perform.
|
||||
* @return The bulk operation.
|
||||
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
||||
*/
|
||||
BulkOperations upsert(List<Pair<Query, Update>> updates);
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.mongodb.client.MongoCollection;
|
||||
* @author Grame Rocher
|
||||
* @author Oliver Gierke
|
||||
* @author John Brisbin
|
||||
* @auhtor Christoph Strobl
|
||||
* @author Christoph Strobl
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface CollectionCallback<T> {
|
||||
|
||||
@@ -95,7 +95,7 @@ public class CollectionOptions {
|
||||
|
||||
/**
|
||||
* Create new {@link CollectionOptions} with already given settings and capped set to {@literal true}. <br />
|
||||
* <strong>NOTE</strong> Using capped collections requires defining {@link #size(int)}.
|
||||
* <strong>NOTE</strong> Using capped collections requires defining {@link #size(long)}.
|
||||
*
|
||||
* @return new {@link CollectionOptions}.
|
||||
* @since 2.0
|
||||
|
||||
@@ -43,9 +43,10 @@ public interface CursorPreparer extends ReadPreferenceAware {
|
||||
/**
|
||||
* Prepare the given cursor (apply limits, skips and so on). Returns the prepared cursor.
|
||||
*
|
||||
* @param cursor
|
||||
* @param iterable must not be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
FindIterable<Document> prepare(FindIterable<Document> cursor);
|
||||
FindIterable<Document> prepare(FindIterable<Document> iterable);
|
||||
|
||||
/**
|
||||
* Apply query specific settings to {@link MongoCollection} and initate a find operation returning a
|
||||
@@ -53,7 +54,7 @@ public interface CursorPreparer extends ReadPreferenceAware {
|
||||
*
|
||||
* @param collection must not be {@literal null}.
|
||||
* @param find must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @throws IllegalArgumentException if one of the required arguments is {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.mongodb.MongoException;
|
||||
/**
|
||||
* An interface used by {@link MongoTemplate} for processing documents returned from a MongoDB query on a per-document
|
||||
* basis. Implementations of this interface perform the actual work of prcoessing each document but don't need to worry
|
||||
* about exception handling. {@MongoException}s will be caught and translated by the calling MongoTemplate An
|
||||
* about exception handling. {@link MongoException}s will be caught and translated by the calling MongoTemplate An
|
||||
* DocumentCallbackHandler is typically stateful: It keeps the result state within the object, to be available later for
|
||||
* later inspection.
|
||||
*
|
||||
|
||||
@@ -66,7 +66,7 @@ class EntityOperations {
|
||||
* Creates a new {@link Entity} for the given bean.
|
||||
*
|
||||
* @param entity must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Entity}.
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <T> Entity<T> forEntity(T entity) {
|
||||
@@ -89,7 +89,7 @@ class EntityOperations {
|
||||
*
|
||||
* @param entity must not be {@literal null}.
|
||||
* @param conversionService must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AdaptibleEntity}.
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <T> AdaptibleEntity<T> forEntity(T entity, ConversionService conversionService) {
|
||||
@@ -108,6 +108,10 @@ class EntityOperations {
|
||||
return AdaptibleMappedEntity.of(entity, context, conversionService);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entityClass should not be null.
|
||||
* @return the {@link MongoPersistentEntity#getCollection() collection name}.
|
||||
*/
|
||||
public String determineCollectionName(@Nullable Class<?> entityClass) {
|
||||
|
||||
if (entityClass == null) {
|
||||
@@ -138,7 +142,7 @@ class EntityOperations {
|
||||
* {@code _id} if no identifier property can be found.
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public String getIdPropertyName(Class<?> type) {
|
||||
|
||||
|
||||
@@ -88,9 +88,9 @@ public interface ExecutableAggregationOperation {
|
||||
|
||||
/**
|
||||
* Apply pipeline operations as specified and stream all matching elements. <br />
|
||||
* Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.Cursor}
|
||||
* Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable}
|
||||
*
|
||||
* @return a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.Cursor} that needs to be closed.
|
||||
* @return a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed.
|
||||
* Never {@literal null}.
|
||||
*/
|
||||
CloseableIterator<T> stream();
|
||||
|
||||
@@ -44,7 +44,7 @@ import com.mongodb.client.MongoCollection;
|
||||
* query(Human.class)
|
||||
* .inCollection("star-wars")
|
||||
* .as(Jedi.class)
|
||||
* .matching(query(where("firstname").is("luke")))
|
||||
* .matching(where("firstname").is("luke"))
|
||||
* .all();
|
||||
* </code>
|
||||
* </pre>
|
||||
@@ -118,7 +118,7 @@ public interface ExecutableFindOperation {
|
||||
/**
|
||||
* Stream all matching elements.
|
||||
*
|
||||
* @return a {@link Stream} that wraps the a Mongo DB {@link com.mongodb.Cursor} that needs to be closed. Never
|
||||
* @return a {@link Stream} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed. Never
|
||||
* {@literal null}.
|
||||
*/
|
||||
Stream<T> stream();
|
||||
@@ -174,13 +174,13 @@ public interface ExecutableFindOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingFind}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @throws IllegalArgumentException if criteria is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingFind<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default TerminatingFind<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,9 +304,21 @@ public interface ExecutableFindOperation {
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingDistinct}.
|
||||
* @throws IllegalArgumentException if resultType is {@literal null}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
*/
|
||||
TerminatingDistinct<T> matching(Query query);
|
||||
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingDistinct}.
|
||||
* @throws IllegalArgumentException if criteria is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingDistinct<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -257,9 +257,9 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
|
||||
* @see org.springframework.data.mongodb.core.CursorPreparer#prepare(com.mongodb.clientFindIterable)
|
||||
*/
|
||||
@Override
|
||||
public FindIterable<Document> prepare(FindIterable<Document> cursor) {
|
||||
public FindIterable<Document> prepare(FindIterable<Document> iterable) {
|
||||
|
||||
FindIterable<Document> target = delegate != null ? delegate.prepare(cursor) : cursor;
|
||||
FindIterable<Document> target = delegate != null ? delegate.prepare(iterable) : iterable;
|
||||
return limit.map(target::limit).orElse(target);
|
||||
}
|
||||
|
||||
|
||||
@@ -152,13 +152,13 @@ public interface ExecutableMapReduceOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingMapReduce}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingMapReduce<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default TerminatingMapReduce<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,13 +124,13 @@ public interface ExecutableRemoveOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingRemove}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingRemove<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default TerminatingRemove<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -215,13 +215,13 @@ public interface ExecutableUpdateOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link UpdateWithUpdate}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default UpdateWithUpdate<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default UpdateWithUpdate<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class FindAndModifyOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link FindAndModifyOptions} based on option of given {@litearl source}.
|
||||
* Create new {@link FindAndModifyOptions} based on option of given {@literal source}.
|
||||
*
|
||||
* @param source can be {@literal null}.
|
||||
* @return new instance of {@link FindAndModifyOptions}.
|
||||
@@ -117,8 +117,8 @@ public class FindAndModifyOptions {
|
||||
/**
|
||||
* Define the {@link Collation} specifying language-specific rules for string comparison.
|
||||
*
|
||||
* @param collation
|
||||
* @return
|
||||
* @param collation can be {@literal null}.
|
||||
* @return this.
|
||||
* @since 2.0
|
||||
*/
|
||||
public FindAndModifyOptions collation(@Nullable Collation collation) {
|
||||
@@ -142,7 +142,7 @@ public class FindAndModifyOptions {
|
||||
/**
|
||||
* Get the {@link Collation} specifying language-specific rules for string comparison.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public Optional<Collation> getCollation() {
|
||||
|
||||
@@ -116,7 +116,7 @@ public class FindAndReplaceOptions {
|
||||
/**
|
||||
* Get the bit indicating to return the replacement document.
|
||||
*
|
||||
* @return
|
||||
* @return {@literal true} if set.
|
||||
*/
|
||||
public boolean isReturnNew() {
|
||||
return returnNew;
|
||||
@@ -125,7 +125,7 @@ public class FindAndReplaceOptions {
|
||||
/**
|
||||
* Get the bit indicating if to create a new document if not exists.
|
||||
*
|
||||
* @return
|
||||
* @return {@literal true} if set.
|
||||
*/
|
||||
public boolean isUpsert() {
|
||||
return upsert;
|
||||
|
||||
@@ -54,7 +54,7 @@ public interface FindPublisherPreparer extends ReadPreferenceAware {
|
||||
*
|
||||
* @param collection must not be {@literal null}.
|
||||
* @param find must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @throws IllegalArgumentException if one of the required arguments is {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ class GeoCommandStatistics {
|
||||
* Creates a new {@link GeoCommandStatistics} from the given command result extracting the statistics.
|
||||
*
|
||||
* @param commandResult must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static GeoCommandStatistics from(Document commandResult) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class GeoCommandStatistics {
|
||||
* Returns the average distance reported by the command result. Mitigating a removal of the field in case the command
|
||||
* didn't return any result introduced in MongoDB 3.2 RC1.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}, uses {@link Double#NaN} if {@literal avgDistance} does not exist.
|
||||
* @see <a href="https://jira.mongodb.org/browse/SERVER-21024">MongoDB Jira SERVER-21024</a>
|
||||
*/
|
||||
public double getAverageDistance() {
|
||||
|
||||
@@ -254,7 +254,7 @@ public abstract class MongoDatabaseFactorySupport<C> implements MongoDatabaseFac
|
||||
factory.addAdvice(new SessionAwareMethodInterceptor<>(session, target, ClientSession.class, MongoDatabase.class,
|
||||
this::proxyDatabase, MongoCollection.class, this::proxyCollection));
|
||||
|
||||
return targetType.cast(factory.getProxy());
|
||||
return targetType.cast(factory.getProxy(target.getClass().getClassLoader()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* The collection name used for the specified class by this template.
|
||||
*
|
||||
* @param entityClass must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
String getCollectionName(Class<?> entityClass);
|
||||
|
||||
@@ -363,7 +363,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Returns the {@link ScriptOperations} that can be performed on {@link com.mongodb.client.MongoDatabase} level.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @since 1.7
|
||||
* @deprecated since 2.2. The {@code eval} command has been removed without replacement in MongoDB Server 4.2.0.
|
||||
*/
|
||||
@@ -1557,7 +1557,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Returns the underlying {@link MongoConverter}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
MongoConverter getConverter();
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ import org.springframework.data.mongodb.core.mapreduce.GroupBy;
|
||||
import org.springframework.data.mongodb.core.mapreduce.GroupByResults;
|
||||
import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
|
||||
import org.springframework.data.mongodb.core.mapreduce.MapReduceResults;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Meta;
|
||||
@@ -238,7 +239,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
this.projectionFactory = new SpelAwareProxyProjectionFactory();
|
||||
this.operations = new EntityOperations(this.mongoConverter.getMappingContext());
|
||||
this.propertyOperations = new PropertyOperations(this.mongoConverter.getMappingContext());
|
||||
this.queryOperations = new QueryOperations(queryMapper, updateMapper, operations, mongoDbFactory);
|
||||
this.queryOperations = new QueryOperations(queryMapper, updateMapper, operations, propertyOperations,
|
||||
mongoDbFactory);
|
||||
|
||||
// We always have a mapping context in the converter, whether it's a simple one or not
|
||||
mappingContext = this.mongoConverter.getMappingContext();
|
||||
@@ -424,8 +426,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityType);
|
||||
|
||||
Document mappedFields = getMappedFieldsObject(query.getFieldsObject(), persistentEntity, returnType);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), persistentEntity);
|
||||
QueryContext queryContext = queryOperations.createQueryContext(query);
|
||||
|
||||
Document mappedQuery = queryContext.getMappedQuery(persistentEntity);
|
||||
Document mappedFields = queryContext.getMappedFields(persistentEntity, returnType, projectionFactory);
|
||||
|
||||
FindIterable<Document> cursor = new QueryCursorPreparer(query, entityType).initiateFind(collection,
|
||||
col -> col.find(mappedQuery, Document.class).projection(mappedFields));
|
||||
@@ -1054,7 +1058,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
QueryContext queryContext = queryOperations.createQueryContext(query);
|
||||
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
Document mappedFields = queryContext.getMappedFields(entity);
|
||||
Document mappedFields = queryContext.getMappedFields(entity, resultType, projectionFactory);
|
||||
Document mappedSort = queryContext.getMappedSort(entity);
|
||||
|
||||
replacement = maybeCallBeforeConvert(replacement, collectionName);
|
||||
@@ -1174,7 +1178,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
/**
|
||||
* Prepare the collection before any processing is done using it. This allows a convenient way to apply settings like
|
||||
* slaveOk() etc. Can be overridden in sub-classes.
|
||||
* withCodecRegistry() etc. Can be overridden in sub-classes.
|
||||
*
|
||||
* @param collection
|
||||
*/
|
||||
@@ -1819,7 +1823,11 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
if (query.getMeta().getMaxTimeMsec() != null) {
|
||||
mapReduce = mapReduce.maxTime(query.getMeta().getMaxTimeMsec(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
mapReduce = mapReduce.sort(getMappedSortObject(query, domainType));
|
||||
|
||||
Document mappedSort = getMappedSortObject(query, domainType);
|
||||
if (mappedSort != null && !mappedSort.isEmpty()) {
|
||||
mapReduce = mapReduce.sort(getMappedSortObject(query, domainType));
|
||||
}
|
||||
|
||||
mapReduce = mapReduce
|
||||
.filter(queryMapper.getMappedObject(query.getQueryObject(), mappingContext.getPersistentEntity(domainType)));
|
||||
@@ -2117,7 +2125,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
List<Document> rawResult = new ArrayList<>();
|
||||
|
||||
Class<?> domainType = aggregation instanceof TypedAggregation ? ((TypedAggregation) aggregation).getInputType()
|
||||
Class<?> domainType = aggregation instanceof TypedAggregation ? ((TypedAggregation<?>) aggregation).getInputType()
|
||||
: null;
|
||||
|
||||
Optional<Collation> collation = Optionals.firstNonEmpty(options::getCollation,
|
||||
@@ -2138,6 +2146,17 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
aggregateIterable = aggregateIterable.maxTime(options.getMaxTime().toMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
if (options.isSkipResults()) {
|
||||
|
||||
// toCollection only allowed for $out and $merge if those are the last stages
|
||||
if (aggregation.getPipeline().isOutOrMerge()) {
|
||||
aggregateIterable.toCollection();
|
||||
} else {
|
||||
aggregateIterable.first();
|
||||
}
|
||||
return new AggregationResults<>(Collections.emptyList(), new Document());
|
||||
}
|
||||
|
||||
MongoIterable<O> iterable = aggregateIterable.map(val -> {
|
||||
|
||||
rawResult.add(val);
|
||||
@@ -2435,8 +2454,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
Document mappedFields = queryMapper.getMappedObject(fields, entity);
|
||||
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
|
||||
Document mappedFields = queryContext.getMappedFields(entity, entityClass, projectionFactory);
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("findOne using query: {} fields: {} for class: {} in collection: {}", serializeToJsonSafely(query),
|
||||
@@ -2486,8 +2506,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
Document mappedFields = queryMapper.getMappedFields(fields, entity);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
|
||||
Document mappedFields = queryContext.getMappedFields(entity, entityClass, projectionFactory);
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("find using query: {} fields: {} for class: {} in collection: {}",
|
||||
@@ -2509,8 +2530,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(sourceClass);
|
||||
|
||||
Document mappedFields = getMappedFieldsObject(fields, entity, targetClass);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
|
||||
Document mappedFields = queryContext.getMappedFields(entity, targetClass, projectionFactory);
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("find using query: {} fields: {} for class: {} in collection: {}",
|
||||
@@ -2839,23 +2861,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
return queryMapper.getMappedSort(query.getSortObject(), mappingContext.getPersistentEntity(type));
|
||||
}
|
||||
|
||||
private Document getMappedFieldsObject(Document fields, @Nullable MongoPersistentEntity<?> entity,
|
||||
Class<?> targetType) {
|
||||
|
||||
if (entity == null) {
|
||||
return fields;
|
||||
}
|
||||
|
||||
Document projectedFields = propertyOperations.computeFieldsForProjection(projectionFactory, fields,
|
||||
entity.getType(), targetType);
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(fields, projectedFields)) {
|
||||
return queryMapper.getMappedFields(projectedFields, entity);
|
||||
}
|
||||
|
||||
return queryMapper.getMappedFields(projectedFields, mappingContext.getRequiredPersistentEntity(targetType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to convert the given {@link RuntimeException} into a {@link DataAccessException} but returns the original
|
||||
* exception if the conversation failed. Thus allows safe re-throwing of the return value.
|
||||
@@ -3129,12 +3134,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
@Nullable
|
||||
public T doWith(@Nullable Document document) {
|
||||
|
||||
T source = null;
|
||||
|
||||
if (document != null) {
|
||||
maybeEmitEvent(new AfterLoadEvent<>(document, type, collectionName));
|
||||
source = reader.read(type, document);
|
||||
}
|
||||
|
||||
T source = reader.read(type, document);
|
||||
|
||||
if (source != null) {
|
||||
maybeEmitEvent(new AfterConvertEvent<>(document, source, collectionName));
|
||||
source = maybeCallAfterConvert(source, document, collectionName);
|
||||
@@ -3175,9 +3181,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
Class<?> typeToRead = targetType.isInterface() || targetType.isAssignableFrom(entityType) ? entityType
|
||||
: targetType;
|
||||
|
||||
if (document != null) {
|
||||
maybeEmitEvent(new AfterLoadEvent<>(document, targetType, collectionName));
|
||||
}
|
||||
maybeEmitEvent(new AfterLoadEvent<>(document, targetType, collectionName));
|
||||
|
||||
Object source = reader.read(typeToRead, document);
|
||||
Object result = targetType.isInterface() ? projectionFactory.createProjection(targetType, source) : source;
|
||||
@@ -3206,9 +3210,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.CursorPreparer#prepare(com.mongodb.DBCursor)
|
||||
*/
|
||||
public FindIterable<Document> prepare(FindIterable<Document> cursor) {
|
||||
public FindIterable<Document> prepare(FindIterable<Document> iterable) {
|
||||
|
||||
FindIterable<Document> cursorToUse = cursor;
|
||||
FindIterable<Document> cursorToUse = iterable;
|
||||
|
||||
operations.forType(type).getCollation(query) //
|
||||
.map(Collation::toMongoCollation) //
|
||||
@@ -3267,6 +3271,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
case PARTIAL:
|
||||
cursorToUse = cursorToUse.partial(true);
|
||||
break;
|
||||
case SECONDARY_READS:
|
||||
case SLAVE_OK:
|
||||
break;
|
||||
default:
|
||||
@@ -3284,7 +3289,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
@Override
|
||||
public ReadPreference getReadPreference() {
|
||||
return query.getMeta().getFlags().contains(CursorOption.SLAVE_OK) ? ReadPreference.primaryPreferred() : null;
|
||||
return (query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS)
|
||||
|| query.getMeta().getFlags().contains(CursorOption.SLAVE_OK)) ? ReadPreference.primaryPreferred() : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,10 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.UpdateDefinition;
|
||||
import org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter;
|
||||
import org.springframework.data.mongodb.util.BsonUtils;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.client.model.CountOptions;
|
||||
@@ -70,6 +72,7 @@ class QueryOperations {
|
||||
private final QueryMapper queryMapper;
|
||||
private final UpdateMapper updateMapper;
|
||||
private final EntityOperations entityOperations;
|
||||
private final PropertyOperations propertyOperations;
|
||||
private final CodecRegistryProvider codecRegistryProvider;
|
||||
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
|
||||
private final AggregationUtil aggregationUtil;
|
||||
@@ -81,14 +84,16 @@ class QueryOperations {
|
||||
* @param queryMapper must not be {@literal null}.
|
||||
* @param updateMapper must not be {@literal null}.
|
||||
* @param entityOperations must not be {@literal null}.
|
||||
* @param propertyOperations must not be {@literal null}.
|
||||
* @param codecRegistryProvider must not be {@literal null}.
|
||||
*/
|
||||
QueryOperations(QueryMapper queryMapper, UpdateMapper updateMapper, EntityOperations entityOperations,
|
||||
CodecRegistryProvider codecRegistryProvider) {
|
||||
PropertyOperations propertyOperations, CodecRegistryProvider codecRegistryProvider) {
|
||||
|
||||
this.queryMapper = queryMapper;
|
||||
this.updateMapper = updateMapper;
|
||||
this.entityOperations = entityOperations;
|
||||
this.propertyOperations = propertyOperations;
|
||||
this.codecRegistryProvider = codecRegistryProvider;
|
||||
this.mappingContext = queryMapper.getMappingContext();
|
||||
this.aggregationUtil = new AggregationUtil(queryMapper, mappingContext);
|
||||
@@ -250,14 +255,31 @@ class QueryOperations {
|
||||
return queryMapper.getMappedObject(getQueryObject(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the already mapped {@link Query#getFieldsObject() fields projection}
|
||||
*
|
||||
* @param entity the Entity to map field names to. Can be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
Document getMappedFields(@Nullable MongoPersistentEntity<?> entity) {
|
||||
return queryMapper.getMappedFields(query.getFieldsObject(), entity);
|
||||
Document getMappedFields(@Nullable MongoPersistentEntity<?> entity, Class<?> targetType,
|
||||
ProjectionFactory projectionFactory) {
|
||||
|
||||
Document fields = query.getFieldsObject();
|
||||
Document mappedFields = fields;
|
||||
|
||||
if (entity == null) {
|
||||
return mappedFields;
|
||||
}
|
||||
|
||||
Document projectedFields = propertyOperations.computeFieldsForProjection(projectionFactory, fields,
|
||||
entity.getType(), targetType);
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(fields, projectedFields)) {
|
||||
mappedFields = queryMapper.getMappedFields(projectedFields, entity);
|
||||
} else {
|
||||
mappedFields = queryMapper.getMappedFields(projectedFields,
|
||||
mappingContext.getRequiredPersistentEntity(targetType));
|
||||
}
|
||||
|
||||
if (entity != null && entity.hasTextScoreProperty() && !query.getQueryObject().containsKey("$text")) {
|
||||
mappedFields.remove(entity.getTextScoreProperty().getFieldName());
|
||||
}
|
||||
|
||||
return mappedFields;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,6 +341,10 @@ class QueryOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
Document getMappedFields(@Nullable MongoPersistentEntity<?> entity, Class<?> targetType, ProjectionFactory projectionFactory) {
|
||||
return getMappedFields(entity);
|
||||
}
|
||||
|
||||
Document getMappedFields(@Nullable MongoPersistentEntity<?> entity) {
|
||||
return queryMapper.getMappedFields(new Document(fieldName, 1), entity);
|
||||
}
|
||||
|
||||
@@ -39,13 +39,14 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
* query(Human.class)
|
||||
* .inCollection("star-wars")
|
||||
* .as(Jedi.class)
|
||||
* .matching(query(where("firstname").is("luke")))
|
||||
* .matching(where("firstname").is("luke"))
|
||||
* .all();
|
||||
* </code>
|
||||
* </pre>
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Juergen Zimmermann
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface ReactiveFindOperation {
|
||||
@@ -148,13 +149,13 @@ public interface ReactiveFindOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingFind}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @throws IllegalArgumentException if criteria is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingFind<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default TerminatingFind<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,9 +273,21 @@ public interface ReactiveFindOperation {
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingDistinct}.
|
||||
* @throws IllegalArgumentException if resultType is {@literal null}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
*/
|
||||
TerminatingDistinct<T> matching(Query query);
|
||||
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingDistinct}.
|
||||
* @throws IllegalArgumentException if criteria is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingDistinct<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,13 +151,13 @@ public interface ReactiveMapReduceOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingMapReduce}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingMapReduce<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default TerminatingMapReduce<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ import com.mongodb.reactivestreams.client.MongoCollection;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Mathieu Ouellet
|
||||
* @since 2.0
|
||||
* @see Flux
|
||||
* @see Mono
|
||||
@@ -298,7 +299,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
|
||||
* @param collectionName name of the collection.
|
||||
* @return an existing collection or one created on first server interaction.
|
||||
*/
|
||||
MongoCollection<Document> getCollection(String collectionName);
|
||||
Mono<MongoCollection<Document>> getCollection(String collectionName);
|
||||
|
||||
/**
|
||||
* Check to see if a collection with a name indicated by the entity class exists.
|
||||
@@ -1238,7 +1239,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
|
||||
* domain type information. Use {@link #updateFirst(Query, UpdateDefinition, Class, String)} to get full type specific
|
||||
* support. <br />
|
||||
* <strong>NOTE:</strong> {@link Query#getSortObject() sorting} is not supported by {@code db.collection.updateOne}.
|
||||
* Use {@link #findAndModify(Query, Update, Class, String)} instead.
|
||||
* Use {@link #findAndModify(Query, UpdateDefinition, Class, String)} instead.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated. Must not be
|
||||
* {@literal null}.
|
||||
@@ -1571,7 +1572,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
|
||||
/**
|
||||
* Returns the underlying {@link MongoConverter}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
MongoConverter getConverter();
|
||||
|
||||
@@ -1579,7 +1580,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
|
||||
* The collection name used for the specified class by this template.
|
||||
*
|
||||
* @param entityClass must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
String getCollectionName(Class<?> entityClass);
|
||||
|
||||
@@ -94,6 +94,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoSimpleTypes;
|
||||
import org.springframework.data.mongodb.core.mapping.event.*;
|
||||
import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.data.mongodb.core.query.Meta;
|
||||
import org.springframework.data.mongodb.core.query.Meta.CursorOption;
|
||||
@@ -156,6 +157,7 @@ import com.mongodb.reactivestreams.client.MongoDatabase;
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Mathieu Ouellet
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ReactiveMongoTemplate implements ReactiveMongoOperations, ApplicationContextAware {
|
||||
@@ -258,7 +260,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
this.mappingContext = this.mongoConverter.getMappingContext();
|
||||
this.operations = new EntityOperations(this.mappingContext);
|
||||
this.propertyOperations = new PropertyOperations(this.mappingContext);
|
||||
this.queryOperations = new QueryOperations(queryMapper, updateMapper, operations, mongoDatabaseFactory);
|
||||
this.queryOperations = new QueryOperations(queryMapper, updateMapper, operations, propertyOperations,
|
||||
mongoDatabaseFactory);
|
||||
|
||||
// We create indexes based on mapping events
|
||||
if (this.mappingContext instanceof MongoMappingContext) {
|
||||
@@ -317,8 +320,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
/**
|
||||
* Configures the {@link WriteConcern} to be used with the template. If none is configured the {@link WriteConcern}
|
||||
* configured on the {@link MongoDatabaseFactory} will apply. If you configured a {@link Mongo} instance no
|
||||
* {@link WriteConcern} will be used.
|
||||
* configured on the {@link MongoDatabaseFactory} will apply.
|
||||
*
|
||||
* @param writeConcern can be {@literal null}.
|
||||
*/
|
||||
@@ -717,15 +719,11 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#getCollection(java.lang.String)
|
||||
*/
|
||||
public MongoCollection<Document> getCollection(String collectionName) {
|
||||
public Mono<MongoCollection<Document>> getCollection(String collectionName) {
|
||||
|
||||
Assert.notNull(collectionName, "Collection name must not be null!");
|
||||
|
||||
try {
|
||||
return this.mongoDatabaseFactory.getMongoDatabase().getCollection(collectionName);
|
||||
} catch (RuntimeException e) {
|
||||
throw potentiallyConvertRuntimeException(e, exceptionTranslator);
|
||||
}
|
||||
return createMono(db -> Mono.just(db.getCollection(collectionName)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -776,7 +774,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return createFlux(MongoDatabase::listCollectionNames);
|
||||
}
|
||||
|
||||
public MongoDatabase getMongoDatabase() {
|
||||
public Mono<MongoDatabase> getMongoDatabase() {
|
||||
return mongoDatabaseFactory.getMongoDatabase();
|
||||
}
|
||||
|
||||
@@ -1019,11 +1017,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
ReadDocumentCallback<O> readCallback = new ReadDocumentCallback<>(mongoConverter, outputType, collectionName);
|
||||
return execute(collectionName, collection -> aggregateAndMap(collection, pipeline, options, readCallback,
|
||||
aggregation instanceof TypedAggregation ? ((TypedAggregation) aggregation).getInputType() : null));
|
||||
return execute(collectionName,
|
||||
collection -> aggregateAndMap(collection, pipeline, aggregation.getPipeline().isOutOrMerge(), options,
|
||||
readCallback,
|
||||
aggregation instanceof TypedAggregation ? ((TypedAggregation<?>) aggregation).getInputType() : null));
|
||||
}
|
||||
|
||||
private <O> Flux<O> aggregateAndMap(MongoCollection<Document> collection, List<Document> pipeline,
|
||||
boolean isOutOrMerge,
|
||||
AggregationOptions options, ReadDocumentCallback<O> readCallback, @Nullable Class<?> inputType) {
|
||||
|
||||
AggregatePublisher<Document> cursor = collection.aggregate(pipeline, Document.class)
|
||||
@@ -1043,6 +1044,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
cursor = cursor.maxTime(options.getMaxTime().toMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
if (options.isSkipResults()) {
|
||||
return (isOutOrMerge ? Flux.from(cursor.toCollection()) : Flux.from(cursor.first())).thenMany(Mono.empty());
|
||||
}
|
||||
|
||||
return Flux.from(cursor).concatMap(readCallback::doWith);
|
||||
}
|
||||
|
||||
@@ -1161,7 +1166,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
QueryContext queryContext = queryOperations.createQueryContext(query);
|
||||
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
Document mappedFields = queryContext.getMappedFields(entity);
|
||||
Document mappedFields = queryContext.getMappedFields(entity, resultType, projectionFactory);
|
||||
Document mappedSort = queryContext.getMappedSort(entity);
|
||||
|
||||
return Mono.defer(() -> {
|
||||
@@ -2073,24 +2078,25 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
FullDocument fullDocument = ClassUtils.isAssignable(Document.class, targetType) ? FullDocument.DEFAULT
|
||||
: FullDocument.UPDATE_LOOKUP;
|
||||
|
||||
MongoDatabase db = StringUtils.hasText(database) ? mongoDatabaseFactory.getMongoDatabase(database)
|
||||
: getMongoDatabase();
|
||||
return ReactiveMongoDatabaseUtils.getDatabase(database, mongoDatabaseFactory) //
|
||||
.map(db -> {
|
||||
ChangeStreamPublisher<Document> publisher;
|
||||
if (StringUtils.hasText(collectionName)) {
|
||||
publisher = filter.isEmpty() ? db.getCollection(collectionName).watch(Document.class)
|
||||
: db.getCollection(collectionName).watch(filter, Document.class);
|
||||
|
||||
ChangeStreamPublisher<Document> publisher;
|
||||
if (StringUtils.hasText(collectionName)) {
|
||||
publisher = filter.isEmpty() ? db.getCollection(collectionName).watch(Document.class)
|
||||
: db.getCollection(collectionName).watch(filter, Document.class);
|
||||
} else {
|
||||
publisher = filter.isEmpty() ? db.watch(Document.class) : db.watch(filter, Document.class);
|
||||
}
|
||||
|
||||
} else {
|
||||
publisher = filter.isEmpty() ? db.watch(Document.class) : db.watch(filter, Document.class);
|
||||
}
|
||||
|
||||
publisher = options.getResumeToken().map(BsonValue::asDocument).map(publisher::resumeAfter).orElse(publisher);
|
||||
publisher = options.getCollation().map(Collation::toMongoCollation).map(publisher::collation).orElse(publisher);
|
||||
publisher = options.getResumeBsonTimestamp().map(publisher::startAtOperationTime).orElse(publisher);
|
||||
publisher = publisher.fullDocument(options.getFullDocumentLookup().orElse(fullDocument));
|
||||
|
||||
return Flux.from(publisher).map(document -> new ChangeStreamEvent<>(document, targetType, getConverter()));
|
||||
publisher = options.getResumeToken().map(BsonValue::asDocument).map(publisher::resumeAfter).orElse(publisher);
|
||||
publisher = options.getCollation().map(Collation::toMongoCollation).map(publisher::collation)
|
||||
.orElse(publisher);
|
||||
publisher = options.getResumeBsonTimestamp().map(publisher::startAtOperationTime).orElse(publisher);
|
||||
return publisher.fullDocument(options.getFullDocumentLookup().orElse(fullDocument));
|
||||
}) //
|
||||
.flatMapMany(publisher -> Flux.from(publisher)
|
||||
.map(document -> new ChangeStreamEvent<>(document, targetType, getConverter())));
|
||||
}
|
||||
|
||||
List<Document> prepareFilter(ChangeStreamOptions options) {
|
||||
@@ -2152,7 +2158,11 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
MapReducePublisher<Document> publisher = collection.mapReduce(mapFunction, reduceFunction, Document.class);
|
||||
|
||||
publisher.filter(mappedQuery);
|
||||
publisher.sort(getMappedSortObject(filterQuery, domainType));
|
||||
|
||||
Document mappedSort = getMappedSortObject(filterQuery, domainType);
|
||||
if (mappedSort != null && !mappedSort.isEmpty()) {
|
||||
publisher.sort(mappedSort);
|
||||
}
|
||||
|
||||
if (filterQuery.getMeta().getMaxTimeMsec() != null) {
|
||||
publisher.maxTime(filterQuery.getMeta().getMaxTimeMsec(), TimeUnit.MILLISECONDS);
|
||||
@@ -2332,7 +2342,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
LOGGER.debug("Created collection [{}]", collectionName);
|
||||
}
|
||||
|
||||
}).thenReturn(getCollection(collectionName));
|
||||
}).then(getCollection(collectionName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2369,8 +2379,11 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
Class<T> entityClass, FindPublisherPreparer preparer) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
Document mappedFields = fields == null ? null : queryMapper.getMappedObject(fields, entity);
|
||||
|
||||
QueryContext queryContext = queryOperations
|
||||
.createQueryContext(new BasicQuery(query, fields != null ? fields : new Document()));
|
||||
Document mappedFields = queryContext.getMappedFields(entity, entityClass, projectionFactory);
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("findOne using query: %s fields: %s for class: %s in collection: %s",
|
||||
@@ -2405,7 +2418,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @param preparer allows for customization of the {@link DBCursor} used when iterating over the result set, (apply
|
||||
* @param preparer allows for customization of the {@link com.mongodb.client.FindIterable} used when iterating over the result set, (apply
|
||||
* limits, skips and so on).
|
||||
* @return the {@link List} of converted objects.
|
||||
*/
|
||||
@@ -2420,8 +2433,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
Document mappedFields = queryMapper.getMappedFields(fields, entity);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
|
||||
Document mappedFields = queryContext.getMappedFields(entity, entityClass, projectionFactory);
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("find using query: %s fields: %s for class: %s in collection: %s",
|
||||
@@ -2443,8 +2457,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(sourceClass);
|
||||
|
||||
Document mappedFields = getMappedFieldsObject(fields, entity, targetClass);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
|
||||
Document mappedFields = queryContext.getMappedFields(entity, targetClass, projectionFactory);
|
||||
Document mappedQuery = queryContext.getMappedQuery(entity);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("find using query: {} fields: {} for class: {} in collection: {}",
|
||||
@@ -2675,7 +2690,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
/**
|
||||
* Prepare the collection before any processing is done using it. This allows a convenient way to apply settings like
|
||||
* slaveOk() etc. Can be overridden in sub-classes.
|
||||
* withCodecRegistry() etc. Can be overridden in sub-classes.
|
||||
*
|
||||
* @param collection
|
||||
*/
|
||||
@@ -2834,7 +2849,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
/**
|
||||
* Simple {@link ReactiveCollectionCallback} that takes a query {@link Document} plus an optional fields specification
|
||||
* {@link Document} and executes that against the {@link DBCollection}.
|
||||
* {@link Document} and executes that against the {@link MongoCollection}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Risberg
|
||||
@@ -3288,7 +3303,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
@Override
|
||||
public ReadPreference getReadPreference() {
|
||||
return query.getMeta().getFlags().contains(CursorOption.SLAVE_OK) ? ReadPreference.primaryPreferred() : null;
|
||||
return (query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS)
|
||||
|| query.getMeta().getFlags().contains(CursorOption.SLAVE_OK)) ? ReadPreference.primaryPreferred() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3340,7 +3356,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoTemplate#getCollection(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public MongoCollection<Document> getCollection(String collectionName) {
|
||||
public Mono<MongoCollection<Document>> getCollection(String collectionName) {
|
||||
|
||||
// native MongoDB objects that offer methods with ClientSession must not be proxied.
|
||||
return delegate.getCollection(collectionName);
|
||||
@@ -3351,7 +3367,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoTemplate#getMongoDatabase()
|
||||
*/
|
||||
@Override
|
||||
public MongoDatabase getMongoDatabase() {
|
||||
public Mono<MongoDatabase> getMongoDatabase() {
|
||||
|
||||
// native MongoDB objects that offer methods with ClientSession must not be proxied.
|
||||
return delegate.getMongoDatabase();
|
||||
|
||||
@@ -111,13 +111,13 @@ public interface ReactiveRemoveOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link TerminatingRemove}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default TerminatingRemove<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default TerminatingRemove<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,13 +176,13 @@ public interface ReactiveUpdateOperation {
|
||||
/**
|
||||
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return new instance of {@link UpdateWithUpdate}.
|
||||
* @throws IllegalArgumentException if query is {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
default UpdateWithUpdate<T> matching(CriteriaDefinition criteriaDefinition) {
|
||||
return matching(Query.query(criteriaDefinition));
|
||||
default UpdateWithUpdate<T> matching(CriteriaDefinition criteria) {
|
||||
return matching(Query.query(criteria));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core;
|
||||
import lombok.Value;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.bson.codecs.configuration.CodecRegistry;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -41,6 +42,7 @@ import com.mongodb.reactivestreams.client.MongoDatabase;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Mathieu Ouellet
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, ReactiveMongoDatabaseFactory {
|
||||
@@ -99,7 +101,7 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDbFactory#getMongoDatabase()
|
||||
*/
|
||||
public MongoDatabase getMongoDatabase() throws DataAccessException {
|
||||
public Mono<MongoDatabase> getMongoDatabase() throws DataAccessException {
|
||||
return getMongoDatabase(databaseName);
|
||||
}
|
||||
|
||||
@@ -107,12 +109,16 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDbFactory#getMongoDatabase(java.lang.String)
|
||||
*/
|
||||
public MongoDatabase getMongoDatabase(String dbName) throws DataAccessException {
|
||||
public Mono<MongoDatabase> getMongoDatabase(String dbName) throws DataAccessException {
|
||||
|
||||
Assert.hasText(dbName, "Database name must not be empty.");
|
||||
|
||||
MongoDatabase db = mongo.getDatabase(dbName);
|
||||
return writeConcern != null ? db.withWriteConcern(writeConcern) : db;
|
||||
return Mono.fromSupplier(() -> {
|
||||
|
||||
MongoDatabase db = mongo.getDatabase(dbName);
|
||||
|
||||
return writeConcern != null ? db.withWriteConcern(writeConcern) : db;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +141,15 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
return this.exceptionTranslator;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#getCodecRegistry()
|
||||
*/
|
||||
@Override
|
||||
public CodecRegistry getCodecRegistry() {
|
||||
return this.mongo.getDatabase(databaseName).getCodecRegistry();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDbFactory#getSession(com.mongodb.ClientSessionOptions)
|
||||
@@ -171,8 +186,8 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#getMongoDatabase()
|
||||
*/
|
||||
@Override
|
||||
public MongoDatabase getMongoDatabase() throws DataAccessException {
|
||||
return decorateDatabase(delegate.getMongoDatabase());
|
||||
public Mono<MongoDatabase> getMongoDatabase() throws DataAccessException {
|
||||
return delegate.getMongoDatabase().map(this::decorateDatabase);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -180,8 +195,8 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#getMongoDatabase(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public MongoDatabase getMongoDatabase(String dbName) throws DataAccessException {
|
||||
return decorateDatabase(delegate.getMongoDatabase(dbName));
|
||||
public Mono<MongoDatabase> getMongoDatabase(String dbName) throws DataAccessException {
|
||||
return delegate.getMongoDatabase(dbName).map(this::decorateDatabase);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -193,6 +208,15 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
return delegate.getExceptionTranslator();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#getCodecRegistry()
|
||||
*/
|
||||
@Override
|
||||
public CodecRegistry getCodecRegistry() {
|
||||
return delegate.getCodecRegistry();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#getSession(com.mongodb.ClientSessionOptions)
|
||||
@@ -242,7 +266,7 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
factory.addAdvice(new SessionAwareMethodInterceptor<>(session, target, ClientSession.class, MongoDatabase.class,
|
||||
this::proxyDatabase, MongoCollection.class, this::proxyCollection));
|
||||
|
||||
return targetType.cast(factory.getProxy());
|
||||
return targetType.cast(factory.getProxy(target.getClass().getClassLoader()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
/**
|
||||
* Enum to represent how strict the check of {@link com.mongodb.WriteResult} shall be. It can either be skipped entirely
|
||||
* (use {@link #NONE}) or cause an exception to be thrown {@link #EXCEPTION}.
|
||||
* Enum to represent how strict the check of {@link com.mongodb.WriteConcernResult} shall be. It can either be skipped
|
||||
* entirely (use {@link #NONE}) or cause an exception to be thrown {@link #EXCEPTION}.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @author Oliver Gierke
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -100,14 +101,14 @@ abstract class AbstractAggregationExpression implements AggregationExpression {
|
||||
return value;
|
||||
}
|
||||
|
||||
protected List<Object> append(Object value) {
|
||||
protected List<Object> append(Object value, Expand expandList) {
|
||||
|
||||
if (this.value instanceof List) {
|
||||
|
||||
List<Object> clone = new ArrayList<Object>((List) this.value);
|
||||
|
||||
if (value instanceof List) {
|
||||
clone.addAll((List) value);
|
||||
if (value instanceof Collection && Expand.EXPAND_VALUES.equals(expandList)) {
|
||||
clone.addAll((Collection<?>) value);
|
||||
} else {
|
||||
clone.add(value);
|
||||
}
|
||||
@@ -117,6 +118,17 @@ abstract class AbstractAggregationExpression implements AggregationExpression {
|
||||
return Arrays.asList(this.value, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a nested list of values to single entries or keep the list.
|
||||
*/
|
||||
protected enum Expand {
|
||||
EXPAND_VALUES, KEEP_SOURCE
|
||||
}
|
||||
|
||||
protected List<Object> append(Object value) {
|
||||
return append(value, Expand.EXPAND_VALUES);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected java.util.Map<String, Object> append(String key, Object value) {
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class AccumulatorOperators {
|
||||
* Take the numeric value referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AccumulatorOperatorFactory}.
|
||||
*/
|
||||
public static AccumulatorOperatorFactory valueOf(String fieldReference) {
|
||||
return new AccumulatorOperatorFactory(fieldReference);
|
||||
@@ -44,7 +44,7 @@ public class AccumulatorOperators {
|
||||
* Take the numeric value referenced resulting from given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AccumulatorOperatorFactory}.
|
||||
*/
|
||||
public static AccumulatorOperatorFactory valueOf(AggregationExpression expression) {
|
||||
return new AccumulatorOperatorFactory(expression);
|
||||
@@ -86,7 +86,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated numeric value expression and calculates and
|
||||
* returns the sum.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Sum}.
|
||||
*/
|
||||
public Sum sum() {
|
||||
return usesFieldRef() ? Sum.sumOf(fieldReference) : Sum.sumOf(expression);
|
||||
@@ -96,7 +96,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated numeric value expression and returns the
|
||||
* average value.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Avg}.
|
||||
*/
|
||||
public Avg avg() {
|
||||
return usesFieldRef() ? Avg.avgOf(fieldReference) : Avg.avgOf(expression);
|
||||
@@ -106,7 +106,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated numeric value expression and returns the
|
||||
* maximum value.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Max}.
|
||||
*/
|
||||
public Max max() {
|
||||
return usesFieldRef() ? Max.maxOf(fieldReference) : Max.maxOf(expression);
|
||||
@@ -116,7 +116,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated numeric value expression and returns the
|
||||
* minimum value.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Min}.
|
||||
*/
|
||||
public Min min() {
|
||||
return usesFieldRef() ? Min.minOf(fieldReference) : Min.minOf(expression);
|
||||
@@ -126,7 +126,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated numeric value expression and calculates the
|
||||
* population standard deviation of the input values.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link StdDevPop}.
|
||||
*/
|
||||
public StdDevPop stdDevPop() {
|
||||
return usesFieldRef() ? StdDevPop.stdDevPopOf(fieldReference) : StdDevPop.stdDevPopOf(expression);
|
||||
@@ -136,7 +136,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated numeric value expression and calculates the
|
||||
* sample standard deviation of the input values.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link StdDevSamp}.
|
||||
*/
|
||||
public StdDevSamp stdDevSamp() {
|
||||
return usesFieldRef() ? StdDevSamp.stdDevSampOf(fieldReference) : StdDevSamp.stdDevSampOf(expression);
|
||||
@@ -167,7 +167,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Sum}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Sum}.
|
||||
*/
|
||||
public static Sum sumOf(String fieldReference) {
|
||||
|
||||
@@ -179,7 +179,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Sum}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Sum}.
|
||||
*/
|
||||
public static Sum sumOf(AggregationExpression expression) {
|
||||
|
||||
@@ -192,7 +192,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Sum}.
|
||||
*/
|
||||
public Sum and(String fieldReference) {
|
||||
|
||||
@@ -205,7 +205,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Sum}.
|
||||
*/
|
||||
public Sum and(AggregationExpression expression) {
|
||||
|
||||
@@ -264,7 +264,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Avg}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Avg}.
|
||||
*/
|
||||
public static Avg avgOf(String fieldReference) {
|
||||
|
||||
@@ -276,7 +276,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Avg}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Avg}.
|
||||
*/
|
||||
public static Avg avgOf(AggregationExpression expression) {
|
||||
|
||||
@@ -289,7 +289,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Avg}.
|
||||
*/
|
||||
public Avg and(String fieldReference) {
|
||||
|
||||
@@ -302,7 +302,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Avg}.
|
||||
*/
|
||||
public Avg and(AggregationExpression expression) {
|
||||
|
||||
@@ -347,7 +347,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Max}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Max}.
|
||||
*/
|
||||
public static Max maxOf(String fieldReference) {
|
||||
|
||||
@@ -359,7 +359,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Max}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Max}.
|
||||
*/
|
||||
public static Max maxOf(AggregationExpression expression) {
|
||||
|
||||
@@ -372,7 +372,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Max}.
|
||||
*/
|
||||
public Max and(String fieldReference) {
|
||||
|
||||
@@ -385,7 +385,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Max}.
|
||||
*/
|
||||
public Max and(AggregationExpression expression) {
|
||||
|
||||
@@ -430,7 +430,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Min}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Min}.
|
||||
*/
|
||||
public static Min minOf(String fieldReference) {
|
||||
|
||||
@@ -442,7 +442,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link Min}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Min}.
|
||||
*/
|
||||
public static Min minOf(AggregationExpression expression) {
|
||||
|
||||
@@ -455,7 +455,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Min}.
|
||||
*/
|
||||
public Min and(String fieldReference) {
|
||||
|
||||
@@ -468,7 +468,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Min}.
|
||||
*/
|
||||
public Min and(AggregationExpression expression) {
|
||||
|
||||
@@ -513,7 +513,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link StdDevPop}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevPop}.
|
||||
*/
|
||||
public static StdDevPop stdDevPopOf(String fieldReference) {
|
||||
|
||||
@@ -525,7 +525,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link StdDevPop} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevPop}.
|
||||
*/
|
||||
public static StdDevPop stdDevPopOf(AggregationExpression expression) {
|
||||
|
||||
@@ -538,7 +538,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevPop}.
|
||||
*/
|
||||
public StdDevPop and(String fieldReference) {
|
||||
|
||||
@@ -551,7 +551,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevPop}.
|
||||
*/
|
||||
public StdDevPop and(AggregationExpression expression) {
|
||||
|
||||
@@ -596,7 +596,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link StdDevSamp}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevSamp}.
|
||||
*/
|
||||
public static StdDevSamp stdDevSampOf(String fieldReference) {
|
||||
|
||||
@@ -608,7 +608,7 @@ public class AccumulatorOperators {
|
||||
* Creates new {@link StdDevSamp}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevSamp}.
|
||||
*/
|
||||
public static StdDevSamp stdDevSampOf(AggregationExpression expression) {
|
||||
|
||||
@@ -621,7 +621,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevSamp}.
|
||||
*/
|
||||
public StdDevSamp and(String fieldReference) {
|
||||
|
||||
@@ -634,7 +634,7 @@ public class AccumulatorOperators {
|
||||
* <strong>NOTE:</strong> Only possible in {@code $project} stage.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StdDevSamp}.
|
||||
*/
|
||||
public StdDevSamp and(AggregationExpression expression) {
|
||||
|
||||
|
||||
@@ -99,6 +99,10 @@ public class AddFieldsOperation extends DocumentEnhancingOperation {
|
||||
return new AddFieldsOperationBuilder(getValueMap());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.DocumentEnhancingOperation#mongoOperator()
|
||||
*/
|
||||
@Override
|
||||
protected String mongoOperator() {
|
||||
return "$addFields";
|
||||
|
||||
@@ -96,7 +96,7 @@ public class Aggregation {
|
||||
public static final AggregationOperationContext DEFAULT_CONTEXT = AggregationOperationRenderer.DEFAULT_CONTEXT;
|
||||
public static final AggregationOptions DEFAULT_OPTIONS = newAggregationOptions().build();
|
||||
|
||||
protected final List<AggregationOperation> operations;
|
||||
protected final AggregationPipeline pipeline;
|
||||
private final AggregationOptions options;
|
||||
|
||||
/**
|
||||
@@ -133,13 +133,13 @@ public class Aggregation {
|
||||
* supported in MongoDB version 2.6+.
|
||||
*
|
||||
* @param options must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Aggregation}.
|
||||
* @since 1.6
|
||||
*/
|
||||
public Aggregation withOptions(AggregationOptions options) {
|
||||
|
||||
Assert.notNull(options, "AggregationOptions must not be null.");
|
||||
return new Aggregation(this.operations, options);
|
||||
return new Aggregation(this.pipeline.getOperations(), options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,26 +202,10 @@ public class Aggregation {
|
||||
Assert.notNull(aggregationOperations, "AggregationOperations must not be null!");
|
||||
Assert.notNull(options, "AggregationOptions must not be null!");
|
||||
|
||||
// check $out/$merge is the last operation if it exists
|
||||
for (AggregationOperation aggregationOperation : aggregationOperations) {
|
||||
|
||||
if (aggregationOperation instanceof OutOperation && !isLast(aggregationOperation, aggregationOperations)) {
|
||||
throw new IllegalArgumentException("The $out operator must be the last stage in the pipeline.");
|
||||
}
|
||||
|
||||
if (aggregationOperation instanceof MergeOperation && !isLast(aggregationOperation, aggregationOperations)) {
|
||||
throw new IllegalArgumentException("The $merge operator must be the last stage in the pipeline.");
|
||||
}
|
||||
}
|
||||
|
||||
this.operations = aggregationOperations;
|
||||
this.pipeline = new AggregationPipeline(aggregationOperations);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
private boolean isLast(AggregationOperation aggregationOperation, List<AggregationOperation> aggregationOperations) {
|
||||
return aggregationOperations.indexOf(aggregationOperation) == aggregationOperations.size() - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link AggregationOptions}.
|
||||
*
|
||||
@@ -259,7 +243,7 @@ public class Aggregation {
|
||||
* Creates a new {@link ProjectionOperation} including the given fields.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ProjectionOperation}.
|
||||
*/
|
||||
public static ProjectionOperation project(String... fields) {
|
||||
return project(fields(fields));
|
||||
@@ -269,7 +253,7 @@ public class Aggregation {
|
||||
* Creates a new {@link ProjectionOperation} including the given {@link Fields}.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ProjectionOperation}.
|
||||
*/
|
||||
public static ProjectionOperation project(Fields fields) {
|
||||
return new ProjectionOperation(fields);
|
||||
@@ -292,7 +276,7 @@ public class Aggregation {
|
||||
* Factory method to create a new {@link UnwindOperation} for the field with the given name.
|
||||
*
|
||||
* @param field must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link UnwindOperation}.
|
||||
*/
|
||||
public static UnwindOperation unwind(String field) {
|
||||
return new UnwindOperation(field(field));
|
||||
@@ -302,7 +286,7 @@ public class Aggregation {
|
||||
* Factory method to create a new {@link ReplaceRootOperation} for the field with the given name.
|
||||
*
|
||||
* @param fieldName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link ReplaceRootOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static ReplaceRootOperation replaceRoot(String fieldName) {
|
||||
@@ -314,7 +298,7 @@ public class Aggregation {
|
||||
* {@link AggregationExpression}.
|
||||
*
|
||||
* @param aggregationExpression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReplaceRootOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static ReplaceRootOperation replaceRoot(AggregationExpression aggregationExpression) {
|
||||
@@ -380,7 +364,7 @@ public class Aggregation {
|
||||
* Creates a new {@link GroupOperation} for the given fields.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link GroupOperation}.
|
||||
*/
|
||||
public static GroupOperation group(String... fields) {
|
||||
return group(fields(fields));
|
||||
@@ -401,7 +385,7 @@ public class Aggregation {
|
||||
* {@link GraphLookupOperation} given {@literal fromCollection}.
|
||||
*
|
||||
* @param fromCollection must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link StartWithBuilder} for creating a {@link GraphLookupOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static StartWithBuilder graphLookup(String fromCollection) {
|
||||
@@ -412,7 +396,7 @@ public class Aggregation {
|
||||
* Factory method to create a new {@link SortOperation} for the given {@link Sort}.
|
||||
*
|
||||
* @param sort must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SortOperation}.
|
||||
*/
|
||||
public static SortOperation sort(Sort sort) {
|
||||
return new SortOperation(sort);
|
||||
@@ -423,7 +407,7 @@ public class Aggregation {
|
||||
*
|
||||
* @param direction must not be {@literal null}.
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SortOperation}.
|
||||
*/
|
||||
public static SortOperation sort(Direction direction, String... fields) {
|
||||
return new SortOperation(Sort.by(direction, fields));
|
||||
@@ -433,7 +417,7 @@ public class Aggregation {
|
||||
* Creates a new {@link SortByCountOperation} given {@literal groupByField}.
|
||||
*
|
||||
* @param field must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link SortByCountOperation}.
|
||||
* @since 2.1
|
||||
*/
|
||||
public static SortByCountOperation sortByCount(String field) {
|
||||
@@ -444,7 +428,7 @@ public class Aggregation {
|
||||
* Creates a new {@link SortByCountOperation} given {@link AggregationExpression group and sort expression}.
|
||||
*
|
||||
* @param groupAndSortExpression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SortByCountOperation}.
|
||||
* @since 2.1
|
||||
*/
|
||||
public static SortByCountOperation sortByCount(AggregationExpression groupAndSortExpression) {
|
||||
@@ -455,9 +439,10 @@ public class Aggregation {
|
||||
* Creates a new {@link SkipOperation} skipping the given number of elements.
|
||||
*
|
||||
* @param elementsToSkip must not be less than zero.
|
||||
* @return
|
||||
* @return new instance of {@link SkipOperation}.
|
||||
* @deprecated prepare to get this one removed in favor of {@link #skip(long)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static SkipOperation skip(int elementsToSkip) {
|
||||
return new SkipOperation(elementsToSkip);
|
||||
}
|
||||
@@ -466,7 +451,7 @@ public class Aggregation {
|
||||
* Creates a new {@link SkipOperation} skipping the given number of elements.
|
||||
*
|
||||
* @param elementsToSkip must not be less than zero.
|
||||
* @return
|
||||
* @return new instance of {@link SkipOperation}.
|
||||
*/
|
||||
public static SkipOperation skip(long elementsToSkip) {
|
||||
return new SkipOperation(elementsToSkip);
|
||||
@@ -476,7 +461,7 @@ public class Aggregation {
|
||||
* Creates a new {@link LimitOperation} limiting the result to the given number of elements.
|
||||
*
|
||||
* @param maxElements must not be less than zero.
|
||||
* @return
|
||||
* @return new instance of {@link LimitOperation}.
|
||||
*/
|
||||
public static LimitOperation limit(long maxElements) {
|
||||
return new LimitOperation(maxElements);
|
||||
@@ -486,7 +471,7 @@ public class Aggregation {
|
||||
* Creates a new {@link SampleOperation} to select the specified number of documents from its input randomly.
|
||||
*
|
||||
* @param sampleSize must not be less than zero.
|
||||
* @return
|
||||
* @return new instance of {@link SampleOperation}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static SampleOperation sample(long sampleSize) {
|
||||
@@ -497,7 +482,7 @@ public class Aggregation {
|
||||
* Creates a new {@link MatchOperation} using the given {@link Criteria}.
|
||||
*
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link MatchOperation}.
|
||||
*/
|
||||
public static MatchOperation match(Criteria criteria) {
|
||||
return new MatchOperation(criteria);
|
||||
@@ -507,7 +492,7 @@ public class Aggregation {
|
||||
* Creates a new {@link MatchOperation} using the given {@link CriteriaDefinition}.
|
||||
*
|
||||
* @param criteria must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link MatchOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static MatchOperation match(CriteriaDefinition criteria) {
|
||||
@@ -520,7 +505,7 @@ public class Aggregation {
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param distanceField must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link GeoNearOperation}.
|
||||
* @since 1.7
|
||||
*/
|
||||
public static GeoNearOperation geoNear(NearQuery query, String distanceField) {
|
||||
@@ -546,7 +531,7 @@ public class Aggregation {
|
||||
* collection in the current database if one does not already exist. The collection is not visible until the
|
||||
* aggregation completes. If the aggregation fails, MongoDB does not create the collection. Must not be
|
||||
* {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link OutOperation}.
|
||||
*/
|
||||
public static OutOperation out(String outCollectionName) {
|
||||
return new OutOperation(outCollectionName);
|
||||
@@ -556,7 +541,7 @@ public class Aggregation {
|
||||
* Creates a new {@link BucketOperation} given {@literal groupByField}.
|
||||
*
|
||||
* @param groupByField must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link BucketOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static BucketOperation bucket(String groupByField) {
|
||||
@@ -567,7 +552,7 @@ public class Aggregation {
|
||||
* Creates a new {@link BucketOperation} given {@link AggregationExpression group-by expression}.
|
||||
*
|
||||
* @param groupByExpression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link BucketOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static BucketOperation bucket(AggregationExpression groupByExpression) {
|
||||
@@ -579,7 +564,7 @@ public class Aggregation {
|
||||
*
|
||||
* @param groupByField must not be {@literal null} or empty.
|
||||
* @param buckets number of buckets, must be a positive integer.
|
||||
* @return
|
||||
* @return new instance of {@link BucketAutoOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static BucketAutoOperation bucketAuto(String groupByField, int buckets) {
|
||||
@@ -591,7 +576,7 @@ public class Aggregation {
|
||||
*
|
||||
* @param groupByExpression must not be {@literal null}.
|
||||
* @param buckets number of buckets, must be a positive integer.
|
||||
* @return
|
||||
* @return new instance of {@link BucketAutoOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static BucketAutoOperation bucketAuto(AggregationExpression groupByExpression, int buckets) {
|
||||
@@ -601,7 +586,7 @@ public class Aggregation {
|
||||
/**
|
||||
* Creates a new {@link FacetOperation}.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link FacetOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static FacetOperation facet() {
|
||||
@@ -612,7 +597,7 @@ public class Aggregation {
|
||||
* Creates a new {@link FacetOperationBuilder} given {@link Aggregation}.
|
||||
*
|
||||
* @param aggregationOperations the sub-pipeline, must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link FacetOperation}.
|
||||
* @since 1.10
|
||||
*/
|
||||
public static FacetOperationBuilder facet(AggregationOperation... aggregationOperations) {
|
||||
@@ -660,9 +645,9 @@ public class Aggregation {
|
||||
/**
|
||||
* Creates a new {@link RedactOperation} that can restrict the content of a document based on information stored
|
||||
* within the document itself.
|
||||
*
|
||||
*
|
||||
* <pre class="code">
|
||||
*
|
||||
*
|
||||
* Aggregation.redact(ConditionalOperators.when(Criteria.where("level").is(5)) //
|
||||
* .then(RedactOperation.PRUNE) //
|
||||
* .otherwise(RedactOperation.DESCEND));
|
||||
@@ -681,7 +666,7 @@ public class Aggregation {
|
||||
* Creates a new {@link Fields} instance for the given field names.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Fields}.
|
||||
* @see Fields#fields(String...)
|
||||
*/
|
||||
public static Fields fields(String... fields) {
|
||||
@@ -693,7 +678,7 @@ public class Aggregation {
|
||||
*
|
||||
* @param name must not be {@literal null} or empty.
|
||||
* @param target must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link Fields}.
|
||||
*/
|
||||
public static Fields bind(String name, String target) {
|
||||
return Fields.from(field(name, target));
|
||||
@@ -702,7 +687,7 @@ public class Aggregation {
|
||||
/**
|
||||
* Returns a new {@link AggregationOptions.Builder}.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link AggregationOptions.Builder}.
|
||||
* @since 1.6
|
||||
*/
|
||||
public static AggregationOptions.Builder newAggregationOptions() {
|
||||
@@ -717,7 +702,15 @@ public class Aggregation {
|
||||
* @since 2.1
|
||||
*/
|
||||
public List<Document> toPipeline(AggregationOperationContext rootContext) {
|
||||
return AggregationOperationRenderer.toDocument(operations, rootContext);
|
||||
return pipeline.toDocuments(rootContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link AggregationPipeline}.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public AggregationPipeline getPipeline() {
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -764,7 +757,7 @@ public class Aggregation {
|
||||
* otherwise.
|
||||
*
|
||||
* @param fieldRef may be {@literal null}.
|
||||
* @return
|
||||
* @return {@literal true} if the given field refers to a {@link SystemVariable}.
|
||||
*/
|
||||
public static boolean isReferingToSystemVariable(@Nullable String fieldRef) {
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ public interface AggregationExpression {
|
||||
* Turns the {@link AggregationExpression} into a {@link Document} within the given
|
||||
* {@link AggregationOperationContext}.
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
* @param context must not be {@literal null}.
|
||||
* @return the MongoDB native ({@link Document}) form of the expression.
|
||||
*/
|
||||
Document toDocument(AggregationOperationContext context);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ interface AggregationExpressionTransformer
|
||||
* @param currentNode must not be {@literal null}.
|
||||
* @param parentNode may be {@literal null}.
|
||||
* @param previousOperationObject may be {@literal null}.
|
||||
* @param aggregationContext must not be {@literal null}.
|
||||
* @param context must not be {@literal null}.
|
||||
*/
|
||||
public AggregationExpressionTransformationContext(T currentNode, @Nullable ExpressionNode parentNode,
|
||||
@Nullable Document previousOperationObject, AggregationOperationContext context) {
|
||||
@@ -67,7 +67,7 @@ interface AggregationExpressionTransformer
|
||||
/**
|
||||
* Returns the underlying {@link AggregationOperationContext}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public AggregationOperationContext getAggregationContext() {
|
||||
return aggregationContext;
|
||||
@@ -76,7 +76,7 @@ interface AggregationExpressionTransformer
|
||||
/**
|
||||
* Returns the {@link FieldReference} for the current {@link ExpressionNode}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public FieldReference getFieldReference() {
|
||||
return aggregationContext.getReference(getCurrentNode().getName());
|
||||
|
||||
@@ -41,7 +41,7 @@ public enum AggregationFunctionExpressions {
|
||||
* Returns an {@link AggregationExpression} build from the current {@link Enum} name and the given parameters.
|
||||
*
|
||||
* @param parameters must not be {@literal null}
|
||||
* @return
|
||||
* @return new instance of {@link AggregationExpression}.
|
||||
*/
|
||||
public AggregationExpression of(Object... parameters) {
|
||||
|
||||
|
||||
@@ -54,4 +54,15 @@ public interface AggregationOperation {
|
||||
default List<Document> toPipelineStages(AggregationOperationContext context) {
|
||||
return Collections.singletonList(toDocument(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MongoDB operator that is used for this {@link AggregationOperation}. Aggregation operations should
|
||||
* implement this method to avoid document rendering.
|
||||
*
|
||||
* @return the operator used for this {@link AggregationOperation}.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
default String getOperator() {
|
||||
return toDocument(Aggregation.DEFAULT_CONTEXT).keySet().iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,20 +57,20 @@ public interface AggregationOperationContext {
|
||||
Document getMappedObject(Document document, @Nullable Class<?> type);
|
||||
|
||||
/**
|
||||
* Returns a {@link FieldReference} for the given field or {@literal null} if the context does not expose the given
|
||||
* field.
|
||||
* Returns a {@link FieldReference} for the given field.
|
||||
*
|
||||
* @param field must not be {@literal null}.
|
||||
* @return
|
||||
* @return the {@link FieldReference} for the given {@link Field}.
|
||||
* @throws IllegalArgumentException if the context does not expose a field with the given name
|
||||
*/
|
||||
FieldReference getReference(Field field);
|
||||
|
||||
/**
|
||||
* Returns the {@link FieldReference} for the field with the given name or {@literal null} if the context does not
|
||||
* expose a field with the given name.
|
||||
* Returns the {@link FieldReference} for the field with the given name.
|
||||
*
|
||||
* @param name must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return the {@link FieldReference} for the field with given {@literal name}.
|
||||
* @throws IllegalArgumentException if the context does not expose a field with the given name
|
||||
*/
|
||||
FieldReference getReference(String name);
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ public class AggregationOptions {
|
||||
private final Optional<Collation> collation;
|
||||
private final Optional<String> comment;
|
||||
private Duration maxTime = Duration.ZERO;
|
||||
private ResultOptions resultOptions = ResultOptions.READ;
|
||||
|
||||
/**
|
||||
* Creates a new {@link AggregationOptions}.
|
||||
@@ -70,7 +71,7 @@ public class AggregationOptions {
|
||||
* @param allowDiskUse whether to off-load intensive sort-operations to disk.
|
||||
* @param explain whether to get the execution plan for the aggregation instead of the actual results.
|
||||
* @param cursor can be {@literal null}, used to pass additional options (such as {@code batchSize}) to the
|
||||
* aggregation.
|
||||
* aggregation.
|
||||
* @param collation collation for string comparison. Can be {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -85,7 +86,7 @@ public class AggregationOptions {
|
||||
* @param allowDiskUse whether to off-load intensive sort-operations to disk.
|
||||
* @param explain whether to get the execution plan for the aggregation instead of the actual results.
|
||||
* @param cursor can be {@literal null}, used to pass additional options (such as {@code batchSize}) to the
|
||||
* aggregation.
|
||||
* aggregation.
|
||||
* @param collation collation for string comparison. Can be {@literal null}.
|
||||
* @param comment execution comment. Can be {@literal null}.
|
||||
* @since 2.2
|
||||
@@ -151,7 +152,7 @@ public class AggregationOptions {
|
||||
* Enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp subdirectory in
|
||||
* the dbPath directory.
|
||||
*
|
||||
* @return
|
||||
* @return {@literal true} if enabled.
|
||||
*/
|
||||
public boolean isAllowDiskUse() {
|
||||
return allowDiskUse;
|
||||
@@ -160,7 +161,7 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Specifies to return the information on the processing of the pipeline.
|
||||
*
|
||||
* @return
|
||||
* @return {@literal true} if enabled.
|
||||
*/
|
||||
public boolean isExplain() {
|
||||
return explain;
|
||||
@@ -185,7 +186,7 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Specify a document that contains options that control the creation of the cursor object.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public Optional<Document> getCursor() {
|
||||
return cursor;
|
||||
@@ -194,7 +195,7 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Get collation settings for string comparison.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public Optional<Collation> getCollation() {
|
||||
@@ -204,7 +205,7 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Get the comment for the aggregation.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
public Optional<String> getComment() {
|
||||
@@ -219,6 +220,15 @@ public class AggregationOptions {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@literal true} to skip results when running an aggregation. Useful in combination with {@code $merge} or
|
||||
* {@code $out}.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public boolean isSkipResults() {
|
||||
return ResultOptions.SKIP.equals(resultOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new potentially adjusted copy for the given {@code aggregationCommandObject} with the configuration
|
||||
* applied.
|
||||
@@ -256,7 +266,7 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Returns a {@link Document} representation of this {@link AggregationOptions}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public Document toDocument() {
|
||||
|
||||
@@ -276,7 +286,7 @@ public class AggregationOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return {@literal true} if {@link #maxTime} is set to a positive value.
|
||||
* @since 3.0
|
||||
*/
|
||||
public boolean hasExecutionTimeLimit() {
|
||||
@@ -309,12 +319,13 @@ public class AggregationOptions {
|
||||
private @Nullable Collation collation;
|
||||
private @Nullable String comment;
|
||||
private @Nullable Duration maxTime;
|
||||
private @Nullable ResultOptions resultOptions;
|
||||
|
||||
/**
|
||||
* Defines whether to off-load intensive sort-operations to disk.
|
||||
*
|
||||
* @param allowDiskUse
|
||||
* @return
|
||||
* @param allowDiskUse use {@literal true} to allow disk use during the aggregation.
|
||||
* @return this.
|
||||
*/
|
||||
public Builder allowDiskUse(boolean allowDiskUse) {
|
||||
|
||||
@@ -325,8 +336,8 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Defines whether to get the execution plan for the aggregation instead of the actual results.
|
||||
*
|
||||
* @param explain
|
||||
* @return
|
||||
* @param explain use {@literal true} to enable explain feature.
|
||||
* @return this.
|
||||
*/
|
||||
public Builder explain(boolean explain) {
|
||||
|
||||
@@ -337,8 +348,8 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Additional options to the aggregation.
|
||||
*
|
||||
* @param cursor
|
||||
* @return
|
||||
* @param cursor must not be {@literal null}.
|
||||
* @return this.
|
||||
*/
|
||||
public Builder cursor(Document cursor) {
|
||||
|
||||
@@ -349,8 +360,8 @@ public class AggregationOptions {
|
||||
/**
|
||||
* Define the initial cursor batch size.
|
||||
*
|
||||
* @param batchSize
|
||||
* @return
|
||||
* @param batchSize use a positive int.
|
||||
* @return this.
|
||||
* @since 2.0
|
||||
*/
|
||||
public Builder cursorBatchSize(int batchSize) {
|
||||
@@ -363,7 +374,7 @@ public class AggregationOptions {
|
||||
* Define collation settings for string comparison.
|
||||
*
|
||||
* @param collation can be {@literal null}.
|
||||
* @return
|
||||
* @return this.
|
||||
* @since 2.0
|
||||
*/
|
||||
public Builder collation(@Nullable Collation collation) {
|
||||
@@ -376,7 +387,7 @@ public class AggregationOptions {
|
||||
* Define a comment to describe the execution.
|
||||
*
|
||||
* @param comment can be {@literal null}.
|
||||
* @return
|
||||
* @return this.
|
||||
* @since 2.2
|
||||
*/
|
||||
public Builder comment(@Nullable String comment) {
|
||||
@@ -389,7 +400,7 @@ public class AggregationOptions {
|
||||
* Set the time limit for processing.
|
||||
*
|
||||
* @param maxTime {@link Duration#ZERO} is used for the default unbounded behavior. {@link Duration#isNegative()
|
||||
* Negative} values will be ignored.
|
||||
* Negative} values will be ignored.
|
||||
* @return this.
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -399,10 +410,24 @@ public class AggregationOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the aggregation, but do NOT read the aggregation result from the store. <br />
|
||||
* If the expected result of the aggregation is rather large, eg. when using an {@literal $out} operation, this
|
||||
* option allows to execute the aggregation without having the cursor return the operation result.
|
||||
*
|
||||
* @return this.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public Builder skipOutput() {
|
||||
|
||||
this.resultOptions = ResultOptions.SKIP;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link AggregationOptions} instance with the given configuration.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link AggregationOptions}.
|
||||
*/
|
||||
public AggregationOptions build() {
|
||||
|
||||
@@ -410,8 +435,26 @@ public class AggregationOptions {
|
||||
if (maxTime != null) {
|
||||
options.maxTime = maxTime;
|
||||
}
|
||||
if (resultOptions != null) {
|
||||
options.resultOptions = resultOptions;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.0
|
||||
*/
|
||||
private enum ResultOptions {
|
||||
|
||||
/**
|
||||
* Just do it!, and do not read the operation result.
|
||||
*/
|
||||
SKIP,
|
||||
/**
|
||||
* Read the aggregation result from the cursor.
|
||||
*/
|
||||
READ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* The {@link AggregationPipeline} holds the collection of {@link AggregationOperation aggregation stages}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public class AggregationPipeline {
|
||||
|
||||
private final List<AggregationOperation> pipeline;
|
||||
|
||||
/**
|
||||
* Create an empty pipeline
|
||||
*/
|
||||
public AggregationPipeline() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new pipeline with given {@link AggregationOperation stages}.
|
||||
*
|
||||
* @param aggregationOperations must not be {@literal null}.
|
||||
*/
|
||||
public AggregationPipeline(List<AggregationOperation> aggregationOperations) {
|
||||
pipeline = new ArrayList<>(aggregationOperations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the given {@link AggregationOperation stage} to the pipeline.
|
||||
*
|
||||
* @param aggregationOperation must not be {@literal null}.
|
||||
* @return this.
|
||||
*/
|
||||
public AggregationPipeline add(AggregationOperation aggregationOperation) {
|
||||
|
||||
Assert.notNull(aggregationOperation, "AggregationOperation must not be null!");
|
||||
|
||||
pipeline.add(aggregationOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of {@link AggregationOperation aggregation stages}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public List<AggregationOperation> getOperations() {
|
||||
return Collections.unmodifiableList(pipeline);
|
||||
}
|
||||
|
||||
List<Document> toDocuments(AggregationOperationContext context) {
|
||||
|
||||
verify();
|
||||
return AggregationOperationRenderer.toDocument(pipeline, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@literal true} if the last aggregation stage is either {@literal $out} or {@literal $merge}.
|
||||
*/
|
||||
public boolean isOutOrMerge() {
|
||||
|
||||
if (pipeline.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String operator = pipeline.get(pipeline.size() - 1).getOperator();
|
||||
return operator.equals("$out") || operator.equals("$merge");
|
||||
}
|
||||
|
||||
void verify() {
|
||||
|
||||
// check $out/$merge is the last operation if it exists
|
||||
for (AggregationOperation aggregationOperation : pipeline) {
|
||||
|
||||
if (aggregationOperation instanceof OutOperation && !isLast(aggregationOperation)) {
|
||||
throw new IllegalArgumentException("The $out operator must be the last stage in the pipeline.");
|
||||
}
|
||||
|
||||
if (aggregationOperation instanceof MergeOperation && !isLast(aggregationOperation)) {
|
||||
throw new IllegalArgumentException("The $merge operator must be the last stage in the pipeline.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLast(AggregationOperation aggregationOperation) {
|
||||
return pipeline.indexOf(aggregationOperation) == pipeline.size() - 1;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class AggregationResults<T> implements Iterable<T> {
|
||||
/**
|
||||
* Returns the aggregation results.
|
||||
*
|
||||
* @return
|
||||
* @return the list of already mapped results or an empty one if none found.
|
||||
*/
|
||||
public List<T> getMappedResults() {
|
||||
return mappedResults;
|
||||
@@ -68,7 +68,7 @@ public class AggregationResults<T> implements Iterable<T> {
|
||||
/**
|
||||
* Returns the unique mapped result. Assumes no result or exactly one.
|
||||
*
|
||||
* @return
|
||||
* @return the single already mapped result object or raise an error if more than one found.
|
||||
* @throws IllegalArgumentException in case more than one result is available.
|
||||
*/
|
||||
@Nullable
|
||||
@@ -88,7 +88,7 @@ public class AggregationResults<T> implements Iterable<T> {
|
||||
/**
|
||||
* Returns the server that has been used to perform the aggregation.
|
||||
*
|
||||
* @return
|
||||
* @return can be {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public String getServerUsed() {
|
||||
@@ -98,7 +98,7 @@ public class AggregationResults<T> implements Iterable<T> {
|
||||
/**
|
||||
* Returns the raw result that was returned by the server.
|
||||
*
|
||||
* @return
|
||||
* @return the raw response.
|
||||
* @since 1.6
|
||||
*/
|
||||
public Document getRawResults() {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class AggregationSpELExpression implements AggregationExpression {
|
||||
*
|
||||
* @param expressionString must not be {@literal null}.
|
||||
* @param parameters can be empty.
|
||||
* @return
|
||||
* @return new instance of {@link AggregationSpELExpression}.
|
||||
*/
|
||||
public static AggregationSpELExpression expressionOf(String expressionString, Object... parameters) {
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ public class AggregationUpdate extends Aggregation implements UpdateDefinition {
|
||||
setOperation.getFields().forEach(it -> {
|
||||
keysTouched.add(it.getName());
|
||||
});
|
||||
operations.add(setOperation);
|
||||
pipeline.add(setOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class AggregationUpdate extends Aggregation implements UpdateDefinition {
|
||||
|
||||
Assert.notNull(unsetOperation, "UnsetOperation must not be null!");
|
||||
|
||||
operations.add(unsetOperation);
|
||||
pipeline.add(unsetOperation);
|
||||
keysTouched.addAll(unsetOperation.removedFieldNames());
|
||||
return this;
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class AggregationUpdate extends Aggregation implements UpdateDefinition {
|
||||
* {@code $replaceWith} replaces the input document with the specified document. The operation replaces all existing
|
||||
* fields in the input document, including the <strong>_id</strong> field.
|
||||
*
|
||||
* @param replaceWithOperation
|
||||
* @param replaceWithOperation must not be {@literal null}.
|
||||
* @return this.
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/">$replaceWith Aggregation
|
||||
* Reference</a>
|
||||
@@ -172,7 +172,7 @@ public class AggregationUpdate extends Aggregation implements UpdateDefinition {
|
||||
public AggregationUpdate replaceWith(ReplaceWithOperation replaceWithOperation) {
|
||||
|
||||
Assert.notNull(replaceWithOperation, "ReplaceWithOperation must not be null!");
|
||||
operations.add(replaceWithOperation);
|
||||
pipeline.add(replaceWithOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -219,8 +219,8 @@ public class AggregationUpdate extends Aggregation implements UpdateDefinition {
|
||||
/**
|
||||
* Short for {@link #unset(UnsetOperation)}.
|
||||
*
|
||||
* @param keys
|
||||
* @return
|
||||
* @param keys the fields to remove.
|
||||
* @return this.
|
||||
*/
|
||||
public AggregationUpdate unset(String... keys) {
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ interface AggregationUtils {
|
||||
* Converts the given {@link Range} into an array of values.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static List<Long> toRangeValues(Range<Long> range) {
|
||||
static List<Long> toRangeValues(Range<Long> range) {
|
||||
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ArithmeticOperators {
|
||||
* Take the field referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArithmeticOperatorFactory}.
|
||||
*/
|
||||
public static ArithmeticOperatorFactory valueOf(String fieldReference) {
|
||||
return new ArithmeticOperatorFactory(fieldReference);
|
||||
@@ -48,7 +48,7 @@ public class ArithmeticOperators {
|
||||
* Take the value resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArithmeticOperatorFactory}.
|
||||
*/
|
||||
public static ArithmeticOperatorFactory valueOf(AggregationExpression expression) {
|
||||
return new ArithmeticOperatorFactory(expression);
|
||||
@@ -89,7 +89,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the absolute value of the associated number.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Abs}.
|
||||
*/
|
||||
public Abs abs() {
|
||||
return usesFieldRef() ? Abs.absoluteValueOf(fieldReference) : Abs.absoluteValueOf(expression);
|
||||
@@ -100,7 +100,7 @@ public class ArithmeticOperators {
|
||||
* number.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public Add add(String fieldReference) {
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ArithmeticOperators {
|
||||
* {@link AggregationExpression} to the associated number.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public Add add(AggregationExpression expression) {
|
||||
|
||||
@@ -125,7 +125,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that adds the given {@literal value} to the associated number.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public Add add(Number value) {
|
||||
|
||||
@@ -141,7 +141,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the smallest integer greater than or equal to the
|
||||
* assoicated number.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Ceil}.
|
||||
*/
|
||||
public Ceil ceil() {
|
||||
return usesFieldRef() ? Ceil.ceilValueOf(fieldReference) : Ceil.ceilValueOf(expression);
|
||||
@@ -152,7 +152,7 @@ public class ArithmeticOperators {
|
||||
* {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public Divide divideBy(String fieldReference) {
|
||||
|
||||
@@ -165,7 +165,7 @@ public class ArithmeticOperators {
|
||||
* {@literal expression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public Divide divideBy(AggregationExpression expression) {
|
||||
|
||||
@@ -176,8 +176,8 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that divides the associated number by given {@literal value}.
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public Divide divideBy(Number value) {
|
||||
|
||||
@@ -192,7 +192,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that raises Euler’s number (i.e. e ) on the associated number.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Exp}.
|
||||
*/
|
||||
public Exp exp() {
|
||||
return usesFieldRef() ? Exp.expValueOf(fieldReference) : Exp.expValueOf(expression);
|
||||
@@ -202,7 +202,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the largest integer less than or equal to the associated
|
||||
* number.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Floor}.
|
||||
*/
|
||||
public Floor floor() {
|
||||
return usesFieldRef() ? Floor.floorValueOf(fieldReference) : Floor.floorValueOf(expression);
|
||||
@@ -212,7 +212,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that calculates the natural logarithm ln (i.e loge) of the assoicated
|
||||
* number.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Ln}.
|
||||
*/
|
||||
public Ln ln() {
|
||||
return usesFieldRef() ? Ln.lnValueOf(fieldReference) : Ln.lnValueOf(expression);
|
||||
@@ -223,7 +223,7 @@ public class ArithmeticOperators {
|
||||
* referenced via {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public Log log(String fieldReference) {
|
||||
|
||||
@@ -236,7 +236,7 @@ public class ArithmeticOperators {
|
||||
* extracted by given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public Log log(AggregationExpression expression) {
|
||||
|
||||
@@ -249,7 +249,7 @@ public class ArithmeticOperators {
|
||||
* {@literal base}.
|
||||
*
|
||||
* @param base must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public Log log(Number base) {
|
||||
|
||||
@@ -264,7 +264,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that calculates the log base 10 for the associated number.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Log10}.
|
||||
*/
|
||||
public Log10 log10() {
|
||||
return usesFieldRef() ? Log10.log10ValueOf(fieldReference) : Log10.log10ValueOf(expression);
|
||||
@@ -275,7 +275,7 @@ public class ArithmeticOperators {
|
||||
* remainder.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public Mod mod(String fieldReference) {
|
||||
|
||||
@@ -288,7 +288,7 @@ public class ArithmeticOperators {
|
||||
* remainder.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public Mod mod(AggregationExpression expression) {
|
||||
|
||||
@@ -301,7 +301,7 @@ public class ArithmeticOperators {
|
||||
* remainder.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public Mod mod(Number value) {
|
||||
|
||||
@@ -317,7 +317,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that multiplies the associated number with another.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public Multiply multiplyBy(String fieldReference) {
|
||||
|
||||
@@ -329,7 +329,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that multiplies the associated number with another.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public Multiply multiplyBy(AggregationExpression expression) {
|
||||
|
||||
@@ -341,7 +341,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that multiplies the associated number with another.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public Multiply multiplyBy(Number value) {
|
||||
|
||||
@@ -357,7 +357,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that raises the associated number to the specified exponent.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Pow pow(String fieldReference) {
|
||||
|
||||
@@ -369,7 +369,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that raises the associated number to the specified exponent.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Pow pow(AggregationExpression expression) {
|
||||
|
||||
@@ -381,7 +381,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that raises the associated number to the specified exponent.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Pow pow(Number value) {
|
||||
|
||||
@@ -396,7 +396,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that calculates the square root of the associated number.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Sqrt}.
|
||||
*/
|
||||
public Sqrt sqrt() {
|
||||
return usesFieldRef() ? Sqrt.sqrtOf(fieldReference) : Sqrt.sqrtOf(expression);
|
||||
@@ -406,7 +406,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that subtracts value of given from the associated number.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Subtract}.
|
||||
*/
|
||||
public Subtract subtract(String fieldReference) {
|
||||
|
||||
@@ -418,7 +418,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link AggregationExpression} that subtracts value of given from the associated number.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Subtract}.
|
||||
*/
|
||||
public Subtract subtract(AggregationExpression expression) {
|
||||
|
||||
@@ -429,8 +429,8 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that subtracts value from the associated number.
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Subtract}.
|
||||
*/
|
||||
public Subtract subtract(Number value) {
|
||||
|
||||
@@ -445,7 +445,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that truncates a number to its integer.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Trunc}.
|
||||
*/
|
||||
public Trunc trunc() {
|
||||
return usesFieldRef() ? Trunc.truncValueOf(fieldReference) : Trunc.truncValueOf(expression);
|
||||
@@ -454,7 +454,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that calculates and returns the sum of numeric values.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Sum}.
|
||||
*/
|
||||
public Sum sum() {
|
||||
return usesFieldRef() ? AccumulatorOperators.Sum.sumOf(fieldReference)
|
||||
@@ -464,7 +464,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the average value of the numeric values.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Avg}.
|
||||
*/
|
||||
public Avg avg() {
|
||||
return usesFieldRef() ? AccumulatorOperators.Avg.avgOf(fieldReference)
|
||||
@@ -474,7 +474,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the maximum value.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Max}.
|
||||
*/
|
||||
public Max max() {
|
||||
return usesFieldRef() ? AccumulatorOperators.Max.maxOf(fieldReference)
|
||||
@@ -484,7 +484,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the minimum value.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Min}.
|
||||
*/
|
||||
public Min min() {
|
||||
return usesFieldRef() ? AccumulatorOperators.Min.minOf(fieldReference)
|
||||
@@ -494,7 +494,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that calculates the population standard deviation of the input values.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link StdDevPop}.
|
||||
*/
|
||||
public StdDevPop stdDevPop() {
|
||||
return usesFieldRef() ? AccumulatorOperators.StdDevPop.stdDevPopOf(fieldReference)
|
||||
@@ -504,7 +504,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that calculates the sample standard deviation of the input values.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link StdDevSamp}.
|
||||
*/
|
||||
public StdDevSamp stdDevSamp() {
|
||||
return usesFieldRef() ? AccumulatorOperators.StdDevSamp.stdDevSampOf(fieldReference)
|
||||
@@ -557,7 +557,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Abs}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Abs}.
|
||||
*/
|
||||
public static Abs absoluteValueOf(String fieldReference) {
|
||||
|
||||
@@ -569,7 +569,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Abs}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Abs}.
|
||||
*/
|
||||
public static Abs absoluteValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -581,7 +581,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Abs}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Abs}.
|
||||
*/
|
||||
public static Abs absoluteValueOf(Number value) {
|
||||
|
||||
@@ -610,7 +610,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Add}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public static Add valueOf(String fieldReference) {
|
||||
|
||||
@@ -622,7 +622,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Add}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public static Add valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -634,7 +634,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Add}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public static Add valueOf(Number value) {
|
||||
|
||||
@@ -642,18 +642,36 @@ public class ArithmeticOperators {
|
||||
return new Add(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the value stored at the given field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public Add add(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Add(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the evaluation result of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public Add add(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Add(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Add}.
|
||||
*/
|
||||
public Add add(Number value) {
|
||||
return new Add(append(value));
|
||||
}
|
||||
@@ -679,7 +697,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Ceil}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ceil}.
|
||||
*/
|
||||
public static Ceil ceilValueOf(String fieldReference) {
|
||||
|
||||
@@ -691,7 +709,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Ceil}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ceil}.
|
||||
*/
|
||||
public static Ceil ceilValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -703,7 +721,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Ceil}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ceil}.
|
||||
*/
|
||||
public static Ceil ceilValueOf(Number value) {
|
||||
|
||||
@@ -732,7 +750,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Divide}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public static Divide valueOf(String fieldReference) {
|
||||
|
||||
@@ -744,7 +762,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Divide}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public static Divide valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -756,7 +774,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Divide}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public static Divide valueOf(Number value) {
|
||||
|
||||
@@ -764,18 +782,36 @@ public class ArithmeticOperators {
|
||||
return new Divide(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide by the value stored at the given field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public Divide divideBy(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Divide(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide by the evaluation results of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public Divide divideBy(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Divide(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide by the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Divide}.
|
||||
*/
|
||||
public Divide divideBy(Number value) {
|
||||
return new Divide(append(value));
|
||||
}
|
||||
@@ -801,7 +837,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Exp}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Exp}.
|
||||
*/
|
||||
public static Exp expValueOf(String fieldReference) {
|
||||
|
||||
@@ -813,7 +849,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Exp}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Exp}.
|
||||
*/
|
||||
public static Exp expValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -825,7 +861,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Exp}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Exp}.
|
||||
*/
|
||||
public static Exp expValueOf(Number value) {
|
||||
|
||||
@@ -854,7 +890,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Floor}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Floor}.
|
||||
*/
|
||||
public static Floor floorValueOf(String fieldReference) {
|
||||
|
||||
@@ -866,7 +902,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Floor}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Floor}.
|
||||
*/
|
||||
public static Floor floorValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -878,7 +914,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Floor}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Floor}.
|
||||
*/
|
||||
public static Floor floorValueOf(Number value) {
|
||||
|
||||
@@ -907,7 +943,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Ln}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ln}.
|
||||
*/
|
||||
public static Ln lnValueOf(String fieldReference) {
|
||||
|
||||
@@ -919,7 +955,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Ln}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ln}.
|
||||
*/
|
||||
public static Ln lnValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -931,7 +967,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Ln}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ln}.
|
||||
*/
|
||||
public static Ln lnValueOf(Number value) {
|
||||
|
||||
@@ -960,7 +996,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Min}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public static Log valueOf(String fieldReference) {
|
||||
|
||||
@@ -972,7 +1008,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Log}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public static Log valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -992,18 +1028,36 @@ public class ArithmeticOperators {
|
||||
return new Log(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the value stored at the given field as log base.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public Log log(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Log(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the evaluated value of the given {@link AggregationExpression} as log base.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public Log log(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Log(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the given value as log base.
|
||||
*
|
||||
* @param base must not be {@literal null}.
|
||||
* @return new instance of {@link Log}.
|
||||
*/
|
||||
public Log log(Number base) {
|
||||
return new Log(append(base));
|
||||
}
|
||||
@@ -1029,7 +1083,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Log10}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log10}.
|
||||
*/
|
||||
public static Log10 log10ValueOf(String fieldReference) {
|
||||
|
||||
@@ -1041,7 +1095,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Log10}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log10}.
|
||||
*/
|
||||
public static Log10 log10ValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1053,7 +1107,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Log10}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Log10}.
|
||||
*/
|
||||
public static Log10 log10ValueOf(Number value) {
|
||||
|
||||
@@ -1082,7 +1136,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Mod}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public static Mod valueOf(String fieldReference) {
|
||||
|
||||
@@ -1094,7 +1148,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Mod}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public static Mod valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1106,7 +1160,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Mod}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public static Mod valueOf(Number value) {
|
||||
|
||||
@@ -1114,18 +1168,36 @@ public class ArithmeticOperators {
|
||||
return new Mod(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the value stored at the given field as mod base.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public Mod mod(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Mod(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use evaluated value of the given {@link AggregationExpression} as mod base.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public Mod mod(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Mod(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the given value as mod base.
|
||||
*
|
||||
* @param base must not be {@literal null}.
|
||||
* @return new instance of {@link Mod}.
|
||||
*/
|
||||
public Mod mod(Number base) {
|
||||
return new Mod(append(base));
|
||||
}
|
||||
@@ -1151,7 +1223,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Multiply}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public static Multiply valueOf(String fieldReference) {
|
||||
|
||||
@@ -1163,7 +1235,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Multiply}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public static Multiply valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1175,7 +1247,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Multiply}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public static Multiply valueOf(Number value) {
|
||||
|
||||
@@ -1183,18 +1255,36 @@ public class ArithmeticOperators {
|
||||
return new Multiply(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply by the value stored at the given field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public Multiply multiplyBy(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Multiply(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply by the evaluated value of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public Multiply multiplyBy(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Multiply(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply by the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Multiply}.
|
||||
*/
|
||||
public Multiply multiplyBy(Number value) {
|
||||
return new Multiply(append(value));
|
||||
}
|
||||
@@ -1252,18 +1342,36 @@ public class ArithmeticOperators {
|
||||
return new Pow(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pow by the value stored at the given field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Pow pow(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Pow(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pow by the evaluated value of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Pow pow(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Pow(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pow by the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Pow pow(Number value) {
|
||||
return new Pow(append(value));
|
||||
}
|
||||
@@ -1289,7 +1397,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Sqrt}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Sqrt}.
|
||||
*/
|
||||
public static Sqrt sqrtOf(String fieldReference) {
|
||||
|
||||
@@ -1301,7 +1409,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Sqrt}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Sqrt}.
|
||||
*/
|
||||
public static Sqrt sqrtOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1313,7 +1421,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Sqrt}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Sqrt}.
|
||||
*/
|
||||
public static Sqrt sqrtOf(Number value) {
|
||||
|
||||
@@ -1342,7 +1450,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Subtract}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Subtract}.
|
||||
*/
|
||||
public static Subtract valueOf(String fieldReference) {
|
||||
|
||||
@@ -1354,7 +1462,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Subtract}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Subtract}.
|
||||
*/
|
||||
public static Subtract valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1366,7 +1474,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Subtract}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Subtract}.
|
||||
*/
|
||||
public static Subtract valueOf(Number value) {
|
||||
|
||||
@@ -1374,18 +1482,36 @@ public class ArithmeticOperators {
|
||||
return new Subtract(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the value stored at the given field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Subtract subtract(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Subtract(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the evaluated value of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Subtract subtract(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Subtract(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Pow}.
|
||||
*/
|
||||
public Subtract subtract(Number value) {
|
||||
return new Subtract(append(value));
|
||||
}
|
||||
@@ -1411,7 +1537,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Trunc}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Trunc}.
|
||||
*/
|
||||
public static Trunc truncValueOf(String fieldReference) {
|
||||
|
||||
@@ -1423,7 +1549,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Trunc}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Trunc}.
|
||||
*/
|
||||
public static Trunc truncValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1435,7 +1561,7 @@ public class ArithmeticOperators {
|
||||
* Creates new {@link Trunc}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Trunc}.
|
||||
*/
|
||||
public static Trunc truncValueOf(Number value) {
|
||||
|
||||
@@ -1502,7 +1628,7 @@ public class ArithmeticOperators {
|
||||
/**
|
||||
* The place to round to. Can be between -20 and 100, exclusive.
|
||||
*
|
||||
* @param place
|
||||
* @param place value between -20 and 100, exclusive.
|
||||
* @return new instance of {@link Round}.
|
||||
*/
|
||||
public Round place(int place) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ArrayOperators {
|
||||
* Take the array referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArrayOperatorFactory}.
|
||||
*/
|
||||
public static ArrayOperatorFactory arrayOf(String fieldReference) {
|
||||
return new ArrayOperatorFactory(fieldReference);
|
||||
@@ -53,7 +53,7 @@ public class ArrayOperators {
|
||||
* Take the array referenced resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArrayOperatorFactory}.
|
||||
*/
|
||||
public static ArrayOperatorFactory arrayOf(AggregationExpression expression) {
|
||||
return new ArrayOperatorFactory(expression);
|
||||
@@ -123,8 +123,8 @@ public class ArrayOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated array and returns the element at the
|
||||
* specified array {@literal position}.
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
* @param position the element index.
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public ArrayElemAt elementAt(int position) {
|
||||
return createArrayElemAt().elementAt(position);
|
||||
@@ -135,7 +135,7 @@ public class ArrayOperators {
|
||||
* resulting form the given {@literal expression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public ArrayElemAt elementAt(AggregationExpression expression) {
|
||||
|
||||
@@ -148,7 +148,7 @@ public class ArrayOperators {
|
||||
* defined by the referenced {@literal field}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public ArrayElemAt elementAt(String fieldReference) {
|
||||
|
||||
@@ -170,7 +170,7 @@ public class ArrayOperators {
|
||||
* {@literal arrayFieldReference} to it.
|
||||
*
|
||||
* @param arrayFieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ConcatArrays}.
|
||||
*/
|
||||
public ConcatArrays concat(String arrayFieldReference) {
|
||||
|
||||
@@ -183,7 +183,7 @@ public class ArrayOperators {
|
||||
* the given {@literal expression} to it.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ConcatArrays}.
|
||||
*/
|
||||
public ConcatArrays concat(AggregationExpression expression) {
|
||||
|
||||
@@ -204,7 +204,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated array and selects a subset of the array to
|
||||
* return based on the specified condition.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link AsBuilder} to create a {@link Filter}.
|
||||
*/
|
||||
public AsBuilder filter() {
|
||||
|
||||
@@ -219,7 +219,7 @@ public class ArrayOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that takes the associated array and an check if its an array.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link IsArray}.
|
||||
*/
|
||||
public IsArray isArray() {
|
||||
|
||||
@@ -231,7 +231,7 @@ public class ArrayOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that takes the associated array and retrieves its length.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Size}.
|
||||
*/
|
||||
public Size length() {
|
||||
|
||||
@@ -245,7 +245,7 @@ public class ArrayOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that takes the associated array and selects a subset from it.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Slice}.
|
||||
*/
|
||||
public Slice slice() {
|
||||
|
||||
@@ -261,7 +261,7 @@ public class ArrayOperators {
|
||||
* value and returns the array index (zero-based) of the first occurrence.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfArray}.
|
||||
*/
|
||||
public IndexOfArray indexOf(Object value) {
|
||||
|
||||
@@ -276,7 +276,7 @@ public class ArrayOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns an array with the elements in reverse order.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link ReverseArray}.
|
||||
*/
|
||||
public ReverseArray reverse() {
|
||||
|
||||
@@ -293,7 +293,7 @@ public class ArrayOperators {
|
||||
* an array and combines them into a single value.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReduceInitialValueBuilder} to create {@link Reduce}.
|
||||
*/
|
||||
public ArrayOperatorFactory.ReduceInitialValueBuilder reduce(AggregationExpression expression) {
|
||||
|
||||
@@ -305,8 +305,8 @@ public class ArrayOperators {
|
||||
* Start creating new {@link AggregationExpression} that applies an {@link AggregationExpression} to each element in
|
||||
* an array and combines them into a single value.
|
||||
*
|
||||
* @param expressions
|
||||
* @return
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return new instance of {@link ReduceInitialValueBuilder} to create {@link Reduce}.
|
||||
*/
|
||||
public ArrayOperatorFactory.ReduceInitialValueBuilder reduce(PropertyExpression... expressions) {
|
||||
|
||||
@@ -320,7 +320,7 @@ public class ArrayOperators {
|
||||
* the second input array, etc.
|
||||
*
|
||||
* @param arrays must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Zip}.
|
||||
*/
|
||||
public Zip zipWith(Object... arrays) {
|
||||
|
||||
@@ -336,7 +336,7 @@ public class ArrayOperators {
|
||||
* associated array.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link In}.
|
||||
*/
|
||||
public In containsValue(Object value) {
|
||||
|
||||
@@ -413,7 +413,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link ArrayElemAt}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public static ArrayElemAt arrayOf(String fieldReference) {
|
||||
|
||||
@@ -425,7 +425,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link ArrayElemAt}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public static ArrayElemAt arrayOf(AggregationExpression expression) {
|
||||
|
||||
@@ -446,16 +446,34 @@ public class ArrayOperators {
|
||||
return new ArrayElemAt(Collections.singletonList(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the element with given index number.
|
||||
*
|
||||
* @param index the index number
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public ArrayElemAt elementAt(int index) {
|
||||
return new ArrayElemAt(append(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the element at the index number evaluated from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public ArrayElemAt elementAt(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new ArrayElemAt(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the element at the index number traken from the given field.
|
||||
*
|
||||
* @param arrayFieldReference the field name.
|
||||
* @return new instance of {@link ArrayElemAt}.
|
||||
*/
|
||||
public ArrayElemAt elementAt(String arrayFieldReference) {
|
||||
|
||||
Assert.notNull(arrayFieldReference, "ArrayReference must not be null!");
|
||||
@@ -483,7 +501,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link ConcatArrays}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ConcatArrays}.
|
||||
*/
|
||||
public static ConcatArrays arrayOf(String fieldReference) {
|
||||
|
||||
@@ -495,7 +513,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link ConcatArrays}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ConcatArrays}.
|
||||
*/
|
||||
public static ConcatArrays arrayOf(AggregationExpression expression) {
|
||||
|
||||
@@ -516,12 +534,24 @@ public class ArrayOperators {
|
||||
return new ConcatArrays(Collections.singletonList(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Concat with the array stored at the given field.
|
||||
*
|
||||
* @param arrayFieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link ConcatArrays}.
|
||||
*/
|
||||
public ConcatArrays concat(String arrayFieldReference) {
|
||||
|
||||
Assert.notNull(arrayFieldReference, "ArrayFieldReference must not be null!");
|
||||
return new ConcatArrays(append(Fields.field(arrayFieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Concat with the array resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link ConcatArrays}.
|
||||
*/
|
||||
public ConcatArrays concat(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
@@ -574,7 +604,7 @@ public class ArrayOperators {
|
||||
* Set the {@literal values} to apply the {@code $filter} to.
|
||||
*
|
||||
* @param values must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AsBuilder} to create the {@link Filter}.
|
||||
*/
|
||||
public static AsBuilder filter(List<?> values) {
|
||||
|
||||
@@ -651,7 +681,7 @@ public class ArrayOperators {
|
||||
* Set the {@literal variableName} for the elements in the input array.
|
||||
*
|
||||
* @param variableName must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
ConditionBuilder as(String variableName);
|
||||
}
|
||||
@@ -665,7 +695,7 @@ public class ArrayOperators {
|
||||
* Set the {@link AggregationExpression} that determines whether to include the element in the resulting array.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
Filter by(AggregationExpression expression);
|
||||
|
||||
@@ -673,7 +703,7 @@ public class ArrayOperators {
|
||||
* Set the {@literal expression} that determines whether to include the element in the resulting array.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
Filter by(String expression);
|
||||
|
||||
@@ -681,7 +711,7 @@ public class ArrayOperators {
|
||||
* Set the {@literal expression} that determines whether to include the element in the resulting array.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
Filter by(Document expression);
|
||||
}
|
||||
@@ -700,7 +730,7 @@ public class ArrayOperators {
|
||||
/**
|
||||
* Creates new {@link InputBuilder}.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link FilterExpressionBuilder}.
|
||||
*/
|
||||
public static InputBuilder newBuilder() {
|
||||
return new FilterExpressionBuilder();
|
||||
@@ -800,7 +830,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link IsArray}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsArray}.
|
||||
*/
|
||||
public static IsArray isArray(String fieldReference) {
|
||||
|
||||
@@ -812,7 +842,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link IsArray}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsArray}.
|
||||
*/
|
||||
public static IsArray isArray(AggregationExpression expression) {
|
||||
|
||||
@@ -841,7 +871,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link Size}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Size}.
|
||||
*/
|
||||
public static Size lengthOfArray(String fieldReference) {
|
||||
|
||||
@@ -853,7 +883,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link Size}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Size}.
|
||||
*/
|
||||
public static Size lengthOfArray(AggregationExpression expression) {
|
||||
|
||||
@@ -895,7 +925,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link Slice}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Slice}.
|
||||
*/
|
||||
public static Slice sliceArrayOf(String fieldReference) {
|
||||
|
||||
@@ -907,7 +937,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link Slice}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Slice}.
|
||||
*/
|
||||
public static Slice sliceArrayOf(AggregationExpression expression) {
|
||||
|
||||
@@ -928,10 +958,22 @@ public class ArrayOperators {
|
||||
return new Slice(Collections.singletonList(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Slice the number of elements.
|
||||
*
|
||||
* @param nrElements elements to slice.
|
||||
* @return new instance of {@link Slice}.
|
||||
*/
|
||||
public Slice itemCount(int nrElements) {
|
||||
return new Slice(append(nrElements));
|
||||
}
|
||||
|
||||
/**
|
||||
* Slice using offset and count.
|
||||
*
|
||||
* @param position the start position
|
||||
* @return new instance of {@link SliceElementsBuilder} to create {@link Slice}.
|
||||
*/
|
||||
public SliceElementsBuilder offset(final int position) {
|
||||
|
||||
return new SliceElementsBuilder() {
|
||||
@@ -978,7 +1020,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link IndexOfArray}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfArray}.
|
||||
*/
|
||||
public static IndexOfArrayBuilder arrayOf(String fieldReference) {
|
||||
|
||||
@@ -990,7 +1032,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link IndexOfArray}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfArray}.
|
||||
*/
|
||||
public static IndexOfArrayBuilder arrayOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1002,7 +1044,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link IndexOfArray}.
|
||||
*
|
||||
* @param values must not be {@literal null}.
|
||||
* @return new instance of {@link IndexOfArray}.
|
||||
* @return new instance of {@link IndexOfArrayBuilder} to create {@link IndexOfArray}.
|
||||
* @since 2.2
|
||||
*/
|
||||
public static IndexOfArrayBuilder arrayOf(Collection<?> values) {
|
||||
@@ -1011,6 +1053,12 @@ public class ArrayOperators {
|
||||
return new IndexOfArrayBuilder(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup within a given range.
|
||||
*
|
||||
* @param range the lookup range.
|
||||
* @return new instance of {@link IndexOfArray}.
|
||||
*/
|
||||
public IndexOfArray within(Range<Long> range) {
|
||||
return new IndexOfArray(append(AggregationUtils.toRangeValues(range)));
|
||||
}
|
||||
@@ -1030,7 +1078,7 @@ public class ArrayOperators {
|
||||
* Set the {@literal value} to check for its index in the array.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfArray}.
|
||||
*/
|
||||
public IndexOfArray indexOf(Object value) {
|
||||
|
||||
@@ -1060,7 +1108,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link RangeOperator}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link RangeOperatorBuilder} to create {@link RangeOperator}.
|
||||
*/
|
||||
public static RangeOperatorBuilder rangeStartingAt(String fieldReference) {
|
||||
return new RangeOperatorBuilder(Fields.field(fieldReference));
|
||||
@@ -1070,7 +1118,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link RangeOperator}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link RangeOperatorBuilder} to create {@link RangeOperator}.
|
||||
*/
|
||||
public static RangeOperatorBuilder rangeStartingAt(AggregationExpression expression) {
|
||||
return new RangeOperatorBuilder(expression);
|
||||
@@ -1080,7 +1128,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link RangeOperator}.
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
* @return new instance of {@link RangeOperator}.
|
||||
*/
|
||||
public static RangeOperatorBuilder rangeStartingAt(long value) {
|
||||
return new RangeOperatorBuilder(value);
|
||||
@@ -1102,7 +1150,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link RangeOperator}.
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
* @return new instance of {@link RangeOperator}.
|
||||
*/
|
||||
public RangeOperator to(long index) {
|
||||
return new RangeOperator(Arrays.asList(startPoint, index));
|
||||
@@ -1112,7 +1160,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link RangeOperator}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link RangeOperator}.
|
||||
*/
|
||||
public RangeOperator to(AggregationExpression expression) {
|
||||
return new RangeOperator(Arrays.asList(startPoint, expression));
|
||||
@@ -1122,7 +1170,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link RangeOperator}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link RangeOperator}.
|
||||
*/
|
||||
public RangeOperator to(String fieldReference) {
|
||||
return new RangeOperator(Arrays.asList(startPoint, Fields.field(fieldReference)));
|
||||
@@ -1150,7 +1198,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link ReverseArray} given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReverseArray}.
|
||||
*/
|
||||
public static ReverseArray reverseArrayOf(String fieldReference) {
|
||||
return new ReverseArray(Fields.field(fieldReference));
|
||||
@@ -1160,7 +1208,7 @@ public class ArrayOperators {
|
||||
* Creates new {@link ReverseArray} given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReverseArray}.
|
||||
*/
|
||||
public static ReverseArray reverseArrayOf(AggregationExpression expression) {
|
||||
return new ReverseArray(expression);
|
||||
@@ -1239,7 +1287,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link Reduce}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link InitialValueBuilder} to create {@link Reduce}.
|
||||
*/
|
||||
public static InitialValueBuilder arrayOf(final String fieldReference) {
|
||||
|
||||
@@ -1267,7 +1315,7 @@ public class ArrayOperators {
|
||||
Assert.notNull(expressions, "PropertyExpressions must not be null");
|
||||
|
||||
return new Reduce(Fields.field(fieldReference), initialValue,
|
||||
Arrays.<AggregationExpression> asList(expressions));
|
||||
Arrays.<AggregationExpression>asList(expressions));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1278,7 +1326,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link Reduce}.
|
||||
*
|
||||
* @param arrayValueExpression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link InitialValueBuilder} to create {@link Reduce}.
|
||||
*/
|
||||
public static InitialValueBuilder arrayOf(final AggregationExpression arrayValueExpression) {
|
||||
|
||||
@@ -1318,7 +1366,7 @@ public class ArrayOperators {
|
||||
* Define the initial cumulative value set before in is applied to the first element of the input array.
|
||||
*
|
||||
* @param initialValue must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
ReduceBuilder withInitialValue(Object initialValue);
|
||||
}
|
||||
@@ -1335,7 +1383,7 @@ public class ArrayOperators {
|
||||
* {@link Variable#VALUE} are available.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Reduce}.
|
||||
*/
|
||||
Reduce reduce(AggregationExpression expression);
|
||||
|
||||
@@ -1346,7 +1394,7 @@ public class ArrayOperators {
|
||||
* {@link Variable#VALUE} are available.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Reduce}.
|
||||
*/
|
||||
Reduce reduce(PropertyExpression... expressions);
|
||||
}
|
||||
@@ -1372,7 +1420,7 @@ public class ArrayOperators {
|
||||
* Define a result property for an {@link AggregationExpression} used in {@link Reduce}.
|
||||
*
|
||||
* @param name must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AsBuilder} to create {@link Reduce}.
|
||||
*/
|
||||
public static AsBuilder property(final String name) {
|
||||
|
||||
@@ -1402,7 +1450,7 @@ public class ArrayOperators {
|
||||
* Set the {@link AggregationExpression} resulting in the properties value.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
PropertyExpression definedAs(AggregationExpression expression);
|
||||
}
|
||||
@@ -1459,7 +1507,7 @@ public class ArrayOperators {
|
||||
* eg. {@code $$value.product}
|
||||
*
|
||||
* @param property must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public Field referringTo(final String property) {
|
||||
|
||||
@@ -1508,7 +1556,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link Zip}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ZipBuilder} to create {@link Zip}.
|
||||
*/
|
||||
public static ZipBuilder arrayOf(String fieldReference) {
|
||||
|
||||
@@ -1520,7 +1568,7 @@ public class ArrayOperators {
|
||||
* Start creating new {@link Zip}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ZipBuilder} to create {@link Zip}.
|
||||
*/
|
||||
public static ZipBuilder arrayOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1544,7 +1592,7 @@ public class ArrayOperators {
|
||||
/**
|
||||
* Create new {@link Zip} and set the {@code useLongestLength} property to {@literal true}.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Zip}.
|
||||
*/
|
||||
public Zip useLongestLength() {
|
||||
return new Zip(append("useLongestLength", true));
|
||||
@@ -1554,7 +1602,7 @@ public class ArrayOperators {
|
||||
* Optionally provide a default value.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Zip}.
|
||||
*/
|
||||
public Zip defaultTo(String fieldReference) {
|
||||
|
||||
@@ -1566,7 +1614,7 @@ public class ArrayOperators {
|
||||
* Optionally provide a default value.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Zip}.
|
||||
*/
|
||||
public Zip defaultTo(AggregationExpression expression) {
|
||||
|
||||
@@ -1578,7 +1626,7 @@ public class ArrayOperators {
|
||||
* Optionally provide a default value.
|
||||
*
|
||||
* @param array must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Zip}.
|
||||
*/
|
||||
public Zip defaultTo(Object[] array) {
|
||||
|
||||
@@ -1602,7 +1650,7 @@ public class ArrayOperators {
|
||||
* array, etc.
|
||||
*
|
||||
* @param arrays arrays to zip the referenced one with. must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Zip}.
|
||||
*/
|
||||
public Zip zip(Object... arrays) {
|
||||
|
||||
@@ -1616,7 +1664,7 @@ public class ArrayOperators {
|
||||
}
|
||||
}
|
||||
|
||||
return new Zip(Collections.<String, Object> singletonMap("inputs", sourceArrays));
|
||||
return new Zip(Collections.<String, Object>singletonMap("inputs", sourceArrays));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1627,7 +1675,7 @@ public class ArrayOperators {
|
||||
* @author Christoph Strobl
|
||||
* @author Shashank Sharma
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/in/">https://docs.mongodb.com/manual/reference/operator/aggregation/in/</a>
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/in/">https://docs.mongodb.com/manual/reference/operator/aggregation/in/</a>
|
||||
* @since 2.2
|
||||
*/
|
||||
public static class In extends AbstractAggregationExpression {
|
||||
@@ -1645,7 +1693,7 @@ public class ArrayOperators {
|
||||
* Start creating {@link In}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link InBuilder} to create {@link In}.
|
||||
*/
|
||||
public static InBuilder arrayOf(String fieldReference) {
|
||||
|
||||
@@ -1662,7 +1710,7 @@ public class ArrayOperators {
|
||||
* Start creating {@link In}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link InBuilder} to create {@link In}.
|
||||
*/
|
||||
public static InBuilder arrayOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1704,7 +1752,7 @@ public class ArrayOperators {
|
||||
* Set the {@literal value} to check for existence in the array.
|
||||
*
|
||||
* @param value must not be {@literal value}.
|
||||
* @return
|
||||
* @return new instance of {@link In}.
|
||||
*/
|
||||
In containsValue(Object value);
|
||||
}
|
||||
@@ -1716,7 +1764,7 @@ public class ArrayOperators {
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/arrayToObject/">https://docs.mongodb.com/manual/reference/operator/aggregation/arrayToObject/</a>
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/arrayToObject/">https://docs.mongodb.com/manual/reference/operator/aggregation/arrayToObject/</a>
|
||||
* @since 2.1
|
||||
*/
|
||||
public static class ArrayToObject extends AbstractAggregationExpression {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class BooleanOperators {
|
||||
* Take the array referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link BooleanOperatorFactory}.
|
||||
*/
|
||||
public static BooleanOperatorFactory valueOf(String fieldReference) {
|
||||
return new BooleanOperatorFactory(fieldReference);
|
||||
@@ -44,7 +44,7 @@ public class BooleanOperators {
|
||||
* Take the value resulting of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link BooleanOperatorFactory}.
|
||||
*/
|
||||
public static BooleanOperatorFactory valueOf(AggregationExpression fieldReference) {
|
||||
return new BooleanOperatorFactory(fieldReference);
|
||||
@@ -55,7 +55,7 @@ public class BooleanOperators {
|
||||
* opposite boolean value.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Not}.
|
||||
*/
|
||||
public static Not not(String fieldReference) {
|
||||
return Not.not(fieldReference);
|
||||
@@ -66,7 +66,7 @@ public class BooleanOperators {
|
||||
* and returns the opposite boolean value.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Not}.
|
||||
*/
|
||||
public static Not not(AggregationExpression expression) {
|
||||
return Not.not(expression);
|
||||
@@ -109,7 +109,7 @@ public class BooleanOperators {
|
||||
* all of the expressions are {@literal true}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link And}.
|
||||
*/
|
||||
public And and(AggregationExpression expression) {
|
||||
|
||||
@@ -122,7 +122,7 @@ public class BooleanOperators {
|
||||
* all of the expressions are {@literal true}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link And}.
|
||||
*/
|
||||
public And and(String fieldReference) {
|
||||
|
||||
@@ -139,7 +139,7 @@ public class BooleanOperators {
|
||||
* any of the expressions are {@literal true}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Or}.
|
||||
*/
|
||||
public Or or(AggregationExpression expression) {
|
||||
|
||||
@@ -152,7 +152,7 @@ public class BooleanOperators {
|
||||
* any of the expressions are {@literal true}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Or}.
|
||||
*/
|
||||
public Or or(String fieldReference) {
|
||||
|
||||
@@ -167,7 +167,7 @@ public class BooleanOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that evaluates a boolean and returns the opposite boolean value.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Not}.
|
||||
*/
|
||||
public Not not() {
|
||||
return usesFieldRef() ? Not.not(fieldReference) : Not.not(expression);
|
||||
@@ -198,8 +198,8 @@ public class BooleanOperators {
|
||||
* Creates new {@link And} that evaluates one or more expressions and returns {@literal true} if all of the
|
||||
* expressions are {@literal true}.
|
||||
*
|
||||
* @param expressions
|
||||
* @return
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return new instance of {@link And}.
|
||||
*/
|
||||
public static And and(Object... expressions) {
|
||||
return new And(Arrays.asList(expressions));
|
||||
@@ -209,7 +209,7 @@ public class BooleanOperators {
|
||||
* Creates new {@link And} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link And}.
|
||||
*/
|
||||
public And andExpression(AggregationExpression expression) {
|
||||
|
||||
@@ -221,7 +221,7 @@ public class BooleanOperators {
|
||||
* Creates new {@link And} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link And}.
|
||||
*/
|
||||
public And andField(String fieldReference) {
|
||||
|
||||
@@ -233,7 +233,7 @@ public class BooleanOperators {
|
||||
* Creates new {@link And} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link And}.
|
||||
*/
|
||||
public And andValue(Object value) {
|
||||
|
||||
@@ -263,7 +263,7 @@ public class BooleanOperators {
|
||||
* expressions are {@literal true}.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Or}.
|
||||
*/
|
||||
public static Or or(Object... expressions) {
|
||||
|
||||
@@ -275,7 +275,7 @@ public class BooleanOperators {
|
||||
* Creates new {@link Or} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Or}.
|
||||
*/
|
||||
public Or orExpression(AggregationExpression expression) {
|
||||
|
||||
@@ -287,7 +287,7 @@ public class BooleanOperators {
|
||||
* Creates new {@link Or} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Or}.
|
||||
*/
|
||||
public Or orField(String fieldReference) {
|
||||
|
||||
@@ -299,7 +299,7 @@ public class BooleanOperators {
|
||||
* Creates new {@link Or} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Or}.
|
||||
*/
|
||||
public Or orValue(Object value) {
|
||||
|
||||
@@ -329,7 +329,7 @@ public class BooleanOperators {
|
||||
* value.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Not}.
|
||||
*/
|
||||
public static Not not(String fieldReference) {
|
||||
|
||||
@@ -342,7 +342,7 @@ public class BooleanOperators {
|
||||
* returns the opposite boolean value.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Not}.
|
||||
*/
|
||||
public static Not not(AggregationExpression expression) {
|
||||
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketAutoOperation.BucketAutoOperationOutputBuilder;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketOperationSupport.OutputBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Encapsulates the aggregation framework {@code $bucketAuto}-operation. <br />
|
||||
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into a
|
||||
@@ -106,14 +105,23 @@ public class BucketAutoOperation extends BucketOperationSupport<BucketAutoOperat
|
||||
|
||||
options.putAll(super.toDocument(context));
|
||||
|
||||
return new Document("$bucketAuto", options);
|
||||
return new Document(getOperator(), options);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$bucketAuto";
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a number of bucket {@literal buckets} and return a new {@link BucketAutoOperation}.
|
||||
*
|
||||
* @param buckets must be a positive number.
|
||||
* @return
|
||||
* @return new instance of {@link BucketAutoOperation}.
|
||||
*/
|
||||
public BucketAutoOperation withBuckets(int buckets) {
|
||||
|
||||
@@ -128,7 +136,7 @@ public class BucketAutoOperation extends BucketOperationSupport<BucketAutoOperat
|
||||
* Use either predefined {@link Granularities} or provide a own one.
|
||||
*
|
||||
* @param granularity must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link BucketAutoOperation}.
|
||||
*/
|
||||
public BucketAutoOperation withGranularity(Granularity granularity) {
|
||||
|
||||
@@ -209,7 +217,7 @@ public class BucketAutoOperation extends BucketOperationSupport<BucketAutoOperat
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @param operation must not be {@literal null}.
|
||||
* @param parameters
|
||||
* @param parameters must not be {@literal null}.
|
||||
*/
|
||||
protected ExpressionBucketAutoOperationBuilder(String expression, BucketAutoOperation operation,
|
||||
Object[] parameters) {
|
||||
|
||||
@@ -20,21 +20,19 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketOperation.BucketOperationOutputBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Encapsulates the aggregation framework {@code $bucket}-operation. <br />
|
||||
*
|
||||
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into
|
||||
* groups, called buckets, based on a specified expression and bucket boundaries. <br />
|
||||
*
|
||||
* We recommend to use the static factory method {@link Aggregation#bucket(String)} instead of creating instances of
|
||||
* this class directly.
|
||||
*
|
||||
* @see <a href="https://docs.mongodb.org/manual/reference/aggregation/bucket/">https://docs.mongodb.org/manual/reference/aggregation/bucket/</a>
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.org/manual/reference/aggregation/bucket/">https://docs.mongodb.org/manual/reference/aggregation/bucket/</a>
|
||||
* @see BucketOperationSupport
|
||||
* @author Mark Paluch
|
||||
* @since 1.10
|
||||
@@ -103,14 +101,23 @@ public class BucketOperation extends BucketOperationSupport<BucketOperation, Buc
|
||||
|
||||
options.putAll(super.toDocument(context));
|
||||
|
||||
return new Document("$bucket", options);
|
||||
return new Document(getOperator(), options);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$bucket";
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a default bucket {@literal literal} and return a new {@link BucketOperation}.
|
||||
*
|
||||
* @param literal must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link BucketOperation}.
|
||||
*/
|
||||
public BucketOperation withDefaultBucket(Object literal) {
|
||||
|
||||
@@ -123,7 +130,7 @@ public class BucketOperation extends BucketOperationSupport<BucketOperation, Buc
|
||||
* preserved and the new {@literal boundaries} are appended.
|
||||
*
|
||||
* @param boundaries must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link BucketOperation}.
|
||||
*/
|
||||
public BucketOperation withBoundaries(Object... boundaries) {
|
||||
|
||||
@@ -204,12 +211,12 @@ public class BucketOperation extends BucketOperationSupport<BucketOperation, Buc
|
||||
extends ExpressionBucketOperationBuilderSupport<BucketOperationOutputBuilder, BucketOperation> {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ExpressionBucketOperationBuilderSupport} for the given value, {@link BucketOperation}
|
||||
* and parameters.
|
||||
* Creates a new {@link ExpressionBucketOperationBuilderSupport} for the given value, {@link BucketOperation} and
|
||||
* parameters.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @param operation must not be {@literal null}.
|
||||
* @param parameters
|
||||
* @param parameters must not be {@literal null}.
|
||||
*/
|
||||
protected ExpressionBucketOperationBuilder(String expression, BucketOperation operation, Object[] parameters) {
|
||||
super(expression, operation, parameters);
|
||||
|
||||
@@ -21,14 +21,13 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketOperationSupport.OutputBuilder;
|
||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||
import org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder;
|
||||
import org.springframework.expression.spel.ast.Projection;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Base class for bucket operations that support output expressions the aggregation framework. <br />
|
||||
* Bucket stages collect documents into buckets and can contribute output fields. <br />
|
||||
@@ -104,7 +103,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
*
|
||||
* @param expression the SpEL expression, must not be {@literal null} or empty.
|
||||
* @param params must not be {@literal null}
|
||||
* @return
|
||||
* @return new instance of {@link ExpressionBucketOperationBuilderSupport} to create {@link BucketOperation}.
|
||||
*/
|
||||
public abstract ExpressionBucketOperationBuilderSupport<B, T> andOutputExpression(String expression,
|
||||
Object... params);
|
||||
@@ -114,7 +113,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
* resulting bucket documents.
|
||||
*
|
||||
* @param expression the SpEL expression, must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public abstract B andOutput(AggregationExpression expression);
|
||||
|
||||
@@ -124,14 +123,14 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
* {@literal fieldName}.
|
||||
*
|
||||
* @param fieldName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public abstract B andOutput(String fieldName);
|
||||
|
||||
/**
|
||||
* Creates a new {@link BucketOperationSupport} given to add a count field to the resulting bucket documents.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B andOutputCount() {
|
||||
return andOutput(new AggregationExpression() {
|
||||
@@ -231,7 +230,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
* Generates a builder for a {@code $sum}-expression. <br />
|
||||
* Count expressions are emulated via {@code $sum: 1}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B count() {
|
||||
return sum(1);
|
||||
@@ -240,7 +239,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for a {@code $sum}-expression for the current value.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B sum() {
|
||||
return apply(Accumulators.SUM);
|
||||
@@ -249,8 +248,8 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for a {@code $sum}-expression for the given {@literal value}.
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
* @param value must not be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B sum(Number value) {
|
||||
return apply(new OperationOutput(Accumulators.SUM.getMongoOperator(), Collections.singleton(value)));
|
||||
@@ -259,7 +258,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for an {@code $last}-expression for the current value..
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B last() {
|
||||
return apply(Accumulators.LAST);
|
||||
@@ -268,7 +267,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for a {@code $first}-expression the current value.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B first() {
|
||||
return apply(Accumulators.FIRST);
|
||||
@@ -277,8 +276,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for an {@code $avg}-expression for the current value.
|
||||
*
|
||||
* @param reference
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B avg() {
|
||||
return apply(Accumulators.AVG);
|
||||
@@ -287,7 +285,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for an {@code $min}-expression for the current value.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B min() {
|
||||
return apply(Accumulators.MIN);
|
||||
@@ -296,7 +294,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for an {@code $max}-expression for the current value.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B max() {
|
||||
return apply(Accumulators.MAX);
|
||||
@@ -305,7 +303,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for an {@code $push}-expression for the current value.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B push() {
|
||||
return apply(Accumulators.PUSH);
|
||||
@@ -314,7 +312,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Generates a builder for an {@code $addToSet}-expression for the current value.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B addToSet() {
|
||||
return apply(Accumulators.ADDTOSET);
|
||||
@@ -325,7 +323,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
*
|
||||
* @param operation the operation name, must not be {@literal null} or empty.
|
||||
* @param values must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public B apply(String operation, Object... values) {
|
||||
|
||||
@@ -342,7 +340,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
* Apply an {@link OperationOutput} to this output.
|
||||
*
|
||||
* @param operationOutput must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
protected abstract B apply(OperationOutput operationOutput);
|
||||
|
||||
@@ -354,7 +352,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
* Returns the finally to be applied {@link BucketOperation} with the given alias.
|
||||
*
|
||||
* @param alias will never be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public T as(String alias) {
|
||||
|
||||
@@ -550,8 +548,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
List<Object> operationArguments = getOperationArguments(context);
|
||||
return new Document(operation,
|
||||
operationArguments.size() == 1 ? operationArguments.get(0) : operationArguments);
|
||||
return new Document(operation, operationArguments.size() == 1 ? operationArguments.get(0) : operationArguments);
|
||||
}
|
||||
|
||||
protected List<Object> getOperationArguments(AggregationOperationContext context) {
|
||||
@@ -579,7 +576,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Returns the field that holds the {@link ProjectionOperationBuilder.OperationProjection}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
protected Field getField() {
|
||||
return getExposedField();
|
||||
@@ -589,7 +586,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
* Creates a new instance of this {@link OperationOutput} with the given alias.
|
||||
*
|
||||
* @param alias the alias to set
|
||||
* @return
|
||||
* @return new instance of {@link OperationOutput}.
|
||||
*/
|
||||
public OperationOutput withAlias(String alias) {
|
||||
|
||||
@@ -658,8 +655,8 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
/**
|
||||
* Creates a new {@link AggregationExpressionOutput}.
|
||||
*
|
||||
* @param field
|
||||
* @param expression
|
||||
* @param field must not be {@literal null}.
|
||||
* @param expression must not be {@literal null}.
|
||||
*/
|
||||
protected AggregationExpressionOutput(Field field, AggregationExpression expression) {
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ComparisonOperators {
|
||||
* Take the field referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ComparisonOperatorFactory}.
|
||||
*/
|
||||
public static ComparisonOperatorFactory valueOf(String fieldReference) {
|
||||
return new ComparisonOperatorFactory(fieldReference);
|
||||
@@ -42,7 +42,7 @@ public class ComparisonOperators {
|
||||
* Take the value resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ComparisonOperatorFactory}.
|
||||
*/
|
||||
public static ComparisonOperatorFactory valueOf(AggregationExpression expression) {
|
||||
return new ComparisonOperatorFactory(expression);
|
||||
@@ -81,7 +81,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link AggregationExpression} that compares two values.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public Cmp compareTo(String fieldReference) {
|
||||
return createCmp().compareTo(fieldReference);
|
||||
@@ -91,7 +91,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link AggregationExpression} that compares two values.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public Cmp compareTo(AggregationExpression expression) {
|
||||
return createCmp().compareTo(expression);
|
||||
@@ -101,7 +101,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link AggregationExpression} that compares two values.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public Cmp compareToValue(Object value) {
|
||||
return createCmp().compareToValue(value);
|
||||
@@ -116,7 +116,7 @@ public class ComparisonOperators {
|
||||
* value is equal to the value of the referenced field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public Eq equalTo(String fieldReference) {
|
||||
return createEq().equalTo(fieldReference);
|
||||
@@ -127,7 +127,7 @@ public class ComparisonOperators {
|
||||
* value is equal to the expression result.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public Eq equalTo(AggregationExpression expression) {
|
||||
return createEq().equalTo(expression);
|
||||
@@ -138,7 +138,7 @@ public class ComparisonOperators {
|
||||
* value is equal to the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public Eq equalToValue(Object value) {
|
||||
return createEq().equalToValue(value);
|
||||
@@ -153,7 +153,7 @@ public class ComparisonOperators {
|
||||
* value is greater than the value of the referenced field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public Gt greaterThan(String fieldReference) {
|
||||
return createGt().greaterThan(fieldReference);
|
||||
@@ -164,7 +164,7 @@ public class ComparisonOperators {
|
||||
* value is greater than the expression result.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public Gt greaterThan(AggregationExpression expression) {
|
||||
return createGt().greaterThan(expression);
|
||||
@@ -175,7 +175,7 @@ public class ComparisonOperators {
|
||||
* value is greater than the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public Gt greaterThanValue(Object value) {
|
||||
return createGt().greaterThanValue(value);
|
||||
@@ -190,7 +190,7 @@ public class ComparisonOperators {
|
||||
* value is greater than or equivalent to the value of the referenced field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public Gte greaterThanEqualTo(String fieldReference) {
|
||||
return createGte().greaterThanEqualTo(fieldReference);
|
||||
@@ -201,7 +201,7 @@ public class ComparisonOperators {
|
||||
* value is greater than or equivalent to the expression result.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public Gte greaterThanEqualTo(AggregationExpression expression) {
|
||||
return createGte().greaterThanEqualTo(expression);
|
||||
@@ -212,7 +212,7 @@ public class ComparisonOperators {
|
||||
* value is greater than or equivalent to the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public Gte greaterThanEqualToValue(Object value) {
|
||||
return createGte().greaterThanEqualToValue(value);
|
||||
@@ -227,7 +227,7 @@ public class ComparisonOperators {
|
||||
* value is less than the value of the referenced field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public Lt lessThan(String fieldReference) {
|
||||
return createLt().lessThan(fieldReference);
|
||||
@@ -238,7 +238,7 @@ public class ComparisonOperators {
|
||||
* value is less than the expression result.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public Lt lessThan(AggregationExpression expression) {
|
||||
return createLt().lessThan(expression);
|
||||
@@ -249,7 +249,7 @@ public class ComparisonOperators {
|
||||
* value is less than to the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public Lt lessThanValue(Object value) {
|
||||
return createLt().lessThanValue(value);
|
||||
@@ -264,7 +264,7 @@ public class ComparisonOperators {
|
||||
* value is less than or equivalent to the value of the referenced field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public Lte lessThanEqualTo(String fieldReference) {
|
||||
return createLte().lessThanEqualTo(fieldReference);
|
||||
@@ -275,7 +275,7 @@ public class ComparisonOperators {
|
||||
* value is less than or equivalent to the expression result.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public Lte lessThanEqualTo(AggregationExpression expression) {
|
||||
return createLte().lessThanEqualTo(expression);
|
||||
@@ -285,8 +285,8 @@ public class ComparisonOperators {
|
||||
* Creates new {@link AggregationExpression} that compares two values and returns {@literal true} when the first
|
||||
* value is less than or equivalent to the given value.
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public Lte lessThanEqualToValue(Object value) {
|
||||
return createLte().lessThanEqualToValue(value);
|
||||
@@ -301,7 +301,7 @@ public class ComparisonOperators {
|
||||
* are not equivalent.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public Ne notEqualTo(String fieldReference) {
|
||||
return createNe().notEqualTo(fieldReference);
|
||||
@@ -312,7 +312,7 @@ public class ComparisonOperators {
|
||||
* are not equivalent.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public Ne notEqualTo(AggregationExpression expression) {
|
||||
return createNe().notEqualTo(expression);
|
||||
@@ -323,7 +323,7 @@ public class ComparisonOperators {
|
||||
* are not equivalent.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public Ne notEqualToValue(Object value) {
|
||||
return createNe().notEqualToValue(value);
|
||||
@@ -358,7 +358,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Cmp}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public static Cmp valueOf(String fieldReference) {
|
||||
|
||||
@@ -370,7 +370,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Cmp}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public static Cmp valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -382,7 +382,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Cmp} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public Cmp compareTo(String fieldReference) {
|
||||
|
||||
@@ -394,7 +394,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Cmp} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public Cmp compareTo(AggregationExpression expression) {
|
||||
|
||||
@@ -406,12 +406,12 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Cmp} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Cmp}.
|
||||
*/
|
||||
public Cmp compareToValue(Object value) {
|
||||
|
||||
Assert.notNull(value, "Value must not be null!");
|
||||
return new Cmp(append(value));
|
||||
return new Cmp(append(value, Expand.KEEP_SOURCE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +435,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Eq}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public static Eq valueOf(String fieldReference) {
|
||||
|
||||
@@ -447,7 +447,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Eq}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public static Eq valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -459,7 +459,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Eq} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public Eq equalTo(String fieldReference) {
|
||||
|
||||
@@ -471,7 +471,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Eq} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public Eq equalTo(AggregationExpression expression) {
|
||||
|
||||
@@ -483,12 +483,12 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Eq} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Eq}.
|
||||
*/
|
||||
public Eq equalToValue(Object value) {
|
||||
|
||||
Assert.notNull(value, "Value must not be null!");
|
||||
return new Eq(append(value));
|
||||
return new Eq(append(value, Expand.KEEP_SOURCE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gt}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public static Gt valueOf(String fieldReference) {
|
||||
|
||||
@@ -524,7 +524,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gt}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public static Gt valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -536,7 +536,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gt} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public Gt greaterThan(String fieldReference) {
|
||||
|
||||
@@ -548,7 +548,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gt} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public Gt greaterThan(AggregationExpression expression) {
|
||||
|
||||
@@ -560,7 +560,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gt} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gt}.
|
||||
*/
|
||||
public Gt greaterThanValue(Object value) {
|
||||
|
||||
@@ -589,7 +589,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lt}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public static Lt valueOf(String fieldReference) {
|
||||
|
||||
@@ -601,7 +601,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lt}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public static Lt valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -613,7 +613,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lt} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public Lt lessThan(String fieldReference) {
|
||||
|
||||
@@ -625,7 +625,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lt} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public Lt lessThan(AggregationExpression expression) {
|
||||
|
||||
@@ -637,7 +637,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lt} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lt}.
|
||||
*/
|
||||
public Lt lessThanValue(Object value) {
|
||||
|
||||
@@ -666,7 +666,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gte}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public static Gte valueOf(String fieldReference) {
|
||||
|
||||
@@ -678,7 +678,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gte}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public static Gte valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -690,7 +690,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gte} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public Gte greaterThanEqualTo(String fieldReference) {
|
||||
|
||||
@@ -702,7 +702,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gte} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public Gte greaterThanEqualTo(AggregationExpression expression) {
|
||||
|
||||
@@ -714,7 +714,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Gte} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Gte}.
|
||||
*/
|
||||
public Gte greaterThanEqualToValue(Object value) {
|
||||
|
||||
@@ -743,7 +743,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lte}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public static Lte valueOf(String fieldReference) {
|
||||
|
||||
@@ -755,7 +755,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lte}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public static Lte valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -767,7 +767,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lte} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public Lte lessThanEqualTo(String fieldReference) {
|
||||
|
||||
@@ -779,7 +779,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lte} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public Lte lessThanEqualTo(AggregationExpression expression) {
|
||||
|
||||
@@ -791,7 +791,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Lte} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Lte}.
|
||||
*/
|
||||
public Lte lessThanEqualToValue(Object value) {
|
||||
|
||||
@@ -820,7 +820,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Ne}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public static Ne valueOf(String fieldReference) {
|
||||
|
||||
@@ -832,7 +832,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Ne}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public static Ne valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -844,7 +844,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Ne} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public Ne notEqualTo(String fieldReference) {
|
||||
|
||||
@@ -856,7 +856,7 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Ne} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public Ne notEqualTo(AggregationExpression expression) {
|
||||
|
||||
@@ -868,12 +868,12 @@ public class ComparisonOperators {
|
||||
* Creates new {@link Eq} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Ne}.
|
||||
*/
|
||||
public Ne notEqualToValue(Object value) {
|
||||
|
||||
Assert.notNull(value, "Value must not be null!");
|
||||
return new Ne(append(value));
|
||||
return new Ne(append(value, Expand.KEEP_SOURCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ConditionalOperators {
|
||||
* Take the field referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ConditionalOperatorFactory}.
|
||||
*/
|
||||
public static ConditionalOperatorFactory when(String fieldReference) {
|
||||
return new ConditionalOperatorFactory(fieldReference);
|
||||
@@ -53,7 +53,7 @@ public class ConditionalOperators {
|
||||
* Take the value resulting from the given {@literal expression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ConditionalOperatorFactory}.
|
||||
*/
|
||||
public static ConditionalOperatorFactory when(AggregationExpression expression) {
|
||||
return new ConditionalOperatorFactory(expression);
|
||||
@@ -63,7 +63,7 @@ public class ConditionalOperators {
|
||||
* Take the value resulting from the given {@literal criteriaDefinition}.
|
||||
*
|
||||
* @param criteriaDefinition must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ConditionalOperatorFactory}.
|
||||
*/
|
||||
public static ConditionalOperatorFactory when(CriteriaDefinition criteriaDefinition) {
|
||||
return new ConditionalOperatorFactory(criteriaDefinition);
|
||||
@@ -75,7 +75,7 @@ public class ConditionalOperators {
|
||||
* instances of undefined values or missing fields, returns the value of the replacement expression.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IfNull.ThenBuilder} to create {@link IfNull}.
|
||||
*/
|
||||
public static IfNull.ThenBuilder ifNull(String fieldReference) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class ConditionalOperators {
|
||||
* instances of undefined values or missing fields, returns the value of the replacement expression.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IfNull.ThenBuilder} to create {@link IfNull}.
|
||||
*/
|
||||
public static IfNull.ThenBuilder ifNull(AggregationExpression expression) {
|
||||
|
||||
@@ -103,7 +103,7 @@ public class ConditionalOperators {
|
||||
* out of the control flow.
|
||||
*
|
||||
* @param conditions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Switch}.
|
||||
*/
|
||||
public static Switch switchCases(CaseOperator... conditions) {
|
||||
return Switch.switchCases(conditions);
|
||||
@@ -115,7 +115,7 @@ public class ConditionalOperators {
|
||||
* out of the control flow.
|
||||
*
|
||||
* @param conditions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Switch}.
|
||||
*/
|
||||
public static Switch switchCases(List<CaseOperator> conditions) {
|
||||
return Switch.switchCases(conditions);
|
||||
@@ -176,7 +176,7 @@ public class ConditionalOperators {
|
||||
* return expressions.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link OtherwiseBuilder} to create {@link Cond}.
|
||||
*/
|
||||
public OtherwiseBuilder then(Object value) {
|
||||
|
||||
@@ -189,7 +189,7 @@ public class ConditionalOperators {
|
||||
* return expressions.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link OtherwiseBuilder} to create {@link Cond}.
|
||||
*/
|
||||
public OtherwiseBuilder thenValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -202,7 +202,7 @@ public class ConditionalOperators {
|
||||
* return expressions.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link OtherwiseBuilder} to create {@link Cond}.
|
||||
*/
|
||||
public OtherwiseBuilder thenValueOf(String fieldReference) {
|
||||
|
||||
@@ -233,9 +233,9 @@ public class ConditionalOperators {
|
||||
* field references}, {@link AggregationExpression expressions}, values of simple MongoDB types or values that can be
|
||||
* converted to a simple MongoDB type.
|
||||
*
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/ifNull/">https://docs.mongodb.com/manual/reference/operator/aggregation/ifNull/</a>
|
||||
* @author Mark Paluch
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/ifNull/">https://docs.mongodb.com/manual/reference/operator/aggregation/ifNull/</a>
|
||||
*/
|
||||
public static class IfNull implements AggregationExpression {
|
||||
|
||||
@@ -251,9 +251,8 @@ public class ConditionalOperators {
|
||||
/**
|
||||
* Creates new {@link IfNull}.
|
||||
*
|
||||
* @param fieldReference the field to check for a {@literal null} value, field reference must not be {@literal null}
|
||||
* .
|
||||
* @return
|
||||
* @param fieldReference the field to check for a {@literal null} value, field reference must not be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static ThenBuilder ifNull(String fieldReference) {
|
||||
|
||||
@@ -265,8 +264,8 @@ public class ConditionalOperators {
|
||||
* Creates new {@link IfNull}.
|
||||
*
|
||||
* @param expression the expression to check for a {@literal null} value, field reference must not be
|
||||
* {@literal null}.
|
||||
* @return
|
||||
* {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static ThenBuilder ifNull(AggregationExpression expression) {
|
||||
|
||||
@@ -316,14 +315,14 @@ public class ConditionalOperators {
|
||||
|
||||
/**
|
||||
* @param fieldReference the field to check for a {@literal null} value, field reference must not be
|
||||
* {@literal null}.
|
||||
* {@literal null}.
|
||||
* @return the {@link ThenBuilder}
|
||||
*/
|
||||
ThenBuilder ifNull(String fieldReference);
|
||||
|
||||
/**
|
||||
* @param expression the expression to check for a {@literal null} value, field name must not be {@literal null}
|
||||
* or empty.
|
||||
* or empty.
|
||||
* @return the {@link ThenBuilder}
|
||||
*/
|
||||
ThenBuilder ifNull(AggregationExpression expression);
|
||||
@@ -336,21 +335,21 @@ public class ConditionalOperators {
|
||||
|
||||
/**
|
||||
* @param value the value to be used if the {@code $ifNull} condition evaluates {@literal true}. Can be a
|
||||
* {@link Document}, a value that is supported by MongoDB or a value that can be converted to a MongoDB
|
||||
* representation but must not be {@literal null}.
|
||||
* @return
|
||||
* {@link Document}, a value that is supported by MongoDB or a value that can be converted to a MongoDB
|
||||
* representation but must not be {@literal null}.
|
||||
* @return new instance of {@link IfNull}.
|
||||
*/
|
||||
IfNull then(Object value);
|
||||
|
||||
/**
|
||||
* @param fieldReference the field holding the replacement value, must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IfNull}.
|
||||
*/
|
||||
IfNull thenValueOf(String fieldReference);
|
||||
|
||||
/**
|
||||
* @param expression the expression yielding to the replacement value, must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IfNull}.
|
||||
*/
|
||||
IfNull thenValueOf(AggregationExpression expression);
|
||||
}
|
||||
@@ -364,7 +363,8 @@ public class ConditionalOperators {
|
||||
|
||||
private @Nullable Object condition;
|
||||
|
||||
private IfNullOperatorBuilder() {}
|
||||
private IfNullOperatorBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new builder for {@link IfNull}.
|
||||
@@ -458,9 +458,15 @@ public class ConditionalOperators {
|
||||
public static Switch switchCases(List<CaseOperator> conditions) {
|
||||
|
||||
Assert.notNull(conditions, "Conditions must not be null!");
|
||||
return new Switch(Collections.<String, Object> singletonMap("branches", new ArrayList<CaseOperator>(conditions)));
|
||||
return new Switch(Collections.<String, Object>singletonMap("branches", new ArrayList<CaseOperator>(conditions)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Switch}.
|
||||
*/
|
||||
public Switch defaultTo(Object value) {
|
||||
return new Switch(append("default", value));
|
||||
}
|
||||
@@ -522,7 +528,7 @@ public class ConditionalOperators {
|
||||
* Set the then {@literal value}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link CaseOperator}.
|
||||
*/
|
||||
CaseOperator then(Object value);
|
||||
}
|
||||
@@ -536,10 +542,10 @@ public class ConditionalOperators {
|
||||
* {@link AggregationExpression expressions}, values of simple MongoDB types or values that can be converted to a
|
||||
* simple MongoDB type.
|
||||
*
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/cond/">https://docs.mongodb.com/manual/reference/operator/aggregation/cond/</a>
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.com/manual/reference/operator/aggregation/cond/">https://docs.mongodb.com/manual/reference/operator/aggregation/cond/</a>
|
||||
*/
|
||||
public static class Cond implements AggregationExpression {
|
||||
|
||||
@@ -664,7 +670,6 @@ public class ConditionalOperators {
|
||||
}
|
||||
|
||||
clauses.add(new Document(key, args));
|
||||
|
||||
} else if (predicate instanceof Document) {
|
||||
|
||||
Document nested = (Document) predicate;
|
||||
@@ -680,7 +685,6 @@ public class ConditionalOperators {
|
||||
args.add(nested.get(s));
|
||||
clauses.add(new Document(s, args));
|
||||
}
|
||||
|
||||
} else if (!isKeyword(key)) {
|
||||
|
||||
List<Object> args = new ArrayList<Object>();
|
||||
@@ -802,8 +806,8 @@ public class ConditionalOperators {
|
||||
|
||||
/**
|
||||
* @param value the value to be used if the condition evaluates {@literal true}. Can be a {@link Document}, a
|
||||
* value that is supported by MongoDB or a value that can be converted to a MongoDB representation but
|
||||
* must not be {@literal null}.
|
||||
* value that is supported by MongoDB or a value that can be converted to a MongoDB representation but
|
||||
* must not be {@literal null}.
|
||||
* @return the {@link OtherwiseBuilder}
|
||||
*/
|
||||
OtherwiseBuilder then(Object value);
|
||||
@@ -828,8 +832,8 @@ public class ConditionalOperators {
|
||||
|
||||
/**
|
||||
* @param value the value to be used if the condition evaluates {@literal false}. Can be a {@link Document}, a
|
||||
* value that is supported by MongoDB or a value that can be converted to a MongoDB representation but
|
||||
* must not be {@literal null}.
|
||||
* value that is supported by MongoDB or a value that can be converted to a MongoDB representation but
|
||||
* must not be {@literal null}.
|
||||
* @return the {@link Cond}
|
||||
*/
|
||||
Cond otherwise(Object value);
|
||||
@@ -857,7 +861,8 @@ public class ConditionalOperators {
|
||||
private @Nullable Object condition;
|
||||
private @Nullable Object thenValue;
|
||||
|
||||
private ConditionalExpressionBuilder() {}
|
||||
private ConditionalExpressionBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new builder for {@link Cond}.
|
||||
|
||||
@@ -34,9 +34,9 @@ public class CountOperation implements FieldsExposingAggregationOperation {
|
||||
private final String fieldName;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CountOperation} given the {@link fieldName} field name.
|
||||
* Creates a new {@link CountOperation} given the {@literal fieldName} field name.
|
||||
*
|
||||
* @param asFieldName must not be {@literal null} or empty.
|
||||
* @param fieldName must not be {@literal null} or empty.
|
||||
*/
|
||||
public CountOperation(String fieldName) {
|
||||
|
||||
@@ -49,7 +49,12 @@ public class CountOperation implements FieldsExposingAggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document("$count", fieldName);
|
||||
return new Document(getOperator(), fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$count";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -71,7 +76,7 @@ public class CountOperation implements FieldsExposingAggregationOperation {
|
||||
* Returns the finally to be applied {@link CountOperation} with the given alias.
|
||||
*
|
||||
* @param fieldName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link CountOperation}.
|
||||
*/
|
||||
public CountOperation as(String fieldName) {
|
||||
return new CountOperation(fieldName);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class DataTypeOperators {
|
||||
* Return the BSON data type of the given {@literal field}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Type}.
|
||||
*/
|
||||
public static Type typeOf(String fieldReference) {
|
||||
return Type.typeOf(fieldReference);
|
||||
@@ -56,7 +56,7 @@ public class DataTypeOperators {
|
||||
* Creates new {@link Type}.
|
||||
*
|
||||
* @param field must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Type}.
|
||||
*/
|
||||
public static Type typeOf(String field) {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DateOperators {
|
||||
* Take the date referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DateOperatorFactory}.
|
||||
*/
|
||||
public static DateOperatorFactory dateOf(String fieldReference) {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DateOperators {
|
||||
* Take the date resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DateOperatorFactory}.
|
||||
*/
|
||||
public static DateOperatorFactory dateOf(AggregationExpression expression) {
|
||||
|
||||
@@ -278,7 +278,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the day of the year for a date as a number between 1 and
|
||||
* 366.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link DayOfYear}.
|
||||
*/
|
||||
public DayOfYear dayOfYear() {
|
||||
return applyTimezone(DayOfYear.dayOfYear(dateReference()), timezone);
|
||||
@@ -288,7 +288,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the day of the month for a date as a number between 1 and
|
||||
* 31.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link DayOfMonth}.
|
||||
*/
|
||||
public DayOfMonth dayOfMonth() {
|
||||
return applyTimezone(DayOfMonth.dayOfMonth(dateReference()), timezone);
|
||||
@@ -298,7 +298,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the day of the week for a date as a number between 1
|
||||
* (Sunday) and 7 (Saturday).
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link DayOfWeek}.
|
||||
*/
|
||||
public DayOfWeek dayOfWeek() {
|
||||
return applyTimezone(DayOfWeek.dayOfWeek(dateReference()), timezone);
|
||||
@@ -307,7 +307,7 @@ public class DateOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the year portion of a date.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Year}.
|
||||
*/
|
||||
public Year year() {
|
||||
return applyTimezone(Year.year(dateReference()), timezone);
|
||||
@@ -316,7 +316,7 @@ public class DateOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the month of a date as a number between 1 and 12.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Month}.
|
||||
*/
|
||||
public Month month() {
|
||||
return applyTimezone(Month.month(dateReference()), timezone);
|
||||
@@ -326,7 +326,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the week of the year for a date as a number between 0 and
|
||||
* 53.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Week}.
|
||||
*/
|
||||
public Week week() {
|
||||
return applyTimezone(Week.week(dateReference()), timezone);
|
||||
@@ -335,7 +335,7 @@ public class DateOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the hour portion of a date as a number between 0 and 23.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Hour}.
|
||||
*/
|
||||
public Hour hour() {
|
||||
return applyTimezone(Hour.hour(dateReference()), timezone);
|
||||
@@ -344,7 +344,7 @@ public class DateOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the minute portion of a date as a number between 0 and 59.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Minute}.
|
||||
*/
|
||||
public Minute minute() {
|
||||
return applyTimezone(Minute.minute(dateReference()), timezone);
|
||||
@@ -354,7 +354,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the second portion of a date as a number between 0 and 59,
|
||||
* but can be 60 to account for leap seconds.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Second}.
|
||||
*/
|
||||
public Second second() {
|
||||
return applyTimezone(Second.second(dateReference()), timezone);
|
||||
@@ -364,7 +364,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the millisecond portion of a date as an integer between 0
|
||||
* and 999.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link Millisecond}.
|
||||
*/
|
||||
public Millisecond millisecond() {
|
||||
return applyTimezone(Millisecond.millisecond(dateReference()), timezone);
|
||||
@@ -375,7 +375,7 @@ public class DateOperators {
|
||||
* {@literal format}.
|
||||
*
|
||||
* @param format must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DateToString}.
|
||||
*/
|
||||
public DateToString toString(String format) {
|
||||
return applyTimezone(DateToString.dateToString(dateReference()).toString(format), timezone);
|
||||
@@ -396,7 +396,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the weekday number in ISO 8601-2018 format, ranging from 1
|
||||
* (for Monday) to 7 (for Sunday).
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link IsoDayOfWeek}.
|
||||
*/
|
||||
public IsoDayOfWeek isoDayOfWeek() {
|
||||
return applyTimezone(IsoDayOfWeek.isoDayWeek(dateReference()), timezone);
|
||||
@@ -406,7 +406,7 @@ public class DateOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the week number in ISO 8601-2018 format, ranging from 1 to
|
||||
* 53.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link IsoWeek}.
|
||||
*/
|
||||
public IsoWeek isoWeek() {
|
||||
return applyTimezone(IsoWeek.isoWeek(dateReference()), timezone);
|
||||
@@ -415,7 +415,7 @@ public class DateOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that returns the year number in ISO 8601-2018 format.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link IsoWeekYear}.
|
||||
*/
|
||||
public IsoWeekYear isoWeekYear() {
|
||||
return applyTimezone(IsoWeekYear.isoWeekYear(dateReference()), timezone);
|
||||
@@ -642,7 +642,7 @@ public class DateOperators {
|
||||
* Creates new {@link DayOfYear}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DayOfYear}.
|
||||
*/
|
||||
public static DayOfYear dayOfYear(String fieldReference) {
|
||||
|
||||
@@ -654,7 +654,7 @@ public class DateOperators {
|
||||
* Creates new {@link DayOfYear}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DayOfYear}.
|
||||
*/
|
||||
public static DayOfYear dayOfYear(AggregationExpression expression) {
|
||||
|
||||
@@ -714,7 +714,7 @@ public class DateOperators {
|
||||
* Creates new {@link DayOfMonth}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DayOfMonth}.
|
||||
*/
|
||||
public static DayOfMonth dayOfMonth(String fieldReference) {
|
||||
|
||||
@@ -726,7 +726,7 @@ public class DateOperators {
|
||||
* Creates new {@link DayOfMonth}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DayOfMonth}.
|
||||
*/
|
||||
public static DayOfMonth dayOfMonth(AggregationExpression expression) {
|
||||
|
||||
@@ -786,7 +786,7 @@ public class DateOperators {
|
||||
* Creates new {@link DayOfWeek}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DayOfWeek}.
|
||||
*/
|
||||
public static DayOfWeek dayOfWeek(String fieldReference) {
|
||||
|
||||
@@ -798,7 +798,7 @@ public class DateOperators {
|
||||
* Creates new {@link DayOfWeek}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DayOfWeek}.
|
||||
*/
|
||||
public static DayOfWeek dayOfWeek(AggregationExpression expression) {
|
||||
|
||||
@@ -858,7 +858,7 @@ public class DateOperators {
|
||||
* Creates new {@link Year}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Year}.
|
||||
*/
|
||||
public static Year yearOf(String fieldReference) {
|
||||
|
||||
@@ -870,7 +870,7 @@ public class DateOperators {
|
||||
* Creates new {@link Year}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Year}.
|
||||
*/
|
||||
public static Year yearOf(AggregationExpression expression) {
|
||||
|
||||
@@ -930,7 +930,7 @@ public class DateOperators {
|
||||
* Creates new {@link Month}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Month}.
|
||||
*/
|
||||
public static Month monthOf(String fieldReference) {
|
||||
|
||||
@@ -942,7 +942,7 @@ public class DateOperators {
|
||||
* Creates new {@link Month}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Month}.
|
||||
*/
|
||||
public static Month monthOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1002,7 +1002,7 @@ public class DateOperators {
|
||||
* Creates new {@link Week}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Week}.
|
||||
*/
|
||||
public static Week weekOf(String fieldReference) {
|
||||
|
||||
@@ -1014,7 +1014,7 @@ public class DateOperators {
|
||||
* Creates new {@link Week}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Week}.
|
||||
*/
|
||||
public static Week weekOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1074,7 +1074,7 @@ public class DateOperators {
|
||||
* Creates new {@link Hour}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Hour}.
|
||||
*/
|
||||
public static Hour hourOf(String fieldReference) {
|
||||
|
||||
@@ -1086,7 +1086,7 @@ public class DateOperators {
|
||||
* Creates new {@link Hour}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Hour}.
|
||||
*/
|
||||
public static Hour hourOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1146,7 +1146,7 @@ public class DateOperators {
|
||||
* Creates new {@link Minute}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Minute}.
|
||||
*/
|
||||
public static Minute minuteOf(String fieldReference) {
|
||||
|
||||
@@ -1158,7 +1158,7 @@ public class DateOperators {
|
||||
* Creates new {@link Minute}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Minute}.
|
||||
*/
|
||||
public static Minute minuteOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1218,7 +1218,7 @@ public class DateOperators {
|
||||
* Creates new {@link Second}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Second}.
|
||||
*/
|
||||
public static Second secondOf(String fieldReference) {
|
||||
|
||||
@@ -1230,7 +1230,7 @@ public class DateOperators {
|
||||
* Creates new {@link Second}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Second}.
|
||||
*/
|
||||
public static Second secondOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1290,7 +1290,7 @@ public class DateOperators {
|
||||
* Creates new {@link Millisecond}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Millisecond}.
|
||||
*/
|
||||
public static Millisecond millisecondOf(String fieldReference) {
|
||||
|
||||
@@ -1302,7 +1302,7 @@ public class DateOperators {
|
||||
* Creates new {@link Millisecond}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Millisecond}.
|
||||
*/
|
||||
public static Millisecond millisecondOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1376,7 +1376,7 @@ public class DateOperators {
|
||||
* Creates new {@link FormatBuilder} allowing to define the date format to apply.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link FormatBuilder} to crate {@link DateToString}.
|
||||
*/
|
||||
public static FormatBuilder dateOf(final String fieldReference) {
|
||||
|
||||
@@ -1388,7 +1388,7 @@ public class DateOperators {
|
||||
* Creates new {@link FormatBuilder} allowing to define the date format to apply.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link FormatBuilder} to crate {@link DateToString}.
|
||||
*/
|
||||
public static FormatBuilder dateOf(final AggregationExpression expression) {
|
||||
|
||||
@@ -1540,7 +1540,7 @@ public class DateOperators {
|
||||
* Creates new {@link IsoDayOfWeek}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsoDayOfWeek}.
|
||||
*/
|
||||
public static IsoDayOfWeek isoDayOfWeek(String fieldReference) {
|
||||
|
||||
@@ -1552,7 +1552,7 @@ public class DateOperators {
|
||||
* Creates new {@link IsoDayOfWeek}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsoDayOfWeek}.
|
||||
*/
|
||||
public static IsoDayOfWeek isoDayOfWeek(AggregationExpression expression) {
|
||||
|
||||
@@ -1612,7 +1612,7 @@ public class DateOperators {
|
||||
* Creates new {@link IsoWeek}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsoWeek}.
|
||||
*/
|
||||
public static IsoWeek isoWeekOf(String fieldReference) {
|
||||
|
||||
@@ -1624,7 +1624,7 @@ public class DateOperators {
|
||||
* Creates new {@link IsoWeek}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsoWeek}.
|
||||
*/
|
||||
public static IsoWeek isoWeekOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1684,7 +1684,7 @@ public class DateOperators {
|
||||
* Creates new {@link IsoWeekYear}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsoWeekYear}.
|
||||
*/
|
||||
public static IsoWeekYear isoWeekYearOf(String fieldReference) {
|
||||
|
||||
@@ -1696,7 +1696,7 @@ public class DateOperators {
|
||||
* Creates new {@link Millisecond}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IsoWeekYear}.
|
||||
*/
|
||||
public static IsoWeekYear isoWeekYearOf(AggregationExpression expression) {
|
||||
|
||||
@@ -2378,6 +2378,7 @@ public class DateOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T extends TimezonedDateAggregationExpression> T applyTimezone(T instance, Timezone timezone) {
|
||||
return !ObjectUtils.nullSafeEquals(Timezone.none(), timezone) && !instance.hasTimezone()
|
||||
? (T) instance.withTimezone(timezone) : instance;
|
||||
? (T) instance.withTimezone(timezone)
|
||||
: instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,15 @@ abstract class DocumentEnhancingOperation implements InheritsFieldsAggregationOp
|
||||
*/
|
||||
protected abstract String mongoOperator();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return mongoOperator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the raw value map
|
||||
*/
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
/**
|
||||
* Returns an empty {@link ExposedFields} instance.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static ExposedFields empty() {
|
||||
@@ -57,7 +57,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
* Creates a new {@link ExposedFields} instance from the given {@link ExposedField}s.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static ExposedFields from(ExposedField... fields) {
|
||||
return from(Arrays.asList(fields));
|
||||
@@ -67,7 +67,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
* Creates a new {@link ExposedFields} instance from the given {@link ExposedField}s.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
private static ExposedFields from(List<ExposedField> fields) {
|
||||
|
||||
@@ -84,7 +84,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
* Creates synthetic {@link ExposedFields} from the given {@link Fields}.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static ExposedFields synthetic(Fields fields) {
|
||||
return createFields(fields, true);
|
||||
@@ -94,7 +94,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
* Creates non-synthetic {@link ExposedFields} from the given {@link Fields}.
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static ExposedFields nonSynthetic(Fields fields) {
|
||||
return createFields(fields, false);
|
||||
@@ -105,7 +105,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
* @param synthetic
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
private static ExposedFields createFields(Fields fields, boolean synthetic) {
|
||||
|
||||
@@ -135,7 +135,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
* Creates a new {@link ExposedFields} adding the given {@link ExposedField}.
|
||||
*
|
||||
* @param field must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ExposedFields}.
|
||||
*/
|
||||
public ExposedFields and(ExposedField field) {
|
||||
|
||||
@@ -151,8 +151,8 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
/**
|
||||
* Returns the field with the given name or {@literal null} if no field with the given name is available.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
* @param name must not be {@literal null}.
|
||||
* @return can be {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public ExposedField getField(String name) {
|
||||
|
||||
@@ -20,12 +20,11 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketOperationSupport.Output;
|
||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Encapsulates the aggregation framework {@code $facet}-operation. <br />
|
||||
* Facet of {@link AggregationOperation}s to be used in an {@link Aggregation}. Processes multiple
|
||||
@@ -84,7 +83,16 @@ public class FacetOperation implements FieldsExposingAggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document("$facet", facets.toDocument(context));
|
||||
return new Document(getOperator(), facets.toDocument(context));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$facet";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.query.NearQuery;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.NumberUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -95,21 +93,27 @@ public class GeoNearOperation implements AggregationOperation {
|
||||
|
||||
Document command = context.getMappedObject(nearQuery.toDocument());
|
||||
|
||||
if(command.containsKey("query")) {
|
||||
if (command.containsKey("query")) {
|
||||
command.replace("query", context.getMappedObject(command.get("query", Document.class)));
|
||||
}
|
||||
|
||||
if(command.containsKey("collation")) {
|
||||
command.remove("collation");
|
||||
}
|
||||
|
||||
command.remove("collation");
|
||||
command.put("distanceField", distanceField);
|
||||
|
||||
if (StringUtils.hasText(indexKey)) {
|
||||
command.put("key", indexKey);
|
||||
}
|
||||
|
||||
return new Document("$geoNear", command);
|
||||
return new Document(getOperator(), command);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$geoNear";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -125,11 +129,11 @@ public class GeoNearOperation implements AggregationOperation {
|
||||
List<Document> stages = new ArrayList<>();
|
||||
stages.add(command);
|
||||
|
||||
if(nearQuery.getSkip() != null && nearQuery.getSkip() > 0){
|
||||
if (nearQuery.getSkip() != null && nearQuery.getSkip() > 0) {
|
||||
stages.add(new Document("$skip", nearQuery.getSkip()));
|
||||
}
|
||||
|
||||
if(limit != null) {
|
||||
if (limit != null) {
|
||||
stages.add(new Document("$limit", limit.longValue()));
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,12 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
graphLookup.put("restrictSearchWithMatch", context.getMappedObject(restrictSearchWithMatch.getCriteriaObject()));
|
||||
}
|
||||
|
||||
return new Document("$graphLookup", graphLookup);
|
||||
return new Document(getOperator(), graphLookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$graphLookup";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -146,7 +151,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* Set the {@literal collectionName} to apply the {@code $graphLookup} to.
|
||||
*
|
||||
* @param collectionName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
StartWithBuilder from(String collectionName);
|
||||
}
|
||||
@@ -161,7 +166,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* Set the startWith {@literal fieldReferences} to apply the {@code $graphLookup} to.
|
||||
*
|
||||
* @param fieldReferences must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
ConnectFromBuilder startWith(String... fieldReferences);
|
||||
|
||||
@@ -169,7 +174,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* Set the startWith {@literal expressions} to apply the {@code $graphLookup} to.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
ConnectFromBuilder startWith(AggregationExpression... expressions);
|
||||
|
||||
@@ -178,7 +183,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* {@link AggregationExpression} to apply the {@code $graphLookup} to.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
ConnectFromBuilder startWith(Object... expressions);
|
||||
@@ -193,7 +198,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* Set the connectFrom {@literal fieldName} to apply the {@code $graphLookup} to.
|
||||
*
|
||||
* @param fieldName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
ConnectToBuilder connectFrom(String fieldName);
|
||||
}
|
||||
@@ -207,7 +212,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* Set the connectTo {@literal fieldName} to apply the {@code $graphLookup} to.
|
||||
*
|
||||
* @param fieldName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
GraphLookupOperationBuilder connectTo(String fieldName);
|
||||
}
|
||||
@@ -360,7 +365,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* Optionally limit the number of recursions.
|
||||
*
|
||||
* @param numberOfRecursions must be greater or equal to zero.
|
||||
* @return
|
||||
* @return this.
|
||||
*/
|
||||
public GraphLookupOperationBuilder maxDepth(long numberOfRecursions) {
|
||||
|
||||
@@ -374,7 +379,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
* Optionally add a depth field {@literal fieldName} to each traversed document in the search path.
|
||||
*
|
||||
* @param fieldName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return this.
|
||||
*/
|
||||
public GraphLookupOperationBuilder depthField(String fieldName) {
|
||||
|
||||
|
||||
@@ -429,7 +429,16 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
|
||||
operationObject.putAll(operation.toDocument(context));
|
||||
}
|
||||
|
||||
return new Document("$group", operationObject);
|
||||
return new Document(getOperator(), operationObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$group";
|
||||
}
|
||||
|
||||
interface Keyword {
|
||||
|
||||
@@ -49,6 +49,15 @@ public class LimitOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document("$limit", Long.valueOf(maxElements));
|
||||
return new Document(getOperator(), Long.valueOf(maxElements));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$limit";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@ public class LiteralOperators {
|
||||
super(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
|
||||
*/
|
||||
@Override
|
||||
protected String getMongoMethod() {
|
||||
return "$literal";
|
||||
|
||||
@@ -83,13 +83,22 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
lookupObject.append("foreignField", foreignField.getTarget());
|
||||
lookupObject.append("as", as.getTarget());
|
||||
|
||||
return new Document("$lookup", lookupObject);
|
||||
return new Document(getOperator(), lookupObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$lookup";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a builder that allows creation of {@link LookupOperation}.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static FromBuilder newLookup() {
|
||||
return new LookupOperationBuilder();
|
||||
@@ -99,7 +108,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
|
||||
/**
|
||||
* @param name the collection in the same database to perform the join with, must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
LocalFieldBuilder from(String name);
|
||||
}
|
||||
@@ -109,7 +118,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
/**
|
||||
* @param name the field from the documents input to the {@code $lookup} stage, must not be {@literal null} or
|
||||
* empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
ForeignFieldBuilder localField(String name);
|
||||
}
|
||||
@@ -118,7 +127,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
|
||||
/**
|
||||
* @param name the field from the documents in the {@code from} collection, must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
AsBuilder foreignField(String name);
|
||||
}
|
||||
@@ -127,7 +136,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
|
||||
/**
|
||||
* @param name the name of the new array field to add to the input documents, must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @return new instance of {@link LookupOperation}.
|
||||
*/
|
||||
LookupOperation as(String name);
|
||||
}
|
||||
@@ -168,8 +177,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
|
||||
Assert.hasText(name, "'As' must not be null or empty!");
|
||||
as = new ExposedField(Fields.field(name), true);
|
||||
return new LookupOperation(from, localField, foreignField,
|
||||
as);
|
||||
return new LookupOperation(from, localField, foreignField, as);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,8 @@ import org.springframework.util.Assert;
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/match/">MongoDB Aggregation Framework: $match</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/match/">MongoDB Aggregation Framework:
|
||||
* $match</a>
|
||||
*/
|
||||
public class MatchOperation implements AggregationOperation {
|
||||
|
||||
@@ -53,6 +54,15 @@ public class MatchOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document("$match", context.getMappedObject(criteriaDefinition.getCriteriaObject()));
|
||||
return new Document(getOperator(), context.getMappedObject(criteriaDefinition.getCriteriaObject()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$match";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
if (isJustCollection()) {
|
||||
return new Document("$merge", into.collection);
|
||||
return new Document(getOperator(), into.collection);
|
||||
}
|
||||
|
||||
Document $merge = new Document();
|
||||
@@ -122,7 +122,16 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
$merge.putAll(whenNotMatched.toDocument(context));
|
||||
}
|
||||
|
||||
return new Document("$merge", $merge);
|
||||
return new Document(getOperator(), $merge);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$merge";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -186,7 +195,7 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
/**
|
||||
* Merge Documents by using the MongoDB {@literal _id} field.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static UniqueMergeId id() {
|
||||
return ID;
|
||||
@@ -375,7 +384,7 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
/**
|
||||
* Factory method creating {@link WhenDocumentsDontMatch} from a {@code value} literal.
|
||||
*
|
||||
* @param value
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link WhenDocumentsDontMatch}.
|
||||
*/
|
||||
public static WhenDocumentsDontMatch whenNotMatchedOf(String value) {
|
||||
@@ -403,7 +412,7 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
/**
|
||||
* Stop and fail the aggregation operation. Does not revert already performed changes on previous documents.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link WhenDocumentsDontMatch}.
|
||||
*/
|
||||
public static WhenDocumentsDontMatch failWhenNotMatch() {
|
||||
return whenNotMatchedOf("fail");
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
import org.springframework.data.mongodb.util.BsonUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -211,7 +210,16 @@ public class OutOperation implements AggregationOperation {
|
||||
$out.append("uniqueKey", uniqueKey);
|
||||
}
|
||||
|
||||
return new Document("$out", $out);
|
||||
return new Document(getOperator(), $out);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$out";
|
||||
}
|
||||
|
||||
private boolean requiresMongoDb42Format() {
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.lang.Nullable;
|
||||
* {@link AggregationOperationContext} implementation prefixing non-command keys on root level with the given prefix.
|
||||
* Useful when mapping fields to domain specific types while having to prefix keys for query purpose.
|
||||
* <p />
|
||||
* Fields to be excluded from prefixing my be added to a {@literal blacklist}.
|
||||
* Fields to be excluded from prefixing my be added to a {@literal denylist}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
@@ -41,18 +41,18 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
|
||||
private final AggregationOperationContext delegate;
|
||||
private final String prefix;
|
||||
private final Set<String> blacklist;
|
||||
private final Set<String> denylist;
|
||||
|
||||
public PrefixingDelegatingAggregationOperationContext(AggregationOperationContext delegate, String prefix) {
|
||||
this(delegate, prefix, Collections.emptySet());
|
||||
}
|
||||
|
||||
public PrefixingDelegatingAggregationOperationContext(AggregationOperationContext delegate, String prefix,
|
||||
Collection<String> blacklist) {
|
||||
Collection<String> denylist) {
|
||||
|
||||
this.delegate = delegate;
|
||||
this.prefix = prefix;
|
||||
this.blacklist = new HashSet<>(blacklist);
|
||||
this.denylist = new HashSet<>(denylist);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -121,7 +121,7 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
}
|
||||
|
||||
private String prefixKey(String key) {
|
||||
return (key.startsWith("$") || isBlacklisted(key)) ? key : (prefix + "." + key);
|
||||
return (key.startsWith("$") || isDenied(key)) ? key : (prefix + "." + key);
|
||||
}
|
||||
|
||||
private Object prefixCollection(Collection<Object> sourceCollection) {
|
||||
@@ -139,9 +139,9 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
return prefixed;
|
||||
}
|
||||
|
||||
private boolean isBlacklisted(String key) {
|
||||
private boolean isDenied(String key) {
|
||||
|
||||
if (blacklist.contains(key)) {
|
||||
if (denylist.contains(key)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String blacklisted : blacklist) {
|
||||
if (key.startsWith(blacklisted + ".")) {
|
||||
for (String denied : denylist) {
|
||||
if (key.startsWith(denied + ".")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,16 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
fieldObject.putAll(projection.toDocument(context));
|
||||
}
|
||||
|
||||
return new Document("$project", fieldObject);
|
||||
return new Document(getOperator(), fieldObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$project";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1548,7 +1557,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
final Field aliasedField = Fields.field(alias, this.field.getName());
|
||||
return new OperationProjection(aliasedField, operation, values.toArray()) {
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.OperationProjection#getField()
|
||||
*/
|
||||
@@ -1749,7 +1758,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.ProjectionOperation.Projection#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
@@ -1877,7 +1886,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
this.projections = projections;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.ProjectionOperation.Projection#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
|
||||
@@ -74,7 +74,16 @@ public class RedactOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document("$redact", condition.toDocument(context));
|
||||
return new Document(getOperator(), condition.toDocument(context));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$redact";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,6 +86,15 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
return new Document("$replaceRoot", new Document("newRoot", getReplacement().toDocumentExpression(context)));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$replaceRoot";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation#getFields()
|
||||
*/
|
||||
@@ -166,7 +175,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
static class ReplaceRootDocumentOperation extends ReplaceRootOperation {
|
||||
public static class ReplaceRootDocumentOperation extends ReplaceRootOperation {
|
||||
|
||||
private final static ReplacementDocument EMPTY = new ReplacementDocument();
|
||||
private final ReplacementDocument current;
|
||||
@@ -346,7 +355,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
/**
|
||||
* Creates a {@link ReplacementDocument} given {@link ReplacementContributor}.
|
||||
*
|
||||
* @param contributor
|
||||
* @param contributor must not be {@literal null}.
|
||||
*/
|
||||
protected ReplacementDocument(ReplacementContributor contributor) {
|
||||
|
||||
@@ -362,7 +371,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
* Creates a {@link ReplacementDocument} given a {@literal value}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReplacementDocument}.
|
||||
*/
|
||||
public static ReplacementDocument valueOf(Object value) {
|
||||
return new ReplacementDocument(new DocumentContributor(value));
|
||||
@@ -372,7 +381,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
* Creates a {@link ReplacementDocument} given a single {@literal field} and {@link AggregationExpression}.
|
||||
*
|
||||
* @param aggregationExpression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReplacementDocument}.
|
||||
*/
|
||||
public static ReplacementDocument forExpression(String field, AggregationExpression aggregationExpression) {
|
||||
return new ReplacementDocument(new ExpressionFieldContributor(Fields.field(field), aggregationExpression));
|
||||
@@ -382,7 +391,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
* Creates a {@link ReplacementDocument} given a single {@literal field} and {@literal value}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReplacementDocument}.
|
||||
*/
|
||||
public static ReplacementDocument forSingleValue(String field, Object value) {
|
||||
return new ReplacementDocument(new ValueFieldContributor(Fields.field(field), value));
|
||||
@@ -438,7 +447,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
* {@link AggregationOperationContext}.
|
||||
*
|
||||
* @param context will never be {@literal null}.
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
Document toDocument(AggregationOperationContext context);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ReplaceWithOperation extends ReplaceRootOperation {
|
||||
* {@link Field field reference}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link ReplaceWithOperation}.
|
||||
*/
|
||||
public static ReplaceWithOperation replaceWithValueOf(Object value) {
|
||||
|
||||
|
||||
@@ -48,6 +48,15 @@ public class SampleOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document("$sample", new Document("size", this.sampleSize));
|
||||
return new Document(getOperator(), new Document("size", this.sampleSize));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$sample";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,10 @@ public class SetOperation extends DocumentEnhancingOperation {
|
||||
return new FieldAppender(getValueMap());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.DocumentEnhancingOperation#mongoOperator()
|
||||
*/
|
||||
@Override
|
||||
protected String mongoOperator() {
|
||||
return "$set";
|
||||
|
||||
@@ -34,7 +34,7 @@ public class SetOperators {
|
||||
* Take the array referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetOperatorFactory}.
|
||||
*/
|
||||
public static SetOperatorFactory arrayAsSet(String fieldReference) {
|
||||
return new SetOperatorFactory(fieldReference);
|
||||
@@ -44,7 +44,7 @@ public class SetOperators {
|
||||
* Take the array resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetOperatorFactory}.
|
||||
*/
|
||||
public static SetOperatorFactory arrayAsSet(AggregationExpression expression) {
|
||||
return new SetOperatorFactory(expression);
|
||||
@@ -87,7 +87,7 @@ public class SetOperators {
|
||||
* returns {@literal true} if they have the same distinct elements and {@literal false} otherwise.
|
||||
*
|
||||
* @param arrayReferences must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetEquals}.
|
||||
*/
|
||||
public SetEquals isEqualTo(String... arrayReferences) {
|
||||
return createSetEquals().isEqualTo(arrayReferences);
|
||||
@@ -98,7 +98,7 @@ public class SetOperators {
|
||||
* returns {@literal true} if they have the same distinct elements and {@literal false} otherwise.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetEquals}.
|
||||
*/
|
||||
public SetEquals isEqualTo(AggregationExpression... expressions) {
|
||||
return createSetEquals().isEqualTo(expressions);
|
||||
@@ -113,7 +113,7 @@ public class SetOperators {
|
||||
* arrays and returns an array that contains the elements that appear in every of those.
|
||||
*
|
||||
* @param arrayReferences must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIntersection}.
|
||||
*/
|
||||
public SetIntersection intersects(String... arrayReferences) {
|
||||
return createSetIntersection().intersects(arrayReferences);
|
||||
@@ -124,7 +124,7 @@ public class SetOperators {
|
||||
* arrays and returns an array that contains the elements that appear in every of those.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIntersection}.
|
||||
*/
|
||||
public SetIntersection intersects(AggregationExpression... expressions) {
|
||||
return createSetIntersection().intersects(expressions);
|
||||
@@ -139,7 +139,7 @@ public class SetOperators {
|
||||
* arrays and returns an array that contains the elements that appear in any of those.
|
||||
*
|
||||
* @param arrayReferences must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetUnion}.
|
||||
*/
|
||||
public SetUnion union(String... arrayReferences) {
|
||||
return createSetUnion().union(arrayReferences);
|
||||
@@ -150,7 +150,7 @@ public class SetOperators {
|
||||
* arrays and returns an array that contains the elements that appear in any of those.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetUnion}.
|
||||
*/
|
||||
public SetUnion union(AggregationExpression... expressions) {
|
||||
return createSetUnion().union(expressions);
|
||||
@@ -165,7 +165,7 @@ public class SetOperators {
|
||||
* containing the elements that do not exist in the given {@literal arrayReference}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetDifference}.
|
||||
*/
|
||||
public SetDifference differenceTo(String arrayReference) {
|
||||
return createSetDifference().differenceTo(arrayReference);
|
||||
@@ -176,7 +176,7 @@ public class SetOperators {
|
||||
* containing the elements that do not exist in the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetDifference}.
|
||||
*/
|
||||
public SetDifference differenceTo(AggregationExpression expression) {
|
||||
return createSetDifference().differenceTo(expression);
|
||||
@@ -191,7 +191,7 @@ public class SetOperators {
|
||||
* {@literal true} if it is a subset of the given {@literal arrayReference}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIsSubset}.
|
||||
*/
|
||||
public SetIsSubset isSubsetOf(String arrayReference) {
|
||||
return createSetIsSubset().isSubsetOf(arrayReference);
|
||||
@@ -202,7 +202,7 @@ public class SetOperators {
|
||||
* {@literal true} if it is a subset of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIsSubset}.
|
||||
*/
|
||||
public SetIsSubset isSubsetOf(AggregationExpression expression) {
|
||||
return createSetIsSubset().isSubsetOf(expression);
|
||||
@@ -216,7 +216,7 @@ public class SetOperators {
|
||||
* Creates new {@link AggregationExpression} that takes array of the previously mentioned field and returns
|
||||
* {@literal true} if any of the elements are {@literal true} and {@literal false} otherwise.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link AnyElementTrue}.
|
||||
*/
|
||||
public AnyElementTrue anyElementTrue() {
|
||||
return usesFieldRef() ? AnyElementTrue.arrayAsSet(fieldReference) : AnyElementTrue.arrayAsSet(expression);
|
||||
@@ -226,7 +226,7 @@ public class SetOperators {
|
||||
* Creates new {@link AggregationExpression} that tkes array of the previously mentioned field and returns
|
||||
* {@literal true} if no elements is {@literal false}.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link AllElementsTrue}.
|
||||
*/
|
||||
public AllElementsTrue allElementsTrue() {
|
||||
return usesFieldRef() ? AllElementsTrue.arrayAsSet(fieldReference) : AllElementsTrue.arrayAsSet(expression);
|
||||
@@ -257,7 +257,7 @@ public class SetOperators {
|
||||
* Create new {@link SetEquals}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetEquals}.
|
||||
*/
|
||||
public static SetEquals arrayAsSet(String arrayReference) {
|
||||
|
||||
@@ -269,7 +269,7 @@ public class SetOperators {
|
||||
* Create new {@link SetEquals}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetEquals}.
|
||||
*/
|
||||
public static SetEquals arrayAsSet(AggregationExpression expression) {
|
||||
|
||||
@@ -281,7 +281,7 @@ public class SetOperators {
|
||||
* Creates new {@link java.util.Set} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param arrayReferences must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetEquals}.
|
||||
*/
|
||||
public SetEquals isEqualTo(String... arrayReferences) {
|
||||
|
||||
@@ -293,7 +293,7 @@ public class SetOperators {
|
||||
* Creates new {@link Sum} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetEquals}.
|
||||
*/
|
||||
public SetEquals isEqualTo(AggregationExpression... expressions) {
|
||||
|
||||
@@ -305,7 +305,7 @@ public class SetOperators {
|
||||
* Creates new {@link Sum} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param array must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetEquals}.
|
||||
*/
|
||||
public SetEquals isEqualTo(Object[] array) {
|
||||
|
||||
@@ -334,7 +334,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIntersection}
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIntersection}.
|
||||
*/
|
||||
public static SetIntersection arrayAsSet(String arrayReference) {
|
||||
|
||||
@@ -346,7 +346,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIntersection}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIntersection}.
|
||||
*/
|
||||
public static SetIntersection arrayAsSet(AggregationExpression expression) {
|
||||
|
||||
@@ -358,7 +358,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIntersection} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param arrayReferences must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIntersection}.
|
||||
*/
|
||||
public SetIntersection intersects(String... arrayReferences) {
|
||||
|
||||
@@ -370,7 +370,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIntersection} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIntersection}.
|
||||
*/
|
||||
public SetIntersection intersects(AggregationExpression... expressions) {
|
||||
|
||||
@@ -399,7 +399,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetUnion}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetUnion}.
|
||||
*/
|
||||
public static SetUnion arrayAsSet(String arrayReference) {
|
||||
|
||||
@@ -411,7 +411,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetUnion}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetUnion}.
|
||||
*/
|
||||
public static SetUnion arrayAsSet(AggregationExpression expression) {
|
||||
|
||||
@@ -423,7 +423,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetUnion} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param arrayReferences must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetUnion}.
|
||||
*/
|
||||
public SetUnion union(String... arrayReferences) {
|
||||
|
||||
@@ -435,7 +435,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetUnion} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expressions must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetUnion}.
|
||||
*/
|
||||
public SetUnion union(AggregationExpression... expressions) {
|
||||
|
||||
@@ -464,7 +464,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetDifference}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetDifference}.
|
||||
*/
|
||||
public static SetDifference arrayAsSet(String arrayReference) {
|
||||
|
||||
@@ -476,7 +476,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetDifference}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetDifference}.
|
||||
*/
|
||||
public static SetDifference arrayAsSet(AggregationExpression expression) {
|
||||
|
||||
@@ -488,7 +488,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetDifference} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetDifference}.
|
||||
*/
|
||||
public SetDifference differenceTo(String arrayReference) {
|
||||
|
||||
@@ -500,7 +500,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetDifference} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetDifference}.
|
||||
*/
|
||||
public SetDifference differenceTo(AggregationExpression expression) {
|
||||
|
||||
@@ -529,7 +529,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIsSubset}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIsSubset}.
|
||||
*/
|
||||
public static SetIsSubset arrayAsSet(String arrayReference) {
|
||||
|
||||
@@ -541,7 +541,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIsSubset}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIsSubset}.
|
||||
*/
|
||||
public static SetIsSubset arrayAsSet(AggregationExpression expression) {
|
||||
|
||||
@@ -553,7 +553,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIsSubset} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIsSubset}.
|
||||
*/
|
||||
public SetIsSubset isSubsetOf(String arrayReference) {
|
||||
|
||||
@@ -565,7 +565,7 @@ public class SetOperators {
|
||||
* Creates new {@link SetIsSubset} with all previously added arguments appending the given one.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SetIsSubset}.
|
||||
*/
|
||||
public SetIsSubset isSubsetOf(AggregationExpression expression) {
|
||||
|
||||
@@ -594,7 +594,7 @@ public class SetOperators {
|
||||
* Creates new {@link AnyElementTrue}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AnyElementTrue}.
|
||||
*/
|
||||
public static AnyElementTrue arrayAsSet(String arrayReference) {
|
||||
|
||||
@@ -606,7 +606,7 @@ public class SetOperators {
|
||||
* Creates new {@link AnyElementTrue}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AnyElementTrue}.
|
||||
*/
|
||||
public static AnyElementTrue arrayAsSet(AggregationExpression expression) {
|
||||
|
||||
@@ -639,7 +639,7 @@ public class SetOperators {
|
||||
* Creates new {@link AllElementsTrue}.
|
||||
*
|
||||
* @param arrayReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AllElementsTrue}.
|
||||
*/
|
||||
public static AllElementsTrue arrayAsSet(String arrayReference) {
|
||||
|
||||
@@ -651,7 +651,7 @@ public class SetOperators {
|
||||
* Creates new {@link AllElementsTrue}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link AllElementsTrue}.
|
||||
*/
|
||||
public static AllElementsTrue arrayAsSet(AggregationExpression expression) {
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ import org.springframework.util.Assert;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/skip/">MongoDB Aggregation Framework: $skip</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/skip/">MongoDB Aggregation Framework:
|
||||
* $skip</a>
|
||||
*/
|
||||
public class SkipOperation implements AggregationOperation {
|
||||
|
||||
@@ -51,6 +52,15 @@ public class SkipOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document("$skip", skipCount);
|
||||
return new Document(getOperator(), skipCount);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$skip";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,14 +67,23 @@ public class SortByCountOperation implements AggregationOperation {
|
||||
this.groupByField = null;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
return new Document("$sortByCount", groupByExpression == null ? context.getReference(groupByField).toString()
|
||||
return new Document(getOperator(), groupByExpression == null ? context.getReference(groupByField).toString()
|
||||
: groupByExpression.toDocument(context));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$sortByCount";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ import org.springframework.util.Assert;
|
||||
* @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>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/sort/">MongoDB Aggregation Framework:
|
||||
* $sort</a>
|
||||
*/
|
||||
public class SortOperation implements AggregationOperation {
|
||||
|
||||
@@ -74,6 +75,15 @@ public class SortOperation implements AggregationOperation {
|
||||
object.put(reference.getRaw(), order.isAscending() ? 1 : -1);
|
||||
}
|
||||
|
||||
return new Document("$sort", object);
|
||||
return new Document(getOperator(), object);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$sort";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class StringOperators {
|
||||
* Take the array referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StringOperatorFactory}.
|
||||
*/
|
||||
public static StringOperatorFactory valueOf(String fieldReference) {
|
||||
return new StringOperatorFactory(fieldReference);
|
||||
@@ -45,7 +45,7 @@ public class StringOperators {
|
||||
* Take the array referenced by given {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StringOperatorFactory}.
|
||||
*/
|
||||
public static StringOperatorFactory valueOf(AggregationExpression fieldReference) {
|
||||
return new StringOperatorFactory(fieldReference);
|
||||
@@ -88,7 +88,7 @@ public class StringOperators {
|
||||
* of the referenced field to it.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public Concat concatValueOf(String fieldReference) {
|
||||
|
||||
@@ -101,7 +101,7 @@ public class StringOperators {
|
||||
* of the given {@link AggregationExpression} to it.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public Concat concatValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -114,7 +114,7 @@ public class StringOperators {
|
||||
* {@literal value} to it.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public Concat concat(String value) {
|
||||
|
||||
@@ -130,8 +130,8 @@ public class StringOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated string representation and returns a substring
|
||||
* starting at a specified index position.
|
||||
*
|
||||
* @param start
|
||||
* @return
|
||||
* @param start start index number (including)
|
||||
* @return new instance of {@link Substr}.
|
||||
*/
|
||||
public Substr substring(int start) {
|
||||
return substring(start, -1);
|
||||
@@ -141,9 +141,9 @@ public class StringOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated string representation and returns a substring
|
||||
* starting at a specified index position including the specified number of characters.
|
||||
*
|
||||
* @param start
|
||||
* @param nrOfChars
|
||||
* @return
|
||||
* @param start start index number (including)
|
||||
* @param nrOfChars number of characters.
|
||||
* @return new instance of {@link Substr}.
|
||||
*/
|
||||
public Substr substring(int start, int nrOfChars) {
|
||||
return createSubstr().substring(start, nrOfChars);
|
||||
@@ -156,7 +156,7 @@ public class StringOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that takes the associated string representation and lowers it.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link ToLower}.
|
||||
*/
|
||||
public ToLower toLower() {
|
||||
return usesFieldRef() ? ToLower.lowerValueOf(fieldReference) : ToLower.lowerValueOf(expression);
|
||||
@@ -165,7 +165,7 @@ public class StringOperators {
|
||||
/**
|
||||
* Creates new {@link AggregationExpression} that takes the associated string representation and uppers it.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link ToUpper}.
|
||||
*/
|
||||
public ToUpper toUpper() {
|
||||
return usesFieldRef() ? ToUpper.upperValueOf(fieldReference) : ToUpper.upperValueOf(expression);
|
||||
@@ -176,7 +176,7 @@ public class StringOperators {
|
||||
* case-insensitive comparison to the given {@literal value}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrCaseCmp}.
|
||||
*/
|
||||
public StrCaseCmp strCaseCmp(String value) {
|
||||
|
||||
@@ -189,7 +189,7 @@ public class StringOperators {
|
||||
* case-insensitive comparison to the referenced {@literal fieldReference}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrCaseCmp}.
|
||||
*/
|
||||
public StrCaseCmp strCaseCmpValueOf(String fieldReference) {
|
||||
|
||||
@@ -202,7 +202,7 @@ public class StringOperators {
|
||||
* case-insensitive comparison to the result of the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrCaseCmp}.
|
||||
*/
|
||||
public StrCaseCmp strCaseCmpValueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -220,7 +220,7 @@ public class StringOperators {
|
||||
* occurrence.
|
||||
*
|
||||
* @param substring must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfBytes}.
|
||||
*/
|
||||
public IndexOfBytes indexOf(String substring) {
|
||||
|
||||
@@ -234,7 +234,7 @@ public class StringOperators {
|
||||
* index (zero-based) of the first occurrence.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfBytes}.
|
||||
*/
|
||||
public IndexOfBytes indexOf(Field fieldReference) {
|
||||
|
||||
@@ -248,7 +248,7 @@ public class StringOperators {
|
||||
* byte index (zero-based) of the first occurrence.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfBytes}.
|
||||
*/
|
||||
public IndexOfBytes indexOf(AggregationExpression expression) {
|
||||
|
||||
@@ -266,7 +266,7 @@ public class StringOperators {
|
||||
* first occurrence.
|
||||
*
|
||||
* @param substring must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public IndexOfCP indexOfCP(String substring) {
|
||||
|
||||
@@ -280,7 +280,7 @@ public class StringOperators {
|
||||
* point index (zero-based) of the first occurrence.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public IndexOfCP indexOfCP(Field fieldReference) {
|
||||
|
||||
@@ -294,7 +294,7 @@ public class StringOperators {
|
||||
* code point index (zero-based) of the first occurrence.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public IndexOfCP indexOfCP(AggregationExpression expression) {
|
||||
|
||||
@@ -311,7 +311,7 @@ public class StringOperators {
|
||||
* substrings based on the given delimiter.
|
||||
*
|
||||
* @param delimiter must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public Split split(String delimiter) {
|
||||
return createSplit().split(delimiter);
|
||||
@@ -322,7 +322,7 @@ public class StringOperators {
|
||||
* substrings based on the delimiter resulting from the referenced field..
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public Split split(Field fieldReference) {
|
||||
return createSplit().split(fieldReference);
|
||||
@@ -333,7 +333,7 @@ public class StringOperators {
|
||||
* substrings based on a delimiter resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public Split split(AggregationExpression expression) {
|
||||
return createSplit().split(expression);
|
||||
@@ -347,7 +347,7 @@ public class StringOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the number of UTF-8 bytes in the associated string
|
||||
* representation.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link StrLenBytes}.
|
||||
*/
|
||||
public StrLenBytes length() {
|
||||
return usesFieldRef() ? StrLenBytes.stringLengthOf(fieldReference) : StrLenBytes.stringLengthOf(expression);
|
||||
@@ -357,7 +357,7 @@ public class StringOperators {
|
||||
* Creates new {@link AggregationExpression} that returns the number of UTF-8 code points in the associated string
|
||||
* representation.
|
||||
*
|
||||
* @return
|
||||
* @return new instance of {@link StrLenCP}.
|
||||
*/
|
||||
public StrLenCP lengthCP() {
|
||||
return usesFieldRef() ? StrLenCP.stringLengthOfCP(fieldReference) : StrLenCP.stringLengthOfCP(expression);
|
||||
@@ -368,7 +368,7 @@ public class StringOperators {
|
||||
* starting at a specified code point index position.
|
||||
*
|
||||
* @param codePointStart
|
||||
* @return
|
||||
* @return new instance of {@link SubstrCP}.
|
||||
*/
|
||||
public SubstrCP substringCP(int codePointStart) {
|
||||
return substringCP(codePointStart, -1);
|
||||
@@ -378,9 +378,9 @@ public class StringOperators {
|
||||
* Creates new {@link AggregationExpression} that takes the associated string representation and returns a substring
|
||||
* starting at a specified code point index position including the specified number of code points.
|
||||
*
|
||||
* @param codePointStart
|
||||
* @param codePointStart start point (including).
|
||||
* @param nrOfCodePoints
|
||||
* @return
|
||||
* @return new instance of {@link SubstrCP}.
|
||||
*/
|
||||
public SubstrCP substringCP(int codePointStart, int nrOfCodePoints) {
|
||||
return createSubstrCP().substringCP(codePointStart, nrOfCodePoints);
|
||||
@@ -541,7 +541,7 @@ public class StringOperators {
|
||||
* Creates new {@link Concat}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public static Concat valueOf(String fieldReference) {
|
||||
|
||||
@@ -553,7 +553,7 @@ public class StringOperators {
|
||||
* Creates new {@link Concat}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public static Concat valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -565,7 +565,7 @@ public class StringOperators {
|
||||
* Creates new {@link Concat}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public static Concat stringValue(String value) {
|
||||
|
||||
@@ -573,18 +573,36 @@ public class StringOperators {
|
||||
return new Concat(Collections.singletonList(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Concat the value of the given field.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public Concat concatValueOf(String fieldReference) {
|
||||
|
||||
Assert.notNull(fieldReference, "FieldReference must not be null!");
|
||||
return new Concat(append(Fields.field(fieldReference)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Concat the value resulting from the given {@link AggregationExpression}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public Concat concatValueOf(AggregationExpression expression) {
|
||||
|
||||
Assert.notNull(expression, "Expression must not be null!");
|
||||
return new Concat(append(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Concat the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return new instance of {@link Concat}.
|
||||
*/
|
||||
public Concat concat(String value) {
|
||||
return new Concat(append(value));
|
||||
}
|
||||
@@ -610,7 +628,7 @@ public class StringOperators {
|
||||
* Creates new {@link Substr}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Substr}.
|
||||
*/
|
||||
public static Substr valueOf(String fieldReference) {
|
||||
|
||||
@@ -622,7 +640,7 @@ public class StringOperators {
|
||||
* Creates new {@link Substr}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Substr}.
|
||||
*/
|
||||
public static Substr valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -630,10 +648,19 @@ public class StringOperators {
|
||||
return new Substr(Collections.singletonList(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param start start index (including)
|
||||
* @return new instance of {@link Substr}.
|
||||
*/
|
||||
public Substr substring(int start) {
|
||||
return substring(start, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param start start index (including)
|
||||
* @param nrOfChars
|
||||
* @return new instance of {@link Substr}.
|
||||
*/
|
||||
public Substr substring(int start, int nrOfChars) {
|
||||
return new Substr(append(Arrays.asList(start, nrOfChars)));
|
||||
}
|
||||
@@ -777,7 +804,7 @@ public class StringOperators {
|
||||
* Creates new {@link StrCaseCmp}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrCaseCmp}.
|
||||
*/
|
||||
public static StrCaseCmp valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -789,7 +816,7 @@ public class StringOperators {
|
||||
* Creates new {@link StrCaseCmp}.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrCaseCmp}.
|
||||
*/
|
||||
public static StrCaseCmp stringValue(String value) {
|
||||
|
||||
@@ -834,7 +861,7 @@ public class StringOperators {
|
||||
* Start creating a new {@link IndexOfBytes}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SubstringBuilder}.
|
||||
*/
|
||||
public static SubstringBuilder valueOf(String fieldReference) {
|
||||
|
||||
@@ -846,7 +873,7 @@ public class StringOperators {
|
||||
* Start creating a new {@link IndexOfBytes}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SubstringBuilder}.
|
||||
*/
|
||||
public static SubstringBuilder valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -858,7 +885,7 @@ public class StringOperators {
|
||||
* Optionally define the substring search start and end position.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfBytes}.
|
||||
*/
|
||||
public IndexOfBytes within(Range<Long> range) {
|
||||
return new IndexOfBytes(append(AggregationUtils.toRangeValues(range)));
|
||||
@@ -876,7 +903,7 @@ public class StringOperators {
|
||||
* Creates a new {@link IndexOfBytes} given {@literal substring}.
|
||||
*
|
||||
* @param substring must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfBytes}.
|
||||
*/
|
||||
public IndexOfBytes indexOf(String substring) {
|
||||
return new IndexOfBytes(Arrays.asList(stringExpression, substring));
|
||||
@@ -886,7 +913,7 @@ public class StringOperators {
|
||||
* Creates a new {@link IndexOfBytes} given {@link AggregationExpression} that resolves to the substring.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfBytes}.
|
||||
*/
|
||||
public IndexOfBytes indexOf(AggregationExpression expression) {
|
||||
return new IndexOfBytes(Arrays.asList(stringExpression, expression));
|
||||
@@ -896,7 +923,7 @@ public class StringOperators {
|
||||
* Creates a new {@link IndexOfBytes} given {@link Field} that resolves to the substring.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfBytes}.
|
||||
*/
|
||||
public IndexOfBytes indexOf(Field fieldReference) {
|
||||
return new IndexOfBytes(Arrays.asList(stringExpression, fieldReference));
|
||||
@@ -924,7 +951,7 @@ public class StringOperators {
|
||||
* Start creating a new {@link IndexOfCP}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public static SubstringBuilder valueOf(String fieldReference) {
|
||||
|
||||
@@ -936,7 +963,7 @@ public class StringOperators {
|
||||
* Start creating a new {@link IndexOfCP}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public static SubstringBuilder valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -948,7 +975,7 @@ public class StringOperators {
|
||||
* Optionally define the substring search start and end position.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public IndexOfCP within(Range<Long> range) {
|
||||
return new IndexOfCP(append(AggregationUtils.toRangeValues(range)));
|
||||
@@ -966,7 +993,7 @@ public class StringOperators {
|
||||
* Creates a new {@link IndexOfCP} given {@literal substring}.
|
||||
*
|
||||
* @param substring must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public IndexOfCP indexOf(String substring) {
|
||||
return new IndexOfCP(Arrays.asList(stringExpression, substring));
|
||||
@@ -976,7 +1003,7 @@ public class StringOperators {
|
||||
* Creates a new {@link IndexOfCP} given {@link AggregationExpression} that resolves to the substring.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link IndexOfCP}.
|
||||
*/
|
||||
public IndexOfCP indexOf(AggregationExpression expression) {
|
||||
return new IndexOfCP(Arrays.asList(stringExpression, expression));
|
||||
@@ -1014,7 +1041,7 @@ public class StringOperators {
|
||||
* Start creating a new {@link Split}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public static Split valueOf(String fieldReference) {
|
||||
|
||||
@@ -1026,7 +1053,7 @@ public class StringOperators {
|
||||
* Start creating a new {@link Split}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public static Split valueOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1038,7 +1065,7 @@ public class StringOperators {
|
||||
* Use given {@link String} as delimiter.
|
||||
*
|
||||
* @param delimiter must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public Split split(String delimiter) {
|
||||
|
||||
@@ -1050,7 +1077,7 @@ public class StringOperators {
|
||||
* Use value of referenced field as delimiter.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public Split split(Field fieldReference) {
|
||||
|
||||
@@ -1062,7 +1089,7 @@ public class StringOperators {
|
||||
* Use value resulting from {@link AggregationExpression} as delimiter.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link Split}.
|
||||
*/
|
||||
public Split split(AggregationExpression expression) {
|
||||
|
||||
@@ -1091,7 +1118,7 @@ public class StringOperators {
|
||||
* Creates new {@link StrLenBytes}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrLenBytes}.
|
||||
*/
|
||||
public static StrLenBytes stringLengthOf(String fieldReference) {
|
||||
return new StrLenBytes(Fields.field(fieldReference));
|
||||
@@ -1101,7 +1128,7 @@ public class StringOperators {
|
||||
* Creates new {@link StrLenBytes}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrLenBytes}.
|
||||
*/
|
||||
public static StrLenBytes stringLengthOf(AggregationExpression expression) {
|
||||
|
||||
@@ -1130,7 +1157,7 @@ public class StringOperators {
|
||||
* Creates new {@link StrLenCP}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrLenCP}.
|
||||
*/
|
||||
public static StrLenCP stringLengthOfCP(String fieldReference) {
|
||||
return new StrLenCP(Fields.field(fieldReference));
|
||||
@@ -1140,7 +1167,7 @@ public class StringOperators {
|
||||
* Creates new {@link StrLenCP}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link StrLenCP}.
|
||||
*/
|
||||
public static StrLenCP stringLengthOfCP(AggregationExpression expression) {
|
||||
|
||||
@@ -1169,7 +1196,7 @@ public class StringOperators {
|
||||
* Creates new {@link SubstrCP}.
|
||||
*
|
||||
* @param fieldReference must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SubstrCP}.
|
||||
*/
|
||||
public static SubstrCP valueOf(String fieldReference) {
|
||||
|
||||
@@ -1181,7 +1208,7 @@ public class StringOperators {
|
||||
* Creates new {@link SubstrCP}.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link SubstrCP}.
|
||||
*/
|
||||
public static SubstrCP valueOf(AggregationExpression expression) {
|
||||
|
||||
|
||||
@@ -81,6 +81,6 @@ public class TypedAggregation<I> extends Aggregation {
|
||||
public TypedAggregation<I> withOptions(AggregationOptions options) {
|
||||
|
||||
Assert.notNull(options, "AggregationOptions must not be null.");
|
||||
return new TypedAggregation<I>(inputType, operations, options);
|
||||
return new TypedAggregation<I>(inputType, pipeline.getOperations(), options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UnsetOperation implements InheritsFieldsAggregationOperation {
|
||||
|
||||
/**
|
||||
* Create new instance of {@link UnsetOperation}.
|
||||
*
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
*/
|
||||
public UnsetOperation(Collection<Object> fields) {
|
||||
@@ -117,13 +117,22 @@ public class UnsetOperation implements InheritsFieldsAggregationOperation {
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
if (fields.size() == 1) {
|
||||
return new Document("$unset", computeFieldName(fields.iterator().next(), context));
|
||||
return new Document(getOperator(), computeFieldName(fields.iterator().next(), context));
|
||||
}
|
||||
|
||||
return new Document("$unset",
|
||||
return new Document(getOperator(),
|
||||
fields.stream().map(it -> computeFieldName(it, context)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$unset";
|
||||
}
|
||||
|
||||
private Object computeFieldName(Object field, AggregationOperationContext context) {
|
||||
|
||||
if (field instanceof Field) {
|
||||
|
||||
@@ -31,7 +31,8 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/">MongoDB Aggregation Framework: $unwind</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/">MongoDB Aggregation Framework:
|
||||
* $unwind</a>
|
||||
*/
|
||||
public class UnwindOperation
|
||||
implements AggregationOperation, FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation {
|
||||
@@ -94,7 +95,7 @@ public class UnwindOperation
|
||||
String path = context.getReference(field).toString();
|
||||
|
||||
if (!preserveNullAndEmptyArrays && arrayIndex == null) {
|
||||
return new Document("$unwind", path);
|
||||
return new Document(getOperator(), path);
|
||||
}
|
||||
|
||||
Document unwindArgs = new Document();
|
||||
@@ -104,7 +105,16 @@ public class UnwindOperation
|
||||
}
|
||||
unwindArgs.put("preserveNullAndEmptyArrays", preserveNullAndEmptyArrays);
|
||||
|
||||
return new Document("$unwind", unwindArgs);
|
||||
return new Document(getOperator(), unwindArgs);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return "$unwind";
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class AbstractMongoConverter implements MongoConverter, Initiali
|
||||
/**
|
||||
* Registers {@link EntityInstantiators} to customize entity instantiation.
|
||||
*
|
||||
* @param instantiators
|
||||
* @param instantiators can be {@literal null}. Uses default {@link EntityInstantiators} if so.
|
||||
*/
|
||||
public void setInstantiators(@Nullable EntityInstantiators instantiators) {
|
||||
this.instantiators = instantiators == null ? new EntityInstantiators() : instantiators;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CustomConversions extends MongoCustomConversions {
|
||||
/**
|
||||
* Creates a new {@link CustomConversions} instance registering the given converters.
|
||||
*
|
||||
* @param converters
|
||||
* @param converters must not be {@literal null}.
|
||||
*/
|
||||
public CustomConversions(List<?> converters) {
|
||||
super(converters);
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface DbRefResolver {
|
||||
* @param property will never be {@literal null}.
|
||||
* @param dbref the {@link DBRef} to resolve.
|
||||
* @param callback will never be {@literal null}.
|
||||
* @return
|
||||
* @return can be {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
Object resolveDbRef(MongoPersistentProperty property, @Nullable DBRef dbref, DbRefResolverCallback callback,
|
||||
@@ -58,7 +58,7 @@ public interface DbRefResolver {
|
||||
* @param annotation will never be {@literal null}.
|
||||
* @param entity will never be {@literal null}.
|
||||
* @param id will never be {@literal null}.
|
||||
* @return
|
||||
* @return new instance of {@link DBRef}.
|
||||
*/
|
||||
default DBRef createDbRef(@Nullable org.springframework.data.mongodb.core.mapping.DBRef annotation,
|
||||
MongoPersistentEntity<?> entity, Object id) {
|
||||
@@ -74,7 +74,7 @@ public interface DbRefResolver {
|
||||
* Actually loads the {@link DBRef} from the datasource.
|
||||
*
|
||||
* @param dbRef must not be {@literal null}.
|
||||
* @return
|
||||
* @return can be {@literal null}.
|
||||
* @since 1.7
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user