Compare commits

...

24 Commits

Author SHA1 Message Date
Jens Schauder
8e51d005d5 DATAMONGO-2421 - Release version 2.1.14 (Lovelace SR14). 2019-12-04 11:42:03 +01:00
Jens Schauder
1940a5c2c2 DATAMONGO-2421 - Prepare 2.1.14 (Lovelace SR14). 2019-12-04 11:40:56 +01:00
Jens Schauder
5a274029d7 DATAMONGO-2421 - Updated changelog. 2019-12-04 11:40:47 +01:00
Mark Paluch
c342bf266e DATAMONGO-2410 - Polishing.
Simplify cast. Extend test with DBObject interface.

Original pull request: #813.
2019-12-04 08:58:36 +01:00
Christoph Strobl
11baf455d2 DATAMONGO-2410 - Fix Document to BasicDBObject conversion.
Original pull request: #813.
2019-12-04 08:58:09 +01:00
Mark Paluch
05882813ac DATAMONGO-2402 - Updated changelog. 2019-11-18 12:43:27 +01:00
Mark Paluch
bd3f26c928 DATAMONGO-2401 - After release cleanups. 2019-11-18 12:10:53 +01:00
Mark Paluch
5555aa970b DATAMONGO-2401 - Prepare next development iteration. 2019-11-18 12:10:52 +01:00
Mark Paluch
e74fe05abd DATAMONGO-2401 - Release version 2.1.13 (Lovelace SR13). 2019-11-18 12:01:05 +01:00
Mark Paluch
d579254fbc DATAMONGO-2401 - Prepare 2.1.13 (Lovelace SR13). 2019-11-18 12:00:43 +01:00
Mark Paluch
71c8e4cc02 DATAMONGO-2401 - Updated changelog. 2019-11-18 12:00:36 +01:00
Mark Paluch
a087c7d17c DATAMONGO-2409 - Polishing.
Adapt also ExecutableFindOperation.DistinctWithProjection.asType() to return the appropriate TerminatingDistinct.

Original pull request: #805.
2019-11-11 10:22:43 +01:00
Christoph Strobl
90cec275a6 DATAMONGO-2409 - Fix return type of Kotlin extension function for ReactiveFindOperation.DistinctWithProjection.asType().
Original pull request: #805.
2019-11-11 10:22:43 +01:00
Christoph Strobl
e4eefe577d DATAMONGO-2382 - Updated changelog. 2019-11-04 15:39:58 +01:00
Christoph Strobl
b57a6612f6 DATAMONGO-2381 - After release cleanups. 2019-11-04 10:26:37 +01:00
Christoph Strobl
62b2d54e0d DATAMONGO-2381 - Prepare next development iteration. 2019-11-04 10:26:35 +01:00
Christoph Strobl
aff823da57 DATAMONGO-2381 - Release version 2.1.12 (Lovelace SR12). 2019-11-04 09:29:50 +01:00
Christoph Strobl
d45b630724 DATAMONGO-2381 - Prepare 2.1.12 (Lovelace SR12). 2019-11-04 09:29:05 +01:00
Christoph Strobl
fc8c97aeb0 DATAMONGO-2381 - Updated changelog. 2019-11-04 09:29:00 +01:00
Mark Paluch
004e7f01b2 DATAMONGO-2388 - Polishing.
Use StringJoiner to create comma-delimited String.

Original pull request: #797.
2019-10-28 10:58:01 +01:00
Christoph Strobl
5c80ee0087 DATAMONGO-2388 - Fix CodecConfigurationException when reading index info that contains DbRef.
Provide the default CodecRegistry when converting partial index data to its String representation used in IndexInfo.

Original pull request: #797.
2019-10-28 10:48:55 +01:00
Mark Paluch
adb9dc29a2 DATAMONGO-2334 - Updated changelog. 2019-09-30 19:58:07 +02:00
Mark Paluch
6eb6feadbb DATAMONGO-2333 - After release cleanups. 2019-09-30 11:15:26 +02:00
Mark Paluch
166aab39c4 DATAMONGO-2333 - Prepare next development iteration. 2019-09-30 11:15:25 +02:00
14 changed files with 209 additions and 17 deletions

View File

