Compare commits

..

16 Commits

Author SHA1 Message Date
Mark Paluch
5d3a3e1fe2 Release version 3.2 GA (2021.0.0).
See #3616
2021-04-14 14:18:47 +02:00
Mark Paluch
e71ec4fc41 Prepare 3.2 GA (2021.0.0).
See #3616
2021-04-14 14:18:21 +02:00
Mark Paluch
f065e295e9 Updated changelog.
See #3616
2021-04-14 14:18:16 +02:00
Mark Paluch
d23e1b3247 Updated changelog.
See #3617
2021-04-14 11:43:30 +02:00
Mark Paluch
a1e8e6f3bc Updated changelog.
See #3597
2021-04-14 11:17:39 +02:00
Mark Paluch
e4030197e8 Polishing.
Fix nullability annotations for isEqual(…) parameters. Fix generics. Reformat code.

Add tests.

See #3414
Original pull request: #3615.
2021-04-13 09:39:33 +02:00
Clement Petit
2885c35511 Handle nested Pattern and Document in Criteria.equals(…).
Closes #3414
Original pull request: #3615.
2021-04-13 09:39:16 +02:00
Mark Paluch
a2a33390b6 Polishing.
Use ObjectUtils for empty check.

See #3623
Original pull request: #3625.
2021-04-13 09:09:33 +02:00
Christoph Strobl
bf606bcc47 Fix NPE in declarative aggregation execution.
This commit fixes an issue where using a simple return type leads to NPE when the actual aggregation result does not contain any values.

Closes: #3623
Original pull request: #3625.
2021-04-13 09:09:29 +02:00
Christoph Strobl
e91809957d Upgrade to MongoDB Java Drivers 4.2.3
Closes: #3621
2021-04-09 12:49:47 +02:00
Christoph Strobl
313a7b86e8 Fix query mapping resolution of properties using underscore within field name.
Closes: #3601
Original pull request: #3607.
2021-04-09 12:26:01 +02:00
Mark Paluch
9d7473487f Upgrade to MongoDB 4.4 on CI.
Closes #3612.
2021-04-08 17:13:49 +02:00
Mark Paluch
2734a7d8d4 Guard tests against unsupported MongoDB versions used for tests.
See #3583
2021-04-08 16:13:13 +02:00
Mark Paluch
0f85808531 Updated changelog.
See #3598
2021-03-31 18:30:43 +02:00
Mark Paluch
7c0afda0a6 After release cleanups.
See #3595
2021-03-31 17:24:05 +02:00
Mark Paluch
dbe17249b7 Prepare next development iteration.
See #3595
2021-03-31 17:24:03 +02:00
19 changed files with 293 additions and 39 deletions

24
Jenkinsfile vendored
View File

