Compare commits
11 Commits
2.1.4.RELE
...
2.1.5.RELE
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3882a5e5c | ||
|
|
8194772388 | ||
|
|
12f18850dc | ||
|
|
816c1da248 | ||
|
|
5a78f19781 | ||
|
|
698837921b | ||
|
|
0f7fc7880b | ||
|
|
6e42f49b08 | ||
|
|
bdfe4e99ed | ||
|
|
85aa3927a6 | ||
|
|
33c4e4294f |
6
pom.xml
6
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.1.4.RELEASE</version>
|
||||
<version>2.1.5.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.4.RELEASE</version>
|
||||
<version>2.1.5.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.4.RELEASE</springdata.commons>
|
||||
<springdata.commons>2.1.5.RELEASE</springdata.commons>
|
||||
<mongo>3.8.2</mongo>
|
||||
<mongo.reactivestreams>1.9.2</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>2.1.4.RELEASE</version>
|
||||
<version>2.1.5.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.1.4.RELEASE</version>
|
||||
<version>2.1.5.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.4.RELEASE</version>
|
||||
<version>2.1.5.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<!-- reactive -->
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.1.4.RELEASE</version>
|
||||
<version>2.1.5.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.1.4.RELEASE</version>
|
||||
<version>2.1.5.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -1720,7 +1720,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
: collection;
|
||||
|
||||
DeleteResult result = multi ? collectionToUse.deleteMany(removeQuery, options)
|
||||
: collection.deleteOne(removeQuery, options);
|
||||
: collectionToUse.deleteOne(removeQuery, options);
|
||||
|
||||
maybeEmitEvent(new AfterDeleteEvent<>(queryObject, entityClass, collectionName));
|
||||
|
||||
|
||||
@@ -1252,7 +1252,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
Mono<T> afterInsert = insertDocument(collectionName, dbDoc, initialized.getClass()).map(id -> {
|
||||
|
||||
T saved = entity.populateIdIfNecessary(id);
|
||||
maybeEmitEvent(new AfterSaveEvent<>(initialized, dbDoc, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(saved, dbDoc, collectionName));
|
||||
return saved;
|
||||
});
|
||||
|
||||
|
||||
@@ -612,7 +612,7 @@ public class QueryMapper {
|
||||
|
||||
/**
|
||||
* Returns whether the given {@link String} is the type key.
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
* @see MongoTypeMapper#isTypeKey(String)
|
||||
@@ -907,8 +907,11 @@ public class QueryMapper {
|
||||
@Override
|
||||
public boolean isIdField() {
|
||||
|
||||
MongoPersistentProperty idProperty = (property != null && property.isIdProperty()) ? property
|
||||
: entity.getIdProperty();
|
||||
if (property != null) {
|
||||
return property.isIdProperty();
|
||||
}
|
||||
|
||||
MongoPersistentProperty idProperty = entity.getIdProperty();
|
||||
|
||||
if (idProperty != null) {
|
||||
|
||||
@@ -1029,7 +1032,7 @@ public class QueryMapper {
|
||||
}
|
||||
|
||||
return propertyPath;
|
||||
} catch (PropertyReferenceException | InvalidPersistentPropertyPath e) {
|
||||
} catch (PropertyReferenceException | InvalidPersistentPropertyPath e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
import static org.springframework.data.mongodb.core.query.Update.*;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -41,10 +39,10 @@ import java.math.BigInteger;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.hamcrest.collection.IsMapContaining;
|
||||
import org.joda.time.DateTime;
|
||||
@@ -87,6 +85,7 @@ import org.springframework.data.mongodb.core.index.IndexInfo;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AuditingEventListener;
|
||||
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent;
|
||||
import org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent;
|
||||
@@ -104,6 +103,8 @@ import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.DBRef;
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoException;
|
||||
@@ -233,6 +234,7 @@ public class MongoTemplateTests {
|
||||
template.dropCollection(WithGeoJson.class);
|
||||
template.dropCollection(DocumentWithNestedTypeHavingStringIdProperty.class);
|
||||
template.dropCollection(ImmutableAudited.class);
|
||||
template.dropCollection(Outer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -3511,6 +3513,35 @@ public class MongoTemplateTests {
|
||||
assertThat(document.id, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2189
|
||||
@DirtiesContext
|
||||
public void afterSaveEventContainsSavedObjectUsingInsertAll() {
|
||||
|
||||
AtomicReference<ImmutableVersioned> saved = createAfterSaveReference();
|
||||
ImmutableVersioned source = new ImmutableVersioned();
|
||||
|
||||
template.insertAll(Collections.singletonList(source));
|
||||
|
||||
assertThat(saved.get(), is(notNullValue()));
|
||||
assertThat(saved.get(), is(not(sameInstance(source))));
|
||||
assertThat(saved.get().id, is(notNullValue()));
|
||||
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2189
|
||||
@DirtiesContext
|
||||
public void afterSaveEventContainsSavedObjectUsingInsert() {
|
||||
|
||||
AtomicReference<ImmutableVersioned> saved = createAfterSaveReference();
|
||||
ImmutableVersioned source = new ImmutableVersioned();
|
||||
|
||||
template.insert(source);
|
||||
|
||||
assertThat(saved.get(), is(notNullValue()));
|
||||
assertThat(saved.get(), is(not(sameInstance(source))));
|
||||
assertThat(saved.get().id, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1509
|
||||
public void findsByGenericNestedListElements() {
|
||||
|
||||
@@ -3633,6 +3664,38 @@ public class MongoTemplateTests {
|
||||
assertThat(read.modified).isEqualTo(result.modified).describedAs("Expected auditing information to be read!");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2193
|
||||
public void shouldNotConvertStringToObjectIdForNonIdField() {
|
||||
|
||||
ObjectId outerId = new ObjectId();
|
||||
String innerId = new ObjectId().toHexString();
|
||||
|
||||
org.bson.Document source = new org.bson.Document() //
|
||||
.append("_id", outerId) //
|
||||
.append("inner", new org.bson.Document("id", innerId).append("value", "boooh"));
|
||||
|
||||
template.getDb().getCollection(template.getCollectionName(Outer.class)).insertOne(source);
|
||||
|
||||
Outer target = template.findOne(query(where("inner.id").is(innerId)), Outer.class);
|
||||
assertThat(target).isNotNull();
|
||||
assertThat(target.id).isEqualTo(outerId);
|
||||
assertThat(target.inner.id).isEqualTo(innerId);
|
||||
}
|
||||
|
||||
private AtomicReference<ImmutableVersioned> createAfterSaveReference() {
|
||||
|
||||
AtomicReference<ImmutableVersioned> saved = new AtomicReference<>();
|
||||
context.addApplicationListener(new AbstractMongoEventListener<ImmutableVersioned>() {
|
||||
|
||||
@Override
|
||||
public void onAfterSave(AfterSaveEvent<ImmutableVersioned> event) {
|
||||
saved.set(event.getSource());
|
||||
}
|
||||
});
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
static class TypeWithNumbers {
|
||||
|
||||
@Id String id;
|
||||
@@ -4134,4 +4197,16 @@ public class MongoTemplateTests {
|
||||
@Id String id;
|
||||
@LastModifiedDate Instant modified;
|
||||
}
|
||||
|
||||
static class Outer {
|
||||
|
||||
@Id ObjectId id;
|
||||
Inner inner;
|
||||
}
|
||||
|
||||
static class Inner {
|
||||
|
||||
@Field("id") String id;
|
||||
String value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.MongoNamespace;
|
||||
import com.mongodb.ReadPreference;
|
||||
import com.mongodb.WriteConcern;
|
||||
import com.mongodb.client.AggregateIterable;
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MapReduceIterable;
|
||||
@@ -96,6 +97,7 @@ import com.mongodb.client.model.FindOneAndUpdateOptions;
|
||||
import com.mongodb.client.model.MapReduceAction;
|
||||
import com.mongodb.client.model.ReplaceOptions;
|
||||
import com.mongodb.client.model.UpdateOptions;
|
||||
import com.mongodb.client.result.DeleteResult;
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
|
||||
/**
|
||||
@@ -114,11 +116,13 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Mock MongoClient mongo;
|
||||
@Mock MongoDatabase db;
|
||||
@Mock MongoCollection<Document> collection;
|
||||
@Mock MongoCollection<Document> collectionWithWriteConcern;
|
||||
@Mock MongoCursor<Document> cursor;
|
||||
@Mock FindIterable<Document> findIterable;
|
||||
@Mock AggregateIterable aggregateIterable;
|
||||
@Mock MapReduceIterable mapReduceIterable;
|
||||
@Mock UpdateResult updateResult;
|
||||
@Mock DeleteResult deleteResult;
|
||||
|
||||
Document commandResultDocument = new Document();
|
||||
|
||||
@@ -141,6 +145,8 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
when(collection.aggregate(any(List.class), any())).thenReturn(aggregateIterable);
|
||||
when(collection.withReadPreference(any())).thenReturn(collection);
|
||||
when(collection.replaceOne(any(), any(), any(ReplaceOptions.class))).thenReturn(updateResult);
|
||||
when(collection.withWriteConcern(any())).thenReturn(collectionWithWriteConcern);
|
||||
when(collectionWithWriteConcern.deleteMany(any(Bson.class), any())).thenReturn(deleteResult);
|
||||
when(findIterable.projection(any())).thenReturn(findIterable);
|
||||
when(findIterable.sort(any(org.bson.Document.class))).thenReturn(findIterable);
|
||||
when(findIterable.collation(any())).thenReturn(findIterable);
|
||||
@@ -731,6 +737,19 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
assertThat(options.getValue().getCollation().getLocale(), is("fr"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2196
|
||||
public void removeShouldApplyWriteConcern() {
|
||||
|
||||
Person person = new Person();
|
||||
person.id = "id-1";
|
||||
|
||||
template.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
|
||||
template.remove(person);
|
||||
|
||||
verify(collection).withWriteConcern(eq(WriteConcern.UNACKNOWLEDGED));
|
||||
verify(collectionWithWriteConcern).deleteMany(any(Bson.class), any());
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1518
|
||||
public void findAndRemoveManyShouldUseCollationWhenPresent() {
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -54,6 +55,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
@@ -71,11 +73,14 @@ import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
|
||||
import org.springframework.data.mongodb.core.index.GeospatialIndex;
|
||||
import org.springframework.data.mongodb.core.index.Index;
|
||||
import org.springframework.data.mongodb.core.index.IndexOperationsAdapter;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.NearQuery;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.data.mongodb.test.util.ReplicaSet;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -95,6 +100,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
@Autowired SimpleReactiveMongoDatabaseFactory factory;
|
||||
@Autowired ReactiveMongoTemplate template;
|
||||
@Autowired ConfigurableApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -1318,6 +1324,38 @@ public class ReactiveMongoTemplateTests {
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2189
|
||||
@DirtiesContext
|
||||
public void afterSaveEventContainsSavedObjectUsingInsert() {
|
||||
|
||||
AtomicReference<ImmutableVersioned> saved = createAfterSaveReference();
|
||||
ImmutableVersioned source = new ImmutableVersioned();
|
||||
|
||||
template.insert(source) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(saved.get()).isNotNull().isNotSameAs(source);
|
||||
assertThat(saved.get().id).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2189
|
||||
@DirtiesContext
|
||||
public void afterSaveEventContainsSavedObjectUsingInsertAll() {
|
||||
|
||||
AtomicReference<ImmutableVersioned> saved = createAfterSaveReference();
|
||||
ImmutableVersioned source = new ImmutableVersioned();
|
||||
|
||||
template.insertAll(Collections.singleton(new ImmutableVersioned())) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(saved.get()).isNotNull().isNotSameAs(source);
|
||||
assertThat(saved.get().id).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2012
|
||||
public void watchesDatabaseCorrectly() throws InterruptedException {
|
||||
|
||||
@@ -1402,6 +1440,20 @@ public class ReactiveMongoTemplateTests {
|
||||
return p;
|
||||
}
|
||||
|
||||
private AtomicReference<ImmutableVersioned> createAfterSaveReference() {
|
||||
|
||||
AtomicReference<ImmutableVersioned> saved = new AtomicReference<>();
|
||||
context.addApplicationListener(new AbstractMongoEventListener<ImmutableVersioned>() {
|
||||
|
||||
@Override
|
||||
public void onAfterSave(AfterSaveEvent<ImmutableVersioned> event) {
|
||||
saved.set(event.getSource());
|
||||
}
|
||||
});
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Wither
|
||||
static class ImmutableVersioned {
|
||||
|
||||
@@ -819,6 +819,18 @@ public class QueryMapperUnitTests {
|
||||
assertThat(mappedObject).containsEntry("className", "foo");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2193
|
||||
public void shouldNotConvertHexStringToObjectIdForRenamedNestedIdField() {
|
||||
|
||||
String idHex = new ObjectId().toHexString();
|
||||
Query query = new Query(where("nested.id").is(idHex));
|
||||
|
||||
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
|
||||
context.getPersistentEntity(RootForClassWithExplicitlyRenamedIdField.class));
|
||||
|
||||
assertThat(document).isEqualTo(new org.bson.Document("nested.id", idHex));
|
||||
}
|
||||
|
||||
@Document
|
||||
public class Foo {
|
||||
@Id private ObjectId id;
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
Spring Data MongoDB Changelog
|
||||
=============================
|
||||
|
||||
Changes in version 2.1.5.RELEASE (2019-02-13)
|
||||
---------------------------------------------
|
||||
* DATAMONGO-2196 - Remove does not apply WriteConcern for single document delete operation.
|
||||
* DATAMONGO-2193 - Query on nested id field incorrectly returns no results.
|
||||
* DATAMONGO-2189 - AfterSaveEvent contains object to save and not the saved instance.
|
||||
* DATAMONGO-2187 - Release 2.1.5 (Lovelace SR5).
|
||||
|
||||
|
||||
Changes in version 2.1.4.RELEASE (2019-01-10)
|
||||
---------------------------------------------
|
||||
* DATAMONGO-2181 - ReactiveMongoRepository.saveAll(…) does not consider collection name for new entities.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Spring Data MongoDB 2.1.4
|
||||
Spring Data MongoDB 2.1.5
|
||||
Copyright (c) [2010-2019] Pivotal Software, Inc.
|
||||
|
||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||
|
||||
Reference in New Issue
Block a user