@@ -5,7 +5,7 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.11.RELEASE</version>
<version>2.1.14.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.1.11.RELEASE</version>
<version>2.1.14.RELEASE</version>
</parent>
<modules>
@@ -27,7 +27,7 @@
<properties>
<project.type>multi</project.type>
<dist.id>spring-data-mongodb</dist.id>
<springdata.commons>2.1.11.RELEASE</springdata.commons>
<springdata.commons>2.1.14.RELEASE</springdata.commons>
<mongo>3.8.2</mongo>
<mongo.reactivestreams>1.9.2</mongo.reactivestreams>
<jmh.version>1.19</jmh.version>

View File

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

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.11.RELEASE</version>
<version>2.1.14.RELEASE</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -50,7 +50,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.1.11.RELEASE</version>
<version>2.1.14.RELEASE</version>
</dependency>
<!-- reactive -->

View File

@@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.11.RELEASE</version>
<version>2.1.14.RELEASE</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>2.1.11.RELEASE</version>
<version>2.1.14.RELEASE</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@@ -211,11 +211,20 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
return conversionService.convert(bson, rawType);
}
if (DBObject.class.isAssignableFrom(rawType)) {
if (Document.class.isAssignableFrom(rawType)) {
return (S) bson;
}
if (Document.class.isAssignableFrom(rawType)) {
if (DBObject.class.isAssignableFrom(rawType)) {
if (bson instanceof DBObject) {
return (S) bson;
}
if (bson instanceof Document) {
return (S) new BasicDBObject((Document) bson);
}
return (S) bson;
}
@@ -1648,7 +1657,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
/**
* Returns whether the given type is a sub type of the given reference, i.e. assignable but not the exact same type.
*
*
* @param type must not be {@literal null}.
* @param reference must not be {@literal null}.
* @return

View File

@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Optional;
import org.bson.Document;
import org.springframework.data.mongodb.util.BsonUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -107,8 +108,8 @@ public class IndexInfo {
boolean sparse = sourceDocument.containsKey("sparse") ? (Boolean) sourceDocument.get("sparse") : false;
String language = sourceDocument.containsKey("default_language") ? (String) sourceDocument.get("default_language")
: "";
String partialFilter = sourceDocument.containsKey("partialFilterExpression")
? ((Document) sourceDocument.get("partialFilterExpression")).toJson() : null;
String partialFilter = extractPartialFilterString(sourceDocument);
IndexInfo info = new IndexInfo(indexFields, name, unique, sparse, language);
info.partialFilterExpression = partialFilter;
@@ -116,6 +117,21 @@ public class IndexInfo {
return info;
}
/**
* @param sourceDocument
* @return the {@link String} representation of the partial filter {@link Document}.
* @since 2.1.11
*/
@Nullable
private static String extractPartialFilterString(Document sourceDocument) {
if (!sourceDocument.containsKey("partialFilterExpression")) {
return null;
}
return BsonUtils.toJson(sourceDocument.get("partialFilterExpression", Document.class));
}
/**
* Returns the individual index fields of the index.
*

View File

@@ -15,17 +15,26 @@
*/
package org.springframework.data.mongodb.util;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.StringJoiner;
import java.util.stream.StreamSupport;
import org.bson.BsonValue;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.json.JsonParseException;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBRef;
import com.mongodb.MongoClientSettings;
/**
* @author Christoph Strobl
@@ -104,4 +113,80 @@ public class BsonUtils {
return value;
}
}
/**
* Serialize the given {@link Document} as Json applying default codecs if necessary.
*
* @param source
* @return
* @since 2.1.12
*/
@Nullable
public static String toJson(@Nullable Document source) {
if (source == null) {
return null;
}
try {
return source.toJson();
} catch (Exception e) {
return toJson((Object) source);
}
}
private static String toJson(@Nullable Object value) {
if (value == null) {
return null;
}
try {
return value instanceof Document
? ((Document) value).toJson(MongoClientSettings.getDefaultCodecRegistry().get(Document.class))
: serializeValue(value);
} catch (Exception e) {
if (value instanceof Collection) {
return toString((Collection<?>) value);
} else if (value instanceof Map) {
return toString((Map<?, ?>) value);
} else if (ObjectUtils.isArray(value)) {
return toString(Arrays.asList(ObjectUtils.toObjectArray(value)));
}
throw e instanceof JsonParseException ? (JsonParseException) e : new JsonParseException(e);
}
}
private static String serializeValue(@Nullable Object value) {
if (value == null) {
return "null";
}
String documentJson = new Document("toBeEncoded", value).toJson();
return documentJson.substring(documentJson.indexOf(':') + 1, documentJson.length() - 1).trim();
}
private static String toString(Map<?, ?> source) {
return iterableToDelimitedString(source.entrySet(), "{ ", " }",
entry -> String.format("\"%s\" : %s", entry.getKey(), toJson(entry.getValue())));
}
private static String toString(Collection<?> source) {
return iterableToDelimitedString(source, "[ ", " ]", BsonUtils::toJson);
}
private static <T> String iterableToDelimitedString(Iterable<T> source, String prefix, String suffix,
Converter<? super T, String> transformer) {
StringJoiner joiner = new StringJoiner(", ", prefix, suffix);
StreamSupport.stream(source.spliterator(), false).map(transformer::convert).forEach(joiner::add);
return joiner.toString();
}
}

View File

@@ -70,7 +70,8 @@ fun <T : Any> ExecutableFindOperation.DistinctWithProjection.asType(resultType:
* Extension for [ExecutableFindOperation.DistinctWithProjection. as] leveraging reified type parameters.
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.1
*/
inline fun <reified T : Any> ExecutableFindOperation.DistinctWithProjection.asType(): ExecutableFindOperation.DistinctWithProjection =
inline fun <reified T : Any> ExecutableFindOperation.DistinctWithProjection.asType(): ExecutableFindOperation.TerminatingDistinct<T> =
`as`(T::class.java)

View File

@@ -68,5 +68,5 @@ fun <T : Any> ReactiveFindOperation.DistinctWithProjection.asType(resultType: KC
* @author Christoph Strobl
* @since 2.1
*/
inline fun <reified T : Any> ReactiveFindOperation.DistinctWithProjection.asType(): ReactiveFindOperation.DistinctWithProjection =
inline fun <reified T : Any> ReactiveFindOperation.DistinctWithProjection.asType(): ReactiveFindOperation.TerminatingDistinct<T> =
`as`(T::class.java)

View File

@@ -21,6 +21,7 @@ import static org.junit.Assume.*;
import static org.springframework.data.mongodb.core.index.PartialIndexFilter.*;
import static org.springframework.data.mongodb.core.query.Criteria.*;
import org.bson.BsonDocument;
import org.bson.Document;
import org.junit.Before;
import org.junit.Test;
@@ -40,6 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.IndexOptions;
/**
* Integration tests for {@link DefaultIndexOperations}.
@@ -150,6 +152,21 @@ public class DefaultIndexOperationsIntegrationTests {
assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"a_g_e\" : { \"$gte\" : 10 } }");
}
@Test // DATAMONGO-2388
public void shouldReadIndexWithPartialFilterContainingDbRefCorrectly() {
BsonDocument partialFilter = BsonDocument.parse(
"{ \"the-ref\" : { \"$ref\" : \"other-collection\", \"$id\" : { \"$oid\" : \"59ce08baf264b906810fe8c5\"} } }");
IndexOptions indexOptions = new IndexOptions();
indexOptions.name("partial-with-dbref");
indexOptions.partialFilterExpression(partialFilter);
collection.createIndex(BsonDocument.parse("{ \"key-1\" : 1, \"key-2\": 1}"), indexOptions);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-dbref");
assertThat(BsonDocument.parse(info.getPartialFilterExpression())).isEqualTo(partialFilter);
}
@Test // DATAMONGO-1518
public void shouldCreateIndexWithCollationCorrectly() {

View File

@@ -48,6 +48,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.ConversionNotSupportedException;
import org.springframework.beans.factory.annotation.Value;
@@ -84,6 +85,8 @@ import org.springframework.data.util.ClassTypeInformation;
import org.springframework.test.util.ReflectionTestUtils;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBRef;
/**
@@ -1926,6 +1929,15 @@ public class MappingMongoConverterUnitTests {
assertThat(order.items).hasSize(3);
}
@Test // DATAMONGO-2410
public void shouldAllowReadingBackDbObject() {
assertThat(converter.read(BasicDBObject.class, new org.bson.Document("property", "value")))
.isEqualTo(new BasicDBObject("property", "value"));
assertThat(converter.read(DBObject.class, new org.bson.Document("property", "value")))
.isEqualTo(new BasicDBObject("property", "value"));
}
static class GenericType<T> {
T content;
}
@@ -1947,7 +1959,7 @@ public class MappingMongoConverterUnitTests {
@Override
void method() {
}
}
};
abstract void method();

View File

@@ -1,6 +1,56 @@
Spring Data MongoDB Changelog
=============================
Changes in version 2.1.14.RELEASE (2019-12-04)
----------------------------------------------
* DATAMONGO-2421 - Release 2.1.14 (Lovelace SR14).
* DATAMONGO-2410 - Using BasicDBObject as an entity caused java.lang.ClassCastException in runtime.
Changes in version 2.2.2.RELEASE (2019-11-18)
---------------------------------------------
* DATAMONGO-2414 - ReactiveGridFsResource.getDownloadStream(…) hang if completion happens on event loop.
* DATAMONGO-2409 - Extension Function ReactiveFindOperation.DistinctWithProjection.asType() has wrong return type.
* DATAMONGO-2403 - ReactiveStringBasedAggregation / AggregationUtils fails on NPE because source or value is null.
* DATAMONGO-2402 - Release 2.2.2 (Moore SR2).
Changes in version 2.1.13.RELEASE (2019-11-18)
----------------------------------------------
* DATAMONGO-2409 - Extension Function ReactiveFindOperation.DistinctWithProjection.asType() has wrong return type.
* DATAMONGO-2401 - Release 2.1.13 (Lovelace SR13).
Changes in version 2.2.1.RELEASE (2019-11-04)
---------------------------------------------
* DATAMONGO-2399 - Upgrade to mongo-java-driver 3.11.1.
* DATAMONGO-2394 - nearSphere query wrongly generated with radian parameter instead of meters.
* DATAMONGO-2393 - Reading large file from ReactiveGridFsTemplate causes a stackoverflow and the code to hang.
* DATAMONGO-2392 - Reading GridFS files written with old api and custom id fails on ReactiveGridFsTemplate.
* DATAMONGO-2388 - IndexOperations.getIndexInfo() fails for index that has partialFilterExpression containing DBRef.
* DATAMONGO-2382 - Release 2.2.1 (Moore SR1).
Changes in version 2.1.12.RELEASE (2019-11-04)
----------------------------------------------
* DATAMONGO-2388 - IndexOperations.getIndexInfo() fails for index that has partialFilterExpression containing DBRef.
* DATAMONGO-2381 - Release 2.1.12 (Lovelace SR12).
Changes in version 2.2.0.RELEASE (2019-09-30)
---------------------------------------------
* DATAMONGO-2380 - Remove @ExperimentalCoroutinesApi annotations.
* DATAMONGO-2379 - Add documentation for Kotlin support.
* DATAMONGO-2378 - Favor com.mongodb.client.MongoClient (over already deprecated com.mongodb.MongoClient) where possible.
* DATAMONGO-2377 - Wrong processing of $$value and $$this.
* DATAMONGO-2374 - Couldn't find PersistentEntity for type class org.bson.Document using query methods.
* DATAMONGO-2366 - CursorReadingTask calls errorHandler.handleError twice for exception raised while reading from the cursor.
* DATAMONGO-2361 - Trivial fix in Mapping Annotation Overview chapter of RefDoc.
* DATAMONGO-2360 - MongoTemplate#count does not use hinted index.
* DATAMONGO-2334 - Release 2.2 GA (Moore).
* DATAMONGO-1731 - Improve JavaDoc of MongoOperations update / findAndModify methods.
Changes in version 2.1.11.RELEASE (2019-09-30)
----------------------------------------------
* DATAMONGO-2377 - Wrong processing of $$value and $$this.
@@ -2770,3 +2820,4 @@ Repository
* Namespace support for Mongo repositories
* Allow usage of pagination and sorting with repositories

View File

@@ -1,4 +1,4 @@
Spring Data MongoDB 2.1.11
Spring Data MongoDB 2.1.14
Copyright (c) [2010-2019] Pivotal Software, Inc.
This product is licensed to you under the Apache License, Version 2.0 (the "License").
@@ -8,3 +8,4 @@ This product may include a number of subcomponents with
separate copyright notices and license terms. Your use of the source
code for the these subcomponents is subject to the terms and
conditions of the subcomponent's license, as noted in the LICENSE file.