Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ebc632130 | ||
|
|
95c1483bb1 | ||
|
|
2486f162ed | ||
|
|
95a05a24e1 | ||
|
|
47f8e0599e | ||
|
|
15ebf4c37c | ||
|
|
da03eb09bf | ||
|
|
69201faf96 | ||
|
|
49081ceced | ||
|
|
f54ca2394f | ||
|
|
2703573d87 | ||
|
|
dee4f3b859 | ||
|
|
34d7a3d654 | ||
|
|
2f3e134680 | ||
|
|
b126165aeb | ||
|
|
4df2c05354 | ||
|
|
c95cb66f99 | ||
|
|
acfc20b73b | ||
|
|
ae21d277c8 | ||
|
|
faa29cb207 |
4
.mvn/wrapper/maven-wrapper.properties
vendored
4
.mvn/wrapper/maven-wrapper.properties
vendored
@@ -1,2 +1,2 @@
|
||||
#Fri Jun 03 09:32:40 CEST 2022
|
||||
distributionUrl=https\://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
|
||||
#Mon Feb 20 11:59:26 CET 2023
|
||||
distributionUrl=https\://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Java versions
|
||||
java.main.tag=17.0.5_8-jdk-focal
|
||||
java.main.tag=17.0.6_10-jdk-focal
|
||||
|
||||
# Docker container images - standard
|
||||
docker.java.main.image=harbor-repo.vmware.com/dockerhub-proxy-cache/library/eclipse-temurin:${java.main.tag}
|
||||
|
||||
# Supported versions of MongoDB
|
||||
docker.mongodb.4.4.version=4.4.17
|
||||
docker.mongodb.5.0.version=5.0.13
|
||||
docker.mongodb.6.0.version=6.0.2
|
||||
docker.mongodb.4.4.version=4.4.18
|
||||
docker.mongodb.5.0.version=5.0.14
|
||||
docker.mongodb.6.0.version=6.0.4
|
||||
|
||||
# Supported versions of Redis
|
||||
docker.redis.6.version=6.2.6
|
||||
docker.redis.6.version=6.2.10
|
||||
|
||||
# Supported versions of Cassandra
|
||||
docker.cassandra.3.version=3.11.14
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<version>4.0.3</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>3.0.1</version>
|
||||
<version>3.0.3</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
@@ -26,7 +26,7 @@
|
||||
<properties>
|
||||
<project.type>multi</project.type>
|
||||
<dist.id>spring-data-mongodb</dist.id>
|
||||
<springdata.commons>3.0.1</springdata.commons>
|
||||
<springdata.commons>3.0.3</springdata.commons>
|
||||
<mongo>4.8.2</mongo>
|
||||
<mongo.reactivestreams>${mongo}</mongo.reactivestreams>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<version>4.0.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<version>4.0.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<version>4.0.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -62,13 +62,14 @@ class MongoRuntimeHints implements RuntimeHintsRegistrar {
|
||||
TypeReference.of(ReactiveAfterSaveCallback.class)),
|
||||
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void registerTransactionProxyHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
|
||||
if (MongoAotPredicates.isSyncClientPresent(classLoader) && ClassUtils.isPresent("org.springframework.aop.SpringProxy", classLoader)) {
|
||||
if (MongoAotPredicates.isSyncClientPresent(classLoader)
|
||||
&& ClassUtils.isPresent("org.springframework.aop.SpringProxy", classLoader)) {
|
||||
|
||||
hints.proxies().registerJdkProxy(TypeReference.of("com.mongodb.client.MongoDatabase"),
|
||||
TypeReference.of("org.springframework.aop.SpringProxy"),
|
||||
@@ -78,4 +79,5 @@ class MongoRuntimeHints implements RuntimeHintsRegistrar {
|
||||
TypeReference.of("org.springframework.core.DecoratingProxy"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -283,6 +283,10 @@ class EntityOperations {
|
||||
* @see EntityProjectionIntrospector#introspect(Class, Class)
|
||||
*/
|
||||
public <M, D> EntityProjection<M, D> introspectProjection(Class<M> resultType, Class<D> entityType) {
|
||||
|
||||
if (!queryMapper.getMappingContext().hasPersistentEntityFor(entityType)) {
|
||||
return (EntityProjection) EntityProjection.nonProjecting(resultType);
|
||||
}
|
||||
return introspector.introspect(resultType, entityType);
|
||||
}
|
||||
|
||||
|
||||
@@ -159,6 +159,7 @@ import com.mongodb.client.result.UpdateResult;
|
||||
* @author Yadhukrishna S Pai
|
||||
* @author Anton Barkan
|
||||
* @author Bartłomiej Mazur
|
||||
* @author Michael Krog
|
||||
*/
|
||||
public class MongoTemplate implements MongoOperations, ApplicationContextAware, IndexOperationsProvider {
|
||||
|
||||
@@ -2357,8 +2358,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
* @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.
|
||||
* @return the {@link List} of converted objects.
|
||||
* @return the converted object or {@literal null} if none exists.
|
||||
*/
|
||||
@Nullable
|
||||
protected <T> T doFindOne(String collectionName, Document query, Document fields, Class<T> entityClass) {
|
||||
return doFindOne(collectionName, query, fields, CursorPreparer.NO_OP_PREPARER, entityClass);
|
||||
}
|
||||
@@ -2372,9 +2374,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @param preparer the preparer used to modify the cursor on execution.
|
||||
* @return the {@link List} of converted objects.
|
||||
* @return the converted object or {@literal null} if none exists.
|
||||
* @since 2.2
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
protected <T> T doFindOne(String collectionName, Document query, Document fields, CursorPreparer preparer,
|
||||
Class<T> entityClass) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.util.Assert;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Yadhukrishna S Pai
|
||||
* @author Soumya Prakash Behera
|
||||
* @see Aggregation#withOptions(AggregationOptions)
|
||||
* @see TypedAggregation#withOptions(AggregationOptions)
|
||||
* @since 1.6
|
||||
@@ -65,7 +66,7 @@ public class AggregationOptions {
|
||||
* @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 to the aggregation.
|
||||
*/
|
||||
public AggregationOptions(boolean allowDiskUse, boolean explain, Document cursor) {
|
||||
public AggregationOptions(boolean allowDiskUse, boolean explain, @Nullable Document cursor) {
|
||||
this(allowDiskUse, explain, cursor, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,15 @@ package org.springframework.data.mongodb.repository.aot;
|
||||
|
||||
import static org.springframework.data.mongodb.aot.MongoAotPredicates.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.mongodb.aot.MongoAotPredicates;
|
||||
import org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor;
|
||||
import org.springframework.data.mongodb.repository.support.ReactiveQuerydslMongoPredicateExecutor;
|
||||
import org.springframework.data.querydsl.QuerydslUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -37,25 +39,42 @@ class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
|
||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
|
||||
hints.reflection().registerTypes(
|
||||
Arrays.asList(TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleMongoRepository")),
|
||||
List.of(TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleMongoRepository")),
|
||||
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
|
||||
if (isReactorPresent()) {
|
||||
|
||||
hints.reflection().registerTypes(
|
||||
Arrays.asList(
|
||||
List.of(
|
||||
TypeReference.of("org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository")),
|
||||
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
}
|
||||
|
||||
if (QuerydslUtils.QUERY_DSL_PRESENT) {
|
||||
registerQuerydslHints(hints, classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
hints.reflection().registerType(
|
||||
TypeReference.of("org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.onReachableType(QuerydslPredicateExecutor.class));
|
||||
/**
|
||||
* Register hints for Querydsl integration.
|
||||
*
|
||||
* @param hints must not be {@literal null}.
|
||||
* @param classLoader can be {@literal null}.
|
||||
* @since 4.0.2
|
||||
*/
|
||||
private static void registerQuerydslHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
|
||||
if (isReactorPresent()) {
|
||||
hints.reflection().registerType(ReactiveQuerydslMongoPredicateExecutor.class,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
|
||||
}
|
||||
|
||||
if (MongoAotPredicates.isSyncClientPresent(classLoader)) {
|
||||
hints.reflection().registerType(QuerydslMongoPredicateExecutor.class, MemberCategory.INVOKE_PUBLIC_METHODS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ import org.bson.codecs.DocumentCodec;
|
||||
import org.bson.json.JsonMode;
|
||||
import org.bson.json.JsonWriterSettings;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.querydsl.core.support.QueryMixin;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
@@ -49,11 +47,10 @@ abstract class SpringDataMongodbQuerySupport<Q extends SpringDataMongodbQuerySup
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
SpringDataMongodbQuerySupport(MongodbDocumentSerializer serializer) {
|
||||
|
||||
super(serializer);
|
||||
this.serializer = serializer;
|
||||
|
||||
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(this);
|
||||
this.superQueryMixin = (QueryMixin<Q>) fieldAccessor.getPropertyValue("queryMixin");
|
||||
this.superQueryMixin = super.getQueryMixin();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2022 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.classloading;
|
||||
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.instrument.classloading.ShadowingClassLoader;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* is intended for testing code that depends on the presence/absence of certain classes. Classes can be:
|
||||
* <ul>
|
||||
* <li>shadowed: reloaded by this classloader no matter if they are loaded already by the SystemClassLoader</li>
|
||||
* <li>hidden: not loaded by this classloader no matter if they are loaded already by the SystemClassLoader. Trying to
|
||||
* load these classes results in a {@link ClassNotFoundException}</li>
|
||||
* <li>all other classes get loaded by the SystemClassLoader</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class HidingClassLoader extends ShadowingClassLoader {
|
||||
|
||||
private final Collection<String> hidden;
|
||||
|
||||
public HidingClassLoader(String... hidden) {
|
||||
this(Arrays.asList(hidden));
|
||||
}
|
||||
|
||||
public HidingClassLoader(Collection<String> hidden) {
|
||||
|
||||
super(URLClassLoader.getSystemClassLoader(), false);
|
||||
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link HidingClassLoader} with the packages of the given classes hidden.
|
||||
*
|
||||
* @param packages must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static HidingClassLoader hide(Class<?>... packages) {
|
||||
|
||||
Assert.notNull(packages, "Packages must not be null");
|
||||
|
||||
return new HidingClassLoader(Arrays.stream(packages)//
|
||||
.map(it -> it.getPackage().getName())//
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public static HidingClassLoader hideTypes(Class<?>... types) {
|
||||
|
||||
Assert.notNull(types, "Types must not be null!");
|
||||
|
||||
return new HidingClassLoader(Arrays.stream(types)//
|
||||
.map(it -> it.getName())//
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
||||
|
||||
Class<?> loaded = super.loadClass(name);
|
||||
checkIfHidden(loaded);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleForShadowing(String className) {
|
||||
return isExcluded(className);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
|
||||
Class<?> loaded = super.findClass(name);
|
||||
checkIfHidden(loaded);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
private void checkIfHidden(Class<?> type) throws ClassNotFoundException {
|
||||
|
||||
if (hidden.stream().anyMatch(it -> type.getName().startsWith(it))) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2526,6 +2526,26 @@ public class MongoTemplateTests {
|
||||
assertThat(projection.getName()).isEqualTo("Walter");
|
||||
}
|
||||
|
||||
@Test // GH-4300
|
||||
public void findAndReplaceShouldAllowNativeDomainTypesAndReturnAProjection() {
|
||||
|
||||
MyPerson person = new MyPerson("Walter");
|
||||
person.address = new Address("TX", "Austin");
|
||||
template.save(person);
|
||||
|
||||
MyPerson previous = template.findAndReplace(query(where("name").is("Walter")),
|
||||
new org.bson.Document("name", "Heisenberg"), FindAndReplaceOptions.options(), org.bson.Document.class,
|
||||
"myPerson", MyPerson.class);
|
||||
|
||||
assertThat(previous).isNotNull();
|
||||
assertThat(previous.getAddress()).isEqualTo(person.address);
|
||||
|
||||
org.bson.Document loaded = template.execute(MyPerson.class, collection -> {
|
||||
return collection.find(new org.bson.Document("name", "Heisenberg")).first();
|
||||
});
|
||||
assertThat(loaded.get("_id")).isEqualTo(new ObjectId(person.id));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-407
|
||||
public void updatesShouldRetainTypeInformationEvenForCollections() {
|
||||
|
||||
|
||||
@@ -2312,6 +2312,17 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
.isEqualTo(new com.mongodb.client.model.TimeSeriesOptions("time_stamp").toString());
|
||||
}
|
||||
|
||||
@Test // GH-4300
|
||||
void findAndReplaceAllowsDocumentSourceType() {
|
||||
|
||||
template.findAndReplace(new Query(), new Document("spring", "data"), FindAndReplaceOptions.options().upsert(),
|
||||
Document.class, "coll-1", Person.class);
|
||||
|
||||
verify(db).getCollection(eq("coll-1"), eq(Document.class));
|
||||
verify(collection).findOneAndReplace((Bson) any(Bson.class), eq(new Document("spring", "data")),
|
||||
any(FindOneAndReplaceOptions.class));
|
||||
}
|
||||
|
||||
class AutogenerateableId {
|
||||
|
||||
@Id BigInteger id;
|
||||
|
||||
@@ -729,6 +729,32 @@ public class ReactiveMongoTemplateTests {
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // GH-4300
|
||||
public void findAndReplaceShouldAllowNativeDomainTypesAndReturnAProjection() {
|
||||
|
||||
MongoTemplateTests.MyPerson person = new MongoTemplateTests.MyPerson("Walter");
|
||||
person.address = new Address("TX", "Austin");
|
||||
template.save(person) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
template
|
||||
.findAndReplace(query(where("name").is("Walter")), new org.bson.Document("name", "Heisenberg"),
|
||||
FindAndReplaceOptions.options(), org.bson.Document.class, "myPerson", MongoTemplateTests.MyPerson.class)
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(actual -> {
|
||||
assertThat(actual.getAddress()).isEqualTo(person.address);
|
||||
}).verifyComplete();
|
||||
|
||||
template.execute(MongoTemplateTests.MyPerson.class, collection -> {
|
||||
return collection.find(new org.bson.Document("name", "Heisenberg")).first();
|
||||
}).as(StepVerifier::create) //
|
||||
.consumeNextWith(loaded -> {
|
||||
assertThat(loaded.get("_id")).isEqualTo(new ObjectId(person.id));
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1827
|
||||
void findAndReplaceShouldReplaceObjectReturingNew() {
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2023 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.repository.aot;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.data.mongodb.classloading.HidingClassLoader;
|
||||
import org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor;
|
||||
import org.springframework.data.mongodb.repository.support.ReactiveQuerydslMongoPredicateExecutor;
|
||||
|
||||
import com.mongodb.client.MongoClient;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RepositoryRuntimeHints}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class RepositoryRuntimeHintsUnitTests {
|
||||
|
||||
@Test // GH-4244
|
||||
void registersTypesForQuerydslIntegration() {
|
||||
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new RepositoryRuntimeHints().registerHints(runtimeHints, null);
|
||||
|
||||
assertThat(runtimeHints).matches(RuntimeHintsPredicates.reflection().onType(QuerydslMongoPredicateExecutor.class)
|
||||
.and(RuntimeHintsPredicates.reflection().onType(ReactiveQuerydslMongoPredicateExecutor.class)));
|
||||
}
|
||||
|
||||
@Test // GH-4244
|
||||
void onlyRegistersReactiveTypesForQuerydslIntegrationWhenNoSyncClientPresent() {
|
||||
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new RepositoryRuntimeHints().registerHints(runtimeHints, HidingClassLoader.hide(MongoClient.class));
|
||||
|
||||
assertThat(runtimeHints).matches(RuntimeHintsPredicates.reflection().onType(QuerydslMongoPredicateExecutor.class)
|
||||
.negate().and(RuntimeHintsPredicates.reflection().onType(ReactiveQuerydslMongoPredicateExecutor.class)));
|
||||
}
|
||||
|
||||
@Test // GH-4244
|
||||
@Disabled("TODO: ReactiveWrappers does not support ClassLoader")
|
||||
void doesNotRegistersReactiveTypesForQuerydslIntegrationWhenReactorNotPresent() {
|
||||
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new RepositoryRuntimeHints().registerHints(runtimeHints, new HidingClassLoader("reactor.core"));
|
||||
|
||||
assertThat(runtimeHints).matches(RuntimeHintsPredicates.reflection().onType(QuerydslMongoPredicateExecutor.class)
|
||||
.and(RuntimeHintsPredicates.reflection().onType(ReactiveQuerydslMongoPredicateExecutor.class).negate()));
|
||||
}
|
||||
}
|
||||
@@ -437,7 +437,7 @@ class Entity {
|
||||
// referenced object
|
||||
{
|
||||
"_id" : "9a48e32",
|
||||
"firsntame" : "Josh", <2>
|
||||
"firstname" : "Josh", <2>
|
||||
"lastname" : "Long", <2>
|
||||
}
|
||||
----
|
||||
|
||||
@@ -9,7 +9,7 @@ The definition may contain simple placeholders like `?0` as well as https://docs
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends CrudReppsitory<Person, String> {
|
||||
public interface PersonRepository extends CrudRepository<Person, String> {
|
||||
|
||||
@Aggregation("{ $group: { _id : $lastname, names : { $addToSet : $firstname } } }")
|
||||
List<PersonAggregate> groupByLastnameAndFirstnames(); <1>
|
||||
@@ -82,7 +82,7 @@ Use the `@Meta` annotation to set those options via `maxExecutionTimeMs`, `comme
|
||||
|
||||
[source,java]
|
||||
----
|
||||
interface PersonRepository extends CrudReppsitory<Person, String> {
|
||||
interface PersonRepository extends CrudRepository<Person, String> {
|
||||
|
||||
@Meta(allowDiskUse = true)
|
||||
@Aggregation("{ $group: { _id : $lastname, names : { $addToSet : $firstname } } }")
|
||||
@@ -99,7 +99,7 @@ Or use `@Meta` to create your own annotation as shown in the sample below.
|
||||
@Meta(allowDiskUse = true)
|
||||
@interface AllowDiskUse { }
|
||||
|
||||
interface PersonRepository extends CrudReppsitory<Person, String> {
|
||||
interface PersonRepository extends CrudRepository<Person, String> {
|
||||
|
||||
@AllowDiskUse
|
||||
@Aggregation("{ $group: { _id : $lastname, names : { $addToSet : $firstname } } }")
|
||||
|
||||
@@ -2198,7 +2198,7 @@ directly there are several methods for those options.
|
||||
----
|
||||
Query query = query(where("firstname").is("luke"))
|
||||
.comment("find luke") <1>
|
||||
.batchSize(100) <2>
|
||||
.cursorBatchSize(100) <2>
|
||||
----
|
||||
<1> The comment propagated to the MongoDB profile log.
|
||||
<2> The number of documents to return in each response batch.
|
||||
@@ -2209,7 +2209,7 @@ On the repository level the `@Meta` annotation provides means to add query optio
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@Meta(comment = "find luke", batchSize = 100, flags = { SLAVE_OK })
|
||||
@Meta(comment = "find luke", cursorBatchSize = 100, flags = { SLAVE_OK })
|
||||
List<Person> findByFirstname(String firstname);
|
||||
----
|
||||
====
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Spring Data MongoDB 4.0.1 (2022.0.1)
|
||||
Spring Data MongoDB 4.0.3 (2022.0.3)
|
||||
Copyright (c) [2010-2019] Pivotal Software, Inc.
|
||||
|
||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||
@@ -40,6 +40,8 @@ conditions of the subcomponent's license, as noted in the LICENSE file.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user