@@ -23,39 +23,39 @@ pipeline {
steps {
script {
def image = docker.build("springci/spring-data-openjdk8-with-mongodb-4.0", "ci/openjdk8-mongodb-4.0/")
def image = docker.build("springci/spring-data-openjdk8-with-mongodb-4.0.23", "ci/openjdk8-mongodb-4.0/")
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
image.push()
}
}
}
}
stage('Publish JDK 8 + MongoDB 4.2') {
stage('Publish JDK 8 + MongoDB 4.4') {
when {
changeset "ci/openjdk8-mongodb-4.2/**"
changeset "ci/openjdk8-mongodb-4.4/**"
}
agent { label 'data' }
options { timeout(time: 30, unit: 'MINUTES') }
steps {
script {
def image = docker.build("springci/spring-data-openjdk8-with-mongodb-4.2.0", "ci/openjdk8-mongodb-4.2/")
def image = docker.build("springci/spring-data-openjdk8-with-mongodb-4.4.4", "ci/openjdk8-mongodb-4.4/")
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
image.push()
}
}
}
}
stage('Publish JDK 15 + MongoDB 4.2') {
stage('Publish JDK 15 + MongoDB 4.4') {
when {
changeset "ci/openjdk15-mongodb-4.2/**"
changeset "ci/openjdk15-mongodb-4.4/**"
}
agent { label 'data' }
options { timeout(time: 30, unit: 'MINUTES') }
steps {
script {
def image = docker.build("springci/spring-data-openjdk15-with-mongodb-4.2.0", "ci/openjdk15-mongodb-4.2/")
def image = docker.build("springci/spring-data-openjdk15-with-mongodb-4.4.4", "ci/openjdk15-mongodb-4.4/")
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
image.push()
}
@@ -79,7 +79,7 @@ pipeline {
steps {
script {
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
docker.image('springci/spring-data-openjdk8-with-mongodb-4.2.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
docker.image('springci/spring-data-openjdk8-with-mongodb-4.0.23:latest').inside('-v $HOME:/tmp/jenkins-home') {
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
sh 'sleep 10'
@@ -108,7 +108,7 @@ pipeline {
steps {
script {
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
docker.image('springci/spring-data-openjdk8-with-mongodb-4.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
docker.image('springci/spring-data-openjdk8-with-mongodb-4.0.23:latest').inside('-v $HOME:/tmp/jenkins-home') {
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
sh 'sleep 10'
@@ -121,7 +121,7 @@ pipeline {
}
}
stage("test: mongodb 4.2 (jdk8)") {
stage("test: mongodb 4.4 (jdk8)") {
agent {
label 'data'
}
@@ -129,7 +129,7 @@ pipeline {
steps {
script {
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
docker.image('springci/spring-data-openjdk8-with-mongodb-4.2.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
docker.image('springci/spring-data-openjdk8-with-mongodb-4.4.4:latest').inside('-v $HOME:/tmp/jenkins-home') {
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
sh 'sleep 10'
@@ -150,7 +150,7 @@ pipeline {
steps {
script {
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
docker.image('springci/spring-data-openjdk15-with-mongodb-4.2.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
docker.image('springci/spring-data-openjdk15-with-mongodb-4.4.4:latest').inside('-v $HOME:/tmp/jenkins-home') {
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
sh 'sleep 10'

View File

@@ -5,11 +5,11 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN set -eux; \
apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2 ; \
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv e162f504a20cdf15827f718d4b7c549a058f8b6b ; \
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list; \
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 656408E390CFB1F5 ; \
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list; \
echo ${TZ} > /etc/timezone;
RUN apt-get update ; \
apt-get install -y mongodb-org=4.2.0 mongodb-org-server=4.2.0 mongodb-org-shell=4.2.0 mongodb-org-mongos=4.2.0 mongodb-org-tools=4.2.0 ; \
apt-get install -y mongodb-org=4.4.4 mongodb-org-server=4.4.4 mongodb-org-shell=4.4.4 mongodb-org-mongos=4.4.4 mongodb-org-tools=4.4.4 ; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*;

View File

@@ -5,11 +5,11 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN set -eux; \
apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2 ; \
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv e162f504a20cdf15827f718d4b7c549a058f8b6b ; \
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list; \
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 656408E390CFB1F5 ; \
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list; \
echo ${TZ} > /etc/timezone;
RUN apt-get update ; \
apt-get install -y mongodb-org=4.2.0 mongodb-org-server=4.2.0 mongodb-org-shell=4.2.0 mongodb-org-mongos=4.2.0 mongodb-org-tools=4.2.0 ; \
apt-get install -y mongodb-org=4.4.4 mongodb-org-server=4.4.4 mongodb-org-shell=4.4.4 mongodb-org-mongos=4.4.4 mongodb-org-tools=4.4.4 ; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*;

View File

@@ -10,6 +10,6 @@ RUN RUN set -eux; \
echo ${TZ} > /etc/timezone;
RUN apt-get update ; \
apt-get install -y mongodb-org=4.0.14 mongodb-org-server=4.0.14 mongodb-org-shell=4.0.14 mongodb-org-mongos=4.0.14 mongodb-org-tools=4.0.14 ; \
apt-get install -y mongodb-org=4.0.23 mongodb-org-server=4.0.23 mongodb-org-shell=4.0.23 mongodb-org-mongos=4.0.23 mongodb-org-tools=4.0.23 ; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*;

View File

@@ -5,11 +5,13 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN set -eux; \
apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2 ; \
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv e162f504a20cdf15827f718d4b7c549a058f8b6b ; \
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list; \
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 656408E390CFB1F5 ; \
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list; \
echo ${TZ} > /etc/timezone;
RUN apt-get update ; \
apt-get install -y mongodb-org=4.2.0 mongodb-org-server=4.2.0 mongodb-org-shell=4.2.0 mongodb-org-mongos=4.2.0 mongodb-org-tools=4.2.0 ; \
ln -T /bin/true /usr/bin/systemctl ; \
apt-get install -y mongodb-org=4.4.4 mongodb-org-server=4.4.4 mongodb-org-shell=4.4.4 mongodb-org-mongos=4.4.4 mongodb-org-tools=4.4.4 ; \
rm /usr/bin/systemctl ; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*;

12
pom.xml
View File

@@ -5,7 +5,7 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-RC1</version>
<version>3.2.0</version>
<packaging>pom</packaging>
<name>Spring Data MongoDB</name>
@@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>2.5.0-RC1</version>
<version>2.5.0</version>
</parent>
<modules>
@@ -26,8 +26,8 @@
<properties>
<project.type>multi</project.type>
<dist.id>spring-data-mongodb</dist.id>
<springdata.commons>2.5.0-RC1</springdata.commons>
<mongo>4.2.2</mongo>
<springdata.commons>2.5.0</springdata.commons>
<mongo>4.2.3</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>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-RC1</version>
<version>3.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-RC1</version>
<version>3.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-RC1</version>
<version>3.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@@ -1170,7 +1170,7 @@ public class QueryMapper {
if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) {
return mappingContext
.getPersistentPropertyPath(PropertyPath.from(sourceProperty.getName(), entity.getTypeInformation()));
.getPersistentPropertyPath(PropertyPath.from(Pattern.quote(sourceProperty.getName()), entity.getTypeInformation()));
}
PropertyPath path = forName(rawPath);
@@ -1229,6 +1229,13 @@ public class QueryMapper {
return forName(path.substring(0, path.length() - 3) + "id");
}
// Ok give it another try quoting
try {
return PropertyPath.from(Pattern.quote(path), entity.getTypeInformation());
} catch (PropertyReferenceException | InvalidPersistentPropertyPath ex) {
}
return null;
}
}

View File

@@ -20,8 +20,10 @@ import static org.springframework.util.ObjectUtils.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -59,6 +61,7 @@ import com.mongodb.BasicDBList;
* @author Mark Paluch
* @author Andreas Zink
* @author Ziemowit Stolarczyk
* @author Clément Petit
*/
public class Criteria implements CriteriaDefinition {
@@ -970,15 +973,15 @@ public class Criteria implements CriteriaDefinition {
* @param right
* @return
*/
private boolean isEqual(Object left, Object right) {
private boolean isEqual(@Nullable Object left, @Nullable Object right) {
if (left == null) {
return right == null;
}
if (Pattern.class.isInstance(left)) {
if (left instanceof Pattern) {
if (!Pattern.class.isInstance(right)) {
if (!(right instanceof Pattern)) {
return false;
}
@@ -989,6 +992,52 @@ public class Criteria implements CriteriaDefinition {
&& leftPattern.flags() == rightPattern.flags();
}
if (left instanceof Document) {
if (!(right instanceof Document)) {
return false;
}
Document leftDocument = (Document) left;
Document rightDocument = (Document) right;
Iterator<Entry<String, Object>> leftIterator = leftDocument.entrySet().iterator();
Iterator<Entry<String, Object>> rightIterator = rightDocument.entrySet().iterator();
while (leftIterator.hasNext() && rightIterator.hasNext()) {
Map.Entry<String, Object> leftEntry = leftIterator.next();
Map.Entry<String, Object> rightEntry = rightIterator.next();
if (!isEqual(leftEntry.getKey(), rightEntry.getKey())
|| !isEqual(leftEntry.getValue(), rightEntry.getValue())) {
return false;
}
}
return !leftIterator.hasNext() && !rightIterator.hasNext();
}
if (Collection.class.isAssignableFrom(left.getClass())) {
if (!Collection.class.isAssignableFrom(right.getClass())) {
return false;
}
Collection<?> leftCollection = (Collection<?>) left;
Collection<?> rightCollection = (Collection<?>) right;
Iterator<?> leftIterator = leftCollection.iterator();
Iterator<?> rightIterator = rightCollection.iterator();
while (leftIterator.hasNext() && rightIterator.hasNext()) {
if (!isEqual(leftIterator.next(), rightIterator.next())) {
return false;
}
}
return !leftIterator.hasNext() && !rightIterator.hasNext();
}
return ObjectUtils.nullSafeEquals(left, right);
}

View File

@@ -33,6 +33,7 @@ import org.springframework.data.repository.query.QueryMethodEvaluationContextPro
import org.springframework.expression.ExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
@@ -163,9 +164,9 @@ abstract class AggregationUtils {
* @throws IllegalArgumentException when none of the above rules is met.
*/
@Nullable
static <T> T extractSimpleTypeResult(Document source, Class<T> targetType, MongoConverter converter) {
static <T> T extractSimpleTypeResult(@Nullable Document source, Class<T> targetType, MongoConverter converter) {
if (source.isEmpty()) {
if (ObjectUtils.isEmpty(source)) {
return null;
}

View File

@@ -34,6 +34,7 @@ import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.Unwrapped;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion;
import org.springframework.data.mongodb.test.util.MongoTemplateExtension;
import org.springframework.data.mongodb.test.util.MongoTestTemplate;
import org.springframework.data.mongodb.test.util.Template;
@@ -42,8 +43,10 @@ import org.springframework.data.mongodb.test.util.Template;
* Integration tests for {@link org.springframework.data.mongodb.core.query.Field}.
*
* @author Christoph Strobl
* @author Mark Paluch
*/
@ExtendWith(MongoTemplateExtension.class)
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.4")
class MongoTemplateFieldProjectionTests {
private static @Template MongoTestTemplate template;

View File

@@ -1191,6 +1191,72 @@ public class QueryMapperUnitTests {
assertThat(document).isEqualTo(new org.bson.Document("stringValue", 1));
}
@Test // GH-3601
void resolvesFieldnameWithUnderscoresCorrectly() {
Query query = query(where("fieldname_with_underscores").exists(true));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
context.getPersistentEntity(WithPropertyUsingUnderscoreInName.class));
assertThat(document).isEqualTo(new org.bson.Document("fieldname_with_underscores", new org.bson.Document("$exists", true)));
}
@Test // GH-3601
void resolvesMappedFieldnameWithUnderscoresCorrectly() {
Query query = query(where("renamed_fieldname_with_underscores").exists(true));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
context.getPersistentEntity(WithPropertyUsingUnderscoreInName.class));
assertThat(document).isEqualTo(new org.bson.Document("renamed", new org.bson.Document("$exists", true)));
}
@Test // GH-3601
void resolvesSimpleNestedFieldnameWithUnderscoresCorrectly() {
Query query = query(where("simple.fieldname_with_underscores").exists(true));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class));
assertThat(document).isEqualTo(new org.bson.Document("simple.fieldname_with_underscores", new org.bson.Document("$exists", true)));
}
@Test // GH-3601
void resolvesSimpleNestedMappedFieldnameWithUnderscoresCorrectly() {
Query query = query(where("simple.renamed_fieldname_with_underscores").exists(true));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class));
assertThat(document).isEqualTo(new org.bson.Document("simple.renamed", new org.bson.Document("$exists", true)));
}
@Test // GH-3601
void resolvesFieldNameWithUnderscoreOnNestedFieldnameWithUnderscoresCorrectly() {
Query query = query(where("double_underscore.fieldname_with_underscores").exists(true));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class));
assertThat(document).isEqualTo(new org.bson.Document("double_underscore.fieldname_with_underscores", new org.bson.Document("$exists", true)));
}
@Test // GH-3601
void resolvesFieldNameWithUnderscoreOnNestedMappedFieldnameWithUnderscoresCorrectly() {
Query query = query(where("double_underscore.renamed_fieldname_with_underscores").exists(true));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class));
assertThat(document).isEqualTo(new org.bson.Document("double_underscore.renamed", new org.bson.Document("$exists", true)));
}
class WithDeepArrayNesting {
List<WithNestedArray> level0;
@@ -1408,4 +1474,17 @@ public class QueryMapperUnitTests {
String transientValue;
}
static class WrapperAroundWithPropertyUsingUnderscoreInName {
WithPropertyUsingUnderscoreInName simple;
WithPropertyUsingUnderscoreInName double_underscore;
}
static class WithPropertyUsingUnderscoreInName {
String fieldname_with_underscores;
@Field("renamed")
String renamed_fieldname_with_underscores;
}
}

View File

@@ -38,6 +38,8 @@ import org.springframework.data.mongodb.core.schema.MongoJsonSchema;
* @author Christoph Strobl
* @author Andreas Zink
* @author Ziemowit Stolarczyk
* @author Clément Petit
* @author Mark Paluch
*/
public class CriteriaUnitTests {
@@ -353,9 +355,72 @@ public class CriteriaUnitTests {
@Test // DATAMONGO-2002
public void shouldEqualForSamePattern() {
Criteria left = new Criteria("field").regex("foo");
Criteria right = new Criteria("field").regex("foo");
assertThat(left).isEqualTo(right);
}
@Test // DATAMONGO-2002
public void shouldEqualForDocument() {
assertThat(new Criteria("field").is(new Document("one", 1).append("two", "two").append("null", null)))
.isEqualTo(new Criteria("field").is(new Document("one", 1).append("two", "two").append("null", null)));
assertThat(new Criteria("field").is(new Document("one", 1).append("two", "two").append("null", null)))
.isNotEqualTo(new Criteria("field").is(new Document("one", 1).append("two", "two")));
assertThat(new Criteria("field").is(new Document("one", 1).append("two", "two")))
.isNotEqualTo(new Criteria("field").is(new Document("one", 1).append("two", "two").append("null", null)));
assertThat(new Criteria("field").is(new Document("one", 1).append("null", null).append("two", "two")))
.isNotEqualTo(new Criteria("field").is(new Document("one", 1).append("two", "two").append("null", null)));
assertThat(new Criteria("field").is(new Document())).isNotEqualTo(new Criteria("field").is("foo"));
assertThat(new Criteria("field").is("foo")).isNotEqualTo(new Criteria("field").is(new Document()));
}
@Test // DATAMONGO-2002
public void shouldEqualForCollection() {
assertThat(new Criteria("field").is(Arrays.asList("foo", "bar")))
.isEqualTo(new Criteria("field").is(Arrays.asList("foo", "bar")));
assertThat(new Criteria("field").is(Arrays.asList("foo", 1)))
.isNotEqualTo(new Criteria("field").is(Arrays.asList("foo", "bar")));
assertThat(new Criteria("field").is(Collections.singletonList("foo")))
.isNotEqualTo(new Criteria("field").is(Arrays.asList("foo", "bar")));
assertThat(new Criteria("field").is(Arrays.asList("foo", "bar")))
.isNotEqualTo(new Criteria("field").is(Collections.singletonList("foo")));
assertThat(new Criteria("field").is(Arrays.asList("foo", "bar"))).isNotEqualTo(new Criteria("field").is("foo"));
assertThat(new Criteria("field").is("foo")).isNotEqualTo(new Criteria("field").is(Arrays.asList("foo", "bar")));
}
@Test // GH-3414
public void shouldEqualForSamePatternAndFlags() {
Criteria left = new Criteria("field").regex("foo", "iu");
Criteria right = new Criteria("field").regex("foo");
assertThat(left).isNotEqualTo(right);
}
@Test // GH-3414
public void shouldEqualForNestedPattern() {
Criteria left = new Criteria("a").orOperator(
new Criteria("foo").regex("value", "i"),
new Criteria("bar").regex("value")
);
Criteria right = new Criteria("a").orOperator(
new Criteria("foo").regex("value", "i"),
new Criteria("bar").regex("value")
);
assertThat(left).isEqualTo(right);
}
}

View File

@@ -63,6 +63,7 @@ import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.Person.Sex;
import org.springframework.data.mongodb.repository.SampleEvaluationContextExtension.SampleSecurityContextHolder;
import org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion;
import org.springframework.data.querydsl.QSort;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.util.ReflectionTestUtils;
@@ -1414,7 +1415,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
assertThat(repository.findByFirstnameIn(".*")).isEmpty();
}
@Test // GH-23583
@Test // GH-3583
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.4")
void annotatedQueryShouldAllowAggregationInProjection() {
Person target = repository.findWithAggregationInProjection(alicia.getId());

View File

@@ -159,6 +159,14 @@ public class StringBasedAggregationUnitTests {
assertThat(executeAggregation("returnCollection").result).isEqualTo(expected);
}
@Test // GH-3623
public void returnNullWhenSingleResultIsNotPresent() {
when(aggregationResults.getMappedResults()).thenReturn(Collections.emptyList());
assertThat(executeAggregation("simpleReturnType").result).isNull();
}
@Test // DATAMONGO-2153
public void returnRawResultType() {
assertThat(executeAggregation("returnRawResultType").result).isEqualTo(aggregationResults);
@@ -312,6 +320,9 @@ public class StringBasedAggregationUnitTests {
@Aggregation(RAW_GROUP_BY_LASTNAME_STRING)
Page<Person> invalidPageReturnType(Pageable page);
@Aggregation(RAW_GROUP_BY_LASTNAME_STRING)
String simpleReturnType();
}
static class PersonAggregate {

View File

@@ -1,6 +1,36 @@
Spring Data MongoDB Changelog
=============================
Changes in version 3.2.0 (2021-04-14)
-------------------------------------
* #3623 - `@Aggregation` repository query method causes `NullPointerException` when the result is empty.
* #3621 - Upgrade to MongoDB Java Drivers 4.2.3.
* #3612 - Upgrade to MongoDB 4.4 on CI.
* #3601 - Criteria object not allowing to use field names with underscore in them.
* #3583 - Support aggregation expression on fields projection.
* #3414 - Criteria or toEquals fail if contains regex [DATAMONGO-2559].
Changes in version 3.1.8 (2021-04-14)
-------------------------------------
* #3623 - `@Aggregation` repository query method causes `NullPointerException` when the result is empty.
* #3601 - Criteria object not allowing to use field names with underscore in them.
* #3414 - Criteria or toEquals fail if contains regex [DATAMONGO-2559].
Changes in version 3.0.9.RELEASE (2021-04-14)
---------------------------------------------
* #3623 - `@Aggregation` repository query method causes `NullPointerException` when the result is empty.
* #3609 - SimpleReactiveMongoRepository#saveAll does not populate @Id property if it is immutable.
* #3414 - Criteria or toEquals fail if contains regex [DATAMONGO-2559].
Changes in version 3.1.7 (2021-03-31)
-------------------------------------
* #3613 - Use StringUtils.replace(…) instead of String.replaceAll(…) for mapKeyDotReplacement.
* #3609 - SimpleReactiveMongoRepository#saveAll does not populate @Id property if it is immutable.
Changes in version 3.2.0-RC1 (2021-03-31)
-----------------------------------------
* #3613 - Use StringUtils.replace(…) instead of String.replaceAll(…) for mapKeyDotReplacement.
@@ -3393,6 +3423,10 @@ Repository

View File

@@ -1,4 +1,4 @@
Spring Data MongoDB 3.2 RC1 (2021.0.0)
Spring Data MongoDB 3.2 GA (2021.0.0)
Copyright (c) [2010-2019] Pivotal Software, Inc.
This product is licensed to you under the Apache License, Version 2.0 (the "License").
@@ -26,3 +26,4 @@ conditions of the subcomponent's license, as noted in the LICENSE file.