DATAMONGO-1762 - Add @Nullable and @NonNullApi annotations.
Marked all packages with Spring Frameworks @NonNullApi. Added Spring's @Nullable to methods, parameters and fields that take or produce null values. Adapted using code to make sure the IDE can evaluate the null flow properly. Fixed Javadoc in places where an invalid null handling policy was advertised. Strengthened null requirements for types that expose null-instances.
This commit is contained in:
committed by
Mark Paluch
parent
e28bede416
commit
bdd5c9dec7
@@ -25,6 +25,7 @@ import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.MongoCredential;
|
||||
@@ -51,7 +52,7 @@ public class MongoCredentialPropertyEditor extends PropertyEditorSupport {
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
public void setAsText(@Nullable String text) throws IllegalArgumentException {
|
||||
|
||||
if (!StringUtils.hasText(text)) {
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.mongodb.config;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.ReadPreference;
|
||||
|
||||
/**
|
||||
@@ -32,7 +34,7 @@ public class ReadPreferencePropertyEditor extends PropertyEditorSupport {
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String readPreferenceString) throws IllegalArgumentException {
|
||||
public void setAsText(@Nullable String readPreferenceString) throws IllegalArgumentException {
|
||||
|
||||
if (readPreferenceString == null) {
|
||||
return;
|
||||
@@ -59,8 +61,8 @@ public class ReadPreferencePropertyEditor extends PropertyEditorSupport {
|
||||
} else if ("NEAREST".equalsIgnoreCase(readPreferenceString)) {
|
||||
setValue(ReadPreference.nearest());
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("Cannot find matching ReadPreference for %s",
|
||||
readPreferenceString));
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Cannot find matching ReadPreference for %s", readPreferenceString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -34,6 +35,7 @@ import com.mongodb.ServerAddress;
|
||||
* @author Mark Pollack
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class ServerAddressPropertyEditor extends PropertyEditorSupport {
|
||||
|
||||
@@ -49,7 +51,7 @@ public class ServerAddressPropertyEditor extends PropertyEditorSupport {
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String replicaSetString) {
|
||||
public void setAsText(@Nullable String replicaSetString) {
|
||||
|
||||
if (!StringUtils.hasText(replicaSetString)) {
|
||||
setValue(null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,9 @@ package org.springframework.data.mongodb.config;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.WriteConcern;
|
||||
|
||||
/**
|
||||
@@ -26,6 +29,7 @@ import com.mongodb.WriteConcern;
|
||||
* string value.
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class WriteConcernPropertyEditor extends PropertyEditorSupport {
|
||||
|
||||
@@ -33,7 +37,11 @@ public class WriteConcernPropertyEditor extends PropertyEditorSupport {
|
||||
* Parse a string to a List<ServerAddress>
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String writeConcernString) {
|
||||
public void setAsText(@Nullable String writeConcernString) {
|
||||
|
||||
if (!StringUtils.hasText(writeConcernString)) {
|
||||
return;
|
||||
}
|
||||
|
||||
WriteConcern writeConcern = WriteConcern.valueOf(writeConcernString);
|
||||
if (writeConcern != null) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Spring XML namespace configuration for MongoDB specific repositories.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.config;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,12 +17,13 @@ package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
/**
|
||||
* Callback interface for executing actions against a {@link MongoCollection}
|
||||
* Callback interface for executing actions against a {@link MongoCollection}.
|
||||
*
|
||||
* @author Mark Pollak
|
||||
* @author Grame Rocher
|
||||
@@ -35,10 +36,11 @@ public interface CollectionCallback<T> {
|
||||
|
||||
/**
|
||||
* @param collection never {@literal null}.
|
||||
* @return
|
||||
* @return can be {@literal null}.
|
||||
* @throws MongoException
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
@Nullable
|
||||
T doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -29,26 +30,27 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class CollectionOptions {
|
||||
|
||||
private Long maxDocuments;
|
||||
private Long size;
|
||||
private Boolean capped;
|
||||
private Collation collation;
|
||||
private @Nullable Long maxDocuments;
|
||||
private @Nullable Long size;
|
||||
private @Nullable Boolean capped;
|
||||
private @Nullable Collation collation;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>CollectionOptions</code> instance.
|
||||
*
|
||||
* @param size the collection size in bytes, this data space is preallocated.
|
||||
* @param maxDocuments the maximum number of documents in the collection.
|
||||
* @param size the collection size in bytes, this data space is preallocated. Can be {@literal null}.
|
||||
* @param maxDocuments the maximum number of documents in the collection. Can be {@literal null}.
|
||||
* @param capped true to created a "capped" collection (fixed size with auto-FIFO behavior based on insertion order),
|
||||
* false otherwise.
|
||||
* false otherwise. Can be {@literal null}.
|
||||
* @deprecated since 2.0 please use {@link CollectionOptions#empty()} as entry point.
|
||||
*/
|
||||
@Deprecated
|
||||
public CollectionOptions(Long size, Long maxDocuments, Boolean capped) {
|
||||
public CollectionOptions(@Nullable Long size, @Nullable Long maxDocuments, @Nullable Boolean capped) {
|
||||
this(size, maxDocuments, capped, null);
|
||||
}
|
||||
|
||||
private CollectionOptions(Long size, Long maxDocuments, Boolean capped, Collation collation) {
|
||||
private CollectionOptions(@Nullable Long size, @Nullable Long maxDocuments, @Nullable Boolean capped,
|
||||
@Nullable Collation collation) {
|
||||
|
||||
this.maxDocuments = maxDocuments;
|
||||
this.size = size;
|
||||
@@ -120,7 +122,7 @@ public class CollectionOptions {
|
||||
* @return new {@link CollectionOptions}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public CollectionOptions collation(Collation collation) {
|
||||
public CollectionOptions collation(@Nullable Collation collation) {
|
||||
return new CollectionOptions(size, maxDocuments, capped, collation);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +16,29 @@
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
/**
|
||||
* Callback interface for executing actions against a {@link MongoDatabase}.
|
||||
*
|
||||
* @param <T>
|
||||
* @author Mark Pollak
|
||||
* @author Graeme Rocher
|
||||
* @author Thomas Risberg
|
||||
* @author Oliver Gierke
|
||||
* @author John Brisbin
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface DbCallback<T> {
|
||||
|
||||
/**
|
||||
* @param db must not be {@literal null}.
|
||||
* @return can be {@literal null}.
|
||||
* @throws MongoException
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
@Nullable
|
||||
T doInDB(MongoDatabase db) throws MongoException, DataAccessException;
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import org.springframework.transaction.support.ResourceHolderSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
class DbHolder extends ResourceHolderSupport {
|
||||
private static final Object DEFAULT_KEY = new Object();
|
||||
|
||||
private final Map<Object, DB> dbMap = new ConcurrentHashMap<Object, DB>();
|
||||
|
||||
public DbHolder(DB db) {
|
||||
addDB(db);
|
||||
}
|
||||
|
||||
public DbHolder(Object key, DB db) {
|
||||
addDB(key, db);
|
||||
}
|
||||
|
||||
public DB getDB() {
|
||||
return getDB(DEFAULT_KEY);
|
||||
}
|
||||
|
||||
public DB getDB(Object key) {
|
||||
return this.dbMap.get(key);
|
||||
}
|
||||
|
||||
public DB getAnyDB() {
|
||||
if (!this.dbMap.isEmpty()) {
|
||||
return this.dbMap.values().iterator().next();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addDB(DB session) {
|
||||
addDB(DEFAULT_KEY, session);
|
||||
}
|
||||
|
||||
public void addDB(Object key, DB session) {
|
||||
Assert.notNull(key, "Key must not be null");
|
||||
Assert.notNull(session, "DB must not be null");
|
||||
this.dbMap.put(key, session);
|
||||
}
|
||||
|
||||
public DB removeDB(Object key) {
|
||||
return this.dbMap.remove(key);
|
||||
}
|
||||
|
||||
public boolean containsDB(DB session) {
|
||||
return this.dbMap.containsValue(session);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.dbMap.isEmpty();
|
||||
}
|
||||
|
||||
public boolean doesNotHoldNonDefaultDB() {
|
||||
synchronized (this.dbMap) {
|
||||
return this.dbMap.isEmpty() || (this.dbMap.size() == 1 && this.dbMap.containsKey(DEFAULT_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.BulkWriteException;
|
||||
@@ -67,7 +68,7 @@ class DefaultBulkOperations implements BulkOperations {
|
||||
private final List<WriteModel<Document>> models = new ArrayList<>();
|
||||
|
||||
private PersistenceExceptionTranslator exceptionTranslator;
|
||||
private WriteConcern defaultWriteConcern;
|
||||
private @Nullable WriteConcern defaultWriteConcern;
|
||||
|
||||
private BulkWriteOptions bulkOptions;
|
||||
|
||||
@@ -99,7 +100,7 @@ class DefaultBulkOperations implements BulkOperations {
|
||||
*
|
||||
* @param exceptionTranslator can be {@literal null}.
|
||||
*/
|
||||
public void setExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) {
|
||||
public void setExceptionTranslator(@Nullable PersistenceExceptionTranslator exceptionTranslator) {
|
||||
this.exceptionTranslator = exceptionTranslator == null ? new MongoExceptionTranslator() : exceptionTranslator;
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ class DefaultBulkOperations implements BulkOperations {
|
||||
*
|
||||
* @param defaultWriteConcern can be {@literal null}.
|
||||
*/
|
||||
void setDefaultWriteConcern(WriteConcern defaultWriteConcern) {
|
||||
void setDefaultWriteConcern(@Nullable WriteConcern defaultWriteConcern) {
|
||||
this.defaultWriteConcern = defaultWriteConcern;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.data.mongodb.core.index.IndexDefinition;
|
||||
import org.springframework.data.mongodb.core.index.IndexInfo;
|
||||
import org.springframework.data.mongodb.core.index.IndexOperations;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
@@ -52,7 +53,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
private final MongoDbFactory mongoDbFactory;
|
||||
private final String collectionName;
|
||||
private final QueryMapper mapper;
|
||||
private final Class<?> type;
|
||||
private final @Nullable Class<?> type;
|
||||
|
||||
/**
|
||||
* Creates a new {@link DefaultIndexOperations}.
|
||||
@@ -62,7 +63,6 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
* @param queryMapper must not be {@literal null}.
|
||||
*/
|
||||
public DefaultIndexOperations(MongoDbFactory mongoDbFactory, String collectionName, QueryMapper queryMapper) {
|
||||
|
||||
this(mongoDbFactory, collectionName, queryMapper, null);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
* @since 1.10
|
||||
*/
|
||||
public DefaultIndexOperations(MongoDbFactory mongoDbFactory, String collectionName, QueryMapper queryMapper,
|
||||
Class<?> type) {
|
||||
@Nullable Class<?> type) {
|
||||
|
||||
Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null!");
|
||||
Assert.notNull(collectionName, "Collection name can not be null!");
|
||||
@@ -116,7 +116,8 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
});
|
||||
}
|
||||
|
||||
private MongoPersistentEntity<?> lookupPersistentEntity(Class<?> entityType, String collection) {
|
||||
@Nullable
|
||||
private MongoPersistentEntity<?> lookupPersistentEntity(@Nullable Class<?> entityType, String collection) {
|
||||
|
||||
if (entityType != null) {
|
||||
return mapper.getMappingContext().getRequiredPersistentEntity(entityType);
|
||||
@@ -185,6 +186,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T execute(CollectionCallback<T> callback) {
|
||||
|
||||
Assert.notNull(callback, "CollectionCallback must not be null!");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,10 +21,10 @@ import org.springframework.data.mongodb.core.index.IndexOperations;
|
||||
import org.springframework.data.mongodb.core.index.IndexOperationsProvider;
|
||||
|
||||
/**
|
||||
* {@link IndexOperationsProvider} to obtain {@link IndexOperations} from a given {@link MongoDbFactory}. TODO: Review
|
||||
* me
|
||||
* {@link IndexOperationsProvider} to obtain {@link IndexOperations} from a given {@link MongoDbFactory}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0
|
||||
*/
|
||||
class DefaultIndexOperationsProvider implements IndexOperationsProvider {
|
||||
@@ -34,12 +34,16 @@ class DefaultIndexOperationsProvider implements IndexOperationsProvider {
|
||||
|
||||
/**
|
||||
* @param mongoDbFactory must not be {@literal null}.
|
||||
* @param mapper must not be {@literal null}.
|
||||
*/
|
||||
DefaultIndexOperationsProvider(MongoDbFactory mongoDbFactory, QueryMapper mapper) {
|
||||
this.mongoDbFactory = mongoDbFactory; this.mapper = mapper;
|
||||
|
||||
this.mongoDbFactory = mongoDbFactory;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.index.IndexOperationsProvider#reactiveIndexOps(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.springframework.data.mongodb.core.index.ReactiveIndexOperations;
|
||||
import org.springframework.lang.Nullable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -68,7 +69,7 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
|
||||
* @param type used for mapping potential partial index filter expression, must not be {@literal null}.
|
||||
*/
|
||||
public DefaultReactiveIndexOperations(ReactiveMongoOperations mongoOperations, String collectionName,
|
||||
QueryMapper queryMapper, Class<?> type) {
|
||||
QueryMapper queryMapper, @Nullable Class<?> type) {
|
||||
this(mongoOperations, collectionName, queryMapper, Optional.of(type));
|
||||
}
|
||||
|
||||
@@ -85,7 +86,8 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.index.ReactiveIndexOperations#ensureIndex(org.springframework.data.mongodb.core.index.IndexDefinition)
|
||||
*/
|
||||
public Mono<String> ensureIndex(final IndexDefinition indexDefinition) {
|
||||
@@ -117,6 +119,7 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
|
||||
}).next();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MongoPersistentEntity<?> lookupPersistentEntity(String collection) {
|
||||
|
||||
Collection<? extends MongoPersistentEntity<?>> entities = queryMapper.getMappingContext().getPersistentEntities();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import org.bson.types.ObjectId;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.mongodb.core.script.ExecutableMongoScript;
|
||||
import org.springframework.data.mongodb.core.script.NamedMongoScript;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -56,7 +57,7 @@ class DefaultScriptOperations implements ScriptOperations {
|
||||
|
||||
/**
|
||||
* Creates new {@link DefaultScriptOperations} using given {@link MongoOperations}.
|
||||
*
|
||||
*
|
||||
* @param mongoOperations must not be {@literal null}.
|
||||
*/
|
||||
public DefaultScriptOperations(MongoOperations mongoOperations) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
||||
import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -74,8 +75,8 @@ class ExecutableAggregationOperationSupport implements ExecutableAggregationOper
|
||||
|
||||
@NonNull MongoTemplate template;
|
||||
@NonNull Class<T> domainType;
|
||||
Aggregation aggregation;
|
||||
String collection;
|
||||
@Nullable Aggregation aggregation;
|
||||
@Nullable String collection;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.stream.Stream;
|
||||
import org.springframework.data.geo.GeoResults;
|
||||
import org.springframework.data.mongodb.core.query.NearQuery;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link ExecutableFindOperation} allows creation and execution of MongoDB find operations in a fluent API style.
|
||||
@@ -83,6 +84,7 @@ public interface ExecutableFindOperation {
|
||||
* @return {@literal null} if no match found.
|
||||
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
|
||||
*/
|
||||
@Nullable
|
||||
T oneValue();
|
||||
|
||||
/**
|
||||
@@ -99,6 +101,7 @@ public interface ExecutableFindOperation {
|
||||
*
|
||||
* @return {@literal null} if no match found.
|
||||
*/
|
||||
@Nullable
|
||||
T firstValue();
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.SerializationUtils;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.data.util.StreamUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -88,7 +89,7 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
|
||||
@NonNull MongoTemplate template;
|
||||
@NonNull Class<?> domainType;
|
||||
Class<T> returnType;
|
||||
String collection;
|
||||
@Nullable String collection;
|
||||
Query query;
|
||||
|
||||
/*
|
||||
@@ -204,7 +205,7 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
|
||||
return template.exists(query, domainType, getCollectionName());
|
||||
}
|
||||
|
||||
private List<T> doFind(CursorPreparer preparer) {
|
||||
private List<T> doFind(@Nullable CursorPreparer preparer) {
|
||||
|
||||
Document queryObject = query.getQueryObject();
|
||||
Document fieldsObject = query.getFieldsObject();
|
||||
@@ -217,8 +218,8 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
|
||||
return template.doStream(query, domainType, getCollectionName(), returnType);
|
||||
}
|
||||
|
||||
private CursorPreparer getCursorPreparer(Query query, CursorPreparer preparer) {
|
||||
return query == null || preparer != null ? preparer : template.new QueryCursorPreparer(query, domainType);
|
||||
private CursorPreparer getCursorPreparer(Query query, @Nullable CursorPreparer preparer) {
|
||||
return preparer != null ? preparer : template.new QueryCursorPreparer(query, domainType);
|
||||
}
|
||||
|
||||
private String getCollectionName() {
|
||||
@@ -236,10 +237,10 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
|
||||
*/
|
||||
static class DelegatingQueryCursorPreparer implements CursorPreparer {
|
||||
|
||||
private final CursorPreparer delegate;
|
||||
private final @Nullable CursorPreparer delegate;
|
||||
private Optional<Integer> limit = Optional.empty();
|
||||
|
||||
DelegatingQueryCursorPreparer(CursorPreparer delegate) {
|
||||
DelegatingQueryCursorPreparer(@Nullable CursorPreparer delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -75,8 +76,8 @@ class ExecutableInsertOperationSupport implements ExecutableInsertOperation {
|
||||
|
||||
@NonNull MongoTemplate template;
|
||||
@NonNull Class<T> domainType;
|
||||
String collection;
|
||||
BulkMode bulkMode;
|
||||
@Nullable String collection;
|
||||
@Nullable BulkMode bulkMode;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -23,6 +23,7 @@ import lombok.experimental.FieldDefaults;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -77,7 +78,7 @@ class ExecutableRemoveOperationSupport implements ExecutableRemoveOperation {
|
||||
@NonNull MongoTemplate template;
|
||||
@NonNull Class<T> domainType;
|
||||
Query query;
|
||||
String collection;
|
||||
@Nullable String collection;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link ExecutableUpdateOperation} allows creation and execution of MongoDB update / findAndModify operations in a
|
||||
@@ -148,6 +149,7 @@ public interface ExecutableUpdateOperation {
|
||||
*
|
||||
* @return {@literal null} if nothing found.
|
||||
*/
|
||||
@Nullable
|
||||
T findAndModifyValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import lombok.experimental.FieldDefaults;
|
||||
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -76,9 +77,9 @@ class ExecutableUpdateOperationSupport implements ExecutableUpdateOperation {
|
||||
@NonNull MongoTemplate template;
|
||||
@NonNull Class<T> domainType;
|
||||
Query query;
|
||||
Update update;
|
||||
String collection;
|
||||
FindAndModifyOptions options;
|
||||
@Nullable Update update;
|
||||
@Nullable String collection;
|
||||
@Nullable FindAndModifyOptions options;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -160,8 +161,8 @@ class ExecutableUpdateOperationSupport implements ExecutableUpdateOperation {
|
||||
* @see org.springframework.data.mongodb.core.ExecutableUpdateOperation.TerminatingFindAndModify#findAndModifyValue()
|
||||
*/
|
||||
@Override
|
||||
public T findAndModifyValue() {
|
||||
return template.findAndModify(query, update, options, domainType, getCollectionName());
|
||||
public @Nullable T findAndModifyValue() {
|
||||
return template.findAndModify(query, update, options != null ? options : new FindAndModifyOptions(), domainType, getCollectionName());
|
||||
}
|
||||
|
||||
private UpdateResult doUpdate(boolean multi, boolean upsert) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Mark Pollak
|
||||
@@ -30,7 +31,7 @@ public class FindAndModifyOptions {
|
||||
private boolean upsert;
|
||||
private boolean remove;
|
||||
|
||||
private Collation collation;
|
||||
private @Nullable Collation collation;
|
||||
|
||||
/**
|
||||
* Static factory method to create a FindAndModifyOptions instance
|
||||
@@ -46,7 +47,7 @@ public class FindAndModifyOptions {
|
||||
* @return
|
||||
* @since 2.0
|
||||
*/
|
||||
public static FindAndModifyOptions of(FindAndModifyOptions source) {
|
||||
public static FindAndModifyOptions of(@Nullable FindAndModifyOptions source) {
|
||||
|
||||
FindAndModifyOptions options = new FindAndModifyOptions();
|
||||
if (source == null) {
|
||||
@@ -83,7 +84,7 @@ public class FindAndModifyOptions {
|
||||
* @return
|
||||
* @since 2.0
|
||||
*/
|
||||
public FindAndModifyOptions collation(Collation collation) {
|
||||
public FindAndModifyOptions collation(@Nullable Collation collation) {
|
||||
|
||||
this.collation = collation;
|
||||
return this;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import org.bson.Document;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.mongodb.core.index.IndexDefinition;
|
||||
import org.springframework.data.mongodb.core.index.IndexInfo;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.mongodb.client.model.Collation;
|
||||
@@ -119,7 +120,8 @@ abstract class IndexConverters {
|
||||
};
|
||||
}
|
||||
|
||||
public static Collation fromDocument(Document source) {
|
||||
@Nullable
|
||||
public static Collation fromDocument(@Nullable Document source) {
|
||||
|
||||
if (source == null) {
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.WriteConcern;
|
||||
@@ -36,26 +37,28 @@ import com.mongodb.WriteConcern;
|
||||
public class MongoAction {
|
||||
|
||||
private final String collectionName;
|
||||
private final WriteConcern defaultWriteConcern;
|
||||
private final Class<?> entityType;
|
||||
private final MongoActionOperation mongoActionOperation;
|
||||
private final Document query;
|
||||
private final Document document;
|
||||
|
||||
private final @Nullable WriteConcern defaultWriteConcern;
|
||||
private final @Nullable Class<?> entityType;
|
||||
private final @Nullable Document query;
|
||||
private final @Nullable Document document;
|
||||
|
||||
/**
|
||||
* Create an instance of a {@link MongoAction}.
|
||||
*
|
||||
* @param defaultWriteConcern the default write concern.
|
||||
* @param mongoActionOperation action being taken against the collection
|
||||
* @param defaultWriteConcern the default write concern. Can be {@literal null}.
|
||||
* @param mongoActionOperation action being taken against the collection. Must not be {@literal null}.
|
||||
* @param collectionName the collection name, must not be {@literal null} or empty.
|
||||
* @param entityType the POJO that is being operated against
|
||||
* @param document the converted Document from the POJO or Spring Update object
|
||||
* @param query the converted Document from the Spring Query object
|
||||
* @param entityType the POJO that is being operated against. Can be {@literal null}.
|
||||
* @param document the converted Document from the POJO or Spring Update object. Can be {@literal null}.
|
||||
* @param query the converted Document from the Spring Query object. Can be {@literal null}.
|
||||
*/
|
||||
public MongoAction(WriteConcern defaultWriteConcern, MongoActionOperation mongoActionOperation, String collectionName,
|
||||
Class<?> entityType, Document document, Document query) {
|
||||
public MongoAction(@Nullable WriteConcern defaultWriteConcern, MongoActionOperation mongoActionOperation,
|
||||
String collectionName, @Nullable Class<?> entityType, @Nullable Document document, @Nullable Document query) {
|
||||
|
||||
Assert.hasText(collectionName, "Collection name must not be null or empty!");
|
||||
Assert.notNull(mongoActionOperation, "MongoActionOperation must not be null!");
|
||||
|
||||
this.defaultWriteConcern = defaultWriteConcern;
|
||||
this.mongoActionOperation = mongoActionOperation;
|
||||
@@ -69,22 +72,27 @@ public class MongoAction {
|
||||
return collectionName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public WriteConcern getDefaultWriteConcern() {
|
||||
return defaultWriteConcern;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<?> getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MongoActionOperation getMongoActionOperation() {
|
||||
return mongoActionOperation;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Document getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Document getDocument() {
|
||||
return document;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
/**
|
||||
* Mongo server administration exposed via JMX annotations
|
||||
*
|
||||
@@ -42,35 +43,35 @@ public class MongoAdmin implements MongoAdminOperations {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.core.MongoAdminOperations#dropDatabase(java.lang.String)
|
||||
*/
|
||||
* @see org.springframework.data.mongodb.core.core.MongoAdminOperations#dropDatabase(java.lang.String)
|
||||
*/
|
||||
@ManagedOperation
|
||||
public void dropDatabase(String databaseName) {
|
||||
getDB(databaseName).drop();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.core.MongoAdminOperations#createDatabase(java.lang.String)
|
||||
*/
|
||||
* @see org.springframework.data.mongodb.core.core.MongoAdminOperations#createDatabase(java.lang.String)
|
||||
*/
|
||||
@ManagedOperation
|
||||
public void createDatabase(String databaseName) {
|
||||
getDB(databaseName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.core.MongoAdminOperations#getDatabaseStats(java.lang.String)
|
||||
*/
|
||||
* @see org.springframework.data.mongodb.core.core.MongoAdminOperations#getDatabaseStats(java.lang.String)
|
||||
*/
|
||||
@ManagedOperation
|
||||
public String getDatabaseStats(String databaseName) {
|
||||
return getDB(databaseName).runCommand(new Document("dbStats", 1).append("scale" , 1024)).toJson();
|
||||
return getDB(databaseName).runCommand(new Document("dbStats", 1).append("scale", 1024)).toJson();
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public String getServerStatus() {
|
||||
return getDB("admin").runCommand(new Document("serverStatus", 1).append("rangeDeleter", 1).append("repl", 1)).toJson();
|
||||
return getDB("admin").runCommand(new Document("serverStatus", 1).append("rangeDeleter", 1).append("repl", 1))
|
||||
.toJson();
|
||||
}
|
||||
|
||||
|
||||
MongoDatabase getDB(String databaseName) {
|
||||
return mongoClient.getDatabase(databaseName);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -41,11 +42,11 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
|
||||
private static final PersistenceExceptionTranslator DEFAULT_EXCEPTION_TRANSLATOR = new MongoExceptionTranslator();
|
||||
|
||||
private MongoClientOptions mongoClientOptions;
|
||||
private String host;
|
||||
private Integer port;
|
||||
private List<ServerAddress> replicaSetSeeds;
|
||||
private List<MongoCredential> credentials;
|
||||
private @Nullable MongoClientOptions mongoClientOptions;
|
||||
private @Nullable String host;
|
||||
private @Nullable Integer port;
|
||||
private List<ServerAddress> replicaSetSeeds = Collections.emptyList();
|
||||
private List<MongoCredential> credentials = Collections.emptyList();
|
||||
|
||||
private PersistenceExceptionTranslator exceptionTranslator = DEFAULT_EXCEPTION_TRANSLATOR;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
*
|
||||
* @param mongoClientOptions
|
||||
*/
|
||||
public void setMongoClientOptions(MongoClientOptions mongoClientOptions) {
|
||||
public void setMongoClientOptions(@Nullable MongoClientOptions mongoClientOptions) {
|
||||
this.mongoClientOptions = mongoClientOptions;
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
*
|
||||
* @param credentials can be {@literal null}.
|
||||
*/
|
||||
public void setCredentials(MongoCredential[] credentials) {
|
||||
public void setCredentials(@Nullable MongoCredential[] credentials) {
|
||||
this.credentials = filterNonNullElementsAsList(credentials);
|
||||
}
|
||||
|
||||
@@ -72,7 +73,7 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
*
|
||||
* @param replicaSetSeeds can be {@literal null}.
|
||||
*/
|
||||
public void setReplicaSetSeeds(ServerAddress[] replicaSetSeeds) {
|
||||
public void setReplicaSetSeeds(@Nullable ServerAddress[] replicaSetSeeds) {
|
||||
this.replicaSetSeeds = filterNonNullElementsAsList(replicaSetSeeds);
|
||||
}
|
||||
|
||||
@@ -81,7 +82,7 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
*
|
||||
* @param host
|
||||
*/
|
||||
public void setHost(String host) {
|
||||
public void setHost(@Nullable String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
*
|
||||
* @param exceptionTranslator
|
||||
*/
|
||||
public void setExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) {
|
||||
public void setExceptionTranslator(@Nullable PersistenceExceptionTranslator exceptionTranslator) {
|
||||
this.exceptionTranslator = exceptionTranslator == null ? DEFAULT_EXCEPTION_TRANSLATOR : exceptionTranslator;
|
||||
}
|
||||
|
||||
@@ -115,6 +116,7 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.dao.support.PersistenceExceptionTranslator#translateExceptionIfPossible(java.lang.RuntimeException)
|
||||
*/
|
||||
@Nullable
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
return exceptionTranslator.translateExceptionIfPossible(ex);
|
||||
}
|
||||
@@ -142,8 +144,11 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
* @see org.springframework.beans.factory.config.AbstractFactoryBean#destroyInstance(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected void destroyInstance(MongoClient instance) throws Exception {
|
||||
instance.close();
|
||||
protected void destroyInstance(@Nullable MongoClient instance) throws Exception {
|
||||
|
||||
if (instance != null) {
|
||||
instance.close();
|
||||
}
|
||||
}
|
||||
|
||||
private MongoClient createMongoClient() throws UnknownHostException {
|
||||
@@ -169,7 +174,7 @@ public class MongoClientFactoryBean extends AbstractFactoryBean<MongoClient> imp
|
||||
* @param elements the elements to filter <T>, can be {@literal null}.
|
||||
* @return a new unmodifiable {@link List#} from the given elements without {@literal null}s.
|
||||
*/
|
||||
private static <T> List<T> filterNonNullElementsAsList(T[] elements) {
|
||||
private static <T> List<T> filterNonNullElementsAsList(@Nullable T[] elements) {
|
||||
|
||||
if (elements == null) {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientOptions;
|
||||
import com.mongodb.ReadPreference;
|
||||
import com.mongodb.WriteConcern;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* A factory bean for construction of a {@link MongoClientOptions} instance.
|
||||
@@ -66,14 +67,14 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
private int serverSelectionTimeout = DEFAULT_MONGO_OPTIONS.getServerSelectionTimeout();
|
||||
|
||||
private boolean ssl;
|
||||
private SSLSocketFactory sslSocketFactory;
|
||||
private @Nullable SSLSocketFactory sslSocketFactory;
|
||||
|
||||
/**
|
||||
* Set the {@link MongoClient} description.
|
||||
*
|
||||
* @param description
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
public void setDescription(@Nullable String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@@ -166,7 +167,7 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
*
|
||||
* @param readPreference
|
||||
*/
|
||||
public void setReadPreference(ReadPreference readPreference) {
|
||||
public void setReadPreference(@Nullable ReadPreference readPreference) {
|
||||
this.readPreference = readPreference;
|
||||
}
|
||||
|
||||
@@ -176,14 +177,14 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
*
|
||||
* @param writeConcern
|
||||
*/
|
||||
public void setWriteConcern(WriteConcern writeConcern) {
|
||||
public void setWriteConcern(@Nullable WriteConcern writeConcern) {
|
||||
this.writeConcern = writeConcern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param socketFactory
|
||||
*/
|
||||
public void setSocketFactory(SocketFactory socketFactory) {
|
||||
public void setSocketFactory(@Nullable SocketFactory socketFactory) {
|
||||
this.socketFactory = socketFactory;
|
||||
}
|
||||
|
||||
@@ -248,7 +249,7 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
*
|
||||
* @param sslSocketFactory
|
||||
*/
|
||||
public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
|
||||
public void setSslSocketFactory(@Nullable SSLSocketFactory sslSocketFactory) {
|
||||
|
||||
this.sslSocketFactory = sslSocketFactory;
|
||||
this.ssl = sslSocketFactory != null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.WriteResult;
|
||||
@@ -40,7 +41,7 @@ public class MongoDataIntegrityViolationException extends DataIntegrityViolation
|
||||
* @param actionOperation the {@link MongoActionOperation} that caused the exception, must not be {@literal null}.
|
||||
*/
|
||||
public MongoDataIntegrityViolationException(String message, WriteResult writeResult,
|
||||
MongoActionOperation actionOperation) {
|
||||
MongoActionOperation actionOperation) {
|
||||
|
||||
super(message);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.mongodb.BulkOperationException;
|
||||
import org.springframework.data.mongodb.UncategorizedMongoDbException;
|
||||
import org.springframework.data.mongodb.util.MongoDbErrorCodes;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.mongodb.BulkWriteException;
|
||||
@@ -67,6 +68,7 @@ public class MongoExceptionTranslator implements PersistenceExceptionTranslator
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.dao.support.PersistenceExceptionTranslator#translateExceptionIfPossible(java.lang.RuntimeException)
|
||||
*/
|
||||
@Nullable
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
|
||||
// Check for well-known MongoException subclasses.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import javax.validation.constraints.Null;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -38,6 +39,7 @@ 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.util.CloseableIterator;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.Cursor;
|
||||
import com.mongodb.ReadPreference;
|
||||
@@ -95,7 +97,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @return
|
||||
* @since 1.7
|
||||
*/
|
||||
Document executeCommand(Document command, ReadPreference readPreference);
|
||||
Document executeCommand(Document command, @Nullable ReadPreference readPreference);
|
||||
|
||||
/**
|
||||
* Execute a MongoDB query and iterate over the query results on a per-document basis with a DocumentCallbackHandler.
|
||||
@@ -112,10 +114,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||
*
|
||||
* @param action callback object that specifies the MongoDB actions to perform on the passed in DB instance. Must not
|
||||
* be {@literal null}.
|
||||
* @param <T> return type
|
||||
* @param action callback object that specifies the MongoDB actions to perform on the passed in DB instance.
|
||||
* @return a result object returned by the action or <tt>null</tt>
|
||||
* @return a result object returned by the action or {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T execute(DbCallback<T> action);
|
||||
|
||||
/**
|
||||
@@ -123,11 +127,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||
*
|
||||
* @param entityClass class that determines the collection to use
|
||||
* @param <T> return type
|
||||
* @param action callback object that specifies the MongoDB action
|
||||
* @return a result object returned by the action or <tt>null</tt>
|
||||
* @param entityClass class that determines the collection to use. Must not be {@literal null}.
|
||||
* @param action callback object that specifies the MongoDB action. Must not be {@literal null}.
|
||||
* @return a result object returned by the action or {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T execute(Class<?> entityClass, CollectionCallback<T> action);
|
||||
|
||||
/**
|
||||
@@ -136,10 +141,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||
*
|
||||
* @param <T> return type
|
||||
* @param collectionName the name of the collection that specifies which DBCollection instance will be passed into
|
||||
* @param action callback object that specifies the MongoDB action the callback action.
|
||||
* @return a result object returned by the action or <tt>null</tt>
|
||||
* @param collectionName the name of the collection that specifies which DBCollection instance will be passed into.
|
||||
* Must not be {@literal null} or empty.
|
||||
* @param action callback object that specifies the MongoDB action the callback action. Must not be {@literal null}.
|
||||
* @return a result object returned by the action or {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T execute(String collectionName, CollectionCallback<T> action);
|
||||
|
||||
/**
|
||||
@@ -182,11 +189,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Create a collection with a name based on the provided entity class using the options.
|
||||
*
|
||||
* @param entityClass class that determines the collection to create
|
||||
* @param entityClass class that determines the collection to create. Must not be {@literal null}.
|
||||
* @param collectionOptions options to use when creating the collection.
|
||||
* @return the created collection
|
||||
*/
|
||||
<T> MongoCollection<Document> createCollection(Class<T> entityClass, CollectionOptions collectionOptions);
|
||||
<T> MongoCollection<Document> createCollection(Class<T> entityClass, @Nullable CollectionOptions collectionOptions);
|
||||
|
||||
/**
|
||||
* Create an uncapped collection with the provided name.
|
||||
@@ -199,11 +206,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Create a collection with the provided name and options.
|
||||
*
|
||||
* @param collectionName name of the collection
|
||||
* @param collectionName name of the collection. Must not be {@literal null} nor empty.
|
||||
* @param collectionOptions options to use when creating the collection.
|
||||
* @return the created collection
|
||||
*/
|
||||
MongoCollection<Document> createCollection(String collectionName, CollectionOptions collectionOptions);
|
||||
MongoCollection<Document> createCollection(String collectionName, @Nullable CollectionOptions collectionOptions);
|
||||
|
||||
/**
|
||||
* A set of collection names.
|
||||
@@ -217,7 +224,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Translate any exceptions as necessary.
|
||||
*
|
||||
* @param collectionName name of the collection
|
||||
* @param collectionName name of the collection. Must not be {@literal null}.
|
||||
* @return an existing collection or a newly created one.
|
||||
*/
|
||||
MongoCollection<Document> getCollection(String collectionName);
|
||||
@@ -227,7 +234,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Translate any exceptions as necessary.
|
||||
*
|
||||
* @param entityClass class that determines the name of the collection
|
||||
* @param entityClass class that determines the name of the collection. Must not be {@literal null}.
|
||||
* @return true if a collection with the given name is found, false otherwise.
|
||||
*/
|
||||
<T> boolean collectionExists(Class<T> entityClass);
|
||||
@@ -237,7 +244,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Translate any exceptions as necessary.
|
||||
*
|
||||
* @param collectionName name of the collection
|
||||
* @param collectionName name of the collection. Must not be {@literal null}.
|
||||
* @return true if a collection with the given name is found, false otherwise.
|
||||
*/
|
||||
boolean collectionExists(String collectionName);
|
||||
@@ -247,7 +254,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Translate any exceptions as necessary.
|
||||
*
|
||||
* @param entityClass class that determines the collection to drop/delete.
|
||||
* @param entityClass class that determines the collection to drop/delete. Must not be {@literal null}.
|
||||
*/
|
||||
<T> void dropCollection(Class<T> entityClass);
|
||||
|
||||
@@ -307,11 +314,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Returns a new {@link BulkOperations} for the given entity type and collection name.
|
||||
*
|
||||
* @param mode the {@link BulkMode} to use for bulk operations, must not be {@literal null}.
|
||||
* @param entityClass the name of the entity class, must not be {@literal null}.
|
||||
* @param entityClass the name of the entity class. Can be {@literal null}.
|
||||
* @param collectionName the name of the collection to work on, must not be {@literal null} or empty.
|
||||
* @return {@link BulkOperations} on the named collection associated with the given entity class.
|
||||
*/
|
||||
BulkOperations bulkOps(BulkMode mode, Class<?> entityType, String collectionName);
|
||||
BulkOperations bulkOps(BulkMode mode, @Nullable Class<?> entityType, String collectionName);
|
||||
|
||||
/**
|
||||
* Query for a list of objects of type T from the collection used by the entity class.
|
||||
@@ -369,7 +376,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param entityClass The parametrized type of the returned list
|
||||
* @return The results of the group operation
|
||||
*/
|
||||
<T> GroupByResults<T> group(Criteria criteria, String inputCollectionName, GroupBy groupBy, Class<T> entityClass);
|
||||
<T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionName, GroupBy groupBy, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
* Execute an aggregation operation. The raw results will be mapped to the given entity class. The name of the
|
||||
@@ -500,11 +507,10 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Execute a map-reduce operation. The map-reduce operation will be formed with an output type of INLINE
|
||||
*
|
||||
* @param inputCollectionName the collection where the map-reduce will read from
|
||||
* @param mapFunction The JavaScript map function
|
||||
* @param inputCollectionName the collection where the map-reduce will read from. Must not be {@literal null}.
|
||||
* @param mapFunction The JavaScript map function.
|
||||
* @param reduceFunction The JavaScript reduce function
|
||||
* @param mapReduceOptions Options that specify detailed map-reduce behavior
|
||||
* @param entityClass The parametrized type of the returned list
|
||||
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
|
||||
* @return The results of the map reduce operation
|
||||
*/
|
||||
<T> MapReduceResults<T> mapReduce(String inputCollectionName, String mapFunction, String reduceFunction,
|
||||
@@ -513,26 +519,25 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Execute a map-reduce operation that takes additional map-reduce options.
|
||||
*
|
||||
* @param inputCollectionName the collection where the map-reduce will read from
|
||||
* @param inputCollectionName the collection where the map-reduce will read from. Must not be {@literal null}.
|
||||
* @param mapFunction The JavaScript map function
|
||||
* @param reduceFunction The JavaScript reduce function
|
||||
* @param mapReduceOptions Options that specify detailed map-reduce behavior
|
||||
* @param entityClass The parametrized type of the returned list
|
||||
* @param mapReduceOptions Options that specify detailed map-reduce behavior.
|
||||
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
|
||||
* @return The results of the map reduce operation
|
||||
*/
|
||||
<T> MapReduceResults<T> mapReduce(String inputCollectionName, String mapFunction, String reduceFunction,
|
||||
MapReduceOptions mapReduceOptions, Class<T> entityClass);
|
||||
@Nullable MapReduceOptions mapReduceOptions, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
* Execute a map-reduce operation that takes a query. The map-reduce operation will be formed with an output type of
|
||||
* INLINE
|
||||
*
|
||||
* @param query The query to use to select the data for the map phase
|
||||
* @param inputCollectionName the collection where the map-reduce will read from
|
||||
* @param query The query to use to select the data for the map phase. Must not be {@literal null}.
|
||||
* @param inputCollectionName the collection where the map-reduce will read from. Must not be {@literal null}.
|
||||
* @param mapFunction The JavaScript map function
|
||||
* @param reduceFunction The JavaScript reduce function
|
||||
* @param mapReduceOptions Options that specify detailed map-reduce behavior
|
||||
* @param entityClass The parametrized type of the returned list
|
||||
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
|
||||
* @return The results of the map reduce operation
|
||||
*/
|
||||
<T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction,
|
||||
@@ -541,16 +546,16 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Execute a map-reduce operation that takes a query and additional map-reduce options
|
||||
*
|
||||
* @param query The query to use to select the data for the map phase
|
||||
* @param inputCollectionName the collection where the map-reduce will read from
|
||||
* @param query The query to use to select the data for the map phase. Must not be {@literal null}.
|
||||
* @param inputCollectionName the collection where the map-reduce will read from. Must not be {@literal null}.
|
||||
* @param mapFunction The JavaScript map function
|
||||
* @param reduceFunction The JavaScript reduce function
|
||||
* @param mapReduceOptions Options that specify detailed map-reduce behavior
|
||||
* @param entityClass The parametrized type of the returned list
|
||||
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
|
||||
* @return The results of the map reduce operation
|
||||
*/
|
||||
<T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction,
|
||||
MapReduceOptions mapReduceOptions, Class<T> entityClass);
|
||||
@Nullable MapReduceOptions mapReduceOptions, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
* Returns {@link GeoResults} for all entities matching the given {@link NearQuery}. Will consider entity mapping
|
||||
@@ -572,7 +577,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param near must not be {@literal null}.
|
||||
* @param entityClass must not be {@literal null}.
|
||||
* @param collectionName the collection to trigger the query against. If no collection name is given the entity class
|
||||
* will be inspected.
|
||||
* will be inspected. Must not be {@literal null} nor empty.
|
||||
* @return
|
||||
*/
|
||||
<T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass, String collectionName);
|
||||
@@ -592,6 +597,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param entityClass the parametrized type of the returned list.
|
||||
* @return the converted object
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findOne(Query query, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
@@ -610,6 +616,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param collectionName name of the collection to retrieve the objects from
|
||||
* @return the converted object
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findOne(Query query, Class<T> entityClass, String collectionName);
|
||||
|
||||
/**
|
||||
@@ -636,11 +643,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Determine result of given {@link Query} contains at least one element.
|
||||
*
|
||||
* @param query the {@link Query} class that specifies the criteria used to find a record.
|
||||
* @param entityClass the parametrized type.
|
||||
* @param entityClass the parametrized type. Can be {@literal null}.
|
||||
* @param collectionName name of the collection to check for objects.
|
||||
* @return
|
||||
*/
|
||||
boolean exists(Query query, Class<?> entityClass, String collectionName);
|
||||
boolean exists(Query query, @Nullable Class<?> entityClass, String collectionName);
|
||||
|
||||
/**
|
||||
* Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type.
|
||||
@@ -652,8 +659,8 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* feature rich {@link Query}.
|
||||
*
|
||||
* @param query the query class that specifies the criteria used to find a record and also an optional fields
|
||||
* specification
|
||||
* @param entityClass the parametrized type of the returned list.
|
||||
* specification. Must not be {@literal null}.
|
||||
* @param entityClass the parametrized type of the returned list. Must not be {@literal null}.
|
||||
* @return the List of converted objects
|
||||
*/
|
||||
<T> List<T> find(Query query, Class<T> entityClass);
|
||||
@@ -668,9 +675,9 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* feature rich {@link Query}.
|
||||
*
|
||||
* @param query the query class that specifies the criteria used to find a record and also an optional fields
|
||||
* specification
|
||||
* @param entityClass the parametrized type of the returned list.
|
||||
* @param collectionName name of the collection to retrieve the objects from
|
||||
* specification. Must not be {@literal null}.
|
||||
* @param entityClass the parametrized type of the returned list. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to retrieve the objects from. Must not be {@literal null}.
|
||||
* @return the List of converted objects
|
||||
*/
|
||||
<T> List<T> find(Query query, Class<T> entityClass, String collectionName);
|
||||
@@ -680,10 +687,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* derived from the given target class as well.
|
||||
*
|
||||
* @param <T>
|
||||
* @param id the id of the document to return.
|
||||
* @param entityClass the type the document shall be converted into.
|
||||
* @param id the id of the document to return. Must not be {@literal null}.
|
||||
* @param entityClass the type the document shall be converted into. Must not be {@literal null}.
|
||||
* @return the document with the given id mapped onto the given target class.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findById(Object id, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
@@ -693,8 +701,9 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param entityClass the type to convert the document to
|
||||
* @param collectionName the collection to query for the document
|
||||
* @param <T>
|
||||
* @return
|
||||
* @return {@literal null} if document does not exist.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findById(Object id, Class<T> entityClass, String collectionName);
|
||||
|
||||
/**
|
||||
@@ -702,11 +711,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query}.
|
||||
*
|
||||
* @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
|
||||
* fields specification.
|
||||
* @param update the {@link Update} to apply on matching documents.
|
||||
* @param entityClass the parametrized type.
|
||||
* @return
|
||||
* fields specification. Must not be {@literal null}.
|
||||
* @param update the {@link Update} to apply on matching documents. Must not be {@literal null}.
|
||||
* @param entityClass the parametrized type. Must not be {@literal null}.
|
||||
* @return {@literal null} if not found.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findAndModify(Query query, Update update, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
@@ -714,12 +724,13 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query}.
|
||||
*
|
||||
* @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
|
||||
* fields specification.
|
||||
* @param update the {@link Update} to apply on matching documents.
|
||||
* @param entityClass the parametrized type.
|
||||
* @param collectionName the collection to query.
|
||||
* @return
|
||||
* fields specification. Must not be {@literal null}.
|
||||
* @param update the {@link Update} to apply on matching documents. Must not be {@literal null}.
|
||||
* @param entityClass the parametrized type. Must not be {@literal null}.
|
||||
* @param collectionName the collection to query. Must not be {@literal null}.
|
||||
* @return {@literal null} if not found.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findAndModify(Query query, Update update, Class<T> entityClass, String collectionName);
|
||||
|
||||
/**
|
||||
@@ -732,8 +743,9 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param update the {@link Update} to apply on matching documents.
|
||||
* @param options the {@link FindAndModifyOptions} holding additional information.
|
||||
* @param entityClass the parametrized type.
|
||||
* @return
|
||||
* @return {@literal null} if not found.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findAndModify(Query query, Update update, FindAndModifyOptions options, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
@@ -742,13 +754,14 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* {@link FindAndModifyOptions} into account.
|
||||
*
|
||||
* @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
|
||||
* fields specification.
|
||||
* @param update the {@link Update} to apply on matching documents.
|
||||
* @param options the {@link FindAndModifyOptions} holding additional information.
|
||||
* @param entityClass the parametrized type.
|
||||
* @param collectionName the collection to query.
|
||||
* @return
|
||||
* fields specification. Must not be {@literal null}.
|
||||
* @param update the {@link Update} to apply on matching documents. Must not be {@literal null}.
|
||||
* @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
|
||||
* @param entityClass the parametrized type. Must not be {@literal null}.
|
||||
* @param collectionName the collection to query. Must not be {@literal null}.
|
||||
* @return {@literal null} if not found.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findAndModify(Query query, Update update, FindAndModifyOptions options, Class<T> entityClass,
|
||||
String collectionName);
|
||||
|
||||
@@ -767,6 +780,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param entityClass the parametrized type of the returned list.
|
||||
* @return the converted object
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findAndRemove(Query query, Class<T> entityClass);
|
||||
|
||||
/**
|
||||
@@ -785,12 +799,13 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* @param collectionName name of the collection to retrieve the objects from
|
||||
* @return the converted object
|
||||
*/
|
||||
@Nullable
|
||||
<T> T findAndRemove(Query query, Class<T> entityClass, String collectionName);
|
||||
|
||||
/**
|
||||
* Returns the number of documents for the given {@link Query} by querying the collection of the given entity class.
|
||||
*
|
||||
* @param query
|
||||
* @param query must not be {@literal null}.
|
||||
* @param entityClass must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -801,7 +816,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* must solely consist of document field references as we lack type information to map potential property references
|
||||
* onto document fields. Use {@link #count(Query, Class, String)} to get full type specific support.
|
||||
*
|
||||
* @param query
|
||||
* @param query must not be {@literal null}.
|
||||
* @param collectionName must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @see #count(Query, Class, String)
|
||||
@@ -812,12 +827,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Returns the number of documents for the given {@link Query} by querying the given collection using the given entity
|
||||
* class to map the given {@link Query}.
|
||||
*
|
||||
* @param query
|
||||
* @param entityClass must not be {@literal null}.
|
||||
* @param query must not be {@literal null}.
|
||||
* @param entityClass can be be {@literal null}.
|
||||
* @param collectionName must not be {@literal null} or empty.
|
||||
* @return
|
||||
*/
|
||||
long count(Query query, Class<?> entityClass, String collectionName);
|
||||
long count(Query query, @Nullable Class<?> entityClass, String collectionName);
|
||||
|
||||
/**
|
||||
* Insert the object into the collection for the entity type of the object to save.
|
||||
@@ -833,7 +848,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Insert is used to initially store the object into the database. To update an existing object use the save method.
|
||||
*
|
||||
* @param objectToSave the object to store in the collection.
|
||||
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
|
||||
*/
|
||||
void insert(Object objectToSave);
|
||||
|
||||
@@ -845,24 +860,24 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <p/>
|
||||
* Insert is used to initially store the object into the database. To update an existing object use the save method.
|
||||
*
|
||||
* @param objectToSave the object to store in the collection
|
||||
* @param collectionName name of the collection to store the object in
|
||||
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to store the object in. Must not be {@literal null}.
|
||||
*/
|
||||
void insert(Object objectToSave, String collectionName);
|
||||
|
||||
/**
|
||||
* Insert a Collection of objects into a collection in a single batch write to the database.
|
||||
*
|
||||
* @param batchToSave the list of objects to save.
|
||||
* @param entityClass class that determines the collection to use
|
||||
* @param batchToSave the list of objects to save. Must not be {@literal null}.
|
||||
* @param entityClass class that determines the collection to use. Must not be {@literal null}.
|
||||
*/
|
||||
void insert(Collection<? extends Object> batchToSave, Class<?> entityClass);
|
||||
|
||||
/**
|
||||
* Insert a list of objects into the specified collection in a single batch write to the database.
|
||||
*
|
||||
* @param batchToSave the list of objects to save.
|
||||
* @param collectionName name of the collection to store the object in
|
||||
* @param batchToSave the list of objects to save. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to store the object in. Must not be {@literal null}.
|
||||
*/
|
||||
void insert(Collection<? extends Object> batchToSave, String collectionName);
|
||||
|
||||
@@ -870,7 +885,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Insert a mixed Collection of objects into a database collection determining the collection name to use based on the
|
||||
* class.
|
||||
*
|
||||
* @param collectionToSave the list of objects to save.
|
||||
* @param collectionToSave the list of objects to save. Must not be {@literal null}.
|
||||
*/
|
||||
void insertAll(Collection<? extends Object> objectsToSave);
|
||||
|
||||
@@ -887,7 +902,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert" >
|
||||
* Spring's Type Conversion"</a> for more details.
|
||||
*
|
||||
* @param objectToSave the object to store in the collection
|
||||
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
|
||||
*/
|
||||
void save(Object objectToSave);
|
||||
|
||||
@@ -904,8 +919,8 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert">Spring's
|
||||
* Type Conversion"</a> for more details.
|
||||
*
|
||||
* @param objectToSave the object to store in the collection
|
||||
* @param collectionName name of the collection to store the object in
|
||||
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to store the object in. Must not be {@literal null}.
|
||||
*/
|
||||
void save(Object objectToSave, String collectionName);
|
||||
|
||||
@@ -913,9 +928,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
|
||||
* combining the query document and the update document.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be upserted
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing object
|
||||
* @param entityClass class that determines the collection to use
|
||||
* @param query the query document that specifies the criteria used to select a record to be upserted. Must not be
|
||||
* {@literal null}.
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing
|
||||
* object. Must not be {@literal null}.
|
||||
* @param entityClass class that determines the collection to use. Must not be {@literal null}.
|
||||
* @return the WriteResult which lets you access the results of the previous write.
|
||||
*/
|
||||
UpdateResult upsert(Query query, Update update, Class<?> entityClass);
|
||||
@@ -938,10 +955,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
|
||||
* combining the query document and the update document.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be upserted
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing object
|
||||
* @param entityClass class of the pojo to be operated on
|
||||
* @param collectionName name of the collection to update the object in
|
||||
* @param query the query document that specifies the criteria used to select a record to be upserted. Must not be
|
||||
* {@literal null}.
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing
|
||||
* object. Must not be {@literal null}.
|
||||
* @param entityClass class of the pojo to be operated on. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to update the object in. Must not be {@literal null}.
|
||||
* @return the WriteResult which lets you access the results of the previous write.
|
||||
*/
|
||||
UpdateResult upsert(Query query, Update update, Class<?> entityClass, String collectionName);
|
||||
@@ -964,10 +983,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <strong>NOTE:</strong> Any additional support for field mapping, versions, etc. is not available due to the lack of
|
||||
* domain type information. Use {@link #updateFirst(Query, Update, Class, String)} to get full type specific support.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated. Must not be
|
||||
* {@literal null}.
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing
|
||||
* object.
|
||||
* @param collectionName name of the collection to update the object in
|
||||
* object. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to update the object in. Must not be {@literal null}.
|
||||
* @return the WriteResult which lets you access the results of the previous write.
|
||||
*/
|
||||
UpdateResult updateFirst(Query query, Update update, String collectionName);
|
||||
@@ -976,11 +996,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Updates the first object that is found in the specified collection that matches the query document criteria with
|
||||
* the provided updated document.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated. Must not be
|
||||
* {@literal null}.
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing
|
||||
* object.
|
||||
* @param entityClass class of the pojo to be operated on
|
||||
* @param collectionName name of the collection to update the object in
|
||||
* object. Must not be {@literal null}.
|
||||
* @param entityClass class of the pojo to be operated on. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to update the object in. Must not be {@literal null}.
|
||||
* @return the WriteResult which lets you access the results of the previous write.
|
||||
*/
|
||||
UpdateResult updateFirst(Query query, Update update, Class<?> entityClass, String collectionName);
|
||||
@@ -989,10 +1010,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Updates all objects that are found in the collection for the entity class that matches the query document criteria
|
||||
* with the provided updated document.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated. Must not be
|
||||
* {@literal null}.
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing
|
||||
* object.
|
||||
* @param entityClass class that determines the collection to use
|
||||
* object. Must not be {@literal null}.
|
||||
* @param entityClass class that determines the collection to use. Must not be {@literal null}.
|
||||
* @return the WriteResult which lets you access the results of the previous write.
|
||||
*/
|
||||
UpdateResult updateMulti(Query query, Update update, Class<?> entityClass);
|
||||
@@ -1003,10 +1025,11 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* <strong>NOTE:</strong> Any additional support for field mapping, versions, etc. is not available due to the lack of
|
||||
* domain type information. Use {@link #updateMulti(Query, Update, Class, String)} to get full type specific support.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated. Must not be
|
||||
* {@literal null}.
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing
|
||||
* object.
|
||||
* @param collectionName name of the collection to update the object in
|
||||
* object. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to update the object in. Must not be {@literal null}.
|
||||
* @return the WriteResult which lets you access the results of the previous write.
|
||||
*/
|
||||
UpdateResult updateMulti(Query query, Update update, String collectionName);
|
||||
@@ -1015,11 +1038,12 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
* Updates all objects that are found in the collection for the entity class that matches the query document criteria
|
||||
* with the provided updated document.
|
||||
*
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated
|
||||
* @param query the query document that specifies the criteria used to select a record to be updated. Must not be
|
||||
* {@literal null}.
|
||||
* @param update the update document that contains the updated object or $ operators to manipulate the existing
|
||||
* object.
|
||||
* @param entityClass class of the pojo to be operated on
|
||||
* @param collectionName name of the collection to update the object in
|
||||
* object. Must not be {@literal null}.
|
||||
* @param entityClass class of the pojo to be operated on. Must not be {@literal null}.
|
||||
* @param collectionName name of the collection to update the object in. Must not be {@literal null}.
|
||||
* @return the WriteResult which lets you access the results of the previous write.
|
||||
*/
|
||||
UpdateResult updateMulti(final Query query, final Update update, Class<?> entityClass, String collectionName);
|
||||
@@ -1027,7 +1051,9 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
/**
|
||||
* Remove the given object from the collection by id.
|
||||
*
|
||||
* @param object
|
||||
* @param object must not be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
* @throws IllegalArgumentException when {@code object} to remove is {@literal null}.
|
||||
*/
|
||||
DeleteResult remove(Object object);
|
||||
|
||||
@@ -1036,6 +1062,7 @@ public interface MongoOperations extends FluentMongoOperations {
|
||||
*
|
||||
* @param object
|
||||
* @param collection must not be {@literal null} or empty.
|
||||
* @thorws IllegalArgumentException when {@code object} or {@code collection} is {@literal null}.
|
||||
*/
|
||||
DeleteResult remove(Object object, String collection);
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.springframework.transaction.support.ResourceHolder;
|
||||
import org.springframework.transaction.support.ResourceHolderSynchronization;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class MongoSynchronization extends ResourceHolderSynchronization<ResourceHolder, Object> {
|
||||
|
||||
public MongoSynchronization(ResourceHolder resourceHolder, Object resourceKey) {
|
||||
super(resourceHolder, resourceKey);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,6 +19,7 @@ import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
import org.springframework.lang.Nullable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -195,7 +196,7 @@ class ReactiveFindOperationSupport implements ReactiveFindOperation {
|
||||
return template.exists(query, domainType, getCollectionName());
|
||||
}
|
||||
|
||||
private Flux<T> doFind(FindPublisherPreparer preparer) {
|
||||
private Flux<T> doFind(@Nullable FindPublisherPreparer preparer) {
|
||||
|
||||
Document queryObject = query.getQueryObject();
|
||||
Document fieldsObject = query.getFieldsObject();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.mongodb.core;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.async.client.MongoClientSettings;
|
||||
@@ -37,10 +38,10 @@ public class ReactiveMongoClientFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
|
||||
private static final PersistenceExceptionTranslator DEFAULT_EXCEPTION_TRANSLATOR = new MongoExceptionTranslator();
|
||||
|
||||
private String connectionString;
|
||||
private String host;
|
||||
private Integer port;
|
||||
private MongoClientSettings mongoClientSettings;
|
||||
private @Nullable String connectionString;
|
||||
private @Nullable String host;
|
||||
private @Nullable Integer port;
|
||||
private @Nullable MongoClientSettings mongoClientSettings;
|
||||
private PersistenceExceptionTranslator exceptionTranslator = DEFAULT_EXCEPTION_TRANSLATOR;
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,7 @@ public class ReactiveMongoClientFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
*
|
||||
* @param host
|
||||
*/
|
||||
public void setHost(String host) {
|
||||
public void setHost(@Nullable String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@@ -66,7 +67,7 @@ public class ReactiveMongoClientFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
*
|
||||
* @param connectionString
|
||||
*/
|
||||
public void setConnectionString(String connectionString) {
|
||||
public void setConnectionString(@Nullable String connectionString) {
|
||||
this.connectionString = connectionString;
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ public class ReactiveMongoClientFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
*
|
||||
* @param mongoClientSettings
|
||||
*/
|
||||
public void setMongoClientSettings(MongoClientSettings mongoClientSettings) {
|
||||
public void setMongoClientSettings(@Nullable MongoClientSettings mongoClientSettings) {
|
||||
this.mongoClientSettings = mongoClientSettings;
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ public class ReactiveMongoClientFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
*
|
||||
* @param exceptionTranslator
|
||||
*/
|
||||
public void setExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) {
|
||||
public void setExceptionTranslator(@Nullable PersistenceExceptionTranslator exceptionTranslator) {
|
||||
this.exceptionTranslator = exceptionTranslator == null ? DEFAULT_EXCEPTION_TRANSLATOR : exceptionTranslator;
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ public class ReactiveMongoClientFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void destroyInstance(MongoClient instance) throws Exception {
|
||||
protected void destroyInstance(@Nullable MongoClient instance) throws Exception {
|
||||
instance.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -98,7 +99,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
|
||||
* @param readPreference read preferences to use, can be {@literal null}.
|
||||
* @return a result object returned by the action
|
||||
*/
|
||||
Mono<Document> executeCommand(Document command, ReadPreference readPreference);
|
||||
Mono<Document> executeCommand(Document command, @Nullable ReadPreference readPreference);
|
||||
|
||||
/**
|
||||
* Executes a {@link ReactiveDatabaseCallback} translating any exceptions as necessary.
|
||||
@@ -312,11 +313,11 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
|
||||
* Determine result of given {@link Query} contains at least one element.
|
||||
*
|
||||
* @param query the {@link Query} class that specifies the criteria used to find a record.
|
||||
* @param entityClass the parametrized type.
|
||||
* @param entityClass the parametrized type. Can be {@literal null}.
|
||||
* @param collectionName name of the collection to check for objects.
|
||||
* @return
|
||||
*/
|
||||
Mono<Boolean> exists(Query query, Class<?> entityClass, String collectionName);
|
||||
Mono<Boolean> exists(Query query, @Nullable Class<?> entityClass, String collectionName);
|
||||
|
||||
/**
|
||||
* Map the results of an ad-hoc query on the collection for the entity class to a {@link Flux} of the specified type.
|
||||
|
||||
@@ -20,8 +20,6 @@ import static org.springframework.data.mongodb.core.query.SerializationUtils.*;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.projection.ProjectionInformation;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
@@ -40,6 +38,8 @@ import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.bson.types.ObjectId;
|
||||
@@ -105,10 +105,13 @@ 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.util.MongoClientVersion;
|
||||
import org.springframework.data.projection.ProjectionInformation;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.util.Optionals;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -179,12 +182,12 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
private final UpdateMapper updateMapper;
|
||||
private final SpelAwareProxyProjectionFactory projectionFactory;
|
||||
|
||||
private WriteConcern writeConcern;
|
||||
private @Nullable WriteConcern writeConcern;
|
||||
private WriteConcernResolver writeConcernResolver = DefaultWriteConcernResolver.INSTANCE;
|
||||
private WriteResultChecking writeResultChecking = WriteResultChecking.NONE;
|
||||
private ReadPreference readPreference;
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
private MongoPersistentEntityIndexCreator indexCreator;
|
||||
private @Nullable ReadPreference readPreference;
|
||||
private @Nullable ApplicationEventPublisher eventPublisher;
|
||||
private @Nullable MongoPersistentEntityIndexCreator indexCreator;
|
||||
|
||||
/**
|
||||
* Constructor used for a basic template configuration.
|
||||
@@ -209,9 +212,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* Constructor used for a basic template configuration.
|
||||
*
|
||||
* @param mongoDatabaseFactory must not be {@literal null}.
|
||||
* @param mongoConverter
|
||||
* @param mongoConverter can be {@literal null}.
|
||||
*/
|
||||
public ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory, MongoConverter mongoConverter) {
|
||||
public ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory,
|
||||
@Nullable MongoConverter mongoConverter) {
|
||||
|
||||
Assert.notNull(mongoDatabaseFactory, "ReactiveMongoDatabaseFactory must not be null!");
|
||||
|
||||
@@ -242,7 +246,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
*
|
||||
* @param resultChecking
|
||||
*/
|
||||
public void setWriteResultChecking(WriteResultChecking resultChecking) {
|
||||
public void setWriteResultChecking(@Nullable WriteResultChecking resultChecking) {
|
||||
this.writeResultChecking = resultChecking == null ? DEFAULT_WRITE_RESULT_CHECKING : resultChecking;
|
||||
}
|
||||
|
||||
@@ -251,18 +255,18 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* configured on the {@link MongoDbFactory} will apply. If you configured a {@link Mongo} instance no
|
||||
* {@link WriteConcern} will be used.
|
||||
*
|
||||
* @param writeConcern
|
||||
* @param writeConcern can be {@literal null}.
|
||||
*/
|
||||
public void setWriteConcern(WriteConcern writeConcern) {
|
||||
public void setWriteConcern(@Nullable WriteConcern writeConcern) {
|
||||
this.writeConcern = writeConcern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the {@link WriteConcernResolver} to be used with the template.
|
||||
*
|
||||
* @param writeConcernResolver
|
||||
* @param writeConcernResolver can be {@literal null}.
|
||||
*/
|
||||
public void setWriteConcernResolver(WriteConcernResolver writeConcernResolver) {
|
||||
public void setWriteConcernResolver(@Nullable WriteConcernResolver writeConcernResolver) {
|
||||
this.writeConcernResolver = writeConcernResolver;
|
||||
}
|
||||
|
||||
@@ -370,7 +374,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#executeCommand(org.bson.Document, com.mongodb.ReadPreference)
|
||||
*/
|
||||
public Mono<Document> executeCommand(final Document command, final ReadPreference readPreference) {
|
||||
public Mono<Document> executeCommand(final Document command, @Nullable ReadPreference readPreference) {
|
||||
|
||||
Assert.notNull(command, "Command must not be null!");
|
||||
|
||||
@@ -609,7 +613,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#exists(org.springframework.data.mongodb.core.query.Query, java.lang.Class, java.lang.String)
|
||||
*/
|
||||
public Mono<Boolean> exists(final Query query, final Class<?> entityClass, String collectionName) {
|
||||
public Mono<Boolean> exists(final Query query, @Nullable Class<?> entityClass, String collectionName) {
|
||||
|
||||
if (query == null) {
|
||||
throw new InvalidDataAccessApiUsageException("Query passed in to exist can't be null");
|
||||
@@ -722,7 +726,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
protected <O> Flux<O> aggregate(Aggregation aggregation, String collectionName, Class<O> outputType,
|
||||
AggregationOperationContext context) {
|
||||
@Nullable AggregationOperationContext context) {
|
||||
|
||||
Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
|
||||
Assert.hasText(collectionName, "Collection name must not be null or empty!");
|
||||
@@ -904,7 +908,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#count(org.springframework.data.mongodb.core.query.Query, java.lang.Class, java.lang.String)
|
||||
*/
|
||||
public Mono<Long> count(final Query query, final Class<?> entityClass, String collectionName) {
|
||||
public Mono<Long> count(final Query query, @Nullable Class<?> entityClass, String collectionName) {
|
||||
|
||||
Assert.hasText(collectionName, "Collection name must not be null or empty!");
|
||||
|
||||
@@ -1051,7 +1055,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
Mono<List<Tuple2<T, Document>>> prepareDocuments = Flux.fromIterable(batchToSave)
|
||||
.flatMap(new Function<T, Flux<Tuple2<T, Document>>>() {
|
||||
@Override
|
||||
public Flux<Tuple2<T, Document>> apply(T o) {
|
||||
public Flux<Tuple2<T, Document>> apply(@Nullable T o) {
|
||||
|
||||
initializeVersionProperty(o);
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(o, collectionName));
|
||||
@@ -1356,7 +1360,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
protected Mono<UpdateResult> doUpdate(final String collectionName, final Query query, final Update update,
|
||||
final Class<?> entityClass, final boolean upsert, final boolean multi) {
|
||||
@Nullable Class<?> entityClass, final boolean upsert, final boolean multi) {
|
||||
|
||||
MongoPersistentEntity<?> entity = entityClass == null ? null : getPersistentEntity(entityClass);
|
||||
|
||||
@@ -1578,7 +1582,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#remove(org.springframework.data.mongodb.core.query.Query, java.lang.Class, java.lang.String)
|
||||
*/
|
||||
public Mono<DeleteResult> remove(Query query, Class<?> entityClass, String collectionName) {
|
||||
public Mono<DeleteResult> remove(Query query, @Nullable Class<?> entityClass, String collectionName) {
|
||||
return doRemove(collectionName, query, entityClass);
|
||||
}
|
||||
|
||||
@@ -1663,7 +1667,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findAllAndRemove(org.springframework.data.mongodb.core.query.Query, java.lang.Class, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public <T> Flux<T> findAllAndRemove(Query query, Class<T> entityClass, String collectionName) {
|
||||
public <T> Flux<T> findAllAndRemove(Query query, @Nullable Class<T> entityClass, String collectionName) {
|
||||
return doFindAndDelete(collectionName, query, entityClass);
|
||||
}
|
||||
|
||||
@@ -1789,10 +1793,11 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @param collation can be {@literal null}.
|
||||
* @return the {@link List} of converted objects.
|
||||
*/
|
||||
protected <T> Mono<T> doFindOne(String collectionName, Document query, Document fields, Class<T> entityClass,
|
||||
Collation collation) {
|
||||
protected <T> Mono<T> doFindOne(String collectionName, Document query, @Nullable Document fields,
|
||||
Class<T> entityClass, @Nullable Collation collation) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
@@ -1842,7 +1847,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
protected <S, T> Flux<T> doFind(String collectionName, Document query, Document fields, Class<S> entityClass,
|
||||
FindPublisherPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
@Nullable FindPublisherPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
@@ -2128,7 +2133,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @return
|
||||
*/
|
||||
private <T> Flux<T> executeFindMultiInternal(ReactiveCollectionQueryCallback<Document> collectionCallback,
|
||||
FindPublisherPreparer preparer, DocumentCallback<T> objectCallback, String collectionName) {
|
||||
@Nullable FindPublisherPreparer preparer, DocumentCallback<T> objectCallback, String collectionName) {
|
||||
|
||||
return createFlux(collectionName, collection -> {
|
||||
|
||||
@@ -2330,7 +2335,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
private final Document query;
|
||||
private final Document fields;
|
||||
|
||||
FindCallback(Document query) {
|
||||
FindCallback(@Nullable Document query) {
|
||||
this(query, null);
|
||||
}
|
||||
|
||||
@@ -2687,8 +2692,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
static class NoOpDbRefResolver implements DbRefResolver {
|
||||
|
||||
@Override
|
||||
public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback,
|
||||
DbRefProxyHandler proxyHandler) {
|
||||
@Nullable
|
||||
public Object resolveDbRef(@Nonnull MongoPersistentProperty property, @Nonnull DBRef dbref,
|
||||
@Nonnull DbRefResolverCallback callback, @Nonnull DbRefProxyHandler proxyHandler) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.data.mongodb.core.script.ExecutableMongoScript;
|
||||
import org.springframework.data.mongodb.core.script.NamedMongoScript;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.DB;
|
||||
|
||||
@@ -56,6 +57,7 @@ public interface ScriptOperations {
|
||||
* @return the script evaluation result.
|
||||
* @throws org.springframework.dao.DataAccessException
|
||||
*/
|
||||
@Nullable
|
||||
Object execute(ExecutableMongoScript script, Object... args);
|
||||
|
||||
/**
|
||||
@@ -65,6 +67,7 @@ public interface ScriptOperations {
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
Object call(String scriptName, Object... args);
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.mongodb.MongoDbFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.DB;
|
||||
@@ -44,7 +45,7 @@ public class SimpleMongoDbFactory implements DisposableBean, MongoDbFactory {
|
||||
private final boolean mongoInstanceCreated;
|
||||
private final PersistenceExceptionTranslator exceptionTranslator;
|
||||
|
||||
private WriteConcern writeConcern;
|
||||
private @Nullable WriteConcern writeConcern;
|
||||
|
||||
/**
|
||||
* Creates a new {@link SimpleMongoDbFactory} instance from the given {@link MongoClientURI}.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.ConnectionString;
|
||||
@@ -41,9 +42,10 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
|
||||
private final MongoClient mongo;
|
||||
private final String databaseName;
|
||||
private final boolean mongoInstanceCreated;
|
||||
|
||||
private final PersistenceExceptionTranslator exceptionTranslator;
|
||||
|
||||
private WriteConcern writeConcern;
|
||||
private @Nullable WriteConcern writeConcern;
|
||||
|
||||
/**
|
||||
* Creates a new {@link SimpleReactiveMongoDatabaseFactory} instance from the given {@link ConnectionString}.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2012 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.WriteConcern;
|
||||
|
||||
/**
|
||||
@@ -33,5 +35,6 @@ public interface WriteConcernResolver {
|
||||
* should not be resolved.
|
||||
* @return a {@link WriteConcern} based on the passed in {@link MongoAction} value, maybe {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
WriteConcern resolve(MongoAction action);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Optional;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
@@ -242,8 +243,8 @@ public class AggregationOptions {
|
||||
|
||||
private boolean allowDiskUse;
|
||||
private boolean explain;
|
||||
private Document cursor;
|
||||
private Collation collation;
|
||||
private @Nullable Document cursor;
|
||||
private @Nullable Collation collation;
|
||||
|
||||
/**
|
||||
* Defines whether to off-load intensive sort-operations to disk.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016. the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Filter.AsBuilder;
|
||||
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce.PropertyExpression;
|
||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -414,9 +415,9 @@ public class ArrayOperators {
|
||||
*/
|
||||
public static class Filter implements AggregationExpression {
|
||||
|
||||
private Object input;
|
||||
private ExposedField as;
|
||||
private Object condition;
|
||||
private @Nullable Object input;
|
||||
private @Nullable ExposedField as;
|
||||
private @Nullable Object condition;
|
||||
|
||||
private Filter() {
|
||||
// used by builder
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016. the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Co
|
||||
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond.ThenBuilder;
|
||||
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Switch.CaseOperator;
|
||||
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -33,6 +34,7 @@ import org.springframework.util.ClassUtils;
|
||||
* Gateway to {@literal conditional expressions} that evaluate their argument expressions as booleans to a value.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 1.10
|
||||
*/
|
||||
public class ConditionalOperators {
|
||||
@@ -121,9 +123,11 @@ public class ConditionalOperators {
|
||||
|
||||
public static class ConditionalOperatorFactory {
|
||||
|
||||
private final String fieldReference;
|
||||
private final AggregationExpression expression;
|
||||
private final CriteriaDefinition criteriaDefinition;
|
||||
private final @Nullable String fieldReference;
|
||||
|
||||
private final @Nullable AggregationExpression expression;
|
||||
|
||||
private final @Nullable CriteriaDefinition criteriaDefinition;
|
||||
|
||||
/**
|
||||
* Creates new {@link ConditionalOperatorFactory} for given {@literal fieldReference}.
|
||||
@@ -358,7 +362,7 @@ public class ConditionalOperators {
|
||||
*/
|
||||
static final class IfNullOperatorBuilder implements IfNullBuilder, ThenBuilder {
|
||||
|
||||
private Object condition;
|
||||
private @Nullable Object condition;
|
||||
|
||||
private IfNullOperatorBuilder() {}
|
||||
|
||||
@@ -850,8 +854,8 @@ public class ConditionalOperators {
|
||||
*/
|
||||
static class ConditionalExpressionBuilder implements WhenBuilder, ThenBuilder, OtherwiseBuilder {
|
||||
|
||||
private Object condition;
|
||||
private Object thenValue;
|
||||
private @Nullable Object condition;
|
||||
private @Nullable Object thenValue;
|
||||
|
||||
private ConditionalExpressionBuilder() {}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||
import org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation;
|
||||
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -51,12 +52,12 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
private final Field connectFrom;
|
||||
private final Field connectTo;
|
||||
private final Field as;
|
||||
private final Long maxDepth;
|
||||
private final Field depthField;
|
||||
private final CriteriaDefinition restrictSearchWithMatch;
|
||||
private final @Nullable Long maxDepth;
|
||||
private final @Nullable Field depthField;
|
||||
private final @Nullable CriteriaDefinition restrictSearchWithMatch;
|
||||
|
||||
private GraphLookupOperation(String from, List<Object> startWith, Field connectFrom, Field connectTo, Field as,
|
||||
Long maxDepth, Field depthField, CriteriaDefinition restrictSearchWithMatch) {
|
||||
@Nullable Long maxDepth, @Nullable Field depthField, @Nullable CriteriaDefinition restrictSearchWithMatch) {
|
||||
|
||||
this.from = from;
|
||||
this.startWith = startWith;
|
||||
@@ -214,9 +215,9 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
static final class GraphLookupOperationFromBuilder
|
||||
implements FromBuilder, StartWithBuilder, ConnectFromBuilder, ConnectToBuilder {
|
||||
|
||||
private String from;
|
||||
private List<? extends Object> startWith;
|
||||
private String connectFrom;
|
||||
private @Nullable String from;
|
||||
private @Nullable List<? extends Object> startWith;
|
||||
private @Nullable String connectFrom;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.GraphLookupOperation.FromBuilder#from(java.lang.String)
|
||||
@@ -336,9 +337,9 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
private final List<Object> startWith;
|
||||
private final Field connectFrom;
|
||||
private final Field connectTo;
|
||||
private Long maxDepth;
|
||||
private Field depthField;
|
||||
private CriteriaDefinition restrictSearchWithMatch;
|
||||
private @Nullable Long maxDepth;
|
||||
private @Nullable Field depthField;
|
||||
private @Nullable CriteriaDefinition restrictSearchWithMatch;
|
||||
|
||||
protected GraphLookupOperationBuilder(String from, List<? extends Object> startWith, String connectFrom,
|
||||
String connectTo) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core.aggregation;
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||
import org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -28,14 +29,15 @@ import org.springframework.util.Assert;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 1.9
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/">MongoDB Aggregation Framework: $lookup</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/">MongoDB Aggregation Framework:
|
||||
* $lookup</a>
|
||||
*/
|
||||
public class LookupOperation implements FieldsExposingAggregationOperation, InheritsFieldsAggregationOperation {
|
||||
|
||||
private Field from;
|
||||
private Field localField;
|
||||
private Field foreignField;
|
||||
private ExposedField as;
|
||||
private final Field from;
|
||||
private final Field localField;
|
||||
private final Field foreignField;
|
||||
private final ExposedField as;
|
||||
|
||||
/**
|
||||
* Creates a new {@link LookupOperation} for the given {@link Field}s.
|
||||
@@ -58,10 +60,6 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
this.as = new ExposedField(as, true);
|
||||
}
|
||||
|
||||
private LookupOperation() {
|
||||
// used by builder
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation#getFields()
|
||||
@@ -143,11 +141,10 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
public static final class LookupOperationBuilder
|
||||
implements FromBuilder, LocalFieldBuilder, ForeignFieldBuilder, AsBuilder {
|
||||
|
||||
private final LookupOperation lookupOperation;
|
||||
|
||||
private LookupOperationBuilder() {
|
||||
this.lookupOperation = new LookupOperation();
|
||||
}
|
||||
private @Nullable Field from;
|
||||
private @Nullable Field localField;
|
||||
private @Nullable Field foreignField;
|
||||
private @Nullable ExposedField as;
|
||||
|
||||
/**
|
||||
* Creates new builder for {@link LookupOperation}.
|
||||
@@ -162,7 +159,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
public LocalFieldBuilder from(String name) {
|
||||
|
||||
Assert.hasText(name, "'From' must not be null or empty!");
|
||||
lookupOperation.from = Fields.field(name);
|
||||
from = Fields.field(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -170,16 +167,16 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
public LookupOperation as(String name) {
|
||||
|
||||
Assert.hasText(name, "'As' must not be null or empty!");
|
||||
lookupOperation.as = new ExposedField(Fields.field(name), true);
|
||||
return new LookupOperation(lookupOperation.from, lookupOperation.localField, lookupOperation.foreignField,
|
||||
lookupOperation.as);
|
||||
as = new ExposedField(Fields.field(name), true);
|
||||
return new LookupOperation(from, localField, foreignField,
|
||||
as);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsBuilder foreignField(String name) {
|
||||
|
||||
Assert.hasText(name, "'ForeignField' must not be null or empty!");
|
||||
lookupOperation.foreignField = Fields.field(name);
|
||||
foreignField = Fields.field(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -187,7 +184,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
public ForeignFieldBuilder localField(String name) {
|
||||
|
||||
Assert.hasText(name, "'LocalField' must not be null or empty!");
|
||||
lookupOperation.localField = Fields.field(name);
|
||||
localField = Fields.field(name);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,7 @@ public class UnwindOperation
|
||||
implements AggregationOperation, FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation {
|
||||
|
||||
private final ExposedField field;
|
||||
private final ExposedField arrayIndex;
|
||||
private final @Nullable ExposedField arrayIndex;
|
||||
private final boolean preserveNullAndEmptyArrays;
|
||||
|
||||
/**
|
||||
@@ -185,8 +186,8 @@ public class UnwindOperation
|
||||
*/
|
||||
public static final class UnwindOperationBuilder implements PathBuilder, IndexBuilder, EmptyArraysBuilder {
|
||||
|
||||
private Field field;
|
||||
private Field arrayIndex;
|
||||
private @Nullable Field field;
|
||||
private @Nullable Field arrayIndex;
|
||||
|
||||
private UnwindOperationBuilder() {}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* Support for the MongoDB aggregation framework.
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.springframework.data.mongodb.core.convert.MongoConverters.BigIntegerT
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverters.ObjectIdToBigIntegerConverter;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverters.ObjectIdToStringConverter;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverters.StringToObjectIdConverter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base class for {@link MongoConverter} implementations. Sets up a {@link GenericConversionService} and populates basic
|
||||
@@ -36,6 +38,7 @@ import org.springframework.data.mongodb.core.convert.MongoConverters.StringToObj
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public abstract class AbstractMongoConverter implements MongoConverter, InitializingBean {
|
||||
|
||||
@@ -46,18 +49,20 @@ public abstract class AbstractMongoConverter implements MongoConverter, Initiali
|
||||
/**
|
||||
* Creates a new {@link AbstractMongoConverter} using the given {@link GenericConversionService}.
|
||||
*
|
||||
* @param conversionService
|
||||
* @param conversionService can be {@literal null} and defaults to {@link DefaultConversionService}.
|
||||
*/
|
||||
public AbstractMongoConverter(GenericConversionService conversionService) {
|
||||
public AbstractMongoConverter(@Nullable GenericConversionService conversionService) {
|
||||
this.conversionService = conversionService == null ? new DefaultConversionService() : conversionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given custom conversions with the converter.
|
||||
*
|
||||
* @param conversions
|
||||
* @param conversions must not be {@literal null}.
|
||||
*/
|
||||
public void setCustomConversions(CustomConversions conversions) {
|
||||
|
||||
Assert.notNull(conversions, "Conversions must not be null!");
|
||||
this.conversions = conversions;
|
||||
}
|
||||
|
||||
@@ -66,7 +71,7 @@ public abstract class AbstractMongoConverter implements MongoConverter, Initiali
|
||||
*
|
||||
* @param instantiators
|
||||
*/
|
||||
public void setInstantiators(EntityInstantiators instantiators) {
|
||||
public void setInstantiators(@Nullable EntityInstantiators instantiators) {
|
||||
this.instantiators = instantiators == null ? new EntityInstantiators() : instantiators;
|
||||
}
|
||||
|
||||
@@ -91,20 +96,13 @@ public abstract class AbstractMongoConverter implements MongoConverter, Initiali
|
||||
conversions.registerConvertersIn(conversionService);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.convert.MongoWriter#convertToMongoType(java.lang.Object)
|
||||
*/
|
||||
public Object convertToMongoType(Object obj) {
|
||||
return convertToMongoType(obj, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.core.convert.MongoConverter#getConversionService()
|
||||
*/
|
||||
@Override
|
||||
public ConversionService getConversionService() {
|
||||
return conversionService;
|
||||
return conversionService != null ? conversionService : new DefaultConversionService();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.bson.Document;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.DBRef;
|
||||
|
||||
@@ -45,6 +46,7 @@ public interface DbRefResolver {
|
||||
* @param callback will never be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback,
|
||||
DbRefProxyHandler proxyHandler);
|
||||
|
||||
@@ -67,6 +69,7 @@ public interface DbRefResolver {
|
||||
* @return
|
||||
* @since 1.7
|
||||
*/
|
||||
@Nullable
|
||||
Document fetch(DBRef dbRef);
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.stream.Stream;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.bson.Document;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.cglib.proxy.Callback;
|
||||
import org.springframework.cglib.proxy.Enhancer;
|
||||
@@ -44,6 +45,7 @@ import org.springframework.data.mongodb.LazyLoadingException;
|
||||
import org.springframework.data.mongodb.MongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.objenesis.ObjenesisStd;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -89,10 +91,11 @@ public class DefaultDbRefResolver implements DbRefResolver {
|
||||
*/
|
||||
@Override
|
||||
public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback,
|
||||
DbRefProxyHandler handler) {
|
||||
DbRefProxyHandler handler) {
|
||||
|
||||
Assert.notNull(property, "Property must not be null!");
|
||||
Assert.notNull(callback, "Callback must not be null!");
|
||||
Assert.notNull(handler, "Handler must not be null!");
|
||||
|
||||
if (isLazyDbRef(property)) {
|
||||
return createLazyLoadingProxy(property, dbref, callback, handler);
|
||||
@@ -262,7 +265,7 @@ public class DefaultDbRefResolver implements DbRefResolver {
|
||||
private final PersistenceExceptionTranslator exceptionTranslator;
|
||||
|
||||
private volatile boolean resolved;
|
||||
private Object result;
|
||||
private @Nullable Object result;
|
||||
private DBRef dbref;
|
||||
|
||||
static {
|
||||
@@ -301,7 +304,7 @@ public class DefaultDbRefResolver implements DbRefResolver {
|
||||
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
|
||||
*/
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
public Object invoke(@Nullable MethodInvocation invocation) throws Throwable {
|
||||
return intercept(invocation.getThis(), invocation.getMethod(), invocation.getArguments(), null);
|
||||
}
|
||||
|
||||
@@ -310,7 +313,7 @@ public class DefaultDbRefResolver implements DbRefResolver {
|
||||
* @see org.springframework.cglib.proxy.MethodInterceptor#intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], org.springframework.cglib.proxy.MethodProxy)
|
||||
*/
|
||||
@Override
|
||||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
|
||||
public Object intercept(@Nullable Object obj, @Nullable Method method, @Nullable Object[] args, @Nullable MethodProxy proxy) throws Throwable {
|
||||
|
||||
if (INITIALIZE_METHOD.equals(method)) {
|
||||
return ensureResolved();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import org.springframework.context.expression.MapAccessor;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link PropertyAccessor} to allow entity based field access to {@link Document}s.
|
||||
@@ -47,7 +48,7 @@ class DocumentPropertyAccessor extends MapAccessor {
|
||||
* @see org.springframework.context.expression.MapAccessor#canRead(org.springframework.expression.EvaluationContext, java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
public boolean canRead(EvaluationContext context, @Nullable Object target, String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -57,7 +58,11 @@ class DocumentPropertyAccessor extends MapAccessor {
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
public TypedValue read(EvaluationContext context, @Nullable Object target, String name) {
|
||||
|
||||
if (target == null) {
|
||||
return TypedValue.NULL;
|
||||
}
|
||||
|
||||
Map<String, Object> source = (Map<String, Object>) target;
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ import org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent;
|
||||
import org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -94,9 +95,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
protected final DbRefResolver dbRefResolver;
|
||||
protected final DefaultDbRefProxyHandler dbRefProxyHandler;
|
||||
|
||||
protected ApplicationContext applicationContext;
|
||||
protected @Nullable ApplicationContext applicationContext;
|
||||
protected MongoTypeMapper typeMapper;
|
||||
protected String mapKeyDotReplacement = null;
|
||||
protected @Nullable String mapKeyDotReplacement = null;
|
||||
|
||||
private SpELContext spELContext;
|
||||
|
||||
@@ -142,12 +143,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* {@link DefaultMongoTypeMapper} by default. Setting this to {@literal null} will reset the {@link TypeMapper} to the
|
||||
* default one.
|
||||
*
|
||||
* @param typeMapper the typeMapper to set
|
||||
* @param typeMapper the typeMapper to set. Can be {@literal null}.
|
||||
*/
|
||||
public void setTypeMapper(MongoTypeMapper typeMapper) {
|
||||
public void setTypeMapper(@Nullable MongoTypeMapper typeMapper) {
|
||||
this.typeMapper = typeMapper == null
|
||||
? new DefaultMongoTypeMapper(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, mappingContext)
|
||||
: typeMapper;
|
||||
? new DefaultMongoTypeMapper(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, mappingContext) : typeMapper;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -165,9 +165,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* object to fail. If further customization of the translation is needed, have a look at
|
||||
* {@link #potentiallyEscapeMapKey(String)} as well as {@link #potentiallyUnescapeMapKey(String)}.
|
||||
*
|
||||
* @param mapKeyDotReplacement the mapKeyDotReplacement to set
|
||||
* @param mapKeyDotReplacement the mapKeyDotReplacement to set. Can be {@literal null}.
|
||||
*/
|
||||
public void setMapKeyDotReplacement(String mapKeyDotReplacement) {
|
||||
public void setMapKeyDotReplacement(@Nullable String mapKeyDotReplacement) {
|
||||
this.mapKeyDotReplacement = mapKeyDotReplacement;
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.convert.MongoWriter#toDBRef(java.lang.Object, org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)
|
||||
*/
|
||||
public DBRef toDBRef(Object object, MongoPersistentProperty referringProperty) {
|
||||
public DBRef toDBRef(Object object, @Nullable MongoPersistentProperty referringProperty) {
|
||||
|
||||
org.springframework.data.mongodb.core.mapping.DBRef annotation = null;
|
||||
|
||||
@@ -404,7 +404,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* @param bson
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void writeInternal(final Object obj, final Bson bson, final TypeInformation<?> typeHint) {
|
||||
protected void writeInternal(@Nullable Object obj, final Bson bson, final TypeInformation<?> typeHint) {
|
||||
|
||||
if (null == obj) {
|
||||
return;
|
||||
@@ -434,7 +434,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
addCustomTypeKeyIfNecessary(typeHint, obj, bson);
|
||||
}
|
||||
|
||||
protected void writeInternal(Object obj, final Bson bson, MongoPersistentEntity<?> entity) {
|
||||
protected void writeInternal(@Nullable Object obj, final Bson bson, MongoPersistentEntity<?> entity) {
|
||||
|
||||
if (obj == null) {
|
||||
return;
|
||||
@@ -554,8 +554,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = isSubtype(prop.getType(), obj.getClass())
|
||||
? mappingContext.getRequiredPersistentEntity(obj.getClass())
|
||||
: mappingContext.getRequiredPersistentEntity(type);
|
||||
? mappingContext.getRequiredPersistentEntity(obj.getClass()) : mappingContext.getRequiredPersistentEntity(type);
|
||||
|
||||
Object existingValue = accessor.get(prop);
|
||||
Document document = existingValue instanceof Document ? (Document) existingValue : new Document();
|
||||
@@ -774,8 +773,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
return conversions.hasCustomWriteTarget(key.getClass(), String.class)
|
||||
? (String) getPotentiallyConvertedSimpleWrite(key)
|
||||
: key.toString();
|
||||
? (String) getPotentiallyConvertedSimpleWrite(key) : key.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1117,6 +1115,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* @see org.springframework.data.mongodb.core.convert.MongoWriter#convertToMongoType(java.lang.Object, org.springframework.data.util.TypeInformation)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object convertToMongoType(Object obj, TypeInformation<?> typeInformation) {
|
||||
|
||||
if (obj == null) {
|
||||
@@ -1421,8 +1420,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
List<Document> referencedRawDocuments = dbrefs.size() == 1
|
||||
? Collections.singletonList(readRef(dbrefs.iterator().next()))
|
||||
: bulkReadRefs(dbrefs);
|
||||
? Collections.singletonList(readRef(dbrefs.iterator().next())) : bulkReadRefs(dbrefs);
|
||||
String collectionName = dbrefs.iterator().next().getCollectionName();
|
||||
|
||||
List<T> targeList = new ArrayList<>(dbrefs.size());
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.data.convert.JodaTimeConverters;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoSimpleTypes;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Value object to capture custom conversion. {@link MongoCustomConversions} also act as factory for
|
||||
@@ -94,8 +95,8 @@ public class MongoCustomConversions extends org.springframework.data.convert.Cus
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
|
||||
*/
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return source.toString();
|
||||
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return source != null ? source.toString() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.bson.conversions.Bson;
|
||||
import org.springframework.data.convert.EntityWriter;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.DBRef;
|
||||
|
||||
@@ -40,7 +41,10 @@ public interface MongoWriter<T> extends EntityWriter<T, Bson> {
|
||||
* @param obj can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
Object convertToMongoType(Object obj);
|
||||
@Nullable
|
||||
default Object convertToMongoType(@Nullable Object obj) {
|
||||
return convertToMongoType(obj, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given object into one Mongo will be able to store natively but retains the type information in case
|
||||
@@ -50,7 +54,8 @@ public interface MongoWriter<T> extends EntityWriter<T, Bson> {
|
||||
* @param typeInformation can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
Object convertToMongoType(Object obj, TypeInformation<?> typeInformation);
|
||||
@Nullable
|
||||
Object convertToMongoType(@Nullable Object obj, @Nullable TypeInformation<?> typeInformation);
|
||||
|
||||
/**
|
||||
* Creates a {@link DBRef} to refer to the given object.
|
||||
@@ -60,5 +65,5 @@ public interface MongoWriter<T> extends EntityWriter<T, Bson> {
|
||||
* the {@link DBRef} object to create. Can be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
DBRef toDBRef(Object object, MongoPersistentProperty referingProperty);
|
||||
DBRef toDBRef(Object object, @Nullable MongoPersistentProperty referingProperty);
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.mapping.PropertyReferenceException;
|
||||
import org.springframework.data.mapping.context.InvalidPersistentPropertyPath;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentPropertyPath;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter.NestedDocument;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
@@ -48,6 +48,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.util.BsonUtils;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.BasicDBList;
|
||||
@@ -108,7 +109,7 @@ public class QueryMapper {
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public Document getMappedObject(Bson query, MongoPersistentEntity<?> entity) {
|
||||
public Document getMappedObject(Bson query, @Nullable MongoPersistentEntity<?> entity) {
|
||||
|
||||
if (isNestedKeyword(query)) {
|
||||
return getMappedKeyword(new Keyword(query), entity);
|
||||
@@ -161,10 +162,12 @@ public class QueryMapper {
|
||||
* @return
|
||||
* @since 1.6
|
||||
*/
|
||||
public Document getMappedSort(Document sortObject, MongoPersistentEntity<?> entity) {
|
||||
public Document getMappedSort(Document sortObject, @Nullable MongoPersistentEntity<?> entity) {
|
||||
|
||||
if (sortObject == null) {
|
||||
return null;
|
||||
Assert.notNull(sortObject, "SortObject must not be null!");
|
||||
|
||||
if (sortObject.isEmpty()) {
|
||||
return new Document();
|
||||
}
|
||||
|
||||
Document mappedSort = getMappedObject(sortObject, entity);
|
||||
@@ -172,33 +175,27 @@ public class QueryMapper {
|
||||
return mappedSort;
|
||||
}
|
||||
|
||||
public Document getMappedSort(Document sortObject, Optional<? extends MongoPersistentEntity<?>> entity) {
|
||||
return getMappedSort(sortObject, entity.orElse(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps fields to retrieve to the {@link MongoPersistentEntity}s properties. <br />
|
||||
* Also onverts and potentially adds missing property {@code $meta} representation.
|
||||
* Also converts and potentially adds missing property {@code $meta} representation.
|
||||
*
|
||||
* @param fieldsObject
|
||||
* @param entity
|
||||
* @param fieldsObject must not be {@literal null}.
|
||||
* @param entity can be {@litearl null}.
|
||||
* @return
|
||||
* @since 1.6
|
||||
*/
|
||||
public Document getMappedFields(Document fieldsObject, MongoPersistentEntity<?> entity) {
|
||||
public Document getMappedFields(Document fieldsObject, @Nullable MongoPersistentEntity<?> entity) {
|
||||
|
||||
Document mappedFields = fieldsObject != null ? getMappedObject(fieldsObject, entity) : new Document();
|
||||
Assert.notNull(fieldsObject, "FieldsObject must not be null!");
|
||||
|
||||
Document mappedFields = fieldsObject.isEmpty() ? new Document() : getMappedObject(fieldsObject, entity);
|
||||
mapMetaAttributes(mappedFields, entity, MetaMapping.FORCE);
|
||||
return mappedFields.keySet().isEmpty() ? null : mappedFields;
|
||||
return mappedFields;
|
||||
}
|
||||
|
||||
public Document getMappedFields(Document fieldsObject, Optional<? extends MongoPersistentEntity<?>> entity) {
|
||||
return getMappedFields(fieldsObject, entity.orElse(null));
|
||||
}
|
||||
private void mapMetaAttributes(Document source, @Nullable MongoPersistentEntity<?> entity, MetaMapping metaMapping) {
|
||||
|
||||
private void mapMetaAttributes(Document source, MongoPersistentEntity<?> entity, MetaMapping metaMapping) {
|
||||
|
||||
if (entity == null || source == null) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -373,7 +370,7 @@ public class QueryMapper {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
protected boolean isAssociationConversionNecessary(Field documentField, Object value) {
|
||||
protected boolean isAssociationConversionNecessary(Field documentField, @Nullable Object value) {
|
||||
|
||||
Assert.notNull(documentField, "Document field must not be null!");
|
||||
|
||||
@@ -393,8 +390,8 @@ public class QueryMapper {
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = documentField.getPropertyEntity();
|
||||
return entity.hasIdProperty() && (type.equals(DBRef.class)
|
||||
|| entity.getRequiredIdProperty().getActualType().isAssignableFrom(type));
|
||||
return entity.hasIdProperty()
|
||||
&& (type.equals(DBRef.class) || entity.getRequiredIdProperty().getActualType().isAssignableFrom(type));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,7 +434,7 @@ public class QueryMapper {
|
||||
* @param entity
|
||||
* @return the converted mongo type or null if source is null
|
||||
*/
|
||||
protected Object delegateConvertToMongoType(Object source, MongoPersistentEntity<?> entity) {
|
||||
protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) {
|
||||
return converter.convertToMongoType(source, entity == null ? null : entity.getTypeInformation());
|
||||
}
|
||||
|
||||
@@ -490,7 +487,7 @@ public class QueryMapper {
|
||||
* @param value can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected final boolean isDocument(Object value) {
|
||||
protected final boolean isDocument(@Nullable Object value) {
|
||||
return value instanceof Document;
|
||||
}
|
||||
|
||||
@@ -500,7 +497,7 @@ public class QueryMapper {
|
||||
* @param value can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected final boolean isDBObject(Object value) {
|
||||
protected final boolean isDBObject(@Nullable Object value) {
|
||||
return value instanceof DBObject;
|
||||
}
|
||||
|
||||
@@ -511,7 +508,7 @@ public class QueryMapper {
|
||||
* @param value can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected final Entry<String, Object> createMapEntry(Field field, Object value) {
|
||||
protected final Entry<String, Object> createMapEntry(Field field, @Nullable Object value) {
|
||||
return createMapEntry(field.getMappedKey(), value);
|
||||
}
|
||||
|
||||
@@ -522,7 +519,7 @@ public class QueryMapper {
|
||||
* @param value can be {@literal null}
|
||||
* @return
|
||||
*/
|
||||
private Entry<String, Object> createMapEntry(String key, Object value) {
|
||||
private Entry<String, Object> createMapEntry(String key, @Nullable Object value) {
|
||||
|
||||
Assert.hasText(key, "Key must not be null or empty!");
|
||||
return Collections.singletonMap(key, value).entrySet().iterator().next();
|
||||
@@ -543,7 +540,8 @@ public class QueryMapper {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Object convertId(Object id) {
|
||||
@Nullable
|
||||
public Object convertId(@Nullable Object id) {
|
||||
|
||||
if (id == null) {
|
||||
return null;
|
||||
@@ -712,8 +710,9 @@ public class QueryMapper {
|
||||
* property that represents the value to handle. This means it'll be the leaf property for plain paths or the
|
||||
* association property in case we refer to an association somewhere in the path.
|
||||
*
|
||||
* @return
|
||||
* @return can be {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public MongoPersistentProperty getProperty() {
|
||||
return null;
|
||||
}
|
||||
@@ -721,8 +720,9 @@ public class QueryMapper {
|
||||
/**
|
||||
* Returns the {@link MongoPersistentEntity} that field is conatined in.
|
||||
*
|
||||
* @return
|
||||
* @return can be {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public MongoPersistentEntity<?> getPropertyEntity() {
|
||||
return null;
|
||||
}
|
||||
@@ -754,6 +754,7 @@ public class QueryMapper {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Association<MongoPersistentProperty> getAssociation() {
|
||||
return null;
|
||||
}
|
||||
@@ -803,7 +804,7 @@ public class QueryMapper {
|
||||
*/
|
||||
public MetadataBackedField(String name, MongoPersistentEntity<?> entity,
|
||||
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> context,
|
||||
MongoPersistentProperty property) {
|
||||
@Nullable MongoPersistentProperty property) {
|
||||
|
||||
super(name);
|
||||
|
||||
@@ -884,6 +885,7 @@ public class QueryMapper {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
private Association<MongoPersistentProperty> findAssociation() {
|
||||
|
||||
if (this.path != null) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.data.mongodb.core.query.Update.Modifier;
|
||||
import org.springframework.data.mongodb.core.query.Update.Modifiers;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* A subclass of {@link QueryMapper} that retains type information on the mongo types.
|
||||
@@ -60,7 +61,7 @@ public class UpdateMapper extends QueryMapper {
|
||||
* @see org.springframework.data.mongodb.core.convert.QueryMapper#getMappedObject(Bson, MongoPersistentEntity)
|
||||
*/
|
||||
@Override
|
||||
public Document getMappedObject(Bson query, MongoPersistentEntity<?> entity) {
|
||||
public Document getMappedObject(Bson query, @Nullable MongoPersistentEntity<?> entity) {
|
||||
|
||||
Document document = super.getMappedObject(query, entity);
|
||||
|
||||
@@ -102,10 +103,10 @@ public class UpdateMapper extends QueryMapper {
|
||||
/**
|
||||
* Returns {@literal true} if the given {@link Document} is an update object that uses update operators.
|
||||
*
|
||||
* @param updateObj
|
||||
* @param updateObj can be {@literal null}.
|
||||
* @return {@literal true} if the given {@link Document} is an update object.
|
||||
*/
|
||||
public static boolean isUpdateObject(Document updateObj) {
|
||||
public static boolean isUpdateObject(@Nullable Document updateObj) {
|
||||
|
||||
if (updateObj == null) {
|
||||
return false;
|
||||
@@ -128,7 +129,7 @@ public class UpdateMapper extends QueryMapper {
|
||||
* org.springframework.data.mongodb.core.mapping.MongoPersistentEntity)
|
||||
*/
|
||||
@Override
|
||||
protected Object delegateConvertToMongoType(Object source, MongoPersistentEntity<?> entity) {
|
||||
protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) {
|
||||
return converter.convertToMongoType(source,
|
||||
entity == null ? ClassTypeInformation.OBJECT : getTypeHintForEntity(source, entity));
|
||||
}
|
||||
@@ -184,23 +185,23 @@ public class UpdateMapper extends QueryMapper {
|
||||
* @see org.springframework.data.mongodb.core.convert.QueryMapper#isAssociationConversionNecessary(org.springframework.data.mongodb.core.convert.QueryMapper.Field, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected boolean isAssociationConversionNecessary(Field documentField, Object value) {
|
||||
protected boolean isAssociationConversionNecessary(Field documentField, @Nullable Object value) {
|
||||
return super.isAssociationConversionNecessary(documentField, value) || documentField.containsAssociation();
|
||||
}
|
||||
|
||||
private boolean isUpdateModifier(Object value) {
|
||||
private boolean isUpdateModifier(@Nullable Object value) {
|
||||
return value instanceof Modifier || value instanceof Modifiers;
|
||||
}
|
||||
|
||||
private boolean isQuery(Object value) {
|
||||
private boolean isQuery(@Nullable Object value) {
|
||||
return value instanceof Query;
|
||||
}
|
||||
|
||||
private Document getMappedValue(Field field, Modifier modifier) {
|
||||
private Document getMappedValue(@Nullable Field field, Modifier modifier) {
|
||||
return new Document(modifier.getKey(), getMappedModifier(field, modifier));
|
||||
}
|
||||
|
||||
private Object getMappedModifier(Field field, Modifier modifier) {
|
||||
private Object getMappedModifier(@Nullable Field field, Modifier modifier) {
|
||||
|
||||
Object value = modifier.getValue();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Spring Data MongoDB specific converter infrastructure.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.convert;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@@ -64,7 +65,8 @@ public class GeoJsonModule extends SimpleModule {
|
||||
* @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
|
||||
*/
|
||||
@Override
|
||||
public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
public T deserialize(@Nullable JsonParser jp, @Nullable DeserializationContext ctxt)
|
||||
throws IOException, JsonProcessingException {
|
||||
|
||||
JsonNode node = jp.readValueAsTree();
|
||||
JsonNode coordinates = node.get("coordinates");
|
||||
|
||||
@@ -16,5 +16,6 @@
|
||||
/**
|
||||
* Support for MongoDB geo-spatial queries.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.geo;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ import java.util.Optional;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -33,13 +34,13 @@ import org.springframework.util.StringUtils;
|
||||
public class GeospatialIndex implements IndexDefinition {
|
||||
|
||||
private final String field;
|
||||
private String name;
|
||||
private Integer min;
|
||||
private Integer max;
|
||||
private Integer bits;
|
||||
private @Nullable String name;
|
||||
private @Nullable Integer min;
|
||||
private @Nullable Integer max;
|
||||
private @Nullable Integer bits;
|
||||
private GeoSpatialIndexType type = GeoSpatialIndexType.GEO_2D;
|
||||
private Double bucketSize = 1.0;
|
||||
private String additionalField;
|
||||
private @Nullable String additionalField;
|
||||
private Optional<IndexFilter> filter = Optional.empty();
|
||||
private Optional<Collation> collation = Optional.empty();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -40,7 +41,7 @@ public class Index implements IndexDefinition {
|
||||
}
|
||||
|
||||
private final Map<String, Direction> fieldSpec = new LinkedHashMap<String, Direction>();
|
||||
private String name;
|
||||
private @Nullable String name;
|
||||
private boolean unique = false;
|
||||
private boolean dropDuplicates = false;
|
||||
private boolean sparse = false;
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -46,8 +47,8 @@ public class IndexInfo {
|
||||
private final boolean unique;
|
||||
private final boolean sparse;
|
||||
private final String language;
|
||||
private String partialFilterExpression;
|
||||
private Document collation;
|
||||
private @Nullable String partialFilterExpression;
|
||||
private @Nullable Document collation;
|
||||
|
||||
public IndexInfo(List<IndexField> indexFields, String name, boolean unique, boolean sparse, String language) {
|
||||
|
||||
@@ -167,6 +168,7 @@ public class IndexInfo {
|
||||
* @return
|
||||
* @since 1.0
|
||||
*/
|
||||
@Nullable
|
||||
public String getPartialFilterExpression() {
|
||||
return partialFilterExpression;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011 by the original author(s).
|
||||
* Copyright 2011-2017 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +16,18 @@
|
||||
|
||||
package org.springframework.data.mongodb.core.index;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public abstract class IndexPredicate {
|
||||
|
||||
private String name;
|
||||
private @Nullable String name;
|
||||
private IndexDirection direction = IndexDirection.ASCENDING;
|
||||
private boolean unique = false;
|
||||
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Set;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -33,11 +34,11 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class TextIndexDefinition implements IndexDefinition {
|
||||
|
||||
private String name;
|
||||
private @Nullable String name;
|
||||
private Set<TextIndexedFieldSpec> fieldSpecs;
|
||||
private String defaultLanguage;
|
||||
private String languageOverride;
|
||||
private IndexFilter filter;
|
||||
private @Nullable String defaultLanguage;
|
||||
private @Nullable String languageOverride;
|
||||
private @Nullable IndexFilter filter;
|
||||
|
||||
TextIndexDefinition() {
|
||||
fieldSpecs = new LinkedHashSet<TextIndexedFieldSpec>();
|
||||
@@ -142,7 +143,7 @@ public class TextIndexDefinition implements IndexDefinition {
|
||||
public static class TextIndexedFieldSpec {
|
||||
|
||||
private final String fieldname;
|
||||
private final Float weight;
|
||||
private final @Nullable Float weight;
|
||||
|
||||
/**
|
||||
* Create new {@link TextIndexedFieldSpec} for given fieldname without any weight.
|
||||
@@ -159,7 +160,7 @@ public class TextIndexDefinition implements IndexDefinition {
|
||||
* @param fieldname
|
||||
* @param weight
|
||||
*/
|
||||
public TextIndexedFieldSpec(String fieldname, Float weight) {
|
||||
public TextIndexedFieldSpec(String fieldname, @Nullable Float weight) {
|
||||
|
||||
Assert.hasText(fieldname, "Text index field cannot be blank.");
|
||||
this.fieldname = fieldname;
|
||||
@@ -180,6 +181,7 @@ public class TextIndexDefinition implements IndexDefinition {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public Float getWeight() {
|
||||
return weight;
|
||||
}
|
||||
@@ -304,7 +306,8 @@ public class TextIndexDefinition implements IndexDefinition {
|
||||
*
|
||||
* @param language
|
||||
* @return
|
||||
* @see <a href="https://docs.mongodb.org/manual/tutorial/specify-language-for-text-index/#specify-default-language-text-index">https://docs.mongodb.org/manual/tutorial/specify-language-for-text-index/#specify-default-language-text-index</a>
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.org/manual/tutorial/specify-language-for-text-index/#specify-default-language-text-index">https://docs.mongodb.org/manual/tutorial/specify-language-for-text-index/#specify-default-language-text-index</a>
|
||||
*/
|
||||
public TextIndexDefinitionBuilder withDefaultLanguage(String language) {
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Support for MongoDB document indexing.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.index;
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mongodb.MongoCollectionUtils;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -39,6 +39,7 @@ import org.springframework.expression.ParserContext;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -176,13 +177,17 @@ public class BasicMongoPersistentEntity<T> extends BasicPersistentEntity<T, Mong
|
||||
* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public int compare(MongoPersistentProperty o1, MongoPersistentProperty o2) {
|
||||
public int compare(@Nullable MongoPersistentProperty o1, @Nullable MongoPersistentProperty o2) {
|
||||
|
||||
if (o1.getFieldOrder() == Integer.MAX_VALUE) {
|
||||
if (o1 != null && o1.getFieldOrder() == Integer.MAX_VALUE) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (o2.getFieldOrder() == Integer.MAX_VALUE) {
|
||||
if (o2 != null && o2.getFieldOrder() == Integer.MAX_VALUE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (o1 == null && o2 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core.mapping;
|
||||
import org.springframework.data.mapping.model.FieldNamingStrategy;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link MongoPersistentProperty} caching access to {@link #isIdProperty()} and {@link #getFieldName()}.
|
||||
@@ -26,11 +27,11 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
*/
|
||||
public class CachingMongoPersistentProperty extends BasicMongoPersistentProperty {
|
||||
|
||||
private Boolean isIdProperty;
|
||||
private Boolean isAssociation;
|
||||
private String fieldName;
|
||||
private Boolean usePropertyAccess;
|
||||
private Boolean isTransient;
|
||||
private @Nullable Boolean isIdProperty;
|
||||
private @Nullable Boolean isAssociation;
|
||||
private @Nullable String fieldName;
|
||||
private @Nullable Boolean usePropertyAccess;
|
||||
private @Nullable Boolean isTransient;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CachingMongoPersistentProperty}.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Default implementation of a {@link MappingContext} for MongoDB using {@link BasicMongoPersistentEntity} and
|
||||
@@ -41,7 +42,7 @@ public class MongoMappingContext extends AbstractMappingContext<BasicMongoPersis
|
||||
private static final FieldNamingStrategy DEFAULT_NAMING_STRATEGY = PropertyNameFieldNamingStrategy.INSTANCE;
|
||||
|
||||
private FieldNamingStrategy fieldNamingStrategy = DEFAULT_NAMING_STRATEGY;
|
||||
private ApplicationContext context;
|
||||
private @Nullable ApplicationContext context;
|
||||
|
||||
/**
|
||||
* Creates a new {@link MongoMappingContext}.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 by the original author(s).
|
||||
* Copyright 2011-2017 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,6 +46,7 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void onApplicationEvent(MongoMappingEvent<?> event) {
|
||||
|
||||
if (event instanceof AfterLoadEvent) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,6 +51,7 @@ public class AuditingEventListener implements ApplicationListener<BeforeConvertE
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(BeforeConvertEvent<Object> event) {
|
||||
|
||||
Optional.ofNullable(event.getSource())//
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Mapping event callback infrastructure for the MongoDB document-to-object mapping subsystem.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.mapping.event;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Infrastructure for the MongoDB document-to-object mapping subsystem.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.mapping;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Optional;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Collects the parameters required to perform a group operation on a collection. The query condition and the input
|
||||
@@ -30,8 +31,8 @@ import org.springframework.data.mongodb.core.query.Collation;
|
||||
*/
|
||||
public class GroupBy {
|
||||
|
||||
private Document initialDocument;
|
||||
private String reduce;
|
||||
private @Nullable Document initialDocument;
|
||||
private @Nullable String reduce;
|
||||
|
||||
private Optional<Document> keys = Optional.empty();
|
||||
private Optional<String> keyFunction = Optional.empty();
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,7 @@ public class GroupByResults<T> implements Iterable<T> {
|
||||
|
||||
private double count;
|
||||
private int keys;
|
||||
private String serverUsed;
|
||||
private @Nullable String serverUsed;
|
||||
|
||||
public GroupByResults(List<T> mappedResults, Document rawResults) {
|
||||
|
||||
@@ -59,6 +60,7 @@ public class GroupByResults<T> implements Iterable<T> {
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getServerUsed() {
|
||||
return serverUsed;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.query.Collation;
|
||||
|
||||
import com.mongodb.MapReduceCommand;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Mark Pollack
|
||||
@@ -31,15 +32,15 @@ import com.mongodb.MapReduceCommand;
|
||||
*/
|
||||
public class MapReduceOptions {
|
||||
|
||||
private String outputCollection;
|
||||
private @Nullable String outputCollection;
|
||||
|
||||
private Optional<String> outputDatabase = Optional.empty();
|
||||
private MapReduceCommand.OutputType outputType = MapReduceCommand.OutputType.REPLACE;
|
||||
private Map<String, Object> scopeVariables = new HashMap<String, Object>();
|
||||
private Map<String, Object> extraOptions = new HashMap<String, Object>();
|
||||
private Boolean jsMode;
|
||||
private @Nullable Boolean jsMode;
|
||||
private Boolean verbose = Boolean.TRUE;
|
||||
private Integer limit;
|
||||
private @Nullable Integer limit;
|
||||
|
||||
private Optional<Boolean> outputSharded = Optional.empty();
|
||||
private Optional<String> finalizeFunction = Optional.empty();
|
||||
@@ -251,6 +252,7 @@ public class MapReduceOptions {
|
||||
return this.jsMode;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getOutputCollection() {
|
||||
return this.outputCollection;
|
||||
}
|
||||
@@ -276,6 +278,7 @@ public class MapReduceOptions {
|
||||
*
|
||||
* @return {@literal null} if not set.
|
||||
*/
|
||||
@Nullable
|
||||
public Integer getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Support for MongoDB map-reduce operations.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.mapreduce;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* MongoDB core support.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ public class BasicQuery extends Query {
|
||||
*/
|
||||
public BasicQuery(String query, String fields) {
|
||||
|
||||
this.queryObject = query != null ? Document.parse(query) : new Document();
|
||||
this.fieldsObject = fields != null ? Document.parse(fields) : new Document();
|
||||
this(query != null ? Document.parse(query) : new Document(),
|
||||
fields != null ? Document.parse(fields) : new Document());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +81,7 @@ public class BasicQuery extends Query {
|
||||
|
||||
this.queryObject = queryObject;
|
||||
this.fieldsObject = fieldsObject;
|
||||
this.sortObject = new Document();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -111,19 +112,10 @@ public class BasicQuery extends Query {
|
||||
@Override
|
||||
public Document getFieldsObject() {
|
||||
|
||||
if (fieldsObject == null) {
|
||||
return super.getFieldsObject();
|
||||
}
|
||||
|
||||
if (super.getFieldsObject() != null) {
|
||||
|
||||
Document combinedFieldsObject = new Document();
|
||||
combinedFieldsObject.putAll(fieldsObject);
|
||||
combinedFieldsObject.putAll(super.getFieldsObject());
|
||||
return combinedFieldsObject;
|
||||
}
|
||||
|
||||
return fieldsObject;
|
||||
Document combinedFieldsObject = new Document();
|
||||
combinedFieldsObject.putAll(fieldsObject);
|
||||
combinedFieldsObject.putAll(super.getFieldsObject());
|
||||
return combinedFieldsObject;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -134,10 +126,7 @@ public class BasicQuery extends Query {
|
||||
public Document getSortObject() {
|
||||
|
||||
Document result = new Document();
|
||||
|
||||
if (sortObject != null) {
|
||||
result.putAll(sortObject);
|
||||
}
|
||||
result.putAll(sortObject);
|
||||
|
||||
Document overrides = super.getSortObject();
|
||||
result.putAll(overrides);
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.data.geo.Shape;
|
||||
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
|
||||
import org.springframework.data.mongodb.core.geo.GeoJson;
|
||||
import org.springframework.data.mongodb.core.geo.Sphere;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -59,7 +60,7 @@ public class Criteria implements CriteriaDefinition {
|
||||
*/
|
||||
private static final Object NOT_SET = new Object();
|
||||
|
||||
private String key;
|
||||
private @Nullable String key;
|
||||
private List<Criteria> criteriaChain;
|
||||
private LinkedHashMap<String, Object> criteria = new LinkedHashMap<String, Object>();
|
||||
private Object isValue = NOT_SET;
|
||||
@@ -615,6 +616,11 @@ public class Criteria implements CriteriaDefinition {
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.data.mongodb.core.query.CriteriaDefinition#getKey()
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.mongodb.core.query;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
@@ -25,17 +26,18 @@ public interface CriteriaDefinition {
|
||||
|
||||
/**
|
||||
* Get {@link Document} representation.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
Document getCriteriaObject();
|
||||
|
||||
/**
|
||||
* Get the identifying {@literal key}.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return can be {@literal null}.
|
||||
* @since 1.6
|
||||
*/
|
||||
@Nullable
|
||||
String getKey();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,7 @@ public class Field {
|
||||
private final Map<String, Integer> criteria = new HashMap<String, Integer>();
|
||||
private final Map<String, Object> slices = new HashMap<String, Object>();
|
||||
private final Map<String, Criteria> elemMatchs = new HashMap<String, Criteria>();
|
||||
private String postionKey;
|
||||
private @Nullable String postionKey;
|
||||
private int positionValue;
|
||||
|
||||
public Field include(String key) {
|
||||
|
||||
@@ -24,7 +24,9 @@ import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Metric;
|
||||
import org.springframework.data.geo.Metrics;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Builder class to build near-queries.
|
||||
@@ -36,40 +38,39 @@ import org.springframework.util.Assert;
|
||||
public final class NearQuery {
|
||||
|
||||
private final Point point;
|
||||
private Query query;
|
||||
private Distance maxDistance;
|
||||
private Distance minDistance;
|
||||
private @Nullable Query query;
|
||||
private @Nullable Distance maxDistance;
|
||||
private @Nullable Distance minDistance;
|
||||
private Metric metric;
|
||||
private boolean spherical;
|
||||
private Long num;
|
||||
private Long skip;
|
||||
private @Nullable Long num;
|
||||
private @Nullable Long skip;
|
||||
|
||||
/**
|
||||
* Creates a new {@link NearQuery}.
|
||||
*
|
||||
* @param point must not be {@literal null}.
|
||||
* @param metric must not be {@literal null}.
|
||||
*/
|
||||
private NearQuery(Point point, Metric metric) {
|
||||
|
||||
Assert.notNull(point, "Point must not be null!");
|
||||
Assert.notNull(metric, "Metric must not be null!");
|
||||
|
||||
this.point = point;
|
||||
this.spherical = false;
|
||||
|
||||
if (metric != null) {
|
||||
in(metric);
|
||||
}
|
||||
this.metric = metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link NearQuery} starting near the given coordinates.
|
||||
*
|
||||
* @param i
|
||||
* @param j
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
public static NearQuery near(double x, double y) {
|
||||
return near(x, y, null);
|
||||
return near(x, y, Metrics.NEUTRAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +80,7 @@ public final class NearQuery {
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param metric
|
||||
* @param metric must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static NearQuery near(double x, double y, Metric metric) {
|
||||
@@ -93,7 +94,7 @@ public final class NearQuery {
|
||||
* @return
|
||||
*/
|
||||
public static NearQuery near(Point point) {
|
||||
return near(point, null);
|
||||
return near(point, Metrics.NEUTRAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +103,7 @@ public final class NearQuery {
|
||||
* initially set {@link Metric}.
|
||||
*
|
||||
* @param point must not be {@literal null}.
|
||||
* @param metric
|
||||
* @param metric must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static NearQuery near(Point point, Metric metric) {
|
||||
@@ -116,7 +117,7 @@ public final class NearQuery {
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
public Metric getMetric() {
|
||||
return metric == null ? Metrics.NEUTRAL : metric;
|
||||
return metric;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +192,7 @@ public final class NearQuery {
|
||||
|
||||
/**
|
||||
* Sets the maximum distance to the given {@link Distance}. Will set the returned {@link Metric} to be the one of the
|
||||
* given {@link Distance} if no {@link Metric} was set before.
|
||||
* given {@link Distance} if {@link Metric} was {@link Metrics#NEUTRAL} before.
|
||||
*
|
||||
* @param distance must not be {@literal null}.
|
||||
* @return
|
||||
@@ -204,7 +205,7 @@ public final class NearQuery {
|
||||
this.spherical(true);
|
||||
}
|
||||
|
||||
if (this.metric == null) {
|
||||
if (ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, this.metric)) {
|
||||
in(distance.getMetric());
|
||||
}
|
||||
|
||||
@@ -275,6 +276,7 @@ public final class NearQuery {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public Distance getMaxDistance() {
|
||||
return this.maxDistance;
|
||||
}
|
||||
@@ -285,6 +287,7 @@ public final class NearQuery {
|
||||
* @return
|
||||
* @since 1.7
|
||||
*/
|
||||
@Nullable
|
||||
public Distance getMinDistance() {
|
||||
return this.minDistance;
|
||||
}
|
||||
@@ -378,6 +381,7 @@ public final class NearQuery {
|
||||
public NearQuery query(Query query) {
|
||||
|
||||
Assert.notNull(query, "Cannot apply 'null' query on NearQuery.");
|
||||
|
||||
this.query = query;
|
||||
this.skip = query.getSkip();
|
||||
|
||||
@@ -390,6 +394,7 @@ public final class NearQuery {
|
||||
/**
|
||||
* @return the number of elements to skip.
|
||||
*/
|
||||
@Nullable
|
||||
public Long getSkip() {
|
||||
return skip;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ public class Query {
|
||||
private Sort sort = Sort.unsorted();
|
||||
private long skip;
|
||||
private int limit;
|
||||
private String hint;
|
||||
private @Nullable String hint;
|
||||
|
||||
private Meta meta = new Meta();
|
||||
|
||||
@@ -282,6 +283,7 @@ public class Query {
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public String getHint() {
|
||||
return hint;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -33,8 +34,8 @@ public class TextCriteria implements CriteriaDefinition {
|
||||
|
||||
private final List<Term> terms;
|
||||
private String language;
|
||||
private Boolean caseSensitive;
|
||||
private Boolean diacriticSensitive;
|
||||
private @Nullable Boolean caseSensitive;
|
||||
private @Nullable Boolean diacriticSensitive;
|
||||
|
||||
/**
|
||||
* Creates a new {@link TextCriteria}.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* MongoDB specific query and update support.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.query;
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Abstraction classes javascript function execution within MongoDB Server.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.script;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* Support classes to transform SpEL expressions into MongoDB expressions.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.spel;
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.core.spel;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
* Copyright 2011-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.mongodb.gridfs;
|
||||
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* GridFs-specific helper class to define {@link Criteria}s.
|
||||
@@ -49,7 +50,8 @@ public class GridFsCriteria extends Criteria {
|
||||
* @param metadataKey
|
||||
* @return
|
||||
*/
|
||||
public static GridFsCriteria whereMetaData(String metadataKey) {
|
||||
public static GridFsCriteria whereMetaData(@Nullable String metadataKey) {
|
||||
|
||||
String extension = metadataKey == null ? "" : "." + metadataKey;
|
||||
return new GridFsCriteria(String.format("metadata%s", extension));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.bson.types.ObjectId;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.mongodb.client.gridfs.GridFSFindIterable;
|
||||
import com.mongodb.gridfs.GridFSFile;
|
||||
@@ -53,7 +54,7 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
* @param metadata can be {@literal null}.
|
||||
* @return the {@link GridFSFile} just created
|
||||
*/
|
||||
ObjectId store(InputStream content, Object metadata);
|
||||
ObjectId store(InputStream content, @Nullable Object metadata);
|
||||
|
||||
/**
|
||||
* Stores the given content into a file with the given name.
|
||||
@@ -62,7 +63,7 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
* @param metadata can be {@literal null}.
|
||||
* @return the {@link GridFSFile} just created
|
||||
*/
|
||||
ObjectId store(InputStream content, Document metadata);
|
||||
ObjectId store(InputStream content, @Nullable Document metadata);
|
||||
|
||||
/**
|
||||
* Stores the given content into a file with the given name and content type.
|
||||
@@ -72,18 +73,18 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
* @param contentType can be {@literal null}.
|
||||
* @return the {@link GridFSFile} just created
|
||||
*/
|
||||
ObjectId store(InputStream content, String filename, String contentType);
|
||||
ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType);
|
||||
|
||||
/**
|
||||
* Stores the given content into a file with the given name using the given metadata. The metadata object will be
|
||||
* marshalled before writing.
|
||||
*
|
||||
* @param content must not be {@literal null}.
|
||||
* @param filename must not be {@literal null} or empty.
|
||||
* @param filename can be {@literal null} or empty.
|
||||
* @param metadata can be {@literal null}.
|
||||
* @return the {@link GridFSFile} just created
|
||||
*/
|
||||
ObjectId store(InputStream content, String filename, Object metadata);
|
||||
ObjectId store(InputStream content, @Nullable String filename, @Nullable Object metadata);
|
||||
|
||||
/**
|
||||
* Stores the given content into a file with the given name and content type using the given metadata. The metadata
|
||||
@@ -95,7 +96,7 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
* @param metadata can be {@literal null}
|
||||
* @return the {@link GridFSFile} just created
|
||||
*/
|
||||
ObjectId store(InputStream content, String filename, String contentType, Object metadata);
|
||||
ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Object metadata);
|
||||
|
||||
/**
|
||||
* Stores the given content into a file with the given name using the given metadata.
|
||||
@@ -105,7 +106,7 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
* @param metadata can be {@literal null}.
|
||||
* @return the {@link GridFSFile} just created
|
||||
*/
|
||||
ObjectId store(InputStream content, String filename, Document metadata);
|
||||
ObjectId store(InputStream content, @Nullable String filename, @Nullable Document metadata);
|
||||
|
||||
/**
|
||||
* Stores the given content into a file with the given name and content type using the given metadata.
|
||||
@@ -116,14 +117,14 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
* @param metadata can be {@literal null}.
|
||||
* @return the {@link GridFSFile} just created
|
||||
*/
|
||||
ObjectId store(InputStream content, String filename, String contentType, Document metadata);
|
||||
ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Document metadata);
|
||||
|
||||
/**
|
||||
* Returns all files matching the given query. Note, that currently {@link Sort} criterias defined at the
|
||||
* {@link Query} will not be regarded as MongoDB does not support ordering for GridFS file access.
|
||||
*
|
||||
* @see <a href="https://jira.mongodb.org/browse/JAVA-431">MongoDB Jira: JAVA-431</a>
|
||||
* @param query
|
||||
* @param query must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
GridFSFindIterable find(Query query);
|
||||
@@ -131,22 +132,23 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
/**
|
||||
* Returns a single file matching the given query or {@literal null} in case no file matches.
|
||||
*
|
||||
* @param query
|
||||
* @param query must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
com.mongodb.client.gridfs.model.GridFSFile findOne(Query query);
|
||||
|
||||
/**
|
||||
* Deletes all files matching the given {@link Query}.
|
||||
*
|
||||
* @param query
|
||||
* @param query must not be {@literal null}.
|
||||
*/
|
||||
void delete(Query query);
|
||||
|
||||
/**
|
||||
* Returns all {@link GridFsResource} with the given file name.
|
||||
*
|
||||
* @param filename
|
||||
* @param filename must not be {@literal null}.
|
||||
* @return the resource if it exists or {@literal null}.
|
||||
* @see ResourcePatternResolver#getResource(String)
|
||||
*/
|
||||
@@ -155,7 +157,7 @@ public interface GridFsOperations extends ResourcePatternResolver {
|
||||
/**
|
||||
* Returns all {@link GridFsResource}s matching the given file name pattern.
|
||||
*
|
||||
* @param filenamePattern
|
||||
* @param filenamePattern must not be {@literal null}.
|
||||
* @return
|
||||
* @see ResourcePatternResolver#getResources(String)
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.data.mongodb.MongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -54,6 +55,7 @@ import com.mongodb.client.gridfs.model.GridFSUploadOptions;
|
||||
public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver {
|
||||
|
||||
private final MongoDbFactory dbFactory;
|
||||
|
||||
private final String bucket;
|
||||
private final MongoConverter converter;
|
||||
private final QueryMapper queryMapper;
|
||||
@@ -99,9 +101,8 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.gridfs.GridFsOperations#store(java.io.InputStream, java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ObjectId store(InputStream content, Object metadata) {
|
||||
public ObjectId store(InputStream content, @Nullable Object metadata) {
|
||||
return store(content, null, metadata);
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
* @see org.springframework.data.mongodb.gridfs.GridFsOperations#store(java.io.InputStream, com.mongodb.Document)
|
||||
*/
|
||||
@Override
|
||||
public ObjectId store(InputStream content, Document metadata) {
|
||||
public ObjectId store(InputStream content, @Nullable Document metadata) {
|
||||
return store(content, null, metadata);
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.gridfs.GridFsOperations#store(java.io.InputStream, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public ObjectId store(InputStream content, String filename, String contentType) {
|
||||
public ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType) {
|
||||
return store(content, filename, contentType, (Object) null);
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.gridfs.GridFsOperations#store(java.io.InputStream, java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public ObjectId store(InputStream content, String filename, Object metadata) {
|
||||
public ObjectId store(InputStream content, @Nullable String filename, @Nullable Object metadata) {
|
||||
return store(content, filename, null, metadata);
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.gridfs.GridFsOperations#store(java.io.InputStream, java.lang.String, java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public ObjectId store(InputStream content, String filename, String contentType, Object metadata) {
|
||||
public ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Object metadata) {
|
||||
|
||||
Document document = null;
|
||||
|
||||
@@ -150,7 +151,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.gridfs.GridFsOperations#store(java.io.InputStream, java.lang.String, com.mongodb.Document)
|
||||
*/
|
||||
public ObjectId store(InputStream content, String filename, Document metadata) {
|
||||
public ObjectId store(InputStream content, @Nullable String filename, @Nullable Document metadata) {
|
||||
return this.store(content, filename, null, metadata);
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.gridfs.GridFsOperations#store(java.io.InputStream, java.lang.String, com.mongodb.Document)
|
||||
*/
|
||||
public ObjectId store(InputStream content, String filename, String contentType, Document metadata) {
|
||||
public ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Document metadata) {
|
||||
|
||||
Assert.notNull(content, "InputStream must not be null!");
|
||||
|
||||
@@ -185,9 +186,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
*/
|
||||
public GridFSFindIterable find(Query query) {
|
||||
|
||||
if (query == null) {
|
||||
return getGridFs().find(new Document());
|
||||
}
|
||||
Assert.notNull(query, "Query must not be null!");
|
||||
|
||||
Document queryObject = getMappedQuery(query.getQueryObject());
|
||||
Document sortObject = getMappedQuery(query.getSortObject());
|
||||
@@ -260,7 +259,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
}
|
||||
|
||||
private Document getMappedQuery(Document query) {
|
||||
return query == null ? null : queryMapper.getMappedObject(query, Optional.empty());
|
||||
return queryMapper.getMappedObject(query, Optional.empty());
|
||||
}
|
||||
|
||||
private GridFSBucket getGridFs() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Support for MongoDB GridFS feature.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.gridfs;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* MongoDB specific JMX monitoring support.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.monitor;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Spring Data's MongoDB abstraction.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* CDI support for MongoDB specific repository implementation.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.repository.cdi;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Support infrastructure for the configuration of MongoDB specific repositories.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.repository.config;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* MongoDB specific repository implementation.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.repository;
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public Object execute(Object[] parameters) {
|
||||
|
||||
ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(operations.getConverter(),
|
||||
|
||||
@@ -29,7 +29,10 @@ import org.springframework.data.mongodb.repository.query.MongoParameters.MongoPa
|
||||
import org.springframework.data.repository.query.Parameter;
|
||||
import org.springframework.data.repository.query.Parameters;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Custom extension of {@link Parameters} discovering additional
|
||||
@@ -42,8 +45,7 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
|
||||
private final int rangeIndex;
|
||||
private final int maxDistanceIndex;
|
||||
private final Integer fullTextIndex;
|
||||
|
||||
private Integer nearIndex;
|
||||
private final Integer nearIndex;
|
||||
|
||||
/**
|
||||
* Creates a new {@link MongoParameters} instance from the given {@link Method} and {@link MongoQueryMethod}.
|
||||
@@ -64,11 +66,12 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
|
||||
this.rangeIndex = getTypeIndex(parameterTypeInfo, Range.class, Distance.class);
|
||||
this.maxDistanceIndex = this.rangeIndex == -1 ? getTypeIndex(parameterTypeInfo, Distance.class, null) : -1;
|
||||
|
||||
if (this.nearIndex == null && isGeoNearMethod) {
|
||||
this.nearIndex = getNearIndex(parameterTypes);
|
||||
} else if (this.nearIndex == null) {
|
||||
this.nearIndex = -1;
|
||||
int index = findNearIndexInParameters(method);
|
||||
if (index == -1 && isGeoNearMethod) {
|
||||
index = getNearIndex(parameterTypes);
|
||||
}
|
||||
|
||||
this.nearIndex = index;
|
||||
}
|
||||
|
||||
private MongoParameters(List<MongoParameter> parameters, int maxDistanceIndex, Integer nearIndex,
|
||||
@@ -102,26 +105,36 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findNearIndexInParameters(Method method) {
|
||||
|
||||
int index = -1;
|
||||
for (java.lang.reflect.Parameter p : method.getParameters()) {
|
||||
|
||||
MongoParameter param = createParameter(MethodParameter.forParameter(p));
|
||||
if (param.isManuallyAnnotatedNearParameter()) {
|
||||
if(index == -1) {
|
||||
index = param.getIndex();
|
||||
} else {
|
||||
throw new IllegalStateException(String.format("Found multiple @Near annotations ond method %s! Only one allowed!",
|
||||
method.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.Parameters#createParameter(org.springframework.core.MethodParameter)
|
||||
*/
|
||||
@Override
|
||||
protected MongoParameter createParameter(MethodParameter parameter) {
|
||||
|
||||
MongoParameter mongoParameter = new MongoParameter(parameter);
|
||||
|
||||
// Detect manually annotated @Near Point and reject multiple annotated ones
|
||||
if (this.nearIndex == null && mongoParameter.isManuallyAnnotatedNearParameter()) {
|
||||
this.nearIndex = mongoParameter.getIndex();
|
||||
} else if (mongoParameter.isManuallyAnnotatedNearParameter()) {
|
||||
throw new IllegalStateException(String.format("Found multiple @Near annotations ond method %s! Only one allowed!",
|
||||
parameter.getMethod().toString()));
|
||||
}
|
||||
|
||||
return mongoParameter;
|
||||
return new MongoParameter(parameter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getDistanceRangeIndex() {
|
||||
return -1;
|
||||
}
|
||||
@@ -180,7 +193,7 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
|
||||
return new MongoParameters(parameters, this.maxDistanceIndex, this.nearIndex, this.fullTextIndex, this.rangeIndex);
|
||||
}
|
||||
|
||||
private int getTypeIndex(List<TypeInformation<?>> parameterTypes, Class<?> type, Class<?> componentType) {
|
||||
private int getTypeIndex(List<TypeInformation<?>> parameterTypes, Class<?> type, @Nullable Class<?> componentType) {
|
||||
|
||||
for (int i = 0; i < parameterTypes.size(); i++) {
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.query.QueryMethod;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -57,7 +58,7 @@ public class MongoQueryMethod extends QueryMethod {
|
||||
private final Method method;
|
||||
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
|
||||
|
||||
private MongoEntityMetadata<?> metadata;
|
||||
private @Nullable MongoEntityMetadata<?> metadata;
|
||||
|
||||
/**
|
||||
* Creates a new {@link MongoQueryMethod} from the given {@link Method}.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Query derivation mechanism for MongoDB specific repositories.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user