diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java index 69b396bdb..06fcef41f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java @@ -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. @@ -369,7 +369,9 @@ public class MappingMongoConverterParser implements BeanDefinitionParser { * @param filters */ public NegatingFilter(TypeFilter... filters) { - Assert.notNull(filters); + + Assert.notNull(filters, "TypeFilters must not be null"); + this.delegates = new HashSet(Arrays.asList(filters)); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java index 63e67d030..adf9ccbe7 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java @@ -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. @@ -18,7 +18,6 @@ package org.springframework.data.mongodb.core; import static org.springframework.data.mongodb.core.MongoTemplate.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -189,7 +188,7 @@ public class DefaultIndexOperations implements IndexOperations { public T execute(CollectionCallback callback) { - Assert.notNull(callback); + Assert.notNull(callback, "CollectionCallback must not be null!"); try { MongoCollection collection = mongoDbFactory.getDb().getCollection(collectionName); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java index 804ad5e59..aaa64ff27 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java @@ -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. @@ -27,7 +27,8 @@ import com.mongodb.Mongo; * Mongo server administration exposed via JMX annotations * * @author Mark Pollack - * @author Thomas Darimont + * @author Thomas Darimont + * @author Mark Paluch */ @ManagedResource(description = "Mongo Admin Operations") public class MongoAdmin implements MongoAdminOperations { @@ -35,10 +36,11 @@ public class MongoAdmin implements MongoAdminOperations { private final Mongo mongo; private String username; private String password; - private String authenticationDatabaseName; + private String authenticationDatabaseName; public MongoAdmin(Mongo mongo) { - Assert.notNull(mongo); + + Assert.notNull(mongo, "Mongo must not be null!"); this.mongo = mongo; } @@ -84,16 +86,16 @@ public class MongoAdmin implements MongoAdminOperations { this.password = password; } - /** - * Sets the authenticationDatabaseName to use to authenticate with the Mongo database. - * - * @param authenticationDatabaseName The authenticationDatabaseName to use. - */ - public void setAuthenticationDatabaseName(String authenticationDatabaseName) { - this.authenticationDatabaseName = authenticationDatabaseName; - } - + /** + * Sets the authenticationDatabaseName to use to authenticate with the Mongo database. + * + * @param authenticationDatabaseName The authenticationDatabaseName to use. + */ + public void setAuthenticationDatabaseName(String authenticationDatabaseName) { + this.authenticationDatabaseName = authenticationDatabaseName; + } + DB getDB(String databaseName) { - return MongoDbUtils.getDB(mongo, databaseName, new UserCredentials(username, password), authenticationDatabaseName); + return MongoDbUtils.getDB(mongo, databaseName, new UserCredentials(username, password), authenticationDatabaseName); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java index 6fb9a0ce9..23ae2b1f9 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java @@ -218,7 +218,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, */ public MongoTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter) { - Assert.notNull(mongoDbFactory); + Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null!"); this.mongoDbFactory = mongoDbFactory; this.exceptionTranslator = mongoDbFactory.getExceptionTranslator(); @@ -438,7 +438,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, protected void executeQuery(Query query, String collectionName, DocumentCallbackHandler dch, CursorPreparer preparer) { - Assert.notNull(query); + Assert.notNull(query, "Query must not be null!"); Document queryObject = queryMapper.getMappedObject(query.getQueryObject(), null); Document sortObject = query.getSortObject(); @@ -454,7 +454,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, public T execute(DbCallback action) { - Assert.notNull(action); + Assert.notNull(action, "DbCallbackmust not be null!"); try { MongoDatabase db = this.getDb(); @@ -470,7 +470,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, public T execute(String collectionName, CollectionCallback callback) { - Assert.notNull(callback); + Assert.notNull(callback, "CollectionCallback must not be null!"); try { MongoCollection collection = getAndPrepareCollection(getDb(), collectionName); @@ -735,7 +735,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, } public long count(Query query, Class entityClass) { - Assert.notNull(entityClass); + + Assert.notNull(entityClass, "Entity class must not be null!"); return count(query, entityClass, determineCollectionName(entityClass)); } @@ -749,7 +750,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, */ public long count(Query query, Class entityClass, String collectionName) { - Assert.hasText(collectionName); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); + final Document document = query == null ? null : queryMapper.getMappedObject(query.getQueryObject(), entityClass == null ? null : mappingContext.getPersistentEntity(entityClass)); @@ -932,7 +934,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, protected void doInsertBatch(String collectionName, Collection batchToSave, MongoWriter writer) { - Assert.notNull(writer); + Assert.notNull(writer, "MongoWriter must not be null!"); List documentList = new ArrayList(); for (T o : batchToSave) { @@ -960,14 +962,14 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, public void save(Object objectToSave) { - Assert.notNull(objectToSave); + Assert.notNull(objectToSave, "Object to save must not be null!"); save(objectToSave, determineEntityCollectionName(objectToSave)); } public void save(Object objectToSave, String collectionName) { - Assert.notNull(objectToSave); - Assert.hasText(collectionName); + Assert.notNull(objectToSave, "Object to save must not be null!"); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); MongoPersistentEntity mongoPersistentEntity = getPersistentEntity(objectToSave.getClass()); @@ -1240,7 +1242,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, public DeleteResult remove(Object object, String collection) { - Assert.hasText(collection); + Assert.hasText(collection, "Collection name must not be null or empty!"); if (object == null) { return null; @@ -2348,8 +2350,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, public ReadDocumentCallback(EntityReader reader, Class type, String collectionName) { - Assert.notNull(reader); - Assert.notNull(type); + Assert.notNull(reader, "EntityReader must not be null!"); + Assert.notNull(type, "Entity type must not be null!"); + this.reader = reader; this.type = type; this.collectionName = collectionName; @@ -2491,7 +2494,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, * @param delegate must not be {@literal null}. */ public GeoNearResultDocumentCallback(DocumentCallback delegate, Metric metric) { - Assert.notNull(delegate); + + Assert.notNull(delegate, "DocumentCallback must not be null!"); + this.delegate = delegate; this.metric = metric; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java index b3f9bc7aa..c13bae356 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java @@ -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. @@ -373,7 +373,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#execute(java.lang.String, org.springframework.data.mongodb.core.ReactiveCollectionCallback) */ public Flux execute(String collectionName, ReactiveCollectionCallback callback) { - Assert.notNull(callback); + + Assert.notNull(callback, "ReactiveCollectionCallback must not be null!"); return createFlux(collectionName, callback); } @@ -386,7 +387,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Flux createFlux(ReactiveDatabaseCallback callback) { - Assert.notNull(callback); + Assert.notNull(callback, "ReactiveDatabaseCallback must not be null!"); return Flux.defer(() -> callback.doInDB(getMongoDatabase())).onErrorResumeWith(translateFluxException()); } @@ -400,7 +401,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Mono createMono(final ReactiveDatabaseCallback callback) { - Assert.notNull(callback); + Assert.notNull(callback, "ReactiveDatabaseCallback must not be null!"); return Mono.defer(() -> Mono.from(callback.doInDB(getMongoDatabase()))).otherwise(translateMonoException()); } @@ -414,8 +415,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Flux createFlux(String collectionName, ReactiveCollectionCallback callback) { - Assert.hasText(collectionName); - Assert.notNull(callback); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); + Assert.notNull(callback, "ReactiveDatabaseCallback must not be null!"); Mono> collectionPublisher = Mono .fromCallable(() -> getAndPrepareCollection(getMongoDatabase(), collectionName)); @@ -433,8 +434,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Mono createMono(String collectionName, ReactiveCollectionCallback callback) { - Assert.hasText(collectionName); - Assert.notNull(callback); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); + Assert.notNull(callback, "ReactiveCollectionCallback must not be null!"); Mono> collectionPublisher = Mono .fromCallable(() -> getAndPrepareCollection(getMongoDatabase(), collectionName)); @@ -729,7 +730,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#count(org.springframework.data.mongodb.core.query.Query, java.lang.Class) */ public Mono count(Query query, Class entityClass) { - Assert.notNull(entityClass); + + Assert.notNull(entityClass, "Entity class must not be null!"); + return count(query, entityClass, determineCollectionName(entityClass)); } @@ -745,7 +748,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Mono count(final Query query, final Class entityClass, String collectionName) { - Assert.hasText(collectionName); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); return createMono(collectionName, collection -> { @@ -880,7 +883,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati protected Flux doInsertBatch(final String collectionName, final Collection batchToSave, final MongoWriter writer) { - Assert.notNull(writer); + Assert.notNull(writer, "MongoWriter must not be null!"); Mono>> prepareDocuments = Flux.fromIterable(batchToSave) .flatMap(new Function>>() { @@ -933,7 +936,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Mono save(T objectToSave) { - Assert.notNull(objectToSave); + Assert.notNull(objectToSave, "Object to save must not be null!"); return save(objectToSave, determineEntityCollectionName(objectToSave)); } @@ -942,8 +945,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Mono save(T objectToSave, String collectionName) { - Assert.notNull(objectToSave); - Assert.hasText(collectionName); + Assert.notNull(objectToSave, "Object to save must not be null!"); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); MongoPersistentEntity mongoPersistentEntity = getPersistentEntity(objectToSave.getClass()); @@ -1275,7 +1278,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Mono remove(Object object, String collection) { - Assert.hasText(collection); + Assert.hasText(collection, "Collection name must not be null or empty!"); if (object == null) { return null; @@ -1839,7 +1842,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati private T execute(MongoDatabaseCallback action) { - Assert.notNull(action); + Assert.notNull(action, "MongoDatabaseCallback must not be null!"); try { MongoDatabase db = this.getMongoDatabase(); @@ -2202,8 +2205,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati ReadDocumentCallback(EntityReader reader, Class type, String collectionName) { - Assert.notNull(reader); - Assert.notNull(type); + Assert.notNull(reader, "EntityReader must not be null!"); + Assert.notNull(type, "Entity type must not be null!"); + this.reader = reader; this.type = type; this.collectionName = collectionName; @@ -2240,7 +2244,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ GeoNearResultDbObjectCallback(DocumentCallback delegate, Metric metric) { - Assert.notNull(delegate); + Assert.notNull(delegate, "DocumentCallback must not be null!"); + this.delegate = delegate; this.metric = metric; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java index dec351601..c45d34a82 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 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. @@ -29,6 +29,7 @@ import org.springframework.util.Assert; * @author Oliver Gierke * @author Thomas Darimont * @author Christoph Strobl + * @author Mark Paluch * @param The class in which the results are mapped onto. * @since 1.3 */ @@ -46,8 +47,8 @@ public class AggregationResults implements Iterable { */ public AggregationResults(List mappedResults, Document rawResults) { - Assert.notNull(mappedResults); - Assert.notNull(rawResults); + Assert.notNull(mappedResults, "List of mapped results must not be null!"); + Assert.notNull(rawResults, "Raw results must not be null!"); this.mappedResults = Collections.unmodifiableList(mappedResults); this.rawResults = rawResults; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java index 3365c2359..133d778a5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java @@ -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. @@ -23,6 +23,7 @@ import org.springframework.util.Assert; * Conversion registration information. * * @author Oliver Gierke + * @author Mark Paluch */ class ConverterRegistration { @@ -39,7 +40,7 @@ class ConverterRegistration { */ public ConverterRegistration(ConvertiblePair convertiblePair, boolean isReading, boolean isWriting) { - Assert.notNull(convertiblePair); + Assert.notNull(convertiblePair, "ConvertiblePair must not be null!"); this.convertiblePair = convertiblePair; this.reading = isReading; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java index e57c92a6c..ffea59ed5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java @@ -89,7 +89,7 @@ public class CustomConversions { */ public CustomConversions(List converters) { - Assert.notNull(converters); + Assert.notNull(converters, "List of converters must not be null!"); this.readingPairs = new LinkedHashSet(); this.writingPairs = new LinkedHashSet(); @@ -346,8 +346,8 @@ public class CustomConversions { private static Class getCustomTarget(Class sourceType, Class requestedTargetType, Collection pairs) { - Assert.notNull(sourceType); - Assert.notNull(pairs); + Assert.notNull(sourceType, "Source Class must not be null!"); + Assert.notNull(pairs, "Collection of ConvertiblePair must not be null!"); if (requestedTargetType != null && pairs.contains(new ConvertiblePair(sourceType, requestedTargetType))) { return requestedTargetType; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java index 1fb169435..f7557f30b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java @@ -1,11 +1,11 @@ /* - * Copyright 2011-2017 by the original author(s). + * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -326,7 +326,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App return result; } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.convert.MongoWriter#toDBRef(java.lang.Object, org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) */ @@ -497,7 +497,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App DBRef dbRefObj = null; /* - * If we already have a LazyLoadingProxy, we use it's cached DBRef value instead of + * If we already have a LazyLoadingProxy, we use it's cached DBRef value instead of * unnecessarily initializing it only to convert it to a DBRef a few instructions later. */ if (obj instanceof LazyLoadingProxy) { @@ -851,7 +851,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App protected DBRef createDBRef(Object target, MongoPersistentProperty property) { - Assert.notNull(target); + Assert.notNull(target, "Target object must not be null!"); if (target instanceof DBRef) { return (DBRef) target; @@ -1172,7 +1172,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App /** * Removes the type information from the entire conversion result. - * + * * @param object * @param recursively whether to apply the removal recursively * @return @@ -1237,22 +1237,22 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App /** * Creates a new {@link MongoDbPropertyValueProvider} for the given source, {@link SpELExpressionEvaluator} and * {@link ObjectPath}. - * + * * @param source must not be {@literal null}. * @param evaluator must not be {@literal null}. * @param path can be {@literal null}. */ public MongoDbPropertyValueProvider(Bson source, SpELExpressionEvaluator evaluator, ObjectPath path) { - Assert.notNull(source); - Assert.notNull(evaluator); + Assert.notNull(source, "Bson source must not be null!"); + Assert.notNull(evaluator, "SpELExpressionEvaluator must not be null!"); this.source = new DocumentAccessor(source); this.evaluator = evaluator; this.path = path; } - /* + /* * (non-Javadoc) * @see org.springframework.data.convert.PropertyValueProvider#getPropertyValue(org.springframework.data.mapping.PersistentProperty) */ @@ -1295,7 +1295,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App this.path = path; } - /* + /* * (non-Javadoc) * @see org.springframework.data.mapping.model.SpELExpressionParameterValueProvider#potentiallyConvertSpelValue(java.lang.Object, org.springframework.data.mapping.PreferredConstructor.Parameter) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java index 492cb870a..a00b48dde 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java @@ -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. @@ -86,7 +86,7 @@ public class QueryMapper { */ public QueryMapper(MongoConverter converter) { - Assert.notNull(converter); + Assert.notNull(converter, "MongoConverter must not be null!"); this.conversionService = converter.getConversionService(); this.converter = converter; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java index 0cb623ef2..ccfb41d3c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -29,6 +29,7 @@ import org.springframework.util.Assert; * Represents a geospatial sphere value. * * @author Thomas Darimont + * @author Mark Paluch * @since 1.5 */ public class Sphere implements Shape { @@ -46,8 +47,8 @@ public class Sphere implements Shape { @PersistenceConstructor public Sphere(Point center, Distance radius) { - Assert.notNull(center); - Assert.notNull(radius); + Assert.notNull(center, "Center point must not be null!"); + Assert.notNull(radius, "Radius must not be null!"); Assert.isTrue(radius.getValue() >= 0, "Radius must not be negative!"); this.center = center; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java index 8bf243ee7..dd74cf365 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java @@ -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. @@ -43,8 +43,13 @@ public final class IndexField { private IndexField(String key, Direction direction, Type type, Float weight) { - Assert.hasText(key); - Assert.isTrue(direction != null ^ (Type.GEO.equals(type) || Type.TEXT.equals(type))); + Assert.hasText(key, "Key must not be null or empty"); + + if (Type.GEO.equals(type) || Type.TEXT.equals(type)) { + Assert.isTrue(direction == null, "Geo/Text indexes must not have a direction!"); + } else { + Assert.notNull(direction, "Default indexes require a direction"); + } this.key = key; this.direction = direction; @@ -53,7 +58,9 @@ public final class IndexField { } public static IndexField create(String key, Direction order) { - Assert.notNull(order); + + Assert.notNull(order, "Direction must not be null!"); + return new IndexField(key, order, Type.DEFAULT); } @@ -102,7 +109,7 @@ public final class IndexField { } /** - * Returns wheter the {@link IndexField} is a text index field. + * Returns whether the {@link IndexField} is a text index field. * * @return true if type is {@link Type#TEXT} * @since 1.6 @@ -132,7 +139,7 @@ public final class IndexField { && this.type == that.type; } - /* + /* * (non-Javadoc) * @see java.lang.Object#hashCode() */ @@ -147,7 +154,7 @@ public final class IndexField { return result; } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java index 67c60d45d..f74c69439 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-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,17 +23,15 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import com.mongodb.DBObject; import org.bson.Document; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; -import com.mongodb.DBObject; - /** * @author Mark Pollack * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch */ public class IndexInfo { @@ -132,7 +130,8 @@ public class IndexInfo { */ public boolean isIndexForFields(Collection keys) { - Assert.notNull(keys); + Assert.notNull(keys, "Collection of keys must not be null!"); + List indexKeys = new ArrayList(indexFields.size()); for (IndexField field : indexFields) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java index 26ce21680..4f19ebd6c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java @@ -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. @@ -34,6 +34,7 @@ import org.springframework.util.Assert; * * @author Jon Brisbin * @author Oliver Gierke + * @author Mark Paluch */ public class MongoMappingEventPublisher implements ApplicationEventPublisher { @@ -46,7 +47,7 @@ public class MongoMappingEventPublisher implements ApplicationEventPublisher { */ public MongoMappingEventPublisher(MongoPersistentEntityIndexCreator indexCreator) { - Assert.notNull(indexCreator); + Assert.notNull(indexCreator, "MongoPersistentEntityIndexCreator must not be null!"); this.indexCreator = indexCreator; } @@ -61,7 +62,7 @@ public class MongoMappingEventPublisher implements ApplicationEventPublisher { } } - /* + /* * (non-Javadoc) * @see org.springframework.context.ApplicationEventPublisher#publishEvent(java.lang.Object) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java index 007f9dc66..a1a31e68d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java @@ -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. @@ -23,7 +23,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationListener; import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.context.MappingContextEvent; @@ -82,9 +81,10 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener extends BasicPersistentEntity implements MongoPersistentEntity, ApplicationContextAware { @@ -138,7 +139,7 @@ public class BasicMongoPersistentEntity extends BasicPersistentEntity extends BasicPersistentEntity The class in which the results are mapped onto, accessible via an {@link Iterator}. */ public class GroupByResults implements Iterable { @@ -39,10 +40,12 @@ public class GroupByResults implements Iterable { public GroupByResults(List mappedResults, Document rawResults) { - Assert.notNull(mappedResults); - Assert.notNull(rawResults); + Assert.notNull(mappedResults, "List of mapped results must not be null!"); + Assert.notNull(rawResults, "Raw results must not be null!"); + this.mappedResults = mappedResults; this.rawResults = rawResults; + parseKeys(); parseCount(); parseServerUsed(); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java index 983498f4c..bb7d21bdd 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -29,6 +29,7 @@ import com.mongodb.MapReduceOutput; * @author Mark Pollack * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch * @param The class in which the results are mapped onto, accessible via an iterator. */ public class MapReduceResults implements Iterable { @@ -49,8 +50,8 @@ public class MapReduceResults implements Iterable { @Deprecated public MapReduceResults(List mappedResults, Document rawResults) { - Assert.notNull(mappedResults); - Assert.notNull(rawResults); + Assert.notNull(mappedResults, "List of mapped results must not be null!"); + Assert.notNull(rawResults, "Raw results must not be null!"); this.mappedResults = mappedResults; this.rawResults = rawResults; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index dd2a10476..27f5856ce 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -50,6 +50,7 @@ import com.mongodb.BasicDBList; * @author Oliver Gierke * @author Thomas Darimont * @author Christoph Strobl + * @author Mark Paluch */ public class Criteria implements CriteriaDefinition { @@ -386,7 +387,7 @@ public class Criteria implements CriteriaDefinition { */ public Criteria regex(Pattern pattern) { - Assert.notNull(pattern); + Assert.notNull(pattern, "Pattern must not be null!"); if (lastOperatorWasNot()) { return not(pattern); @@ -407,7 +408,9 @@ public class Criteria implements CriteriaDefinition { } private Pattern toPattern(String regex, String options) { - Assert.notNull(regex); + + Assert.notNull(regex, "Regex string must not be null!"); + return Pattern.compile(regex, options == null ? 0 : BSON.regexFlags(options)); } @@ -421,7 +424,9 @@ public class Criteria implements CriteriaDefinition { * @see MongoDB Query operator: $centerSphere */ public Criteria withinSphere(Circle circle) { - Assert.notNull(circle); + + Assert.notNull(circle, "Circle must not be null!"); + criteria.put("$geoWithin", new GeoCommand(new Sphere(circle))); return this; } @@ -435,7 +440,8 @@ public class Criteria implements CriteriaDefinition { */ public Criteria within(Shape shape) { - Assert.notNull(shape); + Assert.notNull(shape, "Shape must not be null!"); + criteria.put("$geoWithin", new GeoCommand(shape)); return this; } @@ -448,7 +454,9 @@ public class Criteria implements CriteriaDefinition { * @see MongoDB Query operator: $near */ public Criteria near(Point point) { - Assert.notNull(point); + + Assert.notNull(point, "Point must not be null!"); + criteria.put("$near", point); return this; } @@ -462,7 +470,9 @@ public class Criteria implements CriteriaDefinition { * @see MongoDB Query operator: $nearSphere */ public Criteria nearSphere(Point point) { - Assert.notNull(point); + + Assert.notNull(point, "Point must not be null!"); + criteria.put("$nearSphere", point); return this; } @@ -716,7 +726,7 @@ public class Criteria implements CriteriaDefinition { return false; } - /* + /* * (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @@ -779,7 +789,7 @@ public class Criteria implements CriteriaDefinition { return ObjectUtils.nullSafeEquals(left, right); } - /* + /* * (non-Javadoc) * @see java.lang.Object#hashCode() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java index ec2fd0609..add50e92a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -47,11 +47,11 @@ public final class NearQuery { /** * Creates a new {@link NearQuery}. * - * @param point + * @param point must not be {@literal null}. */ private NearQuery(Point point, Metric metric) { - Assert.notNull(point); + Assert.notNull(point, "Point must not be null!"); this.point = point; this.spherical = false; @@ -106,7 +106,6 @@ public final class NearQuery { * @return */ public static NearQuery near(Point point, Metric metric) { - Assert.notNull(point); return new NearQuery(point, metric); } @@ -183,7 +182,8 @@ public final class NearQuery { */ public NearQuery maxDistance(double maxDistance, Metric metric) { - Assert.notNull(metric); + Assert.notNull(metric, "Metric must not be null!"); + return maxDistance(new Distance(maxDistance, metric)); } @@ -196,7 +196,7 @@ public final class NearQuery { */ public NearQuery maxDistance(Distance distance) { - Assert.notNull(distance); + Assert.notNull(distance, "Distance must not be null!"); if (distance.getMetric() != Metrics.NEUTRAL) { this.spherical(true); @@ -239,7 +239,8 @@ public final class NearQuery { */ public NearQuery minDistance(double minDistance, Metric metric) { - Assert.notNull(metric); + Assert.notNull(metric, "Metric must not be null!"); + return minDistance(new Distance(minDistance, metric)); } @@ -253,7 +254,7 @@ public final class NearQuery { */ public NearQuery minDistance(Distance distance) { - Assert.notNull(distance); + Assert.notNull(distance, "Distance must not be null!"); if (distance.getMetric() != Metrics.NEUTRAL) { this.spherical(true); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java index 01c7c1810..9fb3f5b89 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 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. @@ -31,6 +31,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch */ public class ExpressionNode implements Iterable { @@ -173,7 +174,7 @@ public class ExpressionNode implements Iterable { */ public ExpressionNode getChild(int index) { - Assert.isTrue(index >= 0); + Assert.isTrue(index >= 0, "Index must be greater or equal to zero!"); return from(node.getChild(index), state); } @@ -199,7 +200,7 @@ public class ExpressionNode implements Iterable { return from(node, state); } - /* + /* * (non-Javadoc) * @see java.lang.Iterable#iterator() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java index de20bc35d..a9fa8f84b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java @@ -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. @@ -24,6 +24,7 @@ import org.springframework.util.Assert; * Value object to abstract Ant paths. * * @author Oliver Gierke + * @author Mark Paluch */ class AntPath { @@ -38,7 +39,9 @@ class AntPath { * @param path must not be {@literal null}. */ public AntPath(String path) { - Assert.notNull(path); + + Assert.notNull(path, "Path must not be null!"); + this.path = path; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java index 223941dfd..ebb10588b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java @@ -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. @@ -48,6 +48,7 @@ import com.mongodb.client.gridfs.model.GridFSUploadOptions; * @author Thomas Darimont * @author Martin Baumgartner * @author Christoph Strobl + * @author Mark Paluch */ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver { @@ -75,8 +76,8 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver */ public GridFsTemplate(MongoDbFactory dbFactory, MongoConverter converter, String bucket) { - Assert.notNull(dbFactory); - Assert.notNull(converter); + Assert.notNull(dbFactory, "MongoDbFactory must not be null!"); + Assert.notNull(converter, "MongoConverter must not be null!"); this.dbFactory = dbFactory; this.converter = converter; @@ -158,7 +159,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver */ public ObjectId store(InputStream content, String filename, String contentType, Document metadata) { - Assert.notNull(content); + Assert.notNull(content, "InputStream must not be null!"); GridFSUploadOptions opts = new GridFSUploadOptions(); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java index 0a43c72b2..6a43fa025 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java @@ -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. @@ -53,11 +53,11 @@ public class MongoRepositoryBean extends CdiRepositoryBean { super(qualifiers, repositoryType, beanManager, detector); - Assert.notNull(operations); + Assert.notNull(operations, "MongoOperations bean must not be null!"); this.operations = operations; } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java index 15d0cd25e..f49f4d69d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java @@ -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. @@ -42,6 +42,7 @@ import com.mongodb.DBRef; * @author Oliver Gierke * @author Christoph Strobl * @author Thomas Darimont + * @author Mark Paluch */ public class ConvertingParameterAccessor implements MongoParameterAccessor { @@ -56,41 +57,41 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { */ public ConvertingParameterAccessor(MongoWriter writer, MongoParameterAccessor delegate) { - Assert.notNull(writer); - Assert.notNull(delegate); + Assert.notNull(writer, "MongoWriter must not be null!"); + Assert.notNull(delegate, "MongoParameterAccessor must not be null!"); this.writer = writer; this.delegate = delegate; } /* - * (non-Javadoc) - * - * @see java.lang.Iterable#iterator() - */ + * (non-Javadoc) + * + * @see java.lang.Iterable#iterator() + */ public PotentiallyConvertingIterator iterator() { return new ConvertingIterator(delegate.iterator()); } /* - * (non-Javadoc) - * - * @see org.springframework.data.repository.query.ParameterAccessor#getPageable() - */ + * (non-Javadoc) + * + * @see org.springframework.data.repository.query.ParameterAccessor#getPageable() + */ public Pageable getPageable() { return delegate.getPageable(); } /* - * (non-Javadoc) - * - * @see org.springframework.data.repository.query.ParameterAccessor#getSort() - */ + * (non-Javadoc) + * + * @see org.springframework.data.repository.query.ParameterAccessor#getSort() + */ public Sort getSort() { return delegate.getSort(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getDynamicProjection() */ @@ -107,7 +108,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return getConvertedValue(delegate.getBindableValue(index), null); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.query.MongoParameterAccessor#getDistanceRange() */ @@ -116,7 +117,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return delegate.getDistanceRange(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.MongoParameterAccessor#getGeoNearLocation() */ @@ -143,7 +144,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return writer.convertToMongoType(value, typeInformation == null ? null : typeInformation.getActualType()); } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#hasBindableNullValue() */ @@ -185,7 +186,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return delegate.next(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.ConvertingParameterAccessor.PotentiallConvertingIterator#nextConverted() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java index 694593ce5..0d40ed4d2 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java @@ -92,7 +92,7 @@ class MongoQueryCreator extends AbstractQueryCreator { super(tree, accessor); - Assert.notNull(context); + Assert.notNull(context, "MappingContext must not be null!"); this.accessor = accessor; this.isGeoNearQuery = isGeoNearQuery; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java index 4faa11e54..8259141e7 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java @@ -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. @@ -57,7 +57,7 @@ class IndexEnsuringQueryCreationListener implements QueryCreationListener extends SimpleM super(entityInformation, mongoOperations); - Assert.notNull(resolver); + Assert.notNull(resolver, "EntityPathResolver must not be null!"); + EntityPath path = resolver.createPath(entityInformation.getJavaType()); this.builder = new PathBuilder(path.getType(), path.getMetadata()); @@ -125,7 +126,7 @@ public class QueryDslMongoRepository extends SimpleM return applySorting(createQueryFor(predicate), sort).fetchResults().getResults(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(com.mysema.query.types.OrderSpecifier[]) */ @@ -188,7 +189,7 @@ public class QueryDslMongoRepository extends SimpleM return createQueryFor(predicate).fetchCount(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#exists(com.mysema.query.types.Predicate) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java index bce77cd8b..bbfe8dd9b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java @@ -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. @@ -27,6 +27,7 @@ import com.querydsl.mongodb.AbstractMongodbQuery; * Base class to create repository implementations based on Querydsl. * * @author Oliver Gierke + * @author Mark Paluch */ public abstract class QuerydslRepositorySupport { @@ -40,7 +41,7 @@ public abstract class QuerydslRepositorySupport { */ public QuerydslRepositorySupport(MongoOperations operations) { - Assert.notNull(operations); + Assert.notNull(operations, "MongoOperations must not be null!"); this.template = operations; this.context = operations.getConverter().getMappingContext(); @@ -54,7 +55,9 @@ public abstract class QuerydslRepositorySupport { * @return */ protected AbstractMongodbQuery> from(final EntityPath path) { - Assert.notNull(path); + + Assert.notNull(path, "EntityPath must not be null!"); + MongoPersistentEntity entity = context.getPersistentEntity(path.getType()); return from(path, entity.getCollection()); } @@ -68,8 +71,8 @@ public abstract class QuerydslRepositorySupport { */ protected AbstractMongodbQuery> from(final EntityPath path, String collection) { - Assert.notNull(path); - Assert.hasText(collection); + Assert.notNull(path, "EntityPath must not be null!"); + Assert.hasText(collection, "Collection name must not be null or empty!"); return new SpringDataMongodbQuery(template, path.getType(), collection); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveMongoRepositoryFactory.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveMongoRepositoryFactory.java index 1447cc86a..89cb9e7e9 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveMongoRepositoryFactory.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveMongoRepositoryFactory.java @@ -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. @@ -65,7 +65,7 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup */ public ReactiveMongoRepositoryFactory(ReactiveMongoOperations mongoOperations) { - Assert.notNull(mongoOperations); + Assert.notNull(mongoOperations, "ReactiveMongoOperations must not be null!"); this.operations = mongoOperations; this.mappingContext = mongoOperations.getConverter().getMappingContext(); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java index 83665535c..c6549dff6 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java @@ -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. @@ -61,8 +61,8 @@ public class SimpleMongoRepository implements MongoR */ public SimpleMongoRepository(MongoEntityInformation metadata, MongoOperations mongoOperations) { - Assert.notNull(mongoOperations); - Assert.notNull(metadata); + Assert.notNull(metadata, "MongoEntityInformation must not be null!"); + Assert.notNull(mongoOperations, "MongoOperations must not be null!"); this.entityInformation = metadata; this.mongoOperations = mongoOperations; @@ -197,7 +197,7 @@ public class SimpleMongoRepository implements MongoR return findAll(new Query()); } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) */ @@ -231,7 +231,7 @@ public class SimpleMongoRepository implements MongoR return findAll(new Query().with(sort)); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.MongoRepository#insert(java.lang.Object) */ @@ -244,7 +244,7 @@ public class SimpleMongoRepository implements MongoR return entity; } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.MongoRepository#insert(java.lang.Iterable) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java index 93ae0fb9c..7c8fb1a9d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java @@ -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. @@ -27,8 +27,6 @@ import java.util.Set; import org.reactivestreams.Publisher; import org.springframework.data.domain.Example; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.ReactiveMongoOperations; import org.springframework.data.mongodb.core.query.Criteria; @@ -61,8 +59,8 @@ public class SimpleReactiveMongoRepository implement public SimpleReactiveMongoRepository(MongoEntityInformation metadata, ReactiveMongoOperations mongoOperations) { - Assert.notNull(mongoOperations); - Assert.notNull(metadata); + Assert.notNull(metadata, "MongoEntityInformation must not be null!"); + Assert.notNull(mongoOperations, "ReactiveMongoOperations must not be null!"); this.entityInformation = metadata; this.mongoOperations = mongoOperations; diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java index 5d07d58ba..d9d6e66d6 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java @@ -25,8 +25,6 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; import com.mongodb.Mongo; @@ -35,6 +33,7 @@ import com.mongodb.Mongo; * * @author Mark Pollack * @author Thomas Darimont + * @author Mark Paluch */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:infrastructure.xml") @@ -46,7 +45,6 @@ public class MongoMonitorIntegrationTests { public void serverInfo() { ServerInfo serverInfo = new ServerInfo(mongo); serverInfo.getVersion(); - Assert.isTrue(StringUtils.hasText("1.")); } @Test // DATAMONGO-685 diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java index fad394af2..a0a448d6b 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java @@ -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. @@ -17,7 +17,6 @@ package org.springframework.data.mongodb.performance; import static org.springframework.data.mongodb.core.query.Criteria.*; import static org.springframework.data.mongodb.core.query.Query.*; -import static org.springframework.util.Assert.*; import java.text.DecimalFormat; import java.util.ArrayList; @@ -48,6 +47,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean; +import org.springframework.util.Assert; import org.springframework.util.StopWatch; import org.springframework.util.StringUtils; @@ -67,6 +67,7 @@ import com.mongodb.WriteConcern; * * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch */ public class PerformanceTests { @@ -623,7 +624,7 @@ public class PerformanceTests { private static List pickRandomNumerOfItemsFrom(List source) { - isTrue(!source.isEmpty()); + Assert.isTrue(!source.isEmpty(), "Source must not be empty!"); Random random = new Random(); int numberOfItems = random.nextInt(source.size()); @@ -837,7 +838,7 @@ public class PerformanceTests { String.format(" %s%%", DEVIATION_FORMAT.format(getMediaDeviationFrom(referenceMedian)))) + '\n'; } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */ @@ -896,7 +897,7 @@ public class PerformanceTests { return builder.toString(); } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */ diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/ReactivePerformanceTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/ReactivePerformanceTests.java index 4d2698d90..b5d84ffeb 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/ReactivePerformanceTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/ReactivePerformanceTests.java @@ -17,8 +17,8 @@ package org.springframework.data.mongodb.performance; import static org.springframework.data.mongodb.core.query.Criteria.*; import static org.springframework.data.mongodb.core.query.Query.*; -import static org.springframework.util.Assert.*; +import org.springframework.util.Assert; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -670,7 +670,7 @@ public class ReactivePerformanceTests { private static List pickRandomNumerOfItemsFrom(List source) { - isTrue(!source.isEmpty()); + Assert.isTrue(!source.isEmpty(), "Source must not be empty!"); Random random = new Random(); int numberOfItems = random.nextInt(source.size()); @@ -884,7 +884,7 @@ public class ReactivePerformanceTests { String.format(" %s%%", DEVIATION_FORMAT.format(getMediaDeviationFrom(referenceMedian)))) + '\n'; } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */ @@ -943,7 +943,7 @@ public class ReactivePerformanceTests { return builder.toString(); } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */