DATAMONGO-1827 - Polishing.
Use diamond syntax in imperative and reactive Template API implementations. Rename ReactiveMongoTemplate.toDbObject to toDocument. Move Terminating interfaces in ExecutableUpdateOperation and ExecutableRemoveOperation to the top-most position to align with other fluent interface declarations and to improve discoverability of terminating operations. Convert ReactiveMongoTemplateTests assertions to AssertJ. Original Pull Request: #569
This commit is contained in:
committed by
Christoph Strobl
parent
fa880f1c5c
commit
ac89ce1b2c
@@ -53,26 +53,6 @@ public interface ExecutableRemoveOperation {
|
||||
*/
|
||||
<T> ExecutableRemove<T> remove(Class<T> domainType);
|
||||
|
||||
/**
|
||||
* Collection override (optional).
|
||||
*
|
||||
* @param <T>
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
*/
|
||||
interface RemoveWithCollection<T> extends RemoveWithQuery<T> {
|
||||
|
||||
/**
|
||||
* Explicitly set the name of the collection to perform the query on. <br />
|
||||
* Skip this step to use the default collection derived from the domain type.
|
||||
*
|
||||
* @param collection must not be {@literal null} nor {@literal empty}.
|
||||
* @return new instance of {@link RemoveWithCollection}.
|
||||
* @throws IllegalArgumentException if collection is {@literal null}.
|
||||
*/
|
||||
RemoveWithQuery<T> inCollection(String collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
@@ -104,6 +84,27 @@ public interface ExecutableRemoveOperation {
|
||||
List<T> findAndRemove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection override (optional).
|
||||
*
|
||||
* @param <T>
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
*/
|
||||
interface RemoveWithCollection<T> extends RemoveWithQuery<T> {
|
||||
|
||||
/**
|
||||
* Explicitly set the name of the collection to perform the query on. <br />
|
||||
* Skip this step to use the default collection derived from the domain type.
|
||||
*
|
||||
* @param collection must not be {@literal null} nor {@literal empty}.
|
||||
* @return new instance of {@link RemoveWithCollection}.
|
||||
* @throws IllegalArgumentException if collection is {@literal null}.
|
||||
*/
|
||||
RemoveWithQuery<T> inCollection(String collection);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
|
||||
@@ -57,6 +57,82 @@ public interface ExecutableUpdateOperation {
|
||||
*/
|
||||
<T> ExecutableUpdate<T> update(Class<T> domainType);
|
||||
|
||||
/**
|
||||
* Trigger findAndModify execution by calling one of the terminating methods.
|
||||
*/
|
||||
interface TerminatingFindAndModify<T> {
|
||||
|
||||
/**
|
||||
* Find, modify and return the first matching document.
|
||||
*
|
||||
* @return {@link Optional#empty()} if nothing found.
|
||||
*/
|
||||
default Optional<T> findAndModify() {
|
||||
return Optional.ofNullable(findAndModifyValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find, modify and return the first matching document.
|
||||
*
|
||||
* @return {@literal null} if nothing found.
|
||||
*/
|
||||
@Nullable
|
||||
T findAndModifyValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger findAndReplace execution by calling one of the terminating methods.
|
||||
*/
|
||||
interface TerminatingFindAndReplace<T> {
|
||||
|
||||
/**
|
||||
* Find, replace and return the first matching document.
|
||||
*
|
||||
* @return {@link Optional#empty()} if nothing found.
|
||||
*/
|
||||
default Optional<T> findAndReplace() {
|
||||
return Optional.ofNullable(findAndReplaceValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find, replace and return the first matching document.
|
||||
*
|
||||
* @return {@literal null} if nothing found.
|
||||
*/
|
||||
@Nullable
|
||||
T findAndReplaceValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger update execution by calling one of the terminating methods.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
*/
|
||||
interface TerminatingUpdate<T> extends TerminatingFindAndModify<T>, FindAndModifyWithOptions<T> {
|
||||
|
||||
/**
|
||||
* Update all matching documents in the collection.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
UpdateResult all();
|
||||
|
||||
/**
|
||||
* Update the first document in the collection.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
UpdateResult first();
|
||||
|
||||
/**
|
||||
* Creates a new document if no documents match the filter query or updates the matching ones.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
UpdateResult upsert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare the {@link Update} to apply.
|
||||
*
|
||||
@@ -80,7 +156,7 @@ public interface ExecutableUpdateOperation {
|
||||
* @param replacement must not be {@literal null}.
|
||||
* @return new instance of {@link FindAndReplaceOptions}.
|
||||
* @throws IllegalArgumentException if options is {@literal null}.
|
||||
* 2.1
|
||||
* @since 2.1
|
||||
*/
|
||||
FindAndReplaceWithOptions<T> replaceWith(T replacement);
|
||||
}
|
||||
@@ -140,29 +216,6 @@ public interface ExecutableUpdateOperation {
|
||||
TerminatingFindAndModify<T> withOptions(FindAndModifyOptions options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger findAndModify execution by calling one of the terminating methods.
|
||||
*/
|
||||
interface TerminatingFindAndModify<T> {
|
||||
|
||||
/**
|
||||
* Find, modify and return the first matching document.
|
||||
*
|
||||
* @return {@link Optional#empty()} if nothing found.
|
||||
*/
|
||||
default Optional<T> findAndModify() {
|
||||
return Optional.ofNullable(findAndModifyValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find, modify and return the first matching document.
|
||||
*
|
||||
* @return {@literal null} if nothing found.
|
||||
*/
|
||||
@Nullable
|
||||
T findAndModifyValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define {@link FindAndReplaceOptions}.
|
||||
*
|
||||
@@ -181,59 +234,6 @@ public interface ExecutableUpdateOperation {
|
||||
TerminatingFindAndReplace<T> withOptions(FindAndReplaceOptions options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger findAndReplace execution by calling one of the terminating methods.
|
||||
*/
|
||||
interface TerminatingFindAndReplace<T> {
|
||||
|
||||
/**
|
||||
* Find, replace and return the first matching document.
|
||||
*
|
||||
* @return {@link Optional#empty()} if nothing found.
|
||||
*/
|
||||
default Optional<T> findAndReplace() {
|
||||
return Optional.ofNullable(findAndReplaceValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find, replace and return the first matching document.
|
||||
*
|
||||
* @return {@literal null} if nothing found.
|
||||
*/
|
||||
@Nullable
|
||||
T findAndReplaceValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger update execution by calling one of the terminating methods.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
*/
|
||||
interface TerminatingUpdate<T> extends TerminatingFindAndModify<T>, FindAndModifyWithOptions<T> {
|
||||
|
||||
/**
|
||||
* Update all matching documents in the collection.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
UpdateResult all();
|
||||
|
||||
/**
|
||||
* Update the first document in the collection.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
UpdateResult first();
|
||||
|
||||
/**
|
||||
* Creates a new document if no documents match the filter query or updates the matching ones.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
UpdateResult upsert();
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
|
||||
@@ -182,7 +182,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
static {
|
||||
|
||||
Set<String> iterableClasses = new HashSet<String>();
|
||||
Set<String> iterableClasses = new HashSet<>();
|
||||
iterableClasses.add(List.class.getName());
|
||||
iterableClasses.add(Collection.class.getName());
|
||||
iterableClasses.add(Iterator.class.getName());
|
||||
@@ -418,7 +418,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
FindIterable<Document> cursor = new QueryCursorPreparer(query, entityType)
|
||||
.prepare(collection.find(mappedQuery, Document.class).projection(mappedFields));
|
||||
|
||||
return new CloseableIterableCursorAdapter<T>(cursor, exceptionTranslator,
|
||||
return new CloseableIterableCursorAdapter<>(cursor, exceptionTranslator,
|
||||
new ProjectingReadCallback<>(mongoConverter, entityType, returnType, collectionName));
|
||||
}
|
||||
});
|
||||
@@ -998,9 +998,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
List<Object> results = (List<Object>) commandResult.get("results");
|
||||
results = results == null ? Collections.emptyList() : results;
|
||||
|
||||
DocumentCallback<GeoResult<T>> callback = new GeoNearResultDocumentCallback<T>(
|
||||
DocumentCallback<GeoResult<T>> callback = new GeoNearResultDocumentCallback<>(
|
||||
new ProjectingReadCallback<>(mongoConverter, domainType, returnType, collectionName), near.getMetric());
|
||||
List<GeoResult<T>> result = new ArrayList<GeoResult<T>>(results.size());
|
||||
List<GeoResult<T>> result = new ArrayList<>(results.size());
|
||||
|
||||
int index = 0;
|
||||
long elementsToSkip = near.getSkip() != null ? near.getSkip() : 0;
|
||||
@@ -1021,11 +1021,11 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
if (elementsToSkip > 0) {
|
||||
// as we skipped some elements we have to calculate the averageDistance ourselves:
|
||||
return new GeoResults<T>(result, near.getMetric());
|
||||
return new GeoResults<>(result, near.getMetric());
|
||||
}
|
||||
|
||||
GeoCommandStatistics stats = GeoCommandStatistics.from(commandResult);
|
||||
return new GeoResults<T>(result, new Distance(stats.getAverageDistance(), near.getMetric()));
|
||||
return new GeoResults<>(result, new Distance(stats.getAverageDistance(), near.getMetric()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1261,16 +1261,16 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
protected <T> void doInsert(String collectionName, T objectToSave, MongoWriter<T> writer) {
|
||||
|
||||
initializeVersionProperty(objectToSave);
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
maybeEmitEvent(new BeforeConvertEvent<>(objectToSave, collectionName));
|
||||
assertUpdateableIdIfNotSet(objectToSave);
|
||||
|
||||
Document dbDoc = toDocument(objectToSave, writer);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
Object id = insertDocument(collectionName, dbDoc, objectToSave.getClass());
|
||||
|
||||
populateIdIfNecessary(objectToSave, id);
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1343,7 +1343,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
protected <T> void doInsertAll(Collection<? extends T> listToSave, MongoWriter<T> writer) {
|
||||
|
||||
Map<String, List<T>> elementsByCollection = new HashMap<String, List<T>>();
|
||||
Map<String, List<T>> elementsByCollection = new HashMap<>();
|
||||
|
||||
for (T element : listToSave) {
|
||||
|
||||
@@ -1357,7 +1357,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
List<T> collectionElements = elementsByCollection.get(collection);
|
||||
|
||||
if (null == collectionElements) {
|
||||
collectionElements = new ArrayList<T>();
|
||||
collectionElements = new ArrayList<>();
|
||||
elementsByCollection.put(collection, collectionElements);
|
||||
}
|
||||
|
||||
@@ -1373,15 +1373,15 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
Assert.notNull(writer, "MongoWriter must not be null!");
|
||||
|
||||
List<Document> documentList = new ArrayList<Document>();
|
||||
List<Document> documentList = new ArrayList<>();
|
||||
for (T o : batchToSave) {
|
||||
|
||||
initializeVersionProperty(o);
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(o, collectionName));
|
||||
maybeEmitEvent(new BeforeConvertEvent<>(o, collectionName));
|
||||
|
||||
Document document = toDocument(o, writer);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(o, document, collectionName));
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(o, document, collectionName));
|
||||
documentList.add(document);
|
||||
}
|
||||
|
||||
@@ -1391,7 +1391,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
for (T obj : batchToSave) {
|
||||
if (i < ids.size()) {
|
||||
populateIdIfNecessary(obj, ids.get(i));
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(obj, documentList.get(i), collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(obj, documentList.get(i), collectionName));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -1433,14 +1433,14 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
// Bump version number
|
||||
convertingAccessor.setProperty(property, number.longValue() + 1);
|
||||
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
maybeEmitEvent(new BeforeConvertEvent<>(objectToSave, collectionName));
|
||||
assertUpdateableIdIfNotSet(objectToSave);
|
||||
|
||||
Document document = new Document();
|
||||
|
||||
this.mongoConverter.write(objectToSave, document);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, document, collectionName));
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(objectToSave, document, collectionName));
|
||||
Update update = Update.fromDocument(document, ID_FIELD);
|
||||
|
||||
// Create query for entity with the id and old version
|
||||
@@ -1455,7 +1455,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
String.format("Cannot save entity %s with version %s to collection %s. Has it been modified meanwhile?", id,
|
||||
number, collectionName));
|
||||
}
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, document, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(objectToSave, document, collectionName));
|
||||
|
||||
return objectToSave;
|
||||
}
|
||||
@@ -1466,16 +1466,16 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
protected <T> T doSave(String collectionName, T objectToSave, MongoWriter<T> writer) {
|
||||
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
maybeEmitEvent(new BeforeConvertEvent<>(objectToSave, collectionName));
|
||||
assertUpdateableIdIfNotSet(objectToSave);
|
||||
|
||||
Document dbDoc = toDocument(objectToSave, writer);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
Object id = saveDocument(collectionName, dbDoc, objectToSave.getClass());
|
||||
|
||||
populateIdIfNecessary(objectToSave, id);
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
|
||||
return objectToSave;
|
||||
}
|
||||
@@ -1757,7 +1757,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
Iterator<?> it = objects.iterator();
|
||||
Pair<String, Object> pair = extractIdPropertyAndValue(it.next());
|
||||
|
||||
ArrayList<Object> ids = new ArrayList<Object>(objects.size());
|
||||
ArrayList<Object> ids = new ArrayList<>(objects.size());
|
||||
ids.add(pair.getSecond());
|
||||
|
||||
while (it.hasNext()) {
|
||||
@@ -1819,7 +1819,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
public DeleteResult doInCollection(MongoCollection<Document> collection)
|
||||
throws MongoException, DataAccessException {
|
||||
|
||||
maybeEmitEvent(new BeforeDeleteEvent<T>(queryObject, entityClass, collectionName));
|
||||
maybeEmitEvent(new BeforeDeleteEvent<>(queryObject, entityClass, collectionName));
|
||||
|
||||
Document removeQuery = queryObject;
|
||||
|
||||
@@ -1855,7 +1855,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
DeleteResult result = multi ? collectionToUse.deleteMany(removeQuery, options)
|
||||
: collection.deleteOne(removeQuery, options);
|
||||
|
||||
maybeEmitEvent(new AfterDeleteEvent<T>(queryObject, entityClass, collectionName));
|
||||
maybeEmitEvent(new AfterDeleteEvent<>(queryObject, entityClass, collectionName));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1870,7 +1870,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
@Override
|
||||
public <T> List<T> findAll(Class<T> entityClass, String collectionName) {
|
||||
return executeFindMultiInternal(new FindCallback(new Document(), new Document()), null,
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2032,14 +2032,14 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterable<Document> resultSet = (Iterable<Document>) commandResult.get("retval");
|
||||
List<T> mappedResults = new ArrayList<T>();
|
||||
DocumentCallback<T> callback = new ReadDocumentCallback<T>(mongoConverter, entityClass, inputCollectionName);
|
||||
List<T> mappedResults = new ArrayList<>();
|
||||
DocumentCallback<T> callback = new ReadDocumentCallback<>(mongoConverter, entityClass, inputCollectionName);
|
||||
|
||||
for (Document resultDocument : resultSet) {
|
||||
mappedResults.add(callback.doWith(resultDocument));
|
||||
}
|
||||
|
||||
return new GroupByResults<T>(mappedResults, commandResult);
|
||||
return new GroupByResults<>(mappedResults, commandResult);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -2359,7 +2359,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
public Set<String> getCollectionNames() {
|
||||
return execute(new DbCallback<Set<String>>() {
|
||||
public Set<String> doInDB(MongoDatabase db) throws MongoException, DataAccessException {
|
||||
Set<String> result = new LinkedHashSet<String>();
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
for (String name : db.listCollectionNames()) {
|
||||
result.add(name);
|
||||
}
|
||||
@@ -2465,7 +2465,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
}
|
||||
|
||||
return executeFindOneInternal(new FindOneCallback(mappedQuery, mappedFields),
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2480,7 +2480,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
*/
|
||||
protected <T> List<T> doFind(String collectionName, Document query, Document fields, Class<T> entityClass) {
|
||||
return doFind(collectionName, query, fields, entityClass, null,
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName));
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2499,7 +2499,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
protected <T> List<T> doFind(String collectionName, Document query, Document fields, Class<T> entityClass,
|
||||
CursorPreparer preparer) {
|
||||
return doFind(collectionName, query, fields, entityClass, preparer,
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName));
|
||||
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
protected <S, T> List<T> doFind(String collectionName, Document query, Document fields, Class<S> entityClass,
|
||||
@@ -2631,7 +2631,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
return executeFindOneInternal(
|
||||
new FindAndRemoveCallback(queryMapper.getMappedObject(query, entity), fields, sort, collation),
|
||||
new ReadDocumentCallback<T>(readerToUse, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(readerToUse, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
protected <T> T doFindAndModify(String collectionName, Document query, Document fields, Document sort,
|
||||
@@ -2658,7 +2658,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
}
|
||||
|
||||
return executeFindOneInternal(new FindAndModifyCallback(mappedQuery, fields, sort, mappedUpdate, options),
|
||||
new ReadDocumentCallback<T>(readerToUse, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(readerToUse, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
protected <T> T doFindAndReplace(String collectionName, Document query, Document fields, Document sort,
|
||||
@@ -2684,7 +2684,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(replacement, dbDoc, collectionName));
|
||||
|
||||
return executeFindOneInternal(new FindAndReplaceCallback(mappedQuery, fields, sort, dbDoc, options),
|
||||
new ReadDocumentCallback<T>(readerToUse, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(readerToUse, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2795,7 +2795,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
cursor = iterable.iterator();
|
||||
|
||||
List<T> result = new ArrayList<T>();
|
||||
List<T> result = new ArrayList<>();
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
Document object = cursor.next();
|
||||
@@ -3168,13 +3168,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
public T doWith(@Nullable Document object) {
|
||||
|
||||
if (null != object) {
|
||||
maybeEmitEvent(new AfterLoadEvent<T>(object, type, collectionName));
|
||||
maybeEmitEvent(new AfterLoadEvent<>(object, type, collectionName));
|
||||
}
|
||||
|
||||
T source = reader.read(type, object);
|
||||
|
||||
if (null != source) {
|
||||
maybeEmitEvent(new AfterConvertEvent<T>(object, source, collectionName));
|
||||
maybeEmitEvent(new AfterConvertEvent<>(object, source, collectionName));
|
||||
}
|
||||
|
||||
return source;
|
||||
@@ -3213,7 +3213,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
: targetType;
|
||||
|
||||
if (null != object) {
|
||||
maybeEmitEvent(new AfterLoadEvent<T>(object, targetType, collectionName));
|
||||
maybeEmitEvent(new AfterLoadEvent<>(object, targetType, collectionName));
|
||||
}
|
||||
|
||||
Object source = reader.read(typeToRead, object);
|
||||
|
||||
@@ -114,40 +114,13 @@ import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.ClientSessionOptions;
|
||||
import com.mongodb.CursorType;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBCursor;
|
||||
import com.mongodb.DBRef;
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.ReadPreference;
|
||||
import com.mongodb.WriteConcern;
|
||||
import com.mongodb.client.model.CountOptions;
|
||||
import com.mongodb.client.model.CreateCollectionOptions;
|
||||
import com.mongodb.client.model.DeleteOptions;
|
||||
import com.mongodb.client.model.Filters;
|
||||
import com.mongodb.client.model.FindOneAndDeleteOptions;
|
||||
import com.mongodb.client.model.FindOneAndReplaceOptions;
|
||||
import com.mongodb.client.model.FindOneAndUpdateOptions;
|
||||
import com.mongodb.client.model.ReplaceOptions;
|
||||
import com.mongodb.client.model.ReturnDocument;
|
||||
import com.mongodb.client.model.UpdateOptions;
|
||||
import com.mongodb.client.model.ValidationOptions;
|
||||
import com.mongodb.*;
|
||||
import com.mongodb.client.model.*;
|
||||
import com.mongodb.client.model.changestream.FullDocument;
|
||||
import com.mongodb.client.result.DeleteResult;
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
import com.mongodb.reactivestreams.client.AggregatePublisher;
|
||||
import com.mongodb.reactivestreams.client.ChangeStreamPublisher;
|
||||
import com.mongodb.reactivestreams.client.ClientSession;
|
||||
import com.mongodb.reactivestreams.client.DistinctPublisher;
|
||||
import com.mongodb.reactivestreams.client.FindPublisher;
|
||||
import com.mongodb.reactivestreams.client.MapReducePublisher;
|
||||
import com.mongodb.reactivestreams.client.*;
|
||||
import com.mongodb.reactivestreams.client.MongoClient;
|
||||
import com.mongodb.reactivestreams.client.MongoCollection;
|
||||
import com.mongodb.reactivestreams.client.MongoDatabase;
|
||||
import com.mongodb.reactivestreams.client.Success;
|
||||
import com.mongodb.util.JSONParseException;
|
||||
|
||||
/**
|
||||
@@ -713,7 +686,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
*/
|
||||
public Mono<Void> dropCollection(final String collectionName) {
|
||||
|
||||
return createMono(collectionName, collection -> collection.drop()).doOnSuccess(success -> {
|
||||
return createMono(collectionName, MongoCollection::drop).doOnSuccess(success -> {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Dropped collection [" + collectionName + "]");
|
||||
}
|
||||
@@ -1051,7 +1024,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
entityClass, collectionName);
|
||||
}
|
||||
|
||||
GeoNearResultDbObjectCallback<T> callback = new GeoNearResultDbObjectCallback<T>(
|
||||
GeoNearResultDbObjectCallback<T> callback = new GeoNearResultDbObjectCallback<>(
|
||||
new ProjectingReadCallback<>(mongoConverter, entityClass, returnType, collectionName), near.getMetric());
|
||||
|
||||
return executeCommand(command, this.readPreference).flatMapMany(document -> {
|
||||
@@ -1291,15 +1264,15 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return Mono.defer(() -> {
|
||||
|
||||
initializeVersionProperty(objectToSave);
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
maybeEmitEvent(new BeforeConvertEvent<>(objectToSave, collectionName));
|
||||
|
||||
Document dbDoc = toDbObject(objectToSave, writer);
|
||||
Document dbDoc = toDocument(objectToSave, writer);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
|
||||
Mono<T> afterInsert = insertDBObject(collectionName, dbDoc, objectToSave.getClass()).flatMap(id -> {
|
||||
populateIdIfNecessary(objectToSave, id);
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
return Mono.just(objectToSave);
|
||||
});
|
||||
|
||||
@@ -1342,18 +1315,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
protected <T> Flux<T> doInsertAll(Collection<? extends T> listToSave, MongoWriter<Object> writer) {
|
||||
|
||||
final Map<String, List<T>> elementsByCollection = new HashMap<String, List<T>>();
|
||||
final Map<String, List<T>> elementsByCollection = new HashMap<>();
|
||||
|
||||
listToSave.forEach(element -> {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(element.getClass());
|
||||
|
||||
String collection = entity.getCollection();
|
||||
List<T> collectionElements = elementsByCollection.get(collection);
|
||||
|
||||
if (null == collectionElements) {
|
||||
collectionElements = new ArrayList<T>();
|
||||
elementsByCollection.put(collection, collectionElements);
|
||||
}
|
||||
List<T> collectionElements = elementsByCollection.computeIfAbsent(collection, k -> new ArrayList<>());
|
||||
|
||||
collectionElements.add(element);
|
||||
});
|
||||
@@ -1373,11 +1342,11 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
public Flux<Tuple2<T, Document>> apply(T o) {
|
||||
|
||||
initializeVersionProperty(o);
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(o, collectionName));
|
||||
maybeEmitEvent(new BeforeConvertEvent<>(o, collectionName));
|
||||
|
||||
Document dbDoc = toDbObject(o, writer);
|
||||
Document dbDoc = toDocument(o, writer);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(o, dbDoc, collectionName));
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(o, dbDoc, collectionName));
|
||||
return Flux.zip(Mono.just(o), Mono.just(dbDoc));
|
||||
}
|
||||
}).collectList();
|
||||
@@ -1392,7 +1361,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return insertDocuments.map(tuple -> {
|
||||
|
||||
populateIdIfNecessary(tuple.getT1(), tuple.getT2().get(ID_FIELD));
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(tuple.getT1(), tuple.getT2(), collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(tuple.getT1(), tuple.getT2(), collectionName));
|
||||
return tuple.getT1();
|
||||
});
|
||||
}
|
||||
@@ -1480,16 +1449,16 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
// Bump version number
|
||||
convertingAccessor.setProperty(versionProperty, versionNumber.longValue() + 1);
|
||||
|
||||
ReactiveMongoTemplate.this.maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
ReactiveMongoTemplate.this.maybeEmitEvent(new BeforeConvertEvent<>(objectToSave, collectionName));
|
||||
|
||||
Document document = ReactiveMongoTemplate.this.toDbObject(objectToSave, mongoConverter);
|
||||
Document document = ReactiveMongoTemplate.this.toDocument(objectToSave, mongoConverter);
|
||||
|
||||
ReactiveMongoTemplate.this.maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, document, collectionName));
|
||||
ReactiveMongoTemplate.this.maybeEmitEvent(new BeforeSaveEvent<>(objectToSave, document, collectionName));
|
||||
Update update = Update.fromDocument(document, ID_FIELD);
|
||||
|
||||
return doUpdate(collectionName, query, update, objectToSave.getClass(), false, false).map(updateResult -> {
|
||||
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, document, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(objectToSave, document, collectionName));
|
||||
return objectToSave;
|
||||
});
|
||||
});
|
||||
@@ -1501,14 +1470,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
return createMono(collectionName, collection -> {
|
||||
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
Document dbDoc = toDbObject(objectToSave, writer);
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new BeforeConvertEvent<>(objectToSave, collectionName));
|
||||
Document dbDoc = toDocument(objectToSave, writer);
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
|
||||
return saveDocument(collectionName, dbDoc, objectToSave.getClass()).map(id -> {
|
||||
|
||||
populateIdIfNecessary(objectToSave, id);
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<>(objectToSave, dbDoc, collectionName));
|
||||
return objectToSave;
|
||||
});
|
||||
});
|
||||
@@ -1853,7 +1822,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
Iterator<?> it = objects.iterator();
|
||||
Pair<String, Object> firstEntry = extractIdPropertyAndValue(it.next());
|
||||
|
||||
ArrayList<Object> ids = new ArrayList<Object>(objects.size());
|
||||
ArrayList<Object> ids = new ArrayList<>(objects.size());
|
||||
ids.add(firstEntry.getSecond());
|
||||
|
||||
while (it.hasNext()) {
|
||||
@@ -1923,7 +1892,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
Document removeQuey = queryMapper.getMappedObject(queryObject, entity);
|
||||
|
||||
maybeEmitEvent(new BeforeDeleteEvent<T>(removeQuey, entityClass, collectionName));
|
||||
maybeEmitEvent(new BeforeDeleteEvent<>(removeQuey, entityClass, collectionName));
|
||||
|
||||
MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.REMOVE, collectionName, entityClass,
|
||||
null, removeQuey);
|
||||
@@ -1955,7 +1924,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return collectionToUse.deleteMany(removeQuey, deleteOptions);
|
||||
}
|
||||
|
||||
}).doOnNext(deleteResult -> maybeEmitEvent(new AfterDeleteEvent<T>(queryObject, entityClass, collectionName)))
|
||||
}).doOnNext(deleteResult -> maybeEmitEvent(new AfterDeleteEvent<>(queryObject, entityClass, collectionName)))
|
||||
.next();
|
||||
}
|
||||
|
||||
@@ -1973,7 +1942,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
*/
|
||||
public <T> Flux<T> findAll(Class<T> entityClass, String collectionName) {
|
||||
return executeFindMultiInternal(new FindCallback(null), null,
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1981,6 +1950,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findAllAndRemove(org.springframework.data.mongodb.core.query.Query, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Flux<T> findAllAndRemove(Query query, String collectionName) {
|
||||
return (Flux<T>) findAllAndRemove(query, Object.class, collectionName);
|
||||
}
|
||||
@@ -2026,7 +1996,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
return executeFindMultiInternal(
|
||||
collection -> new FindCallback(null).doInCollection(collection).cursorType(CursorType.TailableAwait), null,
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
|
||||
@@ -2311,7 +2281,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
return executeFindOneInternal(new FindOneCallback(mappedQuery, mappedFields, collation),
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2326,7 +2296,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
*/
|
||||
protected <T> Flux<T> doFind(String collectionName, Document query, Document fields, Class<T> entityClass) {
|
||||
return doFind(collectionName, query, fields, entityClass, null,
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName));
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2345,7 +2315,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
protected <T> Flux<T> doFind(String collectionName, Document query, Document fields, Class<T> entityClass,
|
||||
FindPublisherPreparer preparer) {
|
||||
return doFind(collectionName, query, fields, entityClass, preparer,
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName));
|
||||
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
protected <S, T> Flux<T> doFind(String collectionName, Document query, Document fields, Class<S> entityClass,
|
||||
@@ -2484,7 +2454,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
return executeFindOneInternal(
|
||||
new FindAndRemoveCallback(queryMapper.getMappedObject(query, entity), fields, sort, collation),
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
protected <T> Mono<T> doFindAndModify(String collectionName, Document query, Document fields, Document sort,
|
||||
@@ -2507,7 +2477,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
return executeFindOneInternal(new FindAndModifyCallback(mappedQuery, fields, sort, mappedUpdate, options),
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2519,7 +2489,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return Mono.defer(() -> {
|
||||
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
Document dbDoc = toDbObject(replacement, this.mongoConverter);
|
||||
Document dbDoc = toDocument(replacement, this.mongoConverter);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
@@ -2532,7 +2502,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(replacement, dbDoc, collectionName));
|
||||
|
||||
return executeFindOneInternal(new FindAndReplaceCallback(mappedQuery, fields, sort, dbDoc, options),
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2592,16 +2562,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
protected void ensureNotIterable(Object o) {
|
||||
|
||||
boolean isIterable = o.getClass().isArray();
|
||||
|
||||
if (!isIterable) {
|
||||
for (Class iterableClass : ITERABLE_CLASSES) {
|
||||
if (iterableClass.isAssignableFrom(o.getClass()) || o.getClass().getName().equals(iterableClass.getName())) {
|
||||
isIterable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean isIterable = o.getClass().isArray()
|
||||
|| ITERABLE_CLASSES.stream().anyMatch(iterableClass -> iterableClass.isAssignableFrom(o.getClass())
|
||||
|| o.getClass().getName().equals(iterableClass.getName()));
|
||||
|
||||
if (isIterable) {
|
||||
throw new IllegalArgumentException("Cannot use a collection here.");
|
||||
@@ -2820,7 +2783,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @param writer
|
||||
* @return
|
||||
*/
|
||||
private <T> Document toDbObject(T objectToSave, MongoWriter<T> writer) {
|
||||
private <T> Document toDocument(T objectToSave, MongoWriter<T> writer) {
|
||||
|
||||
if (objectToSave instanceof Document) {
|
||||
return (Document) objectToSave;
|
||||
@@ -3128,11 +3091,11 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
public T doWith(@Nullable Document object) {
|
||||
|
||||
if (null != object) {
|
||||
maybeEmitEvent(new AfterLoadEvent<T>(object, type, collectionName));
|
||||
maybeEmitEvent(new AfterLoadEvent<>(object, type, collectionName));
|
||||
}
|
||||
T source = reader.read(type, object);
|
||||
if (null != source) {
|
||||
maybeEmitEvent(new AfterConvertEvent<T>(object, source, collectionName));
|
||||
maybeEmitEvent(new AfterConvertEvent<>(object, source, collectionName));
|
||||
}
|
||||
return source;
|
||||
}
|
||||
@@ -3212,7 +3175,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
T doWith = delegate.doWith(content);
|
||||
|
||||
return new GeoResult<T>(doWith, new Distance(distance, metric));
|
||||
return new GeoResult<>(doWith, new Distance(distance, metric));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
import static org.springframework.data.mongodb.test.util.Assertions.*;
|
||||
|
||||
import lombok.Data;
|
||||
import reactor.core.Disposable;
|
||||
@@ -119,7 +118,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.insert(person)).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(person.getId(), is(notNullValue()));
|
||||
assertThat(person.getId()).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -129,7 +128,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.insertAll(Collections.singleton(person))).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(person.getId(), is(notNullValue()));
|
||||
assertThat(person.getId()).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -140,7 +139,7 @@ public class ReactiveMongoTemplateTests {
|
||||
StepVerifier.create(template.insert(Collections.singleton(person), PersonWithAList.class)).expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(person.getId(), is(notNullValue()));
|
||||
assertThat(person.getId()).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -151,7 +150,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.save(person)).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(person.getId(), is(notNullValue()));
|
||||
assertThat(person.getId()).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -244,7 +243,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.findOne(query, PersonWithAList.class)).consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.getWishList().size(), is(0));
|
||||
assertThat(actual.getWishList()).isEmpty();
|
||||
}).verifyComplete();
|
||||
|
||||
person.addToWishList("please work!");
|
||||
@@ -253,7 +252,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.findOne(query, PersonWithAList.class)).consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.getWishList().size(), is(1));
|
||||
assertThat(actual.getWishList()).hasSize(1);
|
||||
}).verifyComplete();
|
||||
|
||||
Friend friend = new Friend();
|
||||
@@ -265,8 +264,8 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.findOne(query, PersonWithAList.class)).consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.getWishList().size(), is(1));
|
||||
assertThat(actual.getFriends().size(), is(1));
|
||||
assertThat(actual.getWishList()).hasSize(1);
|
||||
assertThat(actual.getFriends()).hasSize(1);
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@@ -285,7 +284,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.findOne(query, PersonWithAList.class)).consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.getFirstName(), is("Mark"));
|
||||
assertThat(actual.getFirstName()).isEqualTo("Mark");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@@ -315,7 +314,7 @@ public class ReactiveMongoTemplateTests {
|
||||
.flatMapMany(p -> template.find(new Query(where("age").is(25)), Person.class)))
|
||||
.consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.getFirstName(), is(equalTo("Sven")));
|
||||
assertThat(actual.getFirstName()).isEqualTo("Sven");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@@ -329,7 +328,7 @@ public class ReactiveMongoTemplateTests {
|
||||
.flatMapMany(p -> template.find(new Query(where("age").is(25)), Person.class, "people")))
|
||||
.consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.getFirstName(), is(equalTo("Sven")));
|
||||
assertThat(actual.getFirstName()).isEqualTo("Sven");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@@ -431,29 +430,29 @@ public class ReactiveMongoTemplateTests {
|
||||
Update update = new Update().inc("age", 1);
|
||||
|
||||
Person p = template.findAndModify(query, update, Person.class).block(); // return old
|
||||
assertThat(p.getFirstName(), is("Harry"));
|
||||
assertThat(p.getAge(), is(23));
|
||||
assertThat(p.getFirstName()).isEqualTo("Harry");
|
||||
assertThat(p.getAge()).isEqualTo(23);
|
||||
p = template.findOne(query, Person.class).block();
|
||||
assertThat(p.getAge(), is(24));
|
||||
assertThat(p.getAge()).isEqualTo(24);
|
||||
|
||||
p = template.findAndModify(query, update, Person.class, "person").block();
|
||||
assertThat(p.getAge(), is(24));
|
||||
assertThat(p.getAge()).isEqualTo(24);
|
||||
p = template.findOne(query, Person.class).block();
|
||||
assertThat(p.getAge(), is(25));
|
||||
assertThat(p.getAge()).isEqualTo(25);
|
||||
|
||||
p = template.findAndModify(query, update, new FindAndModifyOptions().returnNew(true), Person.class).block();
|
||||
assertThat(p.getAge(), is(26));
|
||||
assertThat(p.getAge()).isEqualTo(26);
|
||||
|
||||
p = template.findAndModify(query, update, null, Person.class, "person").block();
|
||||
assertThat(p.getAge(), is(26));
|
||||
assertThat(p.getAge()).isEqualTo(26);
|
||||
p = template.findOne(query, Person.class).block();
|
||||
assertThat(p.getAge(), is(27));
|
||||
assertThat(p.getAge()).isEqualTo(27);
|
||||
|
||||
Query query2 = new Query(where("firstName").is("Mary"));
|
||||
p = template.findAndModify(query2, update, new FindAndModifyOptions().returnNew(true).upsert(true), Person.class)
|
||||
.block();
|
||||
assertThat(p.getFirstName(), is("Mary"));
|
||||
assertThat(p.getAge(), is(1));
|
||||
assertThat(p.getFirstName()).isEqualTo("Mary");
|
||||
assertThat(p.getAge()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1827
|
||||
@@ -468,7 +467,7 @@ public class ReactiveMongoTemplateTests {
|
||||
org.bson.Document.class, "findandreplace") //
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(actual -> {
|
||||
assertThat(actual, hasEntry("foo", "bar"));
|
||||
assertThat(actual).containsEntry("foo", "bar");
|
||||
}).verifyComplete();
|
||||
|
||||
template.findOne(query(where("foo").is("baz")), org.bson.Document.class, "findandreplace") //
|
||||
@@ -486,7 +485,7 @@ public class ReactiveMongoTemplateTests {
|
||||
template.findAndReplace(query(where("name").is("Walter")), new MyPerson("Heisenberg")) //
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(actual -> {
|
||||
assertThat(actual.getName(), is("Walter"));
|
||||
assertThat(actual.getName()).isEqualTo("Walter");
|
||||
}).verifyComplete();
|
||||
|
||||
template.findOne(query(where("name").is("Heisenberg")), MyPerson.class) //
|
||||
@@ -504,7 +503,7 @@ public class ReactiveMongoTemplateTests {
|
||||
FindAndReplaceOptions.options().returnNew(true))
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(actual -> {
|
||||
assertThat(actual.getName(), is("Heisenberg"));
|
||||
assertThat(actual.getName()).isEqualTo("Heisenberg");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@@ -617,7 +616,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.findAll(PersonWithVersionPropertyOfTypeInteger.class)).consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.version, is(0));
|
||||
assertThat(actual.version).isZero();
|
||||
}).verifyComplete();
|
||||
|
||||
StepVerifier.create(template.findAll(PersonWithVersionPropertyOfTypeInteger.class).flatMap(p -> {
|
||||
@@ -627,11 +626,11 @@ public class ReactiveMongoTemplateTests {
|
||||
return template.save(person);
|
||||
})).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(person.version, is(1));
|
||||
assertThat(person.version).isOne();
|
||||
|
||||
StepVerifier.create(template.findAll(PersonWithVersionPropertyOfTypeInteger.class)).consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.version, is(1));
|
||||
assertThat(actual.version).isOne();
|
||||
}).verifyComplete();
|
||||
|
||||
// Optimistic lock exception
|
||||
@@ -697,7 +696,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.save(dbObject, "collection")).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(dbObject.containsKey("_id"), is(true));
|
||||
assertThat(dbObject.containsKey("_id")).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = MappingException.class) // DATAMONGO-1444, DATAMONGO-1730
|
||||
@@ -721,8 +720,8 @@ public class ReactiveMongoTemplateTests {
|
||||
StepVerifier.create(template.findById(dbObject.get("_id"), Document.class, "collection")) //
|
||||
.consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.get("foo"), is(dbObject.get("foo")));
|
||||
assertThat(actual.get("_id"), is(dbObject.get("_id")));
|
||||
assertThat(actual.get("foo")).isEqualTo(dbObject.get("foo"));
|
||||
assertThat(actual.get("_id")).isEqualTo(dbObject.get("_id"));
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@@ -776,7 +775,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.insert(person)).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(person.version, is(0));
|
||||
assertThat(person.version).isZero();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -787,7 +786,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.insertAll(Collections.singleton(person))).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(person.version, is(0));
|
||||
assertThat(person.version).isZero();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -805,10 +804,10 @@ public class ReactiveMongoTemplateTests {
|
||||
person.firstName = "Dave";
|
||||
|
||||
StepVerifier.create(template.save(person, "personX")).expectNextCount(1).verifyComplete();
|
||||
assertThat(person.version, is(0));
|
||||
assertThat(person.version).isZero();
|
||||
|
||||
StepVerifier.create(template.save(person, "personX")).expectNextCount(1).verifyComplete();
|
||||
assertThat(person.version, is(1));
|
||||
assertThat(person.version).isOne();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -818,7 +817,7 @@ public class ReactiveMongoTemplateTests {
|
||||
person.firstName = "Dave";
|
||||
|
||||
StepVerifier.create(template.save(person, "personX")).expectNextCount(1).verifyComplete();
|
||||
assertThat(person.version, is(0L));
|
||||
assertThat(person.version).isZero();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -852,7 +851,7 @@ public class ReactiveMongoTemplateTests {
|
||||
person.firstName = "Dave";
|
||||
|
||||
StepVerifier.create(template.save(person)).expectNextCount(1).verifyComplete();
|
||||
assertThat(person.version, is(0));
|
||||
assertThat(person.version).isZero();
|
||||
|
||||
person.version = null;
|
||||
StepVerifier.create(template.save(person)).expectError(DuplicateKeyException.class).verify();
|
||||
@@ -881,7 +880,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
StepVerifier.create(template.save(person)).expectNextCount(1).verifyComplete();
|
||||
|
||||
assertThat(person.id, is(notNullValue()));
|
||||
assertThat(person.id).isNotNull();
|
||||
|
||||
person.lastname = null;
|
||||
StepVerifier.create(template.save(person)).expectNextCount(1).verifyComplete();
|
||||
@@ -889,7 +888,7 @@ public class ReactiveMongoTemplateTests {
|
||||
StepVerifier.create(template.findOne(query(where("id").is(person.id)), VersionedPerson.class)) //
|
||||
.consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.lastname, is(nullValue()));
|
||||
assertThat(actual.lastname).isNull();
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
@@ -906,7 +905,7 @@ public class ReactiveMongoTemplateTests {
|
||||
StepVerifier.create(template.findOne(query(where("id").is(person.getId())), Person.class)) //
|
||||
.consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.getFirstName(), is(nullValue()));
|
||||
assertThat(actual.getFirstName()).isNull();
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
@@ -921,7 +920,7 @@ public class ReactiveMongoTemplateTests {
|
||||
StepVerifier.create(template.findAll(Document.class, "collection")) //
|
||||
.consumeNextWith(actual -> {
|
||||
|
||||
assertThat(actual.containsKey("first"), is(true));
|
||||
assertThat(actual.containsKey("first")).isTrue();
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
@@ -959,8 +958,8 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
Disposable disposable = capped.doOnNext(documents::add).subscribe();
|
||||
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
assertThat(documents.isEmpty(), is(true));
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS)).isNotNull();
|
||||
assertThat(documents).isEmpty();
|
||||
|
||||
disposable.dispose();
|
||||
}
|
||||
@@ -981,14 +980,14 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
Disposable disposable = capped.doOnNext(documents::add).subscribe();
|
||||
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
assertThat(documents.isEmpty(), is(true));
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS)).isNotNull();
|
||||
assertThat(documents).isEmpty();
|
||||
|
||||
StepVerifier.create(template.insert(new Document("random", Math.random()).append("key", "value"), "capped")) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS)).isNotNull();
|
||||
|
||||
disposable.dispose();
|
||||
|
||||
@@ -996,7 +995,7 @@ public class ReactiveMongoTemplateTests {
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(documents.poll(1, TimeUnit.SECONDS), is(nullValue()));
|
||||
assertThat(documents.poll(1, TimeUnit.SECONDS)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1761
|
||||
|
||||
Reference in New Issue
Block a user