From 054274392effced8ada29964931cda0ef9b0aacd Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Fri, 28 Oct 2016 09:49:30 +0200 Subject: [PATCH] DATAMONGO-1176 - Cleanup. - Update licenses headers. - Renname variables and methods from dbo -> document. - Remove deprecations. - Remove unused code blocks. - Upgrade to MongoDB Java Driver 3.3 --- spring-data-mongodb/pom.xml | 2 +- .../data/mongodb/core/BulkOperations.java | 6 +- .../data/mongodb/core/CollectionCallback.java | 18 +- .../data/mongodb/core/CursorPreparer.java | 6 +- .../data/mongodb/core/DbCallback.java | 6 +- .../mongodb/core/DefaultBulkOperations.java | 5 +- .../mongodb/core/DefaultIndexOperations.java | 39 +--- .../mongodb/core/DocumentCallbackHandler.java | 9 +- .../mongodb/core/GeoCommandStatistics.java | 2 + .../data/mongodb/core/IndexOperations.java | 11 +- .../data/mongodb/core/MongoAction.java | 11 +- .../core/MongoExceptionTranslator.java | 2 +- .../data/mongodb/core/MongoOperations.java | 30 +-- .../data/mongodb/core/MongoTemplate.java | 218 ++++++++---------- .../mongodb/core/ReflectiveDbInvoker.java | 2 +- .../mongodb/core/SimpleMongoDbFactory.java | 2 +- .../mongodb/core/aggregation/Aggregation.java | 8 +- .../aggregation/AggregationExpression.java | 2 +- .../AggregationExpressionTransformer.java | 4 +- .../AggregationFunctionExpressions.java | 9 +- .../aggregation/AggregationOperation.java | 3 +- .../AggregationOperationContext.java | 7 +- .../core/aggregation/AggregationOptions.java | 17 +- .../core/aggregation/AggregationResults.java | 3 +- .../core/aggregation/ConditionalOperator.java | 10 +- ...osedFieldsAggregationOperationContext.java | 5 +- .../core/aggregation/GeoNearOperation.java | 3 +- .../core/aggregation/GroupOperation.java | 5 +- .../core/aggregation/IfNullOperator.java | 3 +- .../core/aggregation/LimitOperation.java | 3 +- .../core/aggregation/OutOperation.java | 4 +- .../core/aggregation/ProjectionOperation.java | 2 +- .../core/aggregation/SkipOperation.java | 1 + .../core/aggregation/SortOperation.java | 3 +- .../SpelExpressionTransformer.java | 12 +- .../TypeBasedAggregationOperationContext.java | 7 +- .../core/convert/DBObjectAccessor.java | 9 +- .../convert/DBObjectPropertyAccessor.java | 3 +- .../convert/DefaultDbRefProxyHandler.java | 5 +- .../core/convert/DefaultDbRefResolver.java | 10 +- .../convert/DefaultDbRefResolverCallback.java | 3 +- .../core/convert/DefaultMongoTypeMapper.java | 1 + .../mongodb/core/convert/GeoConverters.java | 124 +++++----- .../core/convert/MappingMongoConverter.java | 180 +++++++-------- .../mongodb/core/convert/MongoConverter.java | 3 +- .../core/convert/MongoExampleMapper.java | 12 +- .../mongodb/core/convert/MongoTypeMapper.java | 4 +- .../mongodb/core/convert/MongoWriter.java | 3 +- .../data/mongodb/core/convert/ObjectPath.java | 2 +- .../core/convert/ReflectiveDBRefResolver.java | 2 +- .../mongodb/core/convert/UpdateMapper.java | 2 +- .../mongodb/core/convert/ValueResolver.java | 7 +- .../mongodb/core/index/CompoundIndex.java | 11 - .../core/index/CompoundIndexDefinition.java | 10 +- .../mongodb/core/index/GeoSpatialIndexed.java | 10 - .../mongodb/core/index/GeospatialIndex.java | 14 +- .../data/mongodb/core/index/Index.java | 74 ++---- .../mongodb/core/index/IndexDefinition.java | 2 +- .../data/mongodb/core/index/IndexField.java | 26 --- .../data/mongodb/core/index/IndexInfo.java | 13 -- .../data/mongodb/core/index/Indexed.java | 10 - .../MongoPersistentEntityIndexCreator.java | 5 +- .../MongoPersistentEntityIndexResolver.java | 16 +- .../core/index/TextIndexDefinition.java | 10 +- .../mapping/BasicMongoPersistentProperty.java | 2 +- .../core/mapping/MongoSimpleTypes.java | 3 +- .../data/mongodb/core/mapping/Version.java | 39 ---- .../mapping/event/AbstractDeleteEvent.java | 20 +- .../event/AbstractMongoEventListener.java | 1 - .../core/mapping/event/AfterConvertEvent.java | 20 +- .../core/mapping/event/AfterDeleteEvent.java | 18 +- .../core/mapping/event/AfterLoadEvent.java | 20 +- .../core/mapping/event/AfterSaveEvent.java | 20 +- .../mapping/event/BeforeConvertEvent.java | 11 - .../core/mapping/event/BeforeDeleteEvent.java | 20 +- .../core/mapping/event/BeforeSaveEvent.java | 20 +- .../mapping/event/LoggingEventListener.java | 2 +- .../core/mapping/event/MongoMappingEvent.java | 24 +- .../event/ValidatingMongoEventListener.java | 2 +- .../data/mongodb/core/mapreduce/GroupBy.java | 35 +-- .../core/mapreduce/GroupByResults.java | 2 +- .../core/mapreduce/MapReduceOptions.java | 2 +- .../core/mapreduce/MapReduceResults.java | 2 +- .../data/mongodb/core/query/BasicUpdate.java | 8 +- .../data/mongodb/core/query/Criteria.java | 32 +-- .../core/query/CriteriaDefinition.java | 2 +- .../data/mongodb/core/query/Field.java | 13 +- .../data/mongodb/core/query/NearQuery.java | 33 +-- .../data/mongodb/core/query/Order.java | 45 ---- .../data/mongodb/core/query/Query.java | 14 +- .../core/query/SerializationUtils.java | 4 +- .../data/mongodb/core/query/TextQuery.java | 2 +- ...xpressionTransformationContextSupport.java | 3 +- .../data/mongodb/gridfs/GridFsCriteria.java | 3 +- .../data/mongodb/gridfs/GridFsOperations.java | 3 +- .../data/mongodb/gridfs/GridFsResource.java | 3 +- .../data/mongodb/gridfs/GridFsTemplate.java | 8 +- .../data/mongodb/monitor/AssertMetrics.java | 2 +- .../data/mongodb/repository/Meta.java | 11 - .../repository/query/MongoParameters.java | 11 - .../repository/query/MongoQueryExecution.java | 5 +- .../repository/query/MongoQueryMethod.java | 4 +- .../repository/query/PartTreeMongoQuery.java | 4 +- .../mongodb/repository/query/QueryUtils.java | 46 ---- .../query/StringBasedMongoQuery.java | 8 +- .../support/SpringDataMongodbSerializer.java | 9 - .../data/mongodb/util/BsonUtils.java | 4 + ...oseableIterableCursorAdapterUnitTests.java | 4 +- .../core/MongoOperationsUnitTests.java | 16 +- .../core/MongoTemplateMappingTests.java | 4 +- .../data/mongodb/core/MongoTemplateTests.java | 16 +- .../mongodb/core/MongoTemplateUnitTests.java | 2 +- ...nwrapAndReadDbObjectCallbackUnitTests.java | 8 +- .../aggregation/AggregationOptionsTests.java | 2 +- .../aggregation/AggregationUnitTests.java | 53 +++-- .../ConditionalOperatorUnitTests.java | 13 +- .../aggregation/IfNullOperatorUnitTests.java | 6 +- ...dAggregationOperationContextUnitTests.java | 23 +- .../core/convert/GeoConvertersUnitTests.java | 52 ++--- .../convert/GeoJsonConverterUnitTests.java | 30 ++- .../MappingMongoConverterUnitTests.java | 3 +- .../convert/MongoConvertersUnitTests.java | 20 +- .../core/index/IndexFieldUnitTests.java | 2 - .../core/index/IndexInfoUnitTests.java | 2 +- ...ersistentEntityIndexResolverUnitTests.java | 23 +- .../mongodb/core/mapping/GeoLocation.java | 2 +- .../AbstractMongoEventListenerUnitTests.java | 2 +- .../mongodb/core/query/IndexUnitTests.java | 8 - .../ConvertingParameterAccessorUnitTests.java | 6 - .../query/MongoQueryMethodUnitTests.java | 2 +- 130 files changed, 703 insertions(+), 1187 deletions(-) delete mode 100644 spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/Version.java delete mode 100644 spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java delete mode 100644 spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index b808ccf76..9754e8545 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -18,7 +18,7 @@ 1.3 1.5 - 3.2.2 + 3.3.0 diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/BulkOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/BulkOperations.java index 95fd16283..c5be41fb3 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/BulkOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/BulkOperations.java @@ -21,6 +21,8 @@ import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.util.Pair; +import com.mongodb.bulk.BulkWriteResult; + /** * Bulk operations for insert/update/remove actions on a collection. These bulks operation are available since MongoDB * 2.6 and make use of low level bulk commands on the protocol level. This interface defines a fluent API to add @@ -36,7 +38,7 @@ public interface BulkOperations { /** * Mode for bulk operation. **/ - public enum BulkMode { + enum BulkMode { /** Perform bulk operations in sequence. The first error will cancel processing. */ ORDERED, @@ -139,5 +141,5 @@ public interface BulkOperations { * @return Result of the bulk operation providing counters for inserts/updates etc. * @throws {@link BulkOperationException} if an error occurred during bulk processing. */ - com.mongodb.bulk.BulkWriteResult execute(); + BulkWriteResult execute(); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionCallback.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionCallback.java index 3b7fd11a3..28167e53b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionCallback.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionCallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2016 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,8 +21,24 @@ import org.springframework.dao.DataAccessException; import com.mongodb.MongoException; import com.mongodb.client.MongoCollection; +/** + * Callback interface for executing actions against a {@link MongoCollection} + * + * @author Mark Pollak + * @author Grame Rocher + * @author Oliver Gierke + * @author John Brisbin + * @auhtor Christoph Strobl + * @since 1.0 + */ public interface CollectionCallback { + /** + * @param collection never {@literal null}. + * @return + * @throws MongoException + * @throws DataAccessException + */ T doInCollection(MongoCollection collection) throws MongoException, DataAccessException; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CursorPreparer.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CursorPreparer.java index 0262b9b03..6c28d186e 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CursorPreparer.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CursorPreparer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2016 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,13 +17,13 @@ package org.springframework.data.mongodb.core; import org.bson.Document; -import com.mongodb.DBCursor; import com.mongodb.client.FindIterable; /** - * Simple callback interface to allow customization of a {@link DBCursor}. + * Simple callback interface to allow customization of a {@link FindIterable}. * * @author Oliver Gierke + * @author Christoph Strobl */ interface CursorPreparer { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DbCallback.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DbCallback.java index c019b86b1..a8a32040c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DbCallback.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DbCallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2016 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. @@ -20,6 +20,10 @@ import org.springframework.dao.DataAccessException; import com.mongodb.MongoException; import com.mongodb.client.MongoDatabase; +/** + * + * @param + */ public interface DbCallback { T doInDB(MongoDatabase db) throws MongoException, DataAccessException; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultBulkOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultBulkOperations.java index b14304891..bca4e5536 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultBulkOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultBulkOperations.java @@ -43,6 +43,7 @@ import com.mongodb.client.model.WriteModel; * * @author Tobias Trelle * @author Oliver Gierke + * @author Christoph Strobl * @since 1.9 */ class DefaultBulkOperations implements BulkOperations { @@ -50,7 +51,6 @@ class DefaultBulkOperations implements BulkOperations { private final MongoOperations mongoOperations; private final BulkMode bulkMode; private final String collectionName; - private final Class entityType; private PersistenceExceptionTranslator exceptionTranslator; private WriteConcernResolver writeConcernResolver; @@ -79,7 +79,6 @@ class DefaultBulkOperations implements BulkOperations { this.mongoOperations = mongoOperations; this.bulkMode = bulkMode; this.collectionName = collectionName; - this.entityType = entityType; this.exceptionTranslator = new MongoExceptionTranslator(); this.writeConcernResolver = DefaultWriteConcernResolver.INSTANCE; @@ -237,8 +236,6 @@ class DefaultBulkOperations implements BulkOperations { Assert.notNull(query, "Query must not be null!"); models.add(new DeleteManyModel(query.getQueryObject())); - // bulk.find(query.getQueryObject()).remove(); - return this; } 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 402fcd4bb..e9b3c501f 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-2015 the original author or authors. + * Copyright 2011-2016 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,9 +86,6 @@ public class DefaultIndexOperations implements IndexOperations { if (indexOptions.containsKey("unique")) { ops = ops.unique((Boolean) indexOptions.get("unique")); } - // if(indexOptions.containsField("dropDuplicates")) { - // ops = ops.((boolean)indexOptions.get("dropDuplicates")); - // } if (indexOptions.containsKey("sparse")) { ops = ops.sparse((Boolean) indexOptions.get("sparse")); } @@ -151,22 +148,6 @@ public class DefaultIndexOperations implements IndexOperations { dropIndex("*"); } - /* - * (non-Javadoc) - * @see org.springframework.data.mongodb.core.IndexOperations#resetIndexCache() - */ - @Deprecated - public void resetIndexCache() { - mongoOperations.execute(collectionName, new CollectionCallback() { - public Void doInCollection(MongoCollection collection) throws MongoException, DataAccessException { - - // TODO remove this one - // ReflectiveDBCollectionInvoker.resetIndexCache(collection); - return null; - } - }); - } - /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.IndexOperations#getIndexInfo() @@ -177,25 +158,25 @@ public class DefaultIndexOperations implements IndexOperations { public List doInCollection(MongoCollection collection) throws MongoException, DataAccessException { - MongoCursor dbObjectList = collection.listIndexes(Document.class).iterator(); - return getIndexData(dbObjectList); + MongoCursor cursor = collection.listIndexes(Document.class).iterator(); + return getIndexData(cursor); } - private List getIndexData(MongoCursor dbObjectList) { + private List getIndexData(MongoCursor cursor) { List indexInfoList = new ArrayList(); - while (dbObjectList.hasNext()) { + while (cursor.hasNext()) { - Document ix = dbObjectList.next(); - Document keyDbObject = (Document) ix.get("key"); - int numberOfElements = keyDbObject.keySet().size(); + Document ix = cursor.next(); + Document keyDocument = (Document) ix.get("key"); + int numberOfElements = keyDocument.keySet().size(); List indexFields = new ArrayList(numberOfElements); - for (String key : keyDbObject.keySet()) { + for (String key : keyDocument.keySet()) { - Object value = keyDbObject.get(key); + Object value = keyDocument.get(key); if (TWO_D_IDENTIFIERS.contains(value)) { indexFields.add(IndexField.geo(key)); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DocumentCallbackHandler.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DocumentCallbackHandler.java index 15756f2e2..64088a6c0 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DocumentCallbackHandler.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DocumentCallbackHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2016 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. @@ -28,8 +28,13 @@ import com.mongodb.MongoException; * later inspection. * * @author Mark Pollack + * @author Grame Rocher + * @author Oliver Gierke + * @author John Brisbin + * @author Christoph Strobl + * @since 1.0 */ public interface DocumentCallbackHandler { - void processDocument(Document dbObject) throws MongoException, DataAccessException; + void processDocument(Document document) throws MongoException, DataAccessException; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/GeoCommandStatistics.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/GeoCommandStatistics.java index 75649c0dd..420ea5554 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/GeoCommandStatistics.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/GeoCommandStatistics.java @@ -22,7 +22,9 @@ import org.springframework.util.Assert; * Value object to mitigate different representations of geo command execution results in MongoDB. * * @author Oliver Gierke + * @author Christoph Strobl * @soundtrack Fruitcake - Jeff Coffin (The Inside of the Outside) + * @since 1.9 */ class GeoCommandStatistics { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/IndexOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/IndexOperations.java index cc97d7bfb..3ea8cb6e6 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/IndexOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/IndexOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 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. @@ -49,15 +49,6 @@ public interface IndexOperations { */ void dropAllIndexes(); - /** - * Clears all indices that have not yet been applied to this collection. - * - * @deprecated since 1.7. The MongoDB Java driver version 3.0 does no longer support reseting the index cache. - * @throws {@link UnsupportedOperationException} when used with MongoDB Java driver version 3.0. - */ - @Deprecated - void resetIndexCache(); - /** * Returns the index information on the collection. * diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAction.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAction.java index e1f498928..6af857eca 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAction.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 the original author or authors. + * Copyright 2011-2016 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 com.mongodb.WriteConcern; * * @author Mark Pollack * @author Oliver Gierke + * @author Christoph Strobl */ public class MongoAction { @@ -72,14 +73,6 @@ public class MongoAction { return defaultWriteConcern; } - /** - * @deprecated use {@link #getEntityType()} instead. - */ - @Deprecated - public Class getEntityClass() { - return entityType; - } - public Class getEntityType() { return entityType; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoExceptionTranslator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoExceptionTranslator.java index dbbcf173a..0be5bb968 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoExceptionTranslator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoExceptionTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 the original author or authors. + * Copyright 2010-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java index 0e771c6d8..fad14684b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 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. @@ -84,18 +84,6 @@ public interface MongoOperations { */ Document executeCommand(Document command); - /** - * Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's DAO - * exception hierarchy. - * - * @param command a MongoDB command - * @param options query options to use - * @deprecated since 1.7. Please use {@link #executeCommand(Document, ReadPreference)}, as the MongoDB Java driver - * version 3 no longer supports this operation. - */ - @Deprecated - Document executeCommand(Document command, int options); - /** * Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's data * access exception hierarchy. @@ -152,22 +140,6 @@ public interface MongoOperations { */ T execute(String collectionName, CollectionCallback action); - /** - * Executes the given {@link DbCallback} within the same connection to the database so as to ensure consistency in a - * write heavy environment where you may read the data that you wrote. See the comments on {@see Java Driver Concurrency} - *

- * Allows for returning a result object, that is a domain object or a collection of domain objects. - * - * @param return type - * @param action callback that specified the MongoDB actions to perform on the DB instance - * @return a result object returned by the action or null - * @deprecated since 1.7 as the MongoDB Java driver version 3 does not longer support request boundaries via - * {@link DB#requestStart()} and {@link DB#requestDone()}. - */ - @Deprecated - T executeInSession(DbCallback action); - /** * Executes the given {@link Query} on the entity collection of the specified {@code entityType} backed by a Mongo DB * {@link Cursor}. 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 40f9225c2..6426baea3 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 @@ -361,7 +361,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { FindIterable cursor = collection.find(mappedQuery).projection(mappedFields); QueryCursorPreparer cursorPreparer = new QueryCursorPreparer(query, entityType); - ReadDbObjectCallback readCallback = new ReadDbObjectCallback(mongoConverter, entityType, + ReadDocumentCallback readCallback = new ReadDocumentCallback(mongoConverter, entityType, collectionName); return new CloseableIterableCursorAdapter(cursorPreparer.prepare(cursor), exceptionTranslator, readCallback); @@ -393,16 +393,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { return result; } - /* - * (non-Javadoc) - * @see org.springframework.data.mongodb.core.MongoOperations#executeCommand(com.mongodb.Document, int) - */ - @Deprecated - public Document executeCommand(final Document command, final int options) { - return executeCommand(command, - (options & Bytes.QUERYOPTION_SLAVEOK) != 0 ? ReadPreference.secondaryPreferred() : ReadPreference.primary()); - } - /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.MongoOperations#executeCommand(com.mongodb.Document, com.mongodb.ReadPreference) @@ -490,20 +480,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } } - /* - * (non-Javadoc) - * @see org.springframework.data.mongodb.core.MongoOperations#executeInSession(org.springframework.data.mongodb.core.DbCallback) - */ - @Deprecated - public T executeInSession(final DbCallback action) { - - return execute(new DbCallback() { - public T doInDB(MongoDatabase db) throws MongoException, DataAccessException { - return action.doInDB(db); - } - }); - } - public MongoCollection createCollection(Class entityClass) { return createCollection(determineCollectionName(entityClass)); } @@ -518,7 +494,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public MongoCollection createCollection(final String collectionName, final CollectionOptions collectionOptions) { - return doCreateCollection(collectionName, convertToDbObject(collectionOptions)); + return doCreateCollection(collectionName, convertToDocument(collectionOptions)); } public MongoCollection getCollection(final String collectionName) { @@ -697,8 +673,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { List results = (List) commandResult.get("results"); results = results == null ? Collections.emptyList() : results; - DbObjectCallback> callback = new GeoNearResultDbObjectCallback( - new ReadDbObjectCallback(mongoConverter, entityClass, collectionName), near.getMetric()); + DocumentCallback> callback = new GeoNearResultDocumentCallback( + new ReadDocumentCallback(mongoConverter, entityClass, collectionName), near.getMetric()); List> result = new ArrayList>(results.size()); int index = 0; @@ -774,13 +750,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public long count(Query query, Class entityClass, String collectionName) { Assert.hasText(collectionName); - final Document dbObject = query == null ? null + final Document document = query == null ? null : queryMapper.getMappedObject(query.getQueryObject(), entityClass == null ? null : mappingContext.getPersistentEntity(entityClass)); return execute(collectionName, new CollectionCallback() { public Long doInCollection(MongoCollection collection) throws MongoException, DataAccessException { - return collection.count(dbObject); + return collection.count(document); } }); } @@ -860,7 +836,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { maybeEmitEvent(new BeforeConvertEvent(objectToSave, collectionName)); - Document dbDoc = toDbObject(objectToSave, writer); + Document dbDoc = toDocument(objectToSave, writer); maybeEmitEvent(new BeforeSaveEvent(objectToSave, dbDoc, collectionName)); Object id = insertDocument(collectionName, dbDoc, objectToSave.getClass()); @@ -874,7 +850,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { * @param writer * @return */ - private Document toDbObject(T objectToSave, MongoWriter writer) { + private Document toDocument(T objectToSave, MongoWriter writer) { if (objectToSave instanceof Document) { return (Document) objectToSave; @@ -958,7 +934,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { Assert.notNull(writer); - List dbObjectList = new ArrayList(); + List documentList = new ArrayList(); for (T o : batchToSave) { initializeVersionProperty(o); @@ -968,16 +944,16 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { writer.write(o, dbDoc); maybeEmitEvent(new BeforeSaveEvent(o, dbDoc, collectionName)); - dbObjectList.add(dbDoc); + documentList.add(dbDoc); } - List ids = consolidateIdentifiers(insertDBObjectList(collectionName, dbObjectList), dbObjectList); + List ids = consolidateIdentifiers(insertDocumentList(collectionName, documentList), documentList); int i = 0; for (T obj : batchToSave) { if (i < ids.size()) { populateIdIfNecessary(obj, ids.get(i)); - maybeEmitEvent(new AfterSaveEvent(obj, dbObjectList.get(i), collectionName)); + maybeEmitEvent(new AfterSaveEvent(obj, documentList.get(i), collectionName)); } i++; } @@ -1030,13 +1006,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { // Bump version number convertingAccessor.setProperty(versionProperty, versionNumber.longValue() + 1); - Document dbObject = new Document(); + Document document = new Document(); maybeEmitEvent(new BeforeConvertEvent(objectToSave, collectionName)); - this.mongoConverter.write(objectToSave, dbObject); + this.mongoConverter.write(objectToSave, document); - maybeEmitEvent(new BeforeSaveEvent(objectToSave, dbObject, collectionName)); - Update update = Update.fromDocument(dbObject, ID_FIELD); + maybeEmitEvent(new BeforeSaveEvent(objectToSave, document, collectionName)); + Update update = Update.fromDocument(document, ID_FIELD); UpdateResult result = doUpdate(collectionName, query, update, objectToSave.getClass(), false, false); @@ -1045,7 +1021,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { String.format("Cannot save entity %s with version %s to collection %s. Has it been modified meanwhile?", id, versionNumber, collectionName)); } - maybeEmitEvent(new AfterSaveEvent(objectToSave, dbObject, collectionName)); + maybeEmitEvent(new AfterSaveEvent(objectToSave, document, collectionName)); } } @@ -1055,7 +1031,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { maybeEmitEvent(new BeforeConvertEvent(objectToSave, collectionName)); - Document dbDoc = toDbObject(objectToSave, writer); + Document dbDoc = toDocument(objectToSave, writer); maybeEmitEvent(new BeforeSaveEvent(objectToSave, dbDoc, collectionName)); Object id = saveDocument(collectionName, dbDoc, objectToSave.getClass()); @@ -1064,31 +1040,30 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { maybeEmitEvent(new AfterSaveEvent(objectToSave, dbDoc, collectionName)); } - protected Object insertDocument(final String collectionName, final Document dbDoc, final Class entityClass) { + protected Object insertDocument(final String collectionName, final Document document, final Class entityClass) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Inserting Document containing fields: {} in collection: {}", dbDoc.keySet(), collectionName); + LOGGER.debug("Inserting Document containing fields: {} in collection: {}", document.keySet(), collectionName); } return execute(collectionName, new CollectionCallback() { public Object doInCollection(MongoCollection collection) throws MongoException, DataAccessException { MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.INSERT, collectionName, - entityClass, dbDoc, null); + entityClass, document, null); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); if (writeConcernToUse == null) { - collection.insertOne(dbDoc); + collection.insertOne(document); } else { - collection.withWriteConcern(writeConcernToUse).insertOne(dbDoc); + collection.withWriteConcern(writeConcernToUse).insertOne(document); } - // handleAnyWriteResultErrors(writeResult, dbDoc, MongoActionOperation.INSERT); - return dbDoc.get(ID_FIELD); + return document.get(ID_FIELD); } }); } // TODO: 2.0 - Change method signature to return List and return all identifiers (DATAMONGO-1513, // DATAMONGO-1519) - protected List insertDBObjectList(final String collectionName, final List documents) { + protected List insertDocumentList(final String collectionName, final List documents) { if (documents.isEmpty()) { return Collections.emptyList(); } @@ -1109,9 +1084,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { collection.withWriteConcern(writeConcernToUse).insertMany(documents); } - // WriteResult writeResult = writeConcernToUse == null ? collection.insert(dbDocList) - // : collection.insert(dbDocList.toArray((Document[]) new Document[dbDocList.size()]), writeConcernToUse); - // handleAnyWriteResultErrors(writeResult, null, MongoActionOperation.INSERT_LIST); return null; } }); @@ -1155,7 +1127,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { collection.withWriteConcern(writeConcernToUse).replaceOne(Filters.eq(ID_FIELD, dbDoc.get(ID_FIELD)), dbDoc, new UpdateOptions().upsert(true)); } - // handleAnyWriteResultErrors(writeResult, dbDoc, MongoActionOperation.SAVE); return dbDoc.get(ID_FIELD); } }); @@ -1250,13 +1221,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } } - private boolean dbObjectContainsVersionProperty(Document dbObject, MongoPersistentEntity persistentEntity) { + private boolean documentContainsVersionProperty(Document document, MongoPersistentEntity persistentEntity) { if (persistentEntity == null || !persistentEntity.hasVersionProperty()) { return false; } - return dbObject.containsKey(persistentEntity.getVersionProperty().getFieldName()); + return document.containsKey(persistentEntity.getVersionProperty().getFieldName()); } public DeleteResult remove(Object object) { @@ -1389,7 +1360,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { maybeEmitEvent(new BeforeDeleteEvent(queryObject, entityClass, collectionName)); - Document dboq = queryMapper.getMappedObject(queryObject, entity); + Document mappedQuery = queryMapper.getMappedObject(queryObject, entity); MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.REMOVE, collectionName, entityClass, null, queryObject); @@ -1398,13 +1369,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { DeleteResult dr = null; if (LOGGER.isDebugEnabled()) { LOGGER.debug("Remove using query: {} in collection: {}.", - new Object[] { serializeToJsonSafely(dboq), collectionName }); + new Object[] { serializeToJsonSafely(mappedQuery), collectionName }); } if (writeConcernToUse == null) { - dr = collection.deleteMany(dboq); + dr = collection.deleteMany(mappedQuery); } else { - dr = collection.withWriteConcern(writeConcernToUse).deleteMany(dboq); + dr = collection.withWriteConcern(writeConcernToUse).deleteMany(mappedQuery); } maybeEmitEvent(new AfterDeleteEvent(queryObject, entityClass, collectionName)); @@ -1420,7 +1391,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public List findAll(Class entityClass, String collectionName) { return executeFindMultiInternal(new FindCallback(null), null, - new ReadDbObjectCallback(mongoConverter, entityClass, collectionName), collectionName); + new ReadDocumentCallback(mongoConverter, entityClass, collectionName), collectionName); } public MapReduceResults mapReduce(String inputCollectionName, String mapFunction, String reduceFunction, @@ -1448,7 +1419,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { MongoCollection inputCollection = getCollection(inputCollectionName); // MapReduceOp - MapReduceIterable result = inputCollection.mapReduce(mapFunction, reduceFunction); + MapReduceIterable result = inputCollection.mapReduce(mapFunc, reduceFunc); if (query != null && result != null) { if (query.getLimit() > 0 && mapReduceOptions.getLimit() == null) { @@ -1485,10 +1456,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } } List mappedResults = new ArrayList(); - DbObjectCallback callback = new ReadDbObjectCallback(mongoConverter, entityClass, inputCollectionName); + DocumentCallback callback = new ReadDocumentCallback(mongoConverter, entityClass, inputCollectionName); - for (Document dbObject : result) { - mappedResults.add(callback.doWith(dbObject)); + for (Document document : result) { + mappedResults.add(callback.doWith(document)); } return new MapReduceResults(mappedResults, new Document()); @@ -1501,36 +1472,36 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public GroupByResults group(Criteria criteria, String inputCollectionName, GroupBy groupBy, Class entityClass) { - Document dbo = groupBy.getGroupByObject(); - dbo.put("ns", inputCollectionName); + Document document = groupBy.getGroupByObject(); + document.put("ns", inputCollectionName); if (criteria == null) { - dbo.put("cond", null); + document.put("cond", null); } else { - dbo.put("cond", queryMapper.getMappedObject(criteria.getCriteriaObject(), null)); + document.put("cond", queryMapper.getMappedObject(criteria.getCriteriaObject(), null)); } // If initial document was a JavaScript string, potentially loaded by Spring's Resource abstraction, load it and // convert to Document - if (dbo.containsKey("initial")) { - Object initialObj = dbo.get("initial"); + if (document.containsKey("initial")) { + Object initialObj = document.get("initial"); if (initialObj instanceof String) { String initialAsString = replaceWithResourceIfNecessary((String) initialObj); - dbo.put("initial", Document.parse(initialAsString)); + document.put("initial", Document.parse(initialAsString)); } } - if (dbo.containsKey("$reduce")) { - dbo.put("$reduce", replaceWithResourceIfNecessary(dbo.get("$reduce").toString())); + if (document.containsKey("$reduce")) { + document.put("$reduce", replaceWithResourceIfNecessary(document.get("$reduce").toString())); } - if (dbo.containsKey("$keyf")) { - dbo.put("$keyf", replaceWithResourceIfNecessary(dbo.get("$keyf").toString())); + if (document.containsKey("$keyf")) { + document.put("$keyf", replaceWithResourceIfNecessary(document.get("$keyf").toString())); } - if (dbo.containsKey("finalize")) { - dbo.put("finalize", replaceWithResourceIfNecessary(dbo.get("finalize").toString())); + if (document.containsKey("finalize")) { + document.put("finalize", replaceWithResourceIfNecessary(document.get("finalize").toString())); } - Document commandObject = new Document("group", dbo); + Document commandObject = new Document("group", document); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing Group with Document [{}]", serializeToJsonSafely(commandObject)); @@ -1545,10 +1516,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { @SuppressWarnings("unchecked") Iterable resultSet = (Iterable) commandResult.get("retval"); List mappedResults = new ArrayList(); - DbObjectCallback callback = new ReadDbObjectCallback(mongoConverter, entityClass, inputCollectionName); + DocumentCallback callback = new ReadDocumentCallback(mongoConverter, entityClass, inputCollectionName); - for (Document dbObject : resultSet) { - mappedResults.add(callback.doWith(dbObject)); + for (Document resultDocument : resultSet) { + mappedResults.add(callback.doWith(resultDocument)); } return new GroupByResults(mappedResults, commandResult); @@ -1638,7 +1609,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { Assert.notNull(outputType, "Output type must not be null!"); AggregationOperationContext rootContext = context == null ? Aggregation.DEFAULT_CONTEXT : context; - Document command = aggregation.toDbObject(collectionName, rootContext); + Document command = aggregation.toDocument(collectionName, rootContext); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing aggregation: {}", serializeToJsonSafely(command)); @@ -1666,11 +1637,11 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { return Collections.emptyList(); } - DbObjectCallback callback = new UnwrapAndReadDbObjectCallback(mongoConverter, outputType, collectionName); + DocumentCallback callback = new UnwrapAndReadDocumentCallback(mongoConverter, outputType, collectionName); List mappedResults = new ArrayList(); - for (Document dbObject : resultSet) { - mappedResults.add(callback.doWith(dbObject)); + for (Document document : resultSet) { + mappedResults.add(callback.doWith(document)); } return mappedResults; @@ -1785,7 +1756,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } return executeFindOneInternal(new FindOneCallback(mappedQuery, mappedFields), - new ReadDbObjectCallback(this.mongoConverter, entityClass, collectionName), collectionName); + new ReadDocumentCallback(this.mongoConverter, entityClass, collectionName), collectionName); } /** @@ -1800,7 +1771,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { */ protected List doFind(String collectionName, Document query, Document fields, Class entityClass) { return doFind(collectionName, query, fields, entityClass, null, - new ReadDbObjectCallback(this.mongoConverter, entityClass, collectionName)); + new ReadDocumentCallback(this.mongoConverter, entityClass, collectionName)); } /** @@ -1819,11 +1790,11 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { protected List doFind(String collectionName, Document query, Document fields, Class entityClass, CursorPreparer preparer) { return doFind(collectionName, query, fields, entityClass, preparer, - new ReadDbObjectCallback(mongoConverter, entityClass, collectionName)); + new ReadDocumentCallback(mongoConverter, entityClass, collectionName)); } protected List doFind(String collectionName, Document query, Document fields, Class entityClass, - CursorPreparer preparer, DbObjectCallback objectCallback) { + CursorPreparer preparer, DocumentCallback objectCallback) { MongoPersistentEntity entity = mappingContext.getPersistentEntity(entityClass); @@ -1839,20 +1810,20 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { collectionName); } - protected Document convertToDbObject(CollectionOptions collectionOptions) { - Document dbo = new Document(); + protected Document convertToDocument(CollectionOptions collectionOptions) { + Document document = new Document(); if (collectionOptions != null) { if (collectionOptions.getCapped() != null) { - dbo.put("capped", collectionOptions.getCapped().booleanValue()); + document.put("capped", collectionOptions.getCapped().booleanValue()); } if (collectionOptions.getSize() != null) { - dbo.put("size", collectionOptions.getSize().intValue()); + document.put("size", collectionOptions.getSize().intValue()); } if (collectionOptions.getMaxDocuments() != null) { - dbo.put("max", collectionOptions.getMaxDocuments().intValue()); + document.put("max", collectionOptions.getMaxDocuments().intValue()); } } - return dbo; + return document; } /** @@ -1879,7 +1850,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { MongoPersistentEntity entity = mappingContext.getPersistentEntity(entityClass); return executeFindOneInternal(new FindAndRemoveCallback(queryMapper.getMappedObject(query, entity), fields, sort), - new ReadDbObjectCallback(readerToUse, entityClass, collectionName), collectionName); + new ReadDocumentCallback(readerToUse, entityClass, collectionName), collectionName); } protected T doFindAndModify(String collectionName, Document query, Document fields, Document sort, @@ -1906,7 +1877,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } return executeFindOneInternal(new FindAndModifyCallback(mappedQuery, fields, sort, mappedUpdate, options), - new ReadDbObjectCallback(readerToUse, entityClass, collectionName), collectionName); + new ReadDocumentCallback(readerToUse, entityClass, collectionName), collectionName); } /** @@ -1922,8 +1893,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } if (savedObject instanceof Document) { - Document dbObject = (Document) savedObject; - dbObject.put(ID_FIELD, id); + Document document = (Document) savedObject; + document.put(ID_FIELD, id); return; } @@ -1959,17 +1930,17 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { * collection of objects. It will take the following steps *
    *
  1. Execute the given {@link ConnectionCallback} for a {@link Document}.
  2. - *
  3. Apply the given {@link DbObjectCallback} to each of the {@link Document}s to obtain the result.
  4. + *
  5. Apply the given {@link DocumentCallback} to each of the {@link Document}s to obtain the result.
  6. *
      * * @param * @param collectionCallback the callback to retrieve the {@link Document} with - * @param objectCallback the {@link DbObjectCallback} to transform {@link Document}s into the actual domain type + * @param objectCallback the {@link DocumentCallback} to transform {@link Document}s into the actual domain type * @param collectionName the collection to be queried * @return */ private T executeFindOneInternal(CollectionCallback collectionCallback, - DbObjectCallback objectCallback, String collectionName) { + DocumentCallback objectCallback, String collectionName) { try { T result = objectCallback @@ -1987,19 +1958,19 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { *
    1. Execute the given {@link ConnectionCallback} for a {@link DBCursor}.
    2. *
    3. Prepare that {@link DBCursor} with the given {@link CursorPreparer} (will be skipped if {@link CursorPreparer} * is {@literal null}
    4. - *
    5. Iterate over the {@link DBCursor} and applies the given {@link DbObjectCallback} to each of the + *
    6. Iterate over the {@link DBCursor} and applies the given {@link DocumentCallback} to each of the * {@link Document}s collecting the actual result {@link List}.
    7. *
        * * @param * @param collectionCallback the callback to retrieve the {@link DBCursor} with * @param preparer the {@link CursorPreparer} to potentially modify the {@link DBCursor} before ireating over it - * @param objectCallback the {@link DbObjectCallback} to transform {@link Document}s into the actual domain type + * @param objectCallback the {@link DocumentCallback} to transform {@link Document}s into the actual domain type * @param collectionName the collection to be queried * @return */ private List executeFindMultiInternal(CollectionCallback> collectionCallback, - CursorPreparer preparer, DbObjectCallback objectCallback, String collectionName) { + CursorPreparer preparer, DocumentCallback objectCallback, String collectionName) { try { @@ -2054,8 +2025,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { cursor = iterable.iterator(); while (cursor.hasNext()) { - Document dbobject = cursor.next(); - callbackHandler.processDocument(dbobject); + callbackHandler.processDocument(cursor.next()); } } finally { @@ -2355,25 +2325,25 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { * @author Thomas Darimont */ - interface DbObjectCallback { + interface DocumentCallback { T doWith(Document object); } /** - * Simple {@link DbObjectCallback} that will transform {@link Document} into the given target type using the given + * Simple {@link DocumentCallback} that will transform {@link Document} into the given target type using the given * {@link MongoReader}. * * @author Oliver Gierke * @author Christoph Strobl */ - private class ReadDbObjectCallback implements DbObjectCallback { + private class ReadDocumentCallback implements DocumentCallback { private final EntityReader reader; private final Class type; private final String collectionName; - public ReadDbObjectCallback(EntityReader reader, Class type, String collectionName) { + public ReadDocumentCallback(EntityReader reader, Class type, String collectionName) { Assert.notNull(reader); Assert.notNull(type); @@ -2394,9 +2364,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } } - class UnwrapAndReadDbObjectCallback extends ReadDbObjectCallback { + class UnwrapAndReadDocumentCallback extends ReadDocumentCallback { - public UnwrapAndReadDbObjectCallback(EntityReader reader, Class type, String collectionName) { + public UnwrapAndReadDocumentCallback(EntityReader reader, Class type, String collectionName) { super(reader, type, collectionName); } @@ -2459,8 +2429,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { cursorToUse = cursorToUse.limit(query.getLimit()); } if (query.getSortObject() != null) { - Document sortDbo = type != null ? getMappedSortObject(query, type) : query.getSortObject(); - cursorToUse = cursorToUse.sort(sortDbo); + Document sort = type != null ? getMappedSortObject(query, type) : query.getSortObject(); + cursorToUse = cursorToUse.sort(sort); } Document meta = new Document(); @@ -2501,23 +2471,23 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } /** - * {@link DbObjectCallback} that assumes a {@link GeoResult} to be created, delegates actual content unmarshalling to + * {@link DocumentCallback} that assumes a {@link GeoResult} to be created, delegates actual content unmarshalling to * a delegate and creates a {@link GeoResult} from the result. * * @author Oliver Gierke */ - static class GeoNearResultDbObjectCallback implements DbObjectCallback> { + static class GeoNearResultDocumentCallback implements DocumentCallback> { - private final DbObjectCallback delegate; + private final DocumentCallback delegate; private final Metric metric; /** - * Creates a new {@link GeoNearResultDbObjectCallback} using the given {@link DbObjectCallback} delegate for + * Creates a new {@link GeoNearResultDocumentCallback} using the given {@link DocumentCallback} delegate for * {@link GeoResult} content unmarshalling. * * @param delegate must not be {@literal null}. */ - public GeoNearResultDbObjectCallback(DbObjectCallback delegate, Metric metric) { + public GeoNearResultDocumentCallback(DocumentCallback delegate, Metric metric) { Assert.notNull(delegate); this.delegate = delegate; this.metric = metric; @@ -2544,10 +2514,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { private volatile MongoCursor cursor; private PersistenceExceptionTranslator exceptionTranslator; - private DbObjectCallback objectReadCallback; + private DocumentCallback objectReadCallback; CloseableIterableCursorAdapter(MongoCursor cursor, PersistenceExceptionTranslator exceptionTranslator, - DbObjectCallback objectReadCallback) { + DocumentCallback objectReadCallback) { this.cursor = cursor; this.exceptionTranslator = exceptionTranslator; this.objectReadCallback = objectReadCallback; @@ -2561,7 +2531,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { * @param objectReadCallback */ public CloseableIterableCursorAdapter(FindIterable cursor, - PersistenceExceptionTranslator exceptionTranslator, DbObjectCallback objectReadCallback) { + PersistenceExceptionTranslator exceptionTranslator, DocumentCallback objectReadCallback) { this.cursor = cursor.iterator(); this.exceptionTranslator = exceptionTranslator; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReflectiveDbInvoker.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReflectiveDbInvoker.java index 5abe74c0a..9a2280812 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReflectiveDbInvoker.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReflectiveDbInvoker.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleMongoDbFactory.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleMongoDbFactory.java index 841b25235..53583e9bc 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleMongoDbFactory.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleMongoDbFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java index 73efa71d8..eeed1f5ac 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java @@ -494,7 +494,7 @@ public class Aggregation { * @param inputCollectionName the name of the input collection * @return the {@code Document} representing this aggregation */ - public Document toDbObject(String inputCollectionName, AggregationOperationContext rootContext) { + public Document toDocument(String inputCollectionName, AggregationOperationContext rootContext) { AggregationOperationContext context = rootContext; List operationDocuments = new ArrayList(operations.size()); @@ -530,7 +530,7 @@ public class Aggregation { @Override public String toString() { return SerializationUtils - .serializeToJsonSafely(toDbObject("__collection__", new NoOpAggregationOperationContext())); + .serializeToJsonSafely(toDocument("__collection__", new NoOpAggregationOperationContext())); } /** @@ -545,8 +545,8 @@ public class Aggregation { * @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getMappedObject(com.mongodb.Document) */ @Override - public Document getMappedObject(Document dbObject) { - return dbObject; + public Document getMappedObject(Document document) { + return document; } /* diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java index 176923d40..95747a11d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java @@ -34,5 +34,5 @@ public interface AggregationExpression { * @param context * @return */ - Document toDbObject(AggregationOperationContext context); + Document toDocument(AggregationOperationContext context); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpressionTransformer.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpressionTransformer.java index 720388f76..ee08f35db 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpressionTransformer.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpressionTransformer.java @@ -28,6 +28,8 @@ import org.springframework.util.Assert; * {@link AggregationExpressionTransformationContext}. * * @author Oliver Gierke + * @author Christoph Strobl + * @since 1.4 */ interface AggregationExpressionTransformer extends ExpressionTransformer> { @@ -38,7 +40,7 @@ interface AggregationExpressionTransformer * @author Oliver Gierke * @author Thomas Darimont */ - public static class AggregationExpressionTransformationContext + class AggregationExpressionTransformationContext extends ExpressionTransformationContextSupport { private final AggregationOperationContext aggregationContext; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java index d50b5ebe0..e6f9f5bb5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 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 org.springframework.util.Assert; * * @author Thomas Darimont * @author Oliver Gierke - * @since 1.10 + * @author Christoph Strobl + * @since 1.7 */ public enum AggregationFunctionExpressions { @@ -77,7 +78,7 @@ public enum AggregationFunctionExpressions { * @see org.springframework.data.mongodb.core.aggregation.Expression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) */ @Override - public Document toDbObject(AggregationOperationContext context) { + public Document toDocument(AggregationOperationContext context) { List args = new ArrayList(values.size()); @@ -91,7 +92,7 @@ public enum AggregationFunctionExpressions { private static Object unpack(Object value, AggregationOperationContext context) { if (value instanceof AggregationExpression) { - return ((AggregationExpression) value).toDbObject(context); + return ((AggregationExpression) value).toDocument(context); } if (value instanceof Field) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperation.java index a46973408..ae15ab36a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2016 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; * @author Sebastian Herold * @author Thomas Darimont * @author Oliver Gierke + * @author Christoph Strobl * @since 1.3 */ public interface AggregationOperation { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperationContext.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperationContext.java index ac6097ff5..aed2c9926 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperationContext.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOperationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2016 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.data.mongodb.core.aggregation.ExposedFields.FieldRefe * The context for an {@link AggregationOperation}. * * @author Oliver Gierke + * @author Christoph Strobl * @since 1.3 */ public interface AggregationOperationContext { @@ -29,10 +30,10 @@ public interface AggregationOperationContext { /** * Returns the mapped {@link Document}, potentially converting the source considering mapping metadata etc. * - * @param dbObject will never be {@literal null}. + * @param document will never be {@literal null}. * @return must not be {@literal null}. */ - Document getMappedObject(Document dbObject); + Document getMappedObject(Document document); /** * Returns a {@link FieldReference} for the given field or {@literal null} if the context does not expose the given diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java index 591a5f28c..2625d912a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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.bson.Document; * * @author Thomas Darimont * @author Oliver Gierke + * @author Christoph Strobl * @see Aggregation#withOptions(AggregationOptions) * @see TypedAggregation#withOptions(AggregationOptions) * @since 1.6 @@ -111,14 +112,14 @@ public class AggregationOptions { * * @return */ - public Document toDbObject() { + public Document toDocument() { - Document dbo = new Document(); - dbo.put(ALLOW_DISK_USE, allowDiskUse); - dbo.put(EXPLAIN, explain); - dbo.put(CURSOR, cursor); + Document document = new Document(); + document.put(ALLOW_DISK_USE, allowDiskUse); + document.put(EXPLAIN, explain); + document.put(CURSOR, cursor); - return dbo; + return document; } /* (non-Javadoc) @@ -126,7 +127,7 @@ public class AggregationOptions { */ @Override public String toString() { - return toDbObject().toJson(); + return toDocument().toJson(); } /** 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 49fd2dc12..dec351601 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-2014 the original author or authors. + * Copyright 2013-2016 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. @@ -28,6 +28,7 @@ import org.springframework.util.Assert; * @author Tobias Trelle * @author Oliver Gierke * @author Thomas Darimont + * @author Christoph Strobl * @param The class in which the results are mapped onto. * @since 1.3 */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperator.java index a3204f68b..c3b29e269 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperator.java @@ -75,7 +75,7 @@ public class ConditionalOperator implements AggregationExpression { * @param thenValue must not be {@literal null}. * @param otherwiseValue must not be {@literal null}. */ - public ConditionalOperator(DBObject condition, Object thenValue, Object otherwiseValue) { + public ConditionalOperator(Document condition, Object thenValue, Object otherwiseValue) { this((Object) condition, thenValue, otherwiseValue); } @@ -99,7 +99,7 @@ public class ConditionalOperator implements AggregationExpression { * @see org.springframework.data.mongodb.core.aggregation.AggregationExpression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) */ @Override - public Document toDbObject(AggregationOperationContext context) { + public Document toDocument(AggregationOperationContext context) { Document condObject = new Document(); @@ -117,7 +117,7 @@ public class ConditionalOperator implements AggregationExpression { } if (value instanceof ConditionalOperator) { - return ((ConditionalOperator) value).toDbObject(context); + return ((ConditionalOperator) value).toDocument(context); } return context.getMappedObject(new Document("$set", value)).get("$set"); @@ -244,7 +244,7 @@ public class ConditionalOperator implements AggregationExpression { * @param booleanExpression expression that yields in a boolean result, must not be {@literal null}. * @return the {@link ThenBuilder} */ - ThenBuilder when(DBObject booleanExpression); + ThenBuilder when(Document booleanExpression); /** * @param booleanField reference to a field holding a boolean value, must not be {@literal null}. @@ -320,7 +320,7 @@ public class ConditionalOperator implements AggregationExpression { * @see org.springframework.data.mongodb.core.aggregation.ConditionalOperator.WhenBuilder#when(com.mongodb.DBObject) */ @Override - public ConditionalExpressionBuilder when(DBObject booleanExpression) { + public ConditionalExpressionBuilder when(Document booleanExpression) { Assert.notNull(booleanExpression, "'Boolean expression' must not be null!"); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ExposedFieldsAggregationOperationContext.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ExposedFieldsAggregationOperationContext.java index 72c2d60ea..923ae847f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ExposedFieldsAggregationOperationContext.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ExposedFieldsAggregationOperationContext.java @@ -27,6 +27,7 @@ import org.springframework.util.Assert; * @author Thomas Darimont * @author Oliver Gierke * @author Mark Paluch + * @author Christoph Strobl * @since 1.4 */ class ExposedFieldsAggregationOperationContext implements AggregationOperationContext { @@ -56,8 +57,8 @@ class ExposedFieldsAggregationOperationContext implements AggregationOperationCo * @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getMappedObject(com.mongodb.Document) */ @Override - public Document getMappedObject(Document dbObject) { - return rootContext.getMappedObject(dbObject); + public Document getMappedObject(Document document) { + return rootContext.getMappedObject(document); } /* diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GeoNearOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GeoNearOperation.java index 7c8a2de66..1be716b85 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GeoNearOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GeoNearOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 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.util.Assert; * instances of this class directly. * * @author Thomas Darimont + * @author Christoph Strobl * @since 1.3 */ public class GeoNearOperation implements AggregationOperation { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java index 62e28054a..0aa7a7134 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 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. @@ -37,6 +37,7 @@ import org.springframework.util.StringUtils; * @author Sebastian Herold * @author Thomas Darimont * @author Oliver Gierke + * @author Christoph Strobl * @since 1.3 */ public class GroupOperation implements FieldsExposingAggregationOperation { @@ -424,7 +425,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation { if (reference == null) { if (value instanceof AggregationExpression) { - return ((AggregationExpression) value).toDbObject(context); + return ((AggregationExpression) value).toDocument(context); } return value; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/IfNullOperator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/IfNullOperator.java index f46860ec3..130abe69b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/IfNullOperator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/IfNullOperator.java @@ -31,6 +31,7 @@ import com.mongodb.DBObject; * * @see http://docs.mongodb.com/manual/reference/operator/aggregation/ifNull/ * @author Mark Paluch + * @author Christoph Strobl * @since 1.10 */ public class IfNullOperator implements AggregationExpression { @@ -58,7 +59,7 @@ public class IfNullOperator implements AggregationExpression { * @see org.springframework.data.mongodb.core.aggregation.AggregationExpression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) */ @Override - public Document toDbObject(AggregationOperationContext context) { + public Document toDocument(AggregationOperationContext context) { List list = new ArrayList(); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/LimitOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/LimitOperation.java index 4ae0ee877..353b6866b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/LimitOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/LimitOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 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.util.Assert; * @see http://docs.mongodb.org/manual/reference/aggregation/limit/ * @author Thomas Darimont * @author Oliver Gierke + * @author Christoph Strobl * @since 1.3 */ public class LimitOperation implements AggregationOperation { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/OutOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/OutOperation.java index 7c5593b96..edc678c78 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/OutOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/OutOperation.java @@ -15,9 +15,6 @@ */ package org.springframework.data.mongodb.core.aggregation; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; - import org.bson.Document; import org.springframework.util.Assert; @@ -29,6 +26,7 @@ import org.springframework.util.Assert; * * @see http://docs.mongodb.org/manual/reference/aggregation/out/ * @author Nikolay Bogdanov + * @author Christoph Strobl */ public class OutOperation implements AggregationOperation { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java index 8f60d700c..2e3abf033 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java @@ -1065,7 +1065,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation { @Override public Document toDocument(AggregationOperationContext context) { - return new Document(field.getName(), expression.toDbObject(context)); + return new Document(field.getName(), expression.toDocument(context)); } } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SkipOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SkipOperation.java index 1a75a6097..00142222c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SkipOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SkipOperation.java @@ -27,6 +27,7 @@ import org.springframework.util.Assert; * @see http://docs.mongodb.org/manual/reference/aggregation/skip/ * @author Thomas Darimont * @author Oliver Gierke + * @author Christoph Strobl * @since 1.3 */ public class SkipOperation implements AggregationOperation { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java index d740b4f1f..345ba71fc 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SortOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 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; * @see http://docs.mongodb.org/manual/reference/aggregation/sort/#pipe._S_sort * @author Thomas Darimont * @author Oliver Gierke + * @author Christoph Strobl * @since 1.3 */ public class SortOperation implements AggregationOperation { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformer.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformer.java index 4b73f7c31..1e78c94d5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformer.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 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. @@ -248,23 +248,23 @@ class SpelExpressionTransformer implements AggregationExpressionTransformer { private Document createOperationObjectAndAddToPreviousArgumentsIfNecessary( AggregationExpressionTransformationContext context, OperatorNode currentNode) { - Document nextDbObject = new Document(currentNode.getMongoOperator(), new ArrayList()); + Document nextDocument = new Document(currentNode.getMongoOperator(), new ArrayList()); if (!context.hasPreviousOperation()) { - return nextDbObject; + return nextDocument; } if (context.parentIsSameOperation()) { // same operator applied in a row e.g. 1 + 2 + 3 carry on with the operation and render as $add: [1, 2 ,3] - nextDbObject = context.getPreviousOperationObject(); + nextDocument = context.getPreviousOperationObject(); } else if (!currentNode.isUnaryOperator()) { // different operator -> add context object for next level to list if arguments of previous expression - context.addToPreviousOperation(nextDbObject); + context.addToPreviousOperation(nextDocument); } - return nextDbObject; + return nextDocument; } private Object convertUnaryMinusOp(ExpressionTransformationContextSupport context, diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContext.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContext.java index c7d32a616..8d46ebf55 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContext.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2016 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. @@ -33,6 +33,7 @@ import org.springframework.util.Assert; * property references into document field names. * * @author Oliver Gierke + * @author Christoph Strobl * @since 1.3 */ public class TypeBasedAggregationOperationContext implements AggregationOperationContext { @@ -66,8 +67,8 @@ public class TypeBasedAggregationOperationContext implements AggregationOperatio * @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getMappedObject(com.mongodb.Document) */ @Override - public Document getMappedObject(Document dbObject) { - return mapper.getMappedObject(dbObject, mappingContext.getPersistentEntity(type)); + public Document getMappedObject(Document document) { + return mapper.getMappedObject(document, mappingContext.getPersistentEntity(type)); } /* diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectAccessor.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectAccessor.java index e96907598..e2b60e1b7 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectAccessor.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 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,11 +29,12 @@ import com.mongodb.BasicDBObject; import com.mongodb.DBObject; /** - * Wrapper value object for a {@link BasicDocument} to be able to access raw values by {@link MongoPersistentProperty} + * Wrapper value object for a {@link Document} to be able to access raw values by {@link MongoPersistentProperty} * references. The accessors will transparently resolve nested document values that a {@link MongoPersistentProperty} * might refer to through a path expression in field names. * * @author Oliver Gierke + * @author Christoph Strobl */ class DocumentAccessor { @@ -42,7 +43,7 @@ class DocumentAccessor { /** * Creates a new {@link DocumentAccessor} for the given {@link Document}. * - * @param dbObject must be a {@link BasicDocument} effectively, must not be {@literal null}. + * @param dbObject must be a {@link Document} effectively, must not be {@literal null}. */ public DocumentAccessor(Bson dbObject) { @@ -169,7 +170,7 @@ class DocumentAccessor { } /** - * Returns the given source object as map, i.e. {@link BasicDocument}s and maps as is or {@literal null} otherwise. + * Returns the given source object as map, i.e. {@link Document}s and maps as is or {@literal null} otherwise. * * @param source can be {@literal null}. * @return diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectPropertyAccessor.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectPropertyAccessor.java index c10f9f793..8a875e17a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectPropertyAccessor.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DBObjectPropertyAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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.expression.TypedValue; * {@link PropertyAccessor} to allow entity based field access to {@link Document}s. * * @author Oliver Gierke + * @author Christoph Strobl */ class DocumentPropertyAccessor extends MapAccessor { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefProxyHandler.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefProxyHandler.java index 5e9adaa2d..1f86a3511 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefProxyHandler.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefProxyHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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. @@ -28,6 +28,7 @@ import com.mongodb.DBRef; /** * @author Oliver Gierke + * @author Christoph Strobl */ class DefaultDbRefProxyHandler implements DbRefProxyHandler { @@ -37,8 +38,8 @@ class DefaultDbRefProxyHandler implements DbRefProxyHandler { /** * @param spELContext must not be {@literal null}. - * @param conversionService must not be {@literal null}. * @param mappingContext must not be {@literal null}. + * @param resolver must not be {@literal null}. */ public DefaultDbRefProxyHandler(SpELContext spELContext, MappingContext, MongoPersistentProperty> mappingContext, diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java index 6f32aae24..25c6c4e82 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java @@ -27,11 +27,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import com.mongodb.BasicDBObject; -import com.mongodb.BasicDBObjectBuilder; -import com.mongodb.DB; -import com.mongodb.DBObject; -import com.mongodb.client.MongoDatabase; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.bson.Document; @@ -51,7 +46,9 @@ import org.springframework.objenesis.ObjenesisStd; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; +import com.mongodb.DBObject; import com.mongodb.DBRef; +import com.mongodb.client.MongoDatabase; /** * A {@link DbRefResolver} that resolves {@link org.springframework.data.mongodb.core.mapping.DBRef}s by delegating to a @@ -148,8 +145,7 @@ public class DefaultDbRefResolver implements DbRefResolver { MongoDatabase db = mongoDbFactory.getDb(); List result = new ArrayList<>(); - db.getCollection(collection) - .find(new Document("_id", new Document("$in", ids))).into(result); + db.getCollection(collection).find(new Document("_id", new Document("$in", ids))).into(result); Collections.sort(result, new DbRefByReferencePositionComparator(ids)); return result; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolverCallback.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolverCallback.java index c1094557a..423aacd4e 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolverCallback.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolverCallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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.data.mongodb.core.mapping.MongoPersistentProperty; * Default implementation of {@link DbRefResolverCallback}. * * @author Oliver Gierke + * @author Christoph Strobl */ class DefaultDbRefResolverCallback implements DbRefResolverCallback { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultMongoTypeMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultMongoTypeMapper.java index 1fb4b97b5..79493de39 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultMongoTypeMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultMongoTypeMapper.java @@ -42,6 +42,7 @@ import com.mongodb.DBObject; * * @author Oliver Gierke * @author Thomas Darimont + * @author Christoph Strobl */ public class DefaultMongoTypeMapper extends DefaultTypeMapper implements MongoTypeMapper { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java index c4dc2843d..9f5ecc007 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java @@ -69,27 +69,27 @@ abstract class GeoConverters { @SuppressWarnings("unchecked") public static Collection getConvertersToRegister() { return Arrays.asList( // - BoxToDbObjectConverter.INSTANCE // - , PolygonToDbObjectConverter.INSTANCE // - , CircleToDbObjectConverter.INSTANCE // - , SphereToDbObjectConverter.INSTANCE // - , DbObjectToBoxConverter.INSTANCE // - , DbObjectToPolygonConverter.INSTANCE // - , DbObjectToCircleConverter.INSTANCE // - , DbObjectToSphereConverter.INSTANCE // - , DbObjectToPointConverter.INSTANCE // - , PointToDbObjectConverter.INSTANCE // - , GeoCommandToDbObjectConverter.INSTANCE // - , GeoJsonToDbObjectConverter.INSTANCE // - , GeoJsonPointToDbObjectConverter.INSTANCE // - , GeoJsonPolygonToDbObjectConverter.INSTANCE // - , DbObjectToGeoJsonPointConverter.INSTANCE // - , DbObjectToGeoJsonPolygonConverter.INSTANCE // - , DbObjectToGeoJsonLineStringConverter.INSTANCE // - , DbObjectToGeoJsonMultiLineStringConverter.INSTANCE // - , DbObjectToGeoJsonMultiPointConverter.INSTANCE // - , DbObjectToGeoJsonMultiPolygonConverter.INSTANCE // - , DbObjectToGeoJsonGeometryCollectionConverter.INSTANCE); + BoxToDocumentConverter.INSTANCE // + , PolygonToDocumentConverter.INSTANCE // + , CircleToDocumentConverter.INSTANCE // + , SphereToDocumentConverter.INSTANCE // + , DocumentToBoxConverter.INSTANCE // + , DocumentToPolygonConverter.INSTANCE // + , DocumentToCircleConverter.INSTANCE // + , DocumentToSphereConverter.INSTANCE // + , DocumentToPointConverter.INSTANCE // + , PointToDocumentConverter.INSTANCE // + , GeoCommandToDocumentConverter.INSTANCE // + , GeoJsonToDocumentConverter.INSTANCE // + , GeoJsonPointToDocumentConverter.INSTANCE // + , GeoJsonPolygonToDocumentConverter.INSTANCE // + , DocumentToGeoJsonPointConverter.INSTANCE // + , DocumentToGeoJsonPolygonConverter.INSTANCE // + , DocumentToGeoJsonLineStringConverter.INSTANCE // + , DocumentToGeoJsonMultiLineStringConverter.INSTANCE // + , DocumentToGeoJsonMultiPointConverter.INSTANCE // + , DocumentToGeoJsonMultiPolygonConverter.INSTANCE // + , DocumentToGeoJsonGeometryCollectionConverter.INSTANCE); } /** @@ -99,7 +99,7 @@ abstract class GeoConverters { * @since 1.5 */ @ReadingConverter - static enum DbObjectToPointConverter implements Converter { + static enum DocumentToPointConverter implements Converter { INSTANCE; @@ -117,7 +117,7 @@ abstract class GeoConverters { Assert.isTrue(source.keySet().size() == 2, "Source must contain 2 elements"); if (source.containsKey("type")) { - return DbObjectToGeoJsonPointConverter.INSTANCE.convert(source); + return DocumentToGeoJsonPointConverter.INSTANCE.convert(source); } return new Point((Double) source.get("x"), (Double) source.get("y")); @@ -130,7 +130,7 @@ abstract class GeoConverters { * @author Thomas Darimont * @since 1.5 */ - static enum PointToDbObjectConverter implements Converter { + static enum PointToDocumentConverter implements Converter { INSTANCE; @@ -151,7 +151,7 @@ abstract class GeoConverters { * @since 1.5 */ @WritingConverter - static enum BoxToDbObjectConverter implements Converter { + static enum BoxToDocumentConverter implements Converter { INSTANCE; @@ -167,8 +167,8 @@ abstract class GeoConverters { } Document result = new Document(); - result.put("first", PointToDbObjectConverter.INSTANCE.convert(source.getFirst())); - result.put("second", PointToDbObjectConverter.INSTANCE.convert(source.getSecond())); + result.put("first", PointToDocumentConverter.INSTANCE.convert(source.getFirst())); + result.put("second", PointToDocumentConverter.INSTANCE.convert(source.getSecond())); return result; } } @@ -180,7 +180,7 @@ abstract class GeoConverters { * @since 1.5 */ @ReadingConverter - static enum DbObjectToBoxConverter implements Converter { + static enum DocumentToBoxConverter implements Converter { INSTANCE; @@ -195,8 +195,8 @@ abstract class GeoConverters { return null; } - Point first = DbObjectToPointConverter.INSTANCE.convert((Document) source.get("first")); - Point second = DbObjectToPointConverter.INSTANCE.convert((Document) source.get("second")); + Point first = DocumentToPointConverter.INSTANCE.convert((Document) source.get("first")); + Point second = DocumentToPointConverter.INSTANCE.convert((Document) source.get("second")); return new Box(first, second); } @@ -208,7 +208,7 @@ abstract class GeoConverters { * @author Thomas Darimont * @since 1.5 */ - static enum CircleToDbObjectConverter implements Converter { + static enum CircleToDocumentConverter implements Converter { INSTANCE; @@ -224,7 +224,7 @@ abstract class GeoConverters { } Document result = new Document(); - result.put("center", PointToDbObjectConverter.INSTANCE.convert(source.getCenter())); + result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter())); result.put("radius", source.getRadius().getNormalizedValue()); result.put("metric", source.getRadius().getMetric().toString()); return result; @@ -238,7 +238,7 @@ abstract class GeoConverters { * @since 1.5 */ @ReadingConverter - static enum DbObjectToCircleConverter implements Converter { + static enum DocumentToCircleConverter implements Converter { INSTANCE; @@ -269,7 +269,7 @@ abstract class GeoConverters { Assert.notNull(center, "Center must not be null!"); Assert.notNull(radius, "Radius must not be null!"); - return new Circle(DbObjectToPointConverter.INSTANCE.convert(center), distance); + return new Circle(DocumentToPointConverter.INSTANCE.convert(center), distance); } } @@ -279,7 +279,7 @@ abstract class GeoConverters { * @author Thomas Darimont * @since 1.5 */ - static enum SphereToDbObjectConverter implements Converter { + static enum SphereToDocumentConverter implements Converter { INSTANCE; @@ -295,7 +295,7 @@ abstract class GeoConverters { } Document result = new Document(); - result.put("center", PointToDbObjectConverter.INSTANCE.convert(source.getCenter())); + result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter())); result.put("radius", source.getRadius().getNormalizedValue()); result.put("metric", source.getRadius().getMetric().toString()); return result; @@ -309,7 +309,7 @@ abstract class GeoConverters { * @since 1.5 */ @ReadingConverter - static enum DbObjectToSphereConverter implements Converter { + static enum DocumentToSphereConverter implements Converter { INSTANCE; @@ -340,7 +340,7 @@ abstract class GeoConverters { Assert.notNull(center, "Center must not be null!"); Assert.notNull(radius, "Radius must not be null!"); - return new Sphere(DbObjectToPointConverter.INSTANCE.convert(center), distance); + return new Sphere(DocumentToPointConverter.INSTANCE.convert(center), distance); } } @@ -350,7 +350,7 @@ abstract class GeoConverters { * @author Thomas Darimont * @since 1.5 */ - static enum PolygonToDbObjectConverter implements Converter { + static enum PolygonToDocumentConverter implements Converter { INSTANCE; @@ -369,7 +369,7 @@ abstract class GeoConverters { List pointTuples = new ArrayList(points.size()); for (Point point : points) { - pointTuples.add(PointToDbObjectConverter.INSTANCE.convert(point)); + pointTuples.add(PointToDocumentConverter.INSTANCE.convert(point)); } Document result = new Document(); @@ -385,7 +385,7 @@ abstract class GeoConverters { * @since 1.5 */ @ReadingConverter - static enum DbObjectToPolygonConverter implements Converter { + static enum DocumentToPolygonConverter implements Converter { INSTANCE; @@ -407,7 +407,7 @@ abstract class GeoConverters { for (Document element : points) { Assert.notNull(element, "Point elements of polygon must not be null!"); - newPoints.add(DbObjectToPointConverter.INSTANCE.convert(element)); + newPoints.add(DocumentToPointConverter.INSTANCE.convert(element)); } return new Polygon(newPoints); @@ -420,7 +420,7 @@ abstract class GeoConverters { * @author Thomas Darimont * @since 1.5 */ - static enum GeoCommandToDbObjectConverter implements Converter { + static enum GeoCommandToDocumentConverter implements Converter { INSTANCE; @@ -441,7 +441,7 @@ abstract class GeoConverters { Shape shape = source.getShape(); if (shape instanceof GeoJson) { - return GeoJsonToDbObjectConverter.INSTANCE.convert((GeoJson) shape); + return GeoJsonToDocumentConverter.INSTANCE.convert((GeoJson) shape); } if (shape instanceof Box) { @@ -480,7 +480,7 @@ abstract class GeoConverters { * @since 1.7 */ @SuppressWarnings("rawtypes") - static enum GeoJsonToDbObjectConverter implements Converter { + static enum GeoJsonToDocumentConverter implements Converter { INSTANCE; @@ -543,7 +543,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum GeoJsonPointToDbObjectConverter implements Converter { + static enum GeoJsonPointToDocumentConverter implements Converter { INSTANCE; @@ -553,7 +553,7 @@ abstract class GeoConverters { */ @Override public Document convert(GeoJsonPoint source) { - return GeoJsonToDbObjectConverter.INSTANCE.convert(source); + return GeoJsonToDocumentConverter.INSTANCE.convert(source); } } @@ -561,7 +561,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum GeoJsonPolygonToDbObjectConverter implements Converter { + static enum GeoJsonPolygonToDocumentConverter implements Converter { INSTANCE; @@ -571,7 +571,7 @@ abstract class GeoConverters { */ @Override public Document convert(GeoJsonPolygon source) { - return GeoJsonToDbObjectConverter.INSTANCE.convert(source); + return GeoJsonToDocumentConverter.INSTANCE.convert(source); } } @@ -579,7 +579,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum DbObjectToGeoJsonPointConverter implements Converter { + static enum DocumentToGeoJsonPointConverter implements Converter { INSTANCE; @@ -607,7 +607,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum DbObjectToGeoJsonPolygonConverter implements Converter { + static enum DocumentToGeoJsonPolygonConverter implements Converter { INSTANCE; @@ -633,7 +633,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum DbObjectToGeoJsonMultiPolygonConverter implements Converter { + static enum DocumentToGeoJsonMultiPolygonConverter implements Converter { INSTANCE; @@ -666,7 +666,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum DbObjectToGeoJsonLineStringConverter implements Converter { + static enum DocumentToGeoJsonLineStringConverter implements Converter { INSTANCE; @@ -694,7 +694,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum DbObjectToGeoJsonMultiPointConverter implements Converter { + static enum DocumentToGeoJsonMultiPointConverter implements Converter { INSTANCE; @@ -722,7 +722,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum DbObjectToGeoJsonMultiLineStringConverter implements Converter { + static enum DocumentToGeoJsonMultiLineStringConverter implements Converter { INSTANCE; @@ -754,7 +754,7 @@ abstract class GeoConverters { * @author Christoph Strobl * @since 1.7 */ - static enum DbObjectToGeoJsonGeometryCollectionConverter implements Converter { + static enum DocumentToGeoJsonGeometryCollectionConverter implements Converter { INSTANCE; @@ -785,26 +785,26 @@ abstract class GeoConverters { Object type = source.get("type"); if (ObjectUtils.nullSafeEquals(type, "Point")) { - return DbObjectToGeoJsonPointConverter.INSTANCE.convert(source); + return DocumentToGeoJsonPointConverter.INSTANCE.convert(source); } if (ObjectUtils.nullSafeEquals(type, "MultiPoint")) { - return DbObjectToGeoJsonMultiPointConverter.INSTANCE.convert(source); + return DocumentToGeoJsonMultiPointConverter.INSTANCE.convert(source); } if (ObjectUtils.nullSafeEquals(type, "LineString")) { - return DbObjectToGeoJsonLineStringConverter.INSTANCE.convert(source); + return DocumentToGeoJsonLineStringConverter.INSTANCE.convert(source); } if (ObjectUtils.nullSafeEquals(type, "MultiLineString")) { - return DbObjectToGeoJsonMultiLineStringConverter.INSTANCE.convert(source); + return DocumentToGeoJsonMultiLineStringConverter.INSTANCE.convert(source); } if (ObjectUtils.nullSafeEquals(type, "Polygon")) { - return DbObjectToGeoJsonPolygonConverter.INSTANCE.convert(source); + return DocumentToGeoJsonPolygonConverter.INSTANCE.convert(source); } if (ObjectUtils.nullSafeEquals(type, "MultiPolygon")) { - return DbObjectToGeoJsonMultiPolygonConverter.INSTANCE.convert(source); + return DocumentToGeoJsonMultiPolygonConverter.INSTANCE.convert(source); } throw new IllegalArgumentException(String.format("Cannot convert unknown GeoJson type %s", type)); 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 44fafb120..5f1dd3f9f 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 @@ -104,7 +104,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App /** * Creates a new {@link MappingMongoConverter} given the new {@link DbRefResolver} and {@link MappingContext}. * - * @param mongoDbFactory must not be {@literal null}. + * @param dbRefResolver must not be {@literal null}. * @param mappingContext must not be {@literal null}. */ public MappingMongoConverter(DbRefResolver dbRefResolver, @@ -192,50 +192,50 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * (non-Javadoc) * @see org.springframework.data.mongodb.core.core.MongoReader#read(java.lang.Class, com.mongodb.Document) */ - public S read(Class clazz, final Bson dbo) { - return read(ClassTypeInformation.from(clazz), dbo); + public S read(Class clazz, final Bson bson) { + return read(ClassTypeInformation.from(clazz), bson); } - protected S read(TypeInformation type, Bson dbo) { - return read(type, dbo, ObjectPath.ROOT); + protected S read(TypeInformation type, Bson bson) { + return read(type, bson, ObjectPath.ROOT); } @SuppressWarnings("unchecked") - private S read(TypeInformation type, Bson dbo, ObjectPath path) { + private S read(TypeInformation type, Bson bson, ObjectPath path) { - if (null == dbo) { + if (null == bson) { return null; } - TypeInformation typeToUse = typeMapper.readType(dbo, type); + TypeInformation typeToUse = typeMapper.readType(bson, type); Class rawType = typeToUse.getType(); - if (conversions.hasCustomReadTarget(dbo.getClass(), rawType)) { - return conversionService.convert(dbo, rawType); + if (conversions.hasCustomReadTarget(bson.getClass(), rawType)) { + return conversionService.convert(bson, rawType); } if (DBObject.class.isAssignableFrom(rawType)) { - return (S) dbo; + return (S) bson; } if (Document.class.isAssignableFrom(rawType)) { - return (S) dbo; + return (S) bson; } - if (typeToUse.isCollectionLike() && dbo instanceof List) { - return (S) readCollectionOrArray(typeToUse, (List) dbo, path); + if (typeToUse.isCollectionLike() && bson instanceof List) { + return (S) readCollectionOrArray(typeToUse, (List) bson, path); } if (typeToUse.isMap()) { - return (S) readMap(typeToUse, dbo, path); + return (S) readMap(typeToUse, bson, path); } - if (dbo instanceof Collection) { - throw new MappingException(String.format(INCOMPATIBLE_TYPES, dbo, BasicDBList.class, typeToUse.getType(), path)); + if (bson instanceof Collection) { + throw new MappingException(String.format(INCOMPATIBLE_TYPES, bson, BasicDBList.class, typeToUse.getType(), path)); } if (typeToUse.equals(ClassTypeInformation.OBJECT)) { - return (S) dbo; + return (S) bson; } // Retrieve persistent entity info MongoPersistentEntity persistentEntity = (MongoPersistentEntity) mappingContext @@ -244,7 +244,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App throw new MappingException("No mapping metadata found for " + rawType.getName()); } - return read(persistentEntity, dbo, path); + return read(persistentEntity, bson, path); } private ParameterValueProvider getParameterProvider(MongoPersistentEntity entity, @@ -258,11 +258,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App path); } - private S read(final MongoPersistentEntity entity, final Bson dbo, final ObjectPath path) { + private S read(final MongoPersistentEntity entity, final Bson bson, final ObjectPath path) { - final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(dbo, spELContext); + final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(bson, spELContext); - ParameterValueProvider provider = getParameterProvider(entity, dbo, evaluator, path); + ParameterValueProvider provider = getParameterProvider(entity, bson, evaluator, path); EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); S instance = instantiator.createInstance(entity, provider); @@ -274,10 +274,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App // make sure id property is set before all other properties Object idValue = null; - DocumentAccessor documentAccessor = new DocumentAccessor(dbo); + DocumentAccessor documentAccessor = new DocumentAccessor(bson); if (idProperty != null && documentAccessor.hasValue(idProperty)) { - idValue = getValueInternal(idProperty, dbo, evaluator, path); + idValue = getValueInternal(idProperty, bson, evaluator, path); accessor.setProperty(idProperty, idValue); } @@ -296,7 +296,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App return; } - accessor.setProperty(prop, getValueInternal(prop, dbo, evaluator, currentPath)); + accessor.setProperty(prop, getValueInternal(prop, bson, evaluator, currentPath)); } }); @@ -315,7 +315,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App DbRefProxyHandler handler = new DefaultDbRefProxyHandler(spELContext, mappingContext, MappingMongoConverter.this); - DbRefResolverCallback callback = new DefaultDbRefResolverCallback(dbo, currentPath, evaluator, + DbRefResolverCallback callback = new DefaultDbRefResolverCallback(bson, currentPath, evaluator, MappingMongoConverter.this); accessor.setProperty(property, dbRefResolver.resolveDbRef(property, dbref, callback, handler)); @@ -352,7 +352,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * * @see org.springframework.data.mongodb.core.core.convert.MongoWriter#write(java.lang.Object, com.mongodb.Document) */ - public void write(final Object obj, final Bson dbo) { + public void write(final Object obj, final Bson bson) { if (null == obj) { return; @@ -362,15 +362,15 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App boolean handledByCustomConverter = conversions.getCustomWriteTarget(entityType, Document.class) != null; TypeInformation type = ClassTypeInformation.from(entityType); - if (!handledByCustomConverter && !(dbo instanceof Collection)) { - typeMapper.writeType(type, dbo); + if (!handledByCustomConverter && !(bson instanceof Collection)) { + typeMapper.writeType(type, bson); } Object target = obj instanceof LazyLoadingProxy ? ((LazyLoadingProxy) obj).getTarget() : obj; - writeInternal(target, dbo, type); - if (asMap(dbo).containsKey("_is") && asMap(dbo).get("_id") == null) { - removeFromMap(dbo, "_id"); + writeInternal(target, bson, type); + if (asMap(bson).containsKey("_is") && asMap(bson).get("_id") == null) { + removeFromMap(bson, "_id"); } } @@ -378,10 +378,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * Internal write conversion method which should be used for nested invocations. * * @param obj - * @param dbo + * @param bson */ @SuppressWarnings("unchecked") - protected void writeInternal(final Object obj, final Bson dbo, final TypeInformation typeHint) { + protected void writeInternal(final Object obj, final Bson bson, final TypeInformation typeHint) { if (null == obj) { return; @@ -392,26 +392,26 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App if (customTarget != null) { Document result = conversionService.convert(obj, Document.class); - addAllToMap(dbo, result); + addAllToMap(bson, result); return; } if (Map.class.isAssignableFrom(entityType)) { - writeMapInternal((Map) obj, dbo, ClassTypeInformation.MAP); + writeMapInternal((Map) obj, bson, ClassTypeInformation.MAP); return; } if (Collection.class.isAssignableFrom(entityType)) { - writeCollectionInternal((Collection) obj, ClassTypeInformation.LIST, (List) dbo); + writeCollectionInternal((Collection) obj, ClassTypeInformation.LIST, (List) bson); return; } MongoPersistentEntity entity = mappingContext.getPersistentEntity(entityType); - writeInternal(obj, dbo, entity); - addCustomTypeKeyIfNecessary(typeHint, obj, dbo); + writeInternal(obj, bson, entity); + addCustomTypeKeyIfNecessary(typeHint, obj, bson); } - protected void writeInternal(Object obj, final Bson dbo, MongoPersistentEntity entity) { + protected void writeInternal(Object obj, final Bson bson, MongoPersistentEntity entity) { if (obj == null) { return; @@ -424,11 +424,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App final PersistentPropertyAccessor accessor = entity.getPropertyAccessor(obj); final MongoPersistentProperty idProperty = entity.getIdProperty(); - if (!asMap(dbo).containsKey("_id") && null != idProperty) { + if (!asMap(bson).containsKey("_id") && null != idProperty) { try { Object id = accessor.getProperty(idProperty); - addToMap(dbo, "_id", idMapper.convertId(id)); + addToMap(bson, "_id", idMapper.convertId(id)); } catch (ConversionException ignored) {} } @@ -445,9 +445,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App if (null != propertyObj) { if (!conversions.isSimpleType(propertyObj.getClass())) { - writePropertyInternal(propertyObj, dbo, prop); + writePropertyInternal(propertyObj, bson, prop); } else { - writeSimpleInternal(propertyObj, dbo, prop); + writeSimpleInternal(propertyObj, bson, prop); } } } @@ -461,20 +461,20 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App Object propertyObj = accessor.getProperty(inverseProp); if (null != propertyObj) { - writePropertyInternal(propertyObj, dbo, inverseProp); + writePropertyInternal(propertyObj, bson, inverseProp); } } }); } @SuppressWarnings({ "unchecked" }) - protected void writePropertyInternal(Object obj, Bson dbo, MongoPersistentProperty prop) { + protected void writePropertyInternal(Object obj, Bson bson, MongoPersistentProperty prop) { if (obj == null) { return; } - DocumentAccessor accessor = new DocumentAccessor(dbo); + DocumentAccessor accessor = new DocumentAccessor(bson); TypeInformation valueType = ClassTypeInformation.from(obj.getClass()); TypeInformation type = prop.getTypeInformation(); @@ -527,14 +527,14 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App } Object existingValue = accessor.get(prop); - Document propDbObj = existingValue instanceof Document ? (Document) existingValue : new Document(); - addCustomTypeKeyIfNecessary(ClassTypeInformation.from(prop.getRawType()), obj, propDbObj); + Document document = existingValue instanceof Document ? (Document) existingValue : new Document(); + addCustomTypeKeyIfNecessary(ClassTypeInformation.from(prop.getRawType()), obj, document); MongoPersistentEntity entity = isSubtype(prop.getType(), obj.getClass()) ? mappingContext.getPersistentEntity(obj.getClass()) : mappingContext.getPersistentEntity(type); - writeInternal(obj, propDbObj, entity); - accessor.put(prop, propDbObj); + writeInternal(obj, document, entity); + accessor.put(prop, document); } private boolean isSubtype(Class left, Class right) { @@ -602,7 +602,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App return writeMapInternal(map, new Document(), property.getTypeInformation()); } - Document dbObject = new Document(); + Document document = new Document(); for (Map.Entry entry : map.entrySet()) { @@ -612,14 +612,14 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App if (conversions.isSimpleType(key.getClass())) { String simpleKey = prepareMapKey(key.toString()); - dbObject.put(simpleKey, value != null ? createDBRef(value, property) : null); + document.put(simpleKey, value != null ? createDBRef(value, property) : null); } else { throw new MappingException("Cannot use a complex object as a key value."); } } - return dbObject; + return document; } /** @@ -643,9 +643,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App } else if (element instanceof Collection || elementType.isArray()) { sink.add(writeCollectionInternal(asCollection(element), componentType, new BasicDBList())); } else { - Document propDbObj = new Document(); - writeInternal(element, propDbObj, componentType); - sink.add(propDbObj); + Document document = new Document(); + writeInternal(element, document, componentType); + sink.add(document); } } @@ -656,11 +656,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * Writes the given {@link Map} to the given {@link Document} considering the given {@link TypeInformation}. * * @param obj must not be {@literal null}. - * @param dbo must not be {@literal null}. + * @param bson must not be {@literal null}. * @param propertyType must not be {@literal null}. * @return */ - protected Bson writeMapInternal(Map obj, Bson dbo, TypeInformation propertyType) { + protected Bson writeMapInternal(Map obj, Bson bson, TypeInformation propertyType) { for (Map.Entry entry : obj.entrySet()) { @@ -671,23 +671,23 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App String simpleKey = prepareMapKey(key); if (val == null || conversions.isSimpleType(val.getClass())) { - writeSimpleInternal(val, dbo, simpleKey); + writeSimpleInternal(val, bson, simpleKey); } else if (val instanceof Collection || val.getClass().isArray()) { - addToMap(dbo, simpleKey, + addToMap(bson, simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { - Document newDbo = new Document(); + Document document = new Document(); TypeInformation valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType() : ClassTypeInformation.OBJECT; - writeInternal(val, newDbo, valueTypeInfo); - addToMap(dbo, simpleKey, newDbo); + writeInternal(val, document, valueTypeInfo); + addToMap(bson, simpleKey, document); } } else { throw new MappingException("Cannot use a complex object as a key value."); } } - return dbo; + return bson; } /** @@ -762,9 +762,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * * @param type * @param value must not be {@literal null}. - * @param dbObject must not be {@literal null}. + * @param bson must not be {@literal null}. */ - protected void addCustomTypeKeyIfNecessary(TypeInformation type, Object value, Bson dbObject) { + protected void addCustomTypeKeyIfNecessary(TypeInformation type, Object value, Bson bson) { TypeInformation actualType = type != null ? type.getActualType() : null; Class reference = actualType == null ? Object.class : actualType.getType(); @@ -772,7 +772,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App boolean notTheSameClass = !valueType.equals(reference); if (notTheSameClass) { - typeMapper.writeType(valueType, dbObject); + typeMapper.writeType(valueType, bson); } } @@ -787,8 +787,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App addToMap(dbObject, key, getPotentiallyConvertedSimpleWrite(value)); } - private void writeSimpleInternal(Object value, Bson dbObject, MongoPersistentProperty property) { - DocumentAccessor accessor = new DocumentAccessor(dbObject); + private void writeSimpleInternal(Object value, Bson bson, MongoPersistentProperty property) { + DocumentAccessor accessor = new DocumentAccessor(bson); accessor.put(property, getPotentiallyConvertedSimpleWrite(value)); } @@ -891,9 +891,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * @see org.springframework.data.mongodb.core.convert.ValueResolver#getValueInternal(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty, com.mongodb.Document, org.springframework.data.mapping.model.SpELExpressionEvaluator, java.lang.Object) */ @Override - public Object getValueInternal(MongoPersistentProperty prop, Bson dbo, SpELExpressionEvaluator evaluator, + public Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator, ObjectPath path) { - return new MongoDbPropertyValueProvider(dbo, evaluator, path).getPropertyValue(prop); + return new MongoDbPropertyValueProvider(bson, evaluator, path).getPropertyValue(prop); } /** @@ -960,17 +960,17 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * Reads the given {@link Document} into a {@link Map}. will recursively resolve nested {@link Map}s as well. * * @param type the {@link Map} {@link TypeInformation} to be used to unmarshall this {@link Document}. - * @param dbObject must not be {@literal null} + * @param bson must not be {@literal null} * @param path must not be {@literal null} * @return */ @SuppressWarnings("unchecked") - protected Map readMap(TypeInformation type, Bson dbObject, ObjectPath path) { + protected Map readMap(TypeInformation type, Bson bson, ObjectPath path) { - Assert.notNull(dbObject, "Document must not be null!"); + Assert.notNull(bson, "Document must not be null!"); Assert.notNull(path, "Object path must not be null!"); - Class mapType = typeMapper.readType(dbObject, type).getType(); + Class mapType = typeMapper.readType(bson, type).getType(); TypeInformation keyType = type.getComponentType(); Class rawKeyType = keyType == null ? null : keyType.getType(); @@ -978,7 +978,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App TypeInformation valueType = type.getMapValueType(); Class rawValueType = valueType == null ? null : valueType.getType(); - Map sourceMap = asMap(dbObject); + Map sourceMap = asMap(bson); Map map = CollectionFactory.createMap(mapType, rawKeyType, sourceMap.keySet().size()); if (!DBRef.class.equals(rawValueType) && isCollectionOfDbRefWhereBulkFetchIsPossible(sourceMap.values())) { @@ -1094,12 +1094,12 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App } if (obj instanceof Document) { - Document newValueDbo = new Document(); + Document newValueDocument = new Document(); for (String vk : ((Document) obj).keySet()) { Object o = ((Document) obj).get(vk); - newValueDbo.put(vk, convertToMongoType(o, typeHint)); + newValueDocument.put(vk, convertToMongoType(o, typeHint)); } - return newValueDbo; + return newValueDocument; } if (obj instanceof DBObject) { @@ -1131,18 +1131,18 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App return maybeConvertList((Collection) obj, typeHint); } - Document newDbo = new Document(); - this.write(obj, newDbo); + Document newDocument = new Document(); + this.write(obj, newDocument); if (typeInformation == null) { - return removeTypeInfo(newDbo, true); + return removeTypeInfo(newDocument, true); } if (typeInformation.getType().equals(NestedDocument.class)) { - return removeTypeInfo(newDbo, false); + return removeTypeInfo(newDocument, false); } - return !obj.getClass().equals(typeInformation.getType()) ? newDbo : removeTypeInfo(newDbo, true); + return !obj.getClass().equals(typeInformation.getType()) ? newDocument : removeTypeInfo(newDocument, true); } public List maybeConvertList(Iterable source, TypeInformation typeInformation) { @@ -1168,14 +1168,14 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App return object; } - Document dbObject = (Document) object; + Document document = (Document) object; String keyToRemove = null; - for (String key : dbObject.keySet()) { + for (String key : document.keySet()) { if (recursively) { - Object value = dbObject.get(key); + Object value = document.get(key); if (value instanceof BasicDBList) { for (Object element : (BasicDBList) value) { @@ -1201,10 +1201,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App } if (keyToRemove != null) { - dbObject.remove(keyToRemove); + document.remove(keyToRemove); } - return dbObject; + return document; } /** diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoConverter.java index c172bce1b..6867e4f4b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2010-2016 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. @@ -28,6 +28,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty; * * @author Oliver Gierke * @author Thomas Darimont + * @author Christoph Strobl */ public interface MongoConverter extends EntityConverter, MongoPersistentProperty, Object, Bson>, MongoWriter, diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoExampleMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoExampleMapper.java index fe4800291..e43a9ff04 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoExampleMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoExampleMapper.java @@ -251,24 +251,24 @@ public class MongoExampleMapper { private void applyStringMatcher(Map.Entry entry, StringMatcher stringMatcher, boolean ignoreCase) { - Document dbo = new Document(); + Document document = new Document(); if (ObjectUtils.nullSafeEquals(StringMatcher.DEFAULT, stringMatcher)) { if (ignoreCase) { - dbo.put("$regex", Pattern.quote((String) entry.getValue())); - entry.setValue(dbo); + document.put("$regex", Pattern.quote((String) entry.getValue())); + entry.setValue(document); } } else { Type type = stringMatcherPartMapping.get(stringMatcher); String expression = MongoRegexCreator.INSTANCE.toRegularExpression((String) entry.getValue(), type); - dbo.put("$regex", expression); - entry.setValue(dbo); + document.put("$regex", expression); + entry.setValue(document); } if (ignoreCase) { - dbo.put("$options", "i"); + document.put("$options", "i"); } } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoTypeMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoTypeMapper.java index 8634fba12..6501b3b46 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoTypeMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoTypeMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-2016 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,8 @@ import org.springframework.data.convert.TypeMapper; * Mongo-specific {@link TypeMapper} exposing that {@link Document}s might contain a type key. * * @author Oliver Gierke + * @author Christoph Strobl + * @since 1.0 */ public interface MongoTypeMapper extends TypeMapper { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoWriter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoWriter.java index e0f6d57ad..19f03b67c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoWriter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2010-2016 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 com.mongodb.DBRef; * @author Mark Pollack * @author Thomas Risberg * @author Oliver Gierke + * @author Christoph Strobl */ public interface MongoWriter extends EntityWriter { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ObjectPath.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ObjectPath.java index 32e057069..ea1667020 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ObjectPath.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ObjectPath.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReflectiveDBRefResolver.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReflectiveDBRefResolver.java index 95849b8ba..4b9733891 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReflectiveDBRefResolver.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReflectiveDBRefResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/UpdateMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/UpdateMapper.java index 23275337b..4c1aa40c3 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/UpdateMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/UpdateMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ValueResolver.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ValueResolver.java index 93d153e11..24a92a7eb 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ValueResolver.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ValueResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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.data.mongodb.core.mapping.MongoPersistentProperty; * Internal API to trigger the resolution of properties. * * @author Oliver Gierke + * @author Christoph Strobl */ interface ValueResolver { @@ -32,10 +33,10 @@ interface ValueResolver { * {@link SpELExpressionEvaluator} and {@link ObjectPath}. * * @param prop - * @param dbo + * @param bson * @param evaluator * @param parent * @return */ - Object getValueInternal(MongoPersistentProperty prop, Bson dbo, SpELExpressionEvaluator evaluator, ObjectPath parent); + Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator, ObjectPath parent); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java index 9e5c4a088..bb6aa03a2 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java @@ -125,17 +125,6 @@ public @interface CompoundIndex { */ boolean useGeneratedName() default false; - /** - * The collection the index will be created in. Will default to the collection the annotated domain class will be - * stored in. - * - * @return - * @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might - * result in broken definitions. Will be removed in 1.7. - */ - @Deprecated - String collection() default ""; - /** * If {@literal true} the index will be created in the background. * diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndexDefinition.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndexDefinition.java index 34a448fa8..65680192d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndexDefinition.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndexDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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. @@ -46,9 +46,9 @@ public class CompoundIndexDefinition extends Index { @Override public Document getIndexKeys() { - Document dbo = new Document(); - dbo.putAll(this.keys); - dbo.putAll(super.getIndexKeys()); - return dbo; + Document document = new Document(); + document.putAll(this.keys); + document.putAll(super.getIndexKeys()); + return document; } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeoSpatialIndexed.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeoSpatialIndexed.java index ee20619ac..3f50fa3ec 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeoSpatialIndexed.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeoSpatialIndexed.java @@ -83,16 +83,6 @@ public @interface GeoSpatialIndexed { */ boolean useGeneratedName() default false; - /** - * Name of the collection in which to create the index. - * - * @return - * @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might - * result in broken definitions. Will be removed in 1.7. - */ - @Deprecated - String collection() default ""; - /** * Minimum value for indexed values. * diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeospatialIndex.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeospatialIndex.java index dab1e95aa..3ec6ec09b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeospatialIndex.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/GeospatialIndex.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2014 the original author or authors. + * Copyright 2010-2016 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. @@ -119,31 +119,31 @@ public class GeospatialIndex implements IndexDefinition { public Document getIndexKeys() { - Document dbo = new Document(); + Document document = new Document(); switch (type) { case GEO_2D: - dbo.put(field, "2d"); + document.put(field, "2d"); break; case GEO_2DSPHERE: - dbo.put(field, "2dsphere"); + document.put(field, "2dsphere"); break; case GEO_HAYSTACK: - dbo.put(field, "geoHaystack"); + document.put(field, "geoHaystack"); if (!StringUtils.hasText(additionalField)) { throw new IllegalArgumentException("When defining geoHaystack index, an additionnal field must be defined"); } - dbo.put(additionalField, 1); + document.put(additionalField, 1); break; default: throw new IllegalArgumentException("Unsupported geospatial index " + type); } - return dbo; + return document; } public Document getIndexOptions() { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java index c939d3ab7..4827ff30d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 the original author or authors. + * Copyright 2010-2016 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,7 +22,6 @@ import java.util.concurrent.TimeUnit; import org.bson.Document; import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.mongodb.core.query.Order; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -34,17 +33,7 @@ import org.springframework.util.StringUtils; public class Index implements IndexDefinition { public enum Duplicates { - RETAIN, // - - /** - * Dropping Duplicates was removed in MongoDB Server 2.8.0-rc0. - *

        - * See https://jira.mongodb.org/browse/SERVER-14710 - * - * @deprecated since 1.7. - */ - @Deprecated // - DROP + RETAIN } private final Map fieldSpec = new LinkedHashMap(); @@ -67,31 +56,6 @@ public class Index implements IndexDefinition { fieldSpec.put(key, direction); } - /** - * Creates a new {@link Indexed} on the given key and {@link Order}. - * - * @deprecated use {@link #Index(String, Direction)} instead. - * @param key must not be {@literal null} or empty. - * @param order must not be {@literal null}. - */ - @Deprecated - public Index(String key, Order order) { - this(key, order.toDirection()); - } - - /** - * Adds the given field to the index. - * - * @deprecated use {@link #on(String, Direction)} instead. - * @param key must not be {@literal null} or empty. - * @param order must not be {@literal null}. - * @return - */ - @Deprecated - public Index on(String key, Order order) { - return on(key, order.toDirection()); - } - public Index on(String key, Direction direction) { fieldSpec.put(key, direction); return this; @@ -162,56 +126,44 @@ public class Index implements IndexDefinition { return this; } - /** - * @see http://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping - * @param duplicates - * @return - */ - public Index unique(Duplicates duplicates) { - if (duplicates == Duplicates.DROP) { - this.dropDuplicates = true; - } - return unique(); - } - /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.index.IndexDefinition#getIndexKeys() */ public Document getIndexKeys() { - Document dbo = new Document(); + Document document = new Document(); for (Entry entry : fieldSpec.entrySet()) { - dbo.put(entry.getKey(), Direction.ASC.equals(entry.getValue()) ? 1 : -1); + document.put(entry.getKey(), Direction.ASC.equals(entry.getValue()) ? 1 : -1); } - return dbo; + return document; } public Document getIndexOptions() { - Document dbo = new Document(); + Document document = new Document(); if (StringUtils.hasText(name)) { - dbo.put("name", name); + document.put("name", name); } if (unique) { - dbo.put("unique", true); + document.put("unique", true); } if (dropDuplicates) { - dbo.put("dropDups", true); + document.put("dropDups", true); } if (sparse) { - dbo.put("sparse", true); + document.put("sparse", true); } if (background) { - dbo.put("background", true); + document.put("background", true); } if (expire >= 0) { - dbo.put("expireAfterSeconds", expire); + document.put("expireAfterSeconds", expire); } - return dbo; + return document; } @Override diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexDefinition.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexDefinition.java index 80bd096cd..da0acf8ad 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexDefinition.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 by the original author(s). + * Copyright (c) 2011-2016 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. 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 83bf35436..8bf243ee7 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 @@ -16,7 +16,6 @@ package org.springframework.data.mongodb.core.index; import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.mongodb.core.query.Order; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -53,20 +52,6 @@ public final class IndexField { this.weight = weight == null ? Float.NaN : weight; } - /** - * Creates a default {@link IndexField} with the given key and {@link Order}. - * - * @deprecated use {@link #create(String, Direction)}. - * @param key must not be {@literal null} or emtpy. - * @param direction must not be {@literal null}. - * @return - */ - @Deprecated - public static IndexField create(String key, Order order) { - Assert.notNull(order); - return new IndexField(key, order.toDirection(), Type.DEFAULT); - } - public static IndexField create(String key, Direction order) { Assert.notNull(order); return new IndexField(key, order, Type.DEFAULT); @@ -98,17 +83,6 @@ public final class IndexField { return key; } - /** - * Returns the direction of the {@link IndexField} or {@literal null} in case we have a geo index field. - * - * @deprecated use {@link #getDirection()} instead. - * @return the direction - */ - @Deprecated - public Order getOrder() { - return Direction.ASC.equals(direction) ? Order.ASCENDING : Order.DESCENDING; - } - /** * Returns the direction of the {@link IndexField} or {@literal null} in case we have a geo index field. * 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 2073fc1c2..fb8f673ce 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 @@ -38,19 +38,6 @@ public class IndexInfo { private final boolean sparse; private final String language; - /** - * @deprecated Will be removed in 1.7. Please use {@link #IndexInfo(List, String, boolean, boolean, boolean, String)} - * @param indexFields - * @param name - * @param unique - * @param dropDuplicates - * @param sparse - */ - @Deprecated - public IndexInfo(List indexFields, String name, boolean unique, boolean dropDuplicates, boolean sparse) { - this(indexFields, name, unique, dropDuplicates, sparse, ""); - } - public IndexInfo(List indexFields, String name, boolean unique, boolean dropDuplicates, boolean sparse, String language) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java index a32262242..c34e69e01 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java @@ -109,16 +109,6 @@ public @interface Indexed { */ boolean useGeneratedName() default false; - /** - * Collection name for index to be created on. - * - * @return - * @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might - * result in broken definitions. Will be removed in 1.7. - */ - @Deprecated - String collection() default ""; - /** * If {@literal true} the index will be created in the background. * 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 504628347..3956ead3b 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-2015 the original author or authors. + * Copyright 2011-2016 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. @@ -153,9 +153,6 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener entity) { CompoundIndexDefinition indexDefinition = new CompoundIndexDefinition( @@ -332,7 +331,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver { } if (index.unique()) { - indexDefinition.unique(index.dropDups() ? Duplicates.DROP : Duplicates.RETAIN); + indexDefinition.unique(); } if (index.sparse()) { @@ -343,7 +342,6 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver { indexDefinition.background(); } - String collection = StringUtils.hasText(index.collection()) ? index.collection() : fallbackCollection; return new IndexDefinitionHolder(dotPath, indexDefinition, collection); } @@ -379,11 +377,10 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver { * @param persitentProperty * @return */ - protected IndexDefinitionHolder createIndexDefinition(String dotPath, String fallbackCollection, + protected IndexDefinitionHolder createIndexDefinition(String dotPath, String collection, MongoPersistentProperty persitentProperty) { Indexed index = persitentProperty.findAnnotation(Indexed.class); - String collection = StringUtils.hasText(index.collection()) ? index.collection() : fallbackCollection; Index indexDefinition = new Index().on(dotPath, IndexDirection.ASCENDING.equals(index.direction()) ? Sort.Direction.ASC : Sort.Direction.DESC); @@ -393,7 +390,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver { } if (index.unique()) { - indexDefinition.unique(index.dropDups() ? Duplicates.DROP : Duplicates.RETAIN); + indexDefinition.unique(); } if (index.sparse()) { @@ -420,11 +417,10 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver { * @param persistentProperty * @return */ - protected IndexDefinitionHolder createGeoSpatialIndexDefinition(String dotPath, String fallbackCollection, + protected IndexDefinitionHolder createGeoSpatialIndexDefinition(String dotPath, String collection, MongoPersistentProperty persistentProperty) { GeoSpatialIndexed index = persistentProperty.findAnnotation(GeoSpatialIndexed.class); - String collection = StringUtils.hasText(index.collection()) ? index.collection() : fallbackCollection; GeospatialIndex indexDefinition = new GeospatialIndex(dotPath); indexDefinition.withBits(index.bits()); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/TextIndexDefinition.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/TextIndexDefinition.java index 4b2b1df37..b65a2dd8a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/TextIndexDefinition.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/TextIndexDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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. @@ -113,15 +113,15 @@ public class TextIndexDefinition implements IndexDefinition { options.put("default_language", defaultLanguage); } - Document weightsDbo = new Document(); + Document weightsDocument = new Document(); for (TextIndexedFieldSpec fieldSpec : fieldSpecs) { if (fieldSpec.isWeighted()) { - weightsDbo.put(fieldSpec.getFieldname(), fieldSpec.getWeight()); + weightsDocument.put(fieldSpec.getFieldname(), fieldSpec.getWeight()); } } - if (!weightsDbo.isEmpty()) { - options.put("weights", weightsDbo); + if (!weightsDocument.isEmpty()) { + options.put("weights", weightsDocument); } if (StringUtils.hasText(languageOverride)) { options.put("language_override", languageOverride); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java index d8ed71511..ab38336fb 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoSimpleTypes.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoSimpleTypes.java index a4c976de4..db2e63d89 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoSimpleTypes.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoSimpleTypes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 by the original author(s). + * Copyright (c) 2011-2016 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. @@ -34,6 +34,7 @@ import com.mongodb.DBRef; * Simple constant holder for a {@link SimpleTypeHolder} enriched with Mongo specific simple types. * * @author Oliver Gierke + * @author Christoph Strobl */ public abstract class MongoSimpleTypes { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/Version.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/Version.java deleted file mode 100644 index d96670675..000000000 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/Version.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012 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.mapping; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.*; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * Demarcates a property to be used as version field to implement optimistic locking on entities. - * - * @since 1.4 - * @author Patryk Wasik - * @deprecated use {@link org.springframework.data.annotation.Version} instead. - */ -@Deprecated -@Documented -@Target({ FIELD }) -@Retention(RUNTIME) -@org.springframework.data.annotation.Version -public @interface Version { - -} diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractDeleteEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractDeleteEvent.java index 29926250f..b4136b88b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractDeleteEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractDeleteEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 by the original author(s). + * Copyright 2013-2016 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. @@ -31,26 +31,14 @@ public abstract class AbstractDeleteEvent extends MongoMappingEvent /** * Creates a new {@link AbstractDeleteEvent} for the given {@link Document} and type. * - * @param dbo must not be {@literal null}. - * @param type can be {@literal null}. - * @deprecated since 1.8. Please use {@link #AbstractDeleteEvent(Document, Class, String)}. - */ - @Deprecated - public AbstractDeleteEvent(Document dbo, Class type) { - this(dbo, type, null); - } - - /** - * Creates a new {@link AbstractDeleteEvent} for the given {@link Document} and type. - * - * @param dbo must not be {@literal null}. + * @param document must not be {@literal null}. * @param type can be {@literal null}. * @param collectionName can be {@literal null}. * @since 1.8 */ - public AbstractDeleteEvent(Document dbo, Class type, String collectionName) { + public AbstractDeleteEvent(Document document, Class type, String collectionName) { - super(dbo, dbo, collectionName); + super(document, document, collectionName); this.type = type; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.java index 7ebda59a1..f9c12b651 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.java @@ -15,7 +15,6 @@ */ package org.springframework.data.mongodb.core.mapping.event; -import org.bson.Document; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationListener; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterConvertEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterConvertEvent.java index 10f99bc25..a5f662b5f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterConvertEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterConvertEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 by the original author(s). + * Copyright (c) 2011-2016 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. @@ -30,25 +30,13 @@ public class AfterConvertEvent extends MongoMappingEvent { /** * Creates new {@link AfterConvertEvent}. * - * @param dbo can be {@literal null}. - * @param source must not be {@literal null}. - * @deprecated since 1.8. Please use {@link #AfterConvertEvent(Document, Object, String)}. - */ - @Deprecated - public AfterConvertEvent(Document dbo, E source) { - this(dbo, source, null); - } - - /** - * Creates new {@link AfterConvertEvent}. - * - * @param dbo can be {@literal null}. + * @param document can be {@literal null}. * @param source must not be {@literal null}. * @param collectionName can be {@literal null}. * @since 1.8 */ - public AfterConvertEvent(Document dbo, E source, String collectionName) { - super(source, dbo, collectionName); + public AfterConvertEvent(Document document, E source, String collectionName) { + super(source, document, collectionName); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterDeleteEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterDeleteEvent.java index 87fcb4c24..522208aa2 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterDeleteEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterDeleteEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 by the original author(s). + * Copyright 2013-2016 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. @@ -28,18 +28,6 @@ public class AfterDeleteEvent extends AbstractDeleteEvent { private static final long serialVersionUID = 1L; - /** - * Creates a new {@link AfterDeleteEvent} for the given {@link Document} and type. - * - * @param dbo must not be {@literal null}. - * @param type can be {@literal null}. - * @deprecated since 1.8. Please use {@link #AfterDeleteEvent(Document, Class, String)}. - */ - @Deprecated - public AfterDeleteEvent(Document dbo, Class type) { - this(dbo, type, null); - } - /** * Creates a new {@link AfterDeleteEvent} for the given {@link Document}, type and collectionName. * @@ -48,7 +36,7 @@ public class AfterDeleteEvent extends AbstractDeleteEvent { * @param collectionName can be {@literal null}. * @since 1.8 */ - public AfterDeleteEvent(Document dbo, Class type, String collectionName) { - super(dbo, type, collectionName); + public AfterDeleteEvent(Document document, Class type, String collectionName) { + super(document, type, collectionName); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterLoadEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterLoadEvent.java index e3377231e..590eac90d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterLoadEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterLoadEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 by the original author(s). + * Copyright (c) 2011-2016 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. @@ -32,29 +32,17 @@ public class AfterLoadEvent extends MongoMappingEvent { private static final long serialVersionUID = 1L; private final Class type; - /** - * Creates a new {@link AfterLoadEvent} for the given {@link Document} and type. - * - * @param dbo must not be {@literal null}. - * @param type can be {@literal null}. - * @deprecated since 1.8. Please use {@link #AfterLoadEvent(Document, Class, String)}. - */ - @Deprecated - public AfterLoadEvent(Document dbo, Class type) { - this(dbo, type, null); - } - /** * Creates a new {@link AfterLoadEvent} for the given {@link Document}, type and collectionName. * - * @param dbo must not be {@literal null}. + * @param document must not be {@literal null}. * @param type must not be {@literal null}. * @param collectionName can be {@literal null}. * @since 1.8 */ - public AfterLoadEvent(Document dbo, Class type, String collectionName) { + public AfterLoadEvent(Document document, Class type, String collectionName) { - super(dbo, dbo, collectionName); + super(document, document, collectionName); Assert.notNull(type, "Type must not be null!"); this.type = type; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterSaveEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterSaveEvent.java index 79c19ef63..e8e490159 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterSaveEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AfterSaveEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 by the original author(s). + * Copyright (c) 2011-2016 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. @@ -28,28 +28,16 @@ public class AfterSaveEvent extends MongoMappingEvent { private static final long serialVersionUID = 1L; - /** - * Creates new {@link AfterSaveEvent} - * - * @param source must not be {@literal null}. - * @param dbo can be {@literal null}. - * @deprecated since 1.8. Please use {@link #AfterSaveEvent(Object, Document, String)}. - */ - @Deprecated - public AfterSaveEvent(E source, Document dbo) { - super(source, dbo); - } - /** * Creates new {@link AfterSaveEvent}. * * @param source must not be {@literal null}. - * @param dbo can be {@literal null}. + * @param document can be {@literal null}. * @param collectionName can be {@literal null}. * @since 1.8 */ - public AfterSaveEvent(E source, Document dbo, String collectionName) { - super(source, dbo, collectionName); + public AfterSaveEvent(E source, Document document, String collectionName) { + super(source, document, collectionName); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeConvertEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeConvertEvent.java index b894310e9..acb9912f0 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeConvertEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeConvertEvent.java @@ -26,17 +26,6 @@ public class BeforeConvertEvent extends MongoMappingEvent { private static final long serialVersionUID = 252614269008845243L; - /** - * Creates new {@link BeforeConvertEvent}. - * - * @param source must not be {@literal null}. - * @deprecated since 1.8. Please use {@link #BeforeConvertEvent(Object, String)}. - */ - @Deprecated - public BeforeConvertEvent(T source) { - this(source, null); - } - /** * Creates new {@link BeforeConvertEvent}. * diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeDeleteEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeDeleteEvent.java index 9b9aa94d3..12cec1812 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeDeleteEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeDeleteEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 by the original author(s). + * Copyright 2013-2016 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. @@ -28,27 +28,15 @@ public class BeforeDeleteEvent extends AbstractDeleteEvent { private static final long serialVersionUID = -2627547705679734497L; - /** - * Creates a new {@link BeforeDeleteEvent} for the given {@link Document} and type. - * - * @param dbo must not be {@literal null}. - * @param type can be {@literal null}. - * @deprecated since 1.8. Please use {@link #BeforeDeleteEvent(Document, Class, String)}. - */ - @Deprecated - public BeforeDeleteEvent(Document dbo, Class type) { - this(dbo, type, null); - } - /** * Creates a new {@link BeforeDeleteEvent} for the given {@link Document}, type and collectionName. * - * @param dbo must not be {@literal null}. + * @param document must not be {@literal null}. * @param type can be {@literal null}. * @param collectionName can be {@literal null}. * @since 1.8 */ - public BeforeDeleteEvent(Document dbo, Class type, String collectionName) { - super(dbo, type, collectionName); + public BeforeDeleteEvent(Document document, Class type, String collectionName) { + super(document, type, collectionName); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeSaveEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeSaveEvent.java index af2a70fe8..a25155acd 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeSaveEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/BeforeSaveEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 by the original author(s). + * Copyright (c) 2011-2016 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. @@ -32,24 +32,12 @@ public class BeforeSaveEvent extends MongoMappingEvent { * Creates new {@link BeforeSaveEvent}. * * @param source must not be {@literal null}. - * @param dbo can be {@literal null}. - * @deprecated since 1.8. Please use {@link #BeforeSaveEvent(Object, Document, String)}. - */ - @Deprecated - public BeforeSaveEvent(E source, Document dbo) { - super(source, dbo); - } - - /** - * Creates new {@link BeforeSaveEvent}. - * - * @param source must not be {@literal null}. - * @param dbo can be {@literal null}. + * @param document can be {@literal null}. * @param collectionName can be {@literal null}. * @since 1.8 */ - public BeforeSaveEvent(E source, Document dbo, String collectionName) { - super(source, dbo, collectionName); + public BeforeSaveEvent(E source, Document document, String collectionName) { + super(source, document, collectionName); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/LoggingEventListener.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/LoggingEventListener.java index 3438765d6..5e2078812 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/LoggingEventListener.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/LoggingEventListener.java @@ -15,7 +15,6 @@ */ package org.springframework.data.mongodb.core.mapping.event; -import org.bson.Document; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationListener; @@ -26,6 +25,7 @@ import org.springframework.context.ApplicationListener; * @author Jon Brisbin * @author Martin Baumgartner * @author Oliver Gierke + * @author Christoph Strobl */ public class LoggingEventListener extends AbstractMongoEventListener { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/MongoMappingEvent.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/MongoMappingEvent.java index 16450160c..37af9b562 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/MongoMappingEvent.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/MongoMappingEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 by the original author(s). + * Copyright (c) 2011-2016 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. @@ -28,32 +28,20 @@ import org.springframework.context.ApplicationEvent; public class MongoMappingEvent extends ApplicationEvent { private static final long serialVersionUID = 1L; - private final Document dbo; + private final Document document; private final String collectionName; /** * Creates new {@link MongoMappingEvent}. * * @param source must not be {@literal null}. - * @param dbo can be {@literal null}. - * @deprecated since 1.8. Please use {@link #MongoMappingEvent(Object, Document, String)}. - */ - @Deprecated - public MongoMappingEvent(T source, Document dbo) { - this(source, dbo, null); - } - - /** - * Creates new {@link MongoMappingEvent}. - * - * @param source must not be {@literal null}. - * @param dbo can be {@literal null}. + * @param document can be {@literal null}. * @param collectionName can be {@literal null}. */ - public MongoMappingEvent(T source, Document dbo, String collectionName) { + public MongoMappingEvent(T source, Document document, String collectionName) { super(source); - this.dbo = dbo; + this.document = document; this.collectionName = collectionName; } @@ -61,7 +49,7 @@ public class MongoMappingEvent extends ApplicationEvent { * @return {@literal null} if not set. */ public Document getDocument() { - return dbo; + return document; } /** diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/ValidatingMongoEventListener.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/ValidatingMongoEventListener.java index 8fcc02ce0..cc368c338 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/ValidatingMongoEventListener.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/ValidatingMongoEventListener.java @@ -20,7 +20,6 @@ import java.util.Set; import javax.validation.ConstraintViolationException; import javax.validation.Validator; -import org.bson.Document; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.Assert; @@ -31,6 +30,7 @@ import org.springframework.util.Assert; * * @author Maciej Walkowiak * @author Oliver Gierke + * @author Christoph Strobl */ public class ValidatingMongoEventListener extends AbstractMongoEventListener { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupBy.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupBy.java index af511a68d..c6017de6b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupBy.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupBy.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2016 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,33 +23,34 @@ import org.bson.Document; * map-reduce. * * @author Mark Pollack + * @author Christoph Strobl */ public class GroupBy { private Document dboKeys; private String keyFunction; private String initial; - private Document initialDbObject; + private Document initialDocument; private String reduce; private String finalize; public GroupBy(String... keys) { - Document dbo = new Document(); + Document document = new Document(); for (String key : keys) { - dbo.put(key, 1); + document.put(key, 1); } - dboKeys = dbo; + dboKeys = document; } // NOTE GroupByCommand does not handle keyfunction. public GroupBy(String key, boolean isKeyFunction) { - Document dbo = new Document(); + Document document = new Document(); if (isKeyFunction) { keyFunction = key; } else { - dbo.put(key, 1); - dboKeys = dbo; + document.put(key, 1); + dboKeys = document; } } @@ -67,7 +68,7 @@ public class GroupBy { } public GroupBy initialDocument(Document initialDocument) { - initialDbObject = initialDocument; + this.initialDocument = initialDocument; return this; } @@ -83,24 +84,24 @@ public class GroupBy { public Document getGroupByObject() { // return new GroupCommand(dbCollection, dboKeys, condition, initial, reduce, finalize); - Document dbo = new Document(); + Document document = new Document(); if (dboKeys != null) { - dbo.put("key", dboKeys); + document.put("key", dboKeys); } if (keyFunction != null) { - dbo.put("$keyf", keyFunction); + document.put("$keyf", keyFunction); } - dbo.put("$reduce", reduce); + document.put("$reduce", reduce); - dbo.put("initial", initialDbObject); + document.put("initial", initialDocument); if (initial != null) { - dbo.put("initial", initial); + document.put("initial", initial); } if (finalize != null) { - dbo.put("finalize", finalize); + document.put("finalize", finalize); } - return dbo; + return document; } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupByResults.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupByResults.java index abae78a8a..1b4e9db0f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupByResults.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/GroupByResults.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 - 2014 the original author or authors. + * Copyright 2011 - 2016O 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceOptions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceOptions.java index 97aa6dd20..808c0b6b6 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceOptions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 the original author or authors. + * Copyright 2010-2016 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. 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 91ce1574a..983498f4c 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,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/BasicUpdate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/BasicUpdate.java index a33e32b28..eadd87199 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/BasicUpdate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/BasicUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2016 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. @@ -20,6 +20,12 @@ import java.util.Collections; import org.bson.Document; +/** + * @author Thomas Risberg + * @author John Brisbin + * @author Oliver Gierke + * @author Christoph Strobl + */ public class BasicUpdate extends Update { private Document updateObject = null; 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 31d5769eb..f01e05cf2 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 @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 the original author or authors. + * Copyright 2010-2016 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. @@ -617,9 +617,9 @@ public class Criteria implements CriteriaDefinition { } else { Document criteriaObject = new Document(); for (Criteria c : this.criteriaChain) { - Document dbo = c.getSingleCriteriaObject(); - for (String k : dbo.keySet()) { - setValue(criteriaObject, k, dbo.get(k)); + Document document = c.getSingleCriteriaObject(); + for (String k : document.keySet()) { + setValue(criteriaObject, k, document.get(k)); } } return criteriaObject; @@ -628,7 +628,7 @@ public class Criteria implements CriteriaDefinition { protected Document getSingleCriteriaObject() { - Document dbo = new Document(); + Document document = new Document(); boolean not = false; for (Entry entry : criteria.entrySet()) { @@ -641,33 +641,33 @@ public class Criteria implements CriteriaDefinition { } if (not) { - Document notDbo = new Document(); - notDbo.put(key, value); - dbo.put("$not", notDbo); + Document notDocument = new Document(); + notDocument.put(key, value); + document.put("$not", notDocument); not = false; } else { if ("$not".equals(key) && value == null) { not = true; } else { - dbo.put(key, value); + document.put(key, value); } } } if (!StringUtils.hasText(this.key)) { if (not) { - return new Document("$not", dbo); + return new Document("$not", document); } - return dbo; + return document; } Document queryCriteria = new Document(); if (!NOT_SET.equals(isValue)) { queryCriteria.put(this.key, this.isValue); - queryCriteria.putAll(dbo); + queryCriteria.putAll(document); } else { - queryCriteria.put(this.key, dbo); + queryCriteria.put(this.key, document); } return queryCriteria; @@ -681,10 +681,10 @@ public class Criteria implements CriteriaDefinition { return bsonList; } - private void setValue(Document dbo, String key, Object value) { - Object existing = dbo.get(key); + private void setValue(Document document, String key, Object value) { + Object existing = document.get(key); if (existing == null) { - dbo.put(key, value); + document.put(key, value); } else { throw new InvalidMongoDbApiUsageException("Due to limitations of the com.mongodb.BasicDocument, " + "you can't add a second '" + key + "' expression specified as '" + key + " : " + value + "'. " diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/CriteriaDefinition.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/CriteriaDefinition.java index 2d6d3b6f3..744785e37 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/CriteriaDefinition.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/CriteriaDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2014 the original author or authors. + * Copyright 2010-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java index a2df998a7..46575f964 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 the original author or authors. + * Copyright 2010-2016 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.util.ObjectUtils; * @author Thomas Risberg * @author Oliver Gierke * @author Patryk Wasik + * @author Christoph Strobl */ public class Field { @@ -81,22 +82,22 @@ public class Field { public Document getFieldsObject() { - Document dbo = new Document((Map) criteria); + Document document = new Document((Map) criteria); for (Entry entry : slices.entrySet()) { - dbo.put(entry.getKey(), new Document("$slice", entry.getValue())); + document.put(entry.getKey(), new Document("$slice", entry.getValue())); } for (Entry entry : elemMatchs.entrySet()) { Document dbObject = new Document("$elemMatch", entry.getValue().getCriteriaObject()); - dbo.put(entry.getKey(), dbObject); + document.put(entry.getKey(), dbObject); } if (postionKey != null) { - dbo.put(postionKey + ".$", positionValue); + document.put(postionKey + ".$", positionValue); } - return dbo; + return document; } /* 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 3f7617e4c..ec2fd0609 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,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 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. @@ -298,19 +298,6 @@ public final class NearQuery { return this; } - /** - * Configures the distance multiplier to the multiplier of the given {@link Metric}. - * - * @deprecated use {@link #in(Metric)} instead. - * @param metric must not be {@literal null}. - * @return - */ - @Deprecated - public NearQuery distanceMultiplier(Metric metric) { - Assert.notNull(metric); - return in(metric); - } - /** * Configures whether to return spherical values for the actual distance. * @@ -411,32 +398,32 @@ public final class NearQuery { */ public Document toDocument() { - Document dbObject = new Document(); + Document document = new Document(); if (query != null) { - dbObject.put("query", query.getQueryObject()); + document.put("query", query.getQueryObject()); } if (maxDistance != null) { - dbObject.put("maxDistance", maxDistance.getNormalizedValue()); + document.put("maxDistance", maxDistance.getNormalizedValue()); } if (minDistance != null) { - dbObject.put("minDistance", minDistance.getNormalizedValue()); + document.put("minDistance", minDistance.getNormalizedValue()); } if (metric != null) { - dbObject.put("distanceMultiplier", metric.getMultiplier()); + document.put("distanceMultiplier", metric.getMultiplier()); } if (num != null) { - dbObject.put("num", num); + document.put("num", num); } - dbObject.put("near", Arrays.asList(point.getX(), point.getY())); + document.put("near", Arrays.asList(point.getX(), point.getY())); - dbObject.put("spherical", spherical); + document.put("spherical", spherical); - return dbObject; + return document; } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java deleted file mode 100644 index 5936218b7..000000000 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2010-2013 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.query; - -import org.springframework.data.domain.Sort.Direction; - -/** - * An enum that specifies the ordering for sort or index specifications - * - * @deprecated prefer {@link Direction} - * @author Thomas Risberg - * @author Oliver Gierke - */ -@Deprecated -public enum Order { - - ASCENDING { - @Override - public Direction toDirection() { - return Direction.ASC; - } - }, - - DESCENDING { - @Override - public Direction toDirection() { - return Direction.DESC; - } - }; - - public abstract Direction toDirection(); -} diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java index c1fe55177..8e7811b9b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java @@ -218,17 +218,17 @@ public class Query { public Document getQueryObject() { - Document dbo = new Document(); + Document document = new Document(); for (CriteriaDefinition definition : criteria.values()) { - dbo.putAll(definition.getCriteriaObject()); + document.putAll(definition.getCriteriaObject()); } if (!restrictedTypes.isEmpty()) { - dbo.put(RESTRICTED_TYPES_KEY, getRestrictedTypes()); + document.put(RESTRICTED_TYPES_KEY, getRestrictedTypes()); } - return dbo; + return document; } public Document getFieldsObject() { @@ -241,13 +241,13 @@ public class Query { return null; } - Document dbo = new Document(); + Document document = new Document(); for (org.springframework.data.domain.Sort.Order order : this.sort) { - dbo.put(order.getProperty(), order.isAscending() ? 1 : -1); + document.put(order.getProperty(), order.isAscending() ? 1 : -1); } - return dbo; + return document; } /** diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/SerializationUtils.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/SerializationUtils.java index 2a26ca421..507758c6a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/SerializationUtils.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/SerializationUtils.java @@ -77,8 +77,8 @@ public abstract class SerializationUtils { if (source instanceof Document) { - Document dbo = (Document) source; - Iterator> iter = dbo.entrySet().iterator(); + Document document = (Document) source; + Iterator> iter = document.entrySet().iterator(); String pathPrefix = currentPath.isEmpty() ? "" : currentPath + "."; while (iter.hasNext()) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/TextQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/TextQuery.java index f921deaf6..362aa8c33 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/TextQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/TextQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionTransformationContextSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionTransformationContextSupport.java index 73788876b..1770d05b5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionTransformationContextSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionTransformationContextSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2016 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.util.Assert; * * @author Thomas Darimont * @author Oliver Gierke + * @author Christoph Strobl */ public class ExpressionTransformationContextSupport { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsCriteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsCriteria.java index 6bdeeb62b..867e06249 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsCriteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsCriteria.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-2016 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.data.mongodb.core.query.Criteria; * GridFs-specific helper class to define {@link Criteria}s. * * @author Oliver Gierke + * @author Christoph Strobl */ public class GridFsCriteria extends Criteria { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsOperations.java index f38e9f028..296084817 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. @@ -33,6 +33,7 @@ import com.mongodb.gridfs.GridFSFile; * @author Philipp Schneider * @author Thomas Darimont * @author Martin Baumgartner + * @author Christoph Strobl */ public interface GridFsOperations extends ResourcePatternResolver { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java index a3ce8bf04..ec8c8a96d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-2016 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 com.mongodb.gridfs.GridFSDBFile; * {@link GridFSDBFile} based {@link Resource} implementation. * * @author Oliver Gierke + * @author Christoph Strobl */ public class GridFsResource extends InputStreamResource { 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 23389351e..223941dfd 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 @@ -134,14 +134,14 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver */ public ObjectId store(InputStream content, String filename, String contentType, Object metadata) { - Document dbObject = null; + Document document = null; if (metadata != null) { - dbObject = new Document(); - converter.write(metadata, dbObject); + document = new Document(); + converter.write(metadata, document); } - return store(content, filename, contentType, dbObject); + return store(content, filename, contentType, document); } /* diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/monitor/AssertMetrics.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/monitor/AssertMetrics.java index 694028196..72d108aa6 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/monitor/AssertMetrics.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/monitor/AssertMetrics.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2016 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. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Meta.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Meta.java index c953b7d3c..8f128ae81 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Meta.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Meta.java @@ -35,23 +35,12 @@ import org.springframework.data.annotation.QueryAnnotation; @QueryAnnotation public @interface Meta { - /** - * Set the maximum time limit in milliseconds for processing operations. - * - * @deprecated since 1.10 because of spelling issues. Please use {@link #maxExecutionTimeMs()} instead. - * @return - */ - @AliasFor("maxExecutionTimeMs") - @Deprecated - long maxExcecutionTime() default -1; - /** * Set the maximum time limit in milliseconds for processing operations. * * @return * @since 1.10 */ - @AliasFor("maxExcecutionTime") long maxExecutionTimeMs() default -1; /** diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoParameters.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoParameters.java index 1e36047b9..7845a439f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoParameters.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoParameters.java @@ -126,17 +126,6 @@ public class MongoParameters extends Parameters return -1; } - /** - * Returns the index of a {@link Distance} parameter to be used for geo queries. - * - * @return - * @deprecated since 1.7. Please use {@link #getMaxDistanceIndex()} instead. - */ - @Deprecated - public int getDistanceIndex() { - return getMaxDistanceIndex(); - } - /** * Returns the index of the {@link Distance} parameter to be used for max distance in geo queries. * diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryExecution.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryExecution.java index 0b0dab9f1..17ba3c8f4 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryExecution.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryExecution.java @@ -18,7 +18,6 @@ package org.springframework.data.mongodb.repository.query; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import java.util.Collections; import java.util.List; import java.util.function.Function; @@ -48,9 +47,6 @@ import org.springframework.util.ClassUtils; import com.mongodb.client.result.DeleteResult; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - /** * Set of classes to contain query execution strategies. Depending (mostly) on the return type of a * {@link org.springframework.data.repository.query.QueryMethod} a {@link AbstractMongoQuery} can be executed in various @@ -58,6 +54,7 @@ import lombok.RequiredArgsConstructor; * * @author Oliver Gierke * @author Mark Paluch + * @author Christoph Strobl */ interface MongoQueryExecution { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java index 067928b09..80adf849e 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java @@ -233,8 +233,8 @@ public class MongoQueryMethod extends QueryMethod { } org.springframework.data.mongodb.core.query.Meta metaAttributes = new org.springframework.data.mongodb.core.query.Meta(); - if (meta.maxExcecutionTime() > 0) { - metaAttributes.setMaxTimeMsec(meta.maxExcecutionTime()); + if (meta.maxExecutionTimeMs() > 0) { + metaAttributes.setMaxTimeMsec(meta.maxExecutionTimeMs()); } if (meta.maxScanDocuments() > 0) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java index 59aca84b1..ec0ac278f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java @@ -15,8 +15,10 @@ */ package org.springframework.data.mongodb.repository.query; +import com.mongodb.BasicDBObject; import com.mongodb.DBObject; import com.mongodb.util.JSON; +import org.bson.Document; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoTemplate; @@ -112,7 +114,7 @@ public class PartTreeMongoQuery extends AbstractMongoQuery { try { - BasicQuery result = new BasicQuery(query.getQueryObject().toJson(), fieldSpec); + BasicQuery result = new BasicQuery(query.getQueryObject(), new Document((BasicDBObject) JSON.parse(fieldSpec))); result.setSortObject(query.getSortObject()); return result; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java deleted file mode 100644 index 0d92fe7b0..000000000 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2010-2013 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.repository.query; - -import org.springframework.data.domain.Sort.Order; - -import com.mongodb.DBCursor; - -/** - * Collection of utility methods to apply sorting and pagination to a {@link DBCursor}. - * - * @author Oliver Gierke - */ -@Deprecated -public abstract class QueryUtils { - - private QueryUtils() { - - } - - /** - * Turns an {@link Order} into an {@link org.springframework.data.mongodb.core.query.Order}. - * - * @deprecated use {@link Order} directly. - * @param order - * @return - */ - @Deprecated - public static org.springframework.data.mongodb.core.query.Order toOrder(Order order) { - return order.isAscending() ? org.springframework.data.mongodb.core.query.Order.ASCENDING - : org.springframework.data.mongodb.core.query.Order.DESCENDING; - } -} diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQuery.java index 9488c5192..7cbe12c45 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 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. @@ -282,11 +282,11 @@ public class StringBasedMongoQuery extends AbstractMongoQuery { } else if (value instanceof Document) { - Document dbo = (Document) value; + Document document = (Document) value; - for (String field : dbo.keySet()) { + for (String field : document.keySet()) { collectParameterReferencesIntoBindings(bindings, field); - collectParameterReferencesIntoBindings(bindings, dbo.get(field)); + collectParameterReferencesIntoBindings(bindings, document.get(field)); } } else if (value instanceof DBObject) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SpringDataMongodbSerializer.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SpringDataMongodbSerializer.java index 04ebd3d00..ecfea2d29 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SpringDataMongodbSerializer.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SpringDataMongodbSerializer.java @@ -123,17 +123,8 @@ class SpringDataMongodbSerializer extends MongodbSerializer { Document mappedIdValue = mapper.getMappedObject((BasicDBObject) superIdValue, null); DBObject parsedId = (DBObject) JSON.parse(mappedIdValue.toJson()); return parsedId; - // return new BasicDBObject(mapper.getMappedObject((BasicDBObject)super.asDBObject(key, value)), null)); } return super.asDBObject(key, value instanceof Pattern ? value : converter.convertToMongoType(value)); - // Object mapped = value; - // if (value instanceof DBObject) { - // mapped = converter.convertToMongoType(new Document(((DBObject) value).toMap())); - // } else { - // mapped = super.asDBObject(key, value instanceof Pattern ? value : converter.convertToMongoType(value)); - // } - // - // return mapped instanceof Document ? new BasicDBObject((Document) mapped) : (DBObject) mapped; } /* diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/BsonUtils.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/BsonUtils.java index 402d95777..3096151ee 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/BsonUtils.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/BsonUtils.java @@ -23,6 +23,10 @@ import org.bson.conversions.Bson; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; +/** + * @author Christoph Strobl + * @since 2.0 + */ public class BsonUtils { public static T get(Bson bson, String key) { diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/CloseableIterableCursorAdapterUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/CloseableIterableCursorAdapterUnitTests.java index d0197fa33..1fd17a9ad 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/CloseableIterableCursorAdapterUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/CloseableIterableCursorAdapterUnitTests.java @@ -25,7 +25,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.mongodb.core.MongoTemplate.CloseableIterableCursorAdapter; -import org.springframework.data.mongodb.core.MongoTemplate.DbObjectCallback; +import org.springframework.data.mongodb.core.MongoTemplate.DocumentCallback; import org.springframework.data.util.CloseableIterator; import com.mongodb.client.MongoCursor; @@ -40,7 +40,7 @@ import com.mongodb.client.MongoCursor; public class CloseableIterableCursorAdapterUnitTests { @Mock PersistenceExceptionTranslator exceptionTranslator; - @Mock DbObjectCallback callback; + @Mock DocumentCallback callback; MongoCursor cursor; CloseableIterator adapter; diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoOperationsUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoOperationsUnitTests.java index 172463de9..271b96112 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoOperationsUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoOperationsUnitTests.java @@ -65,12 +65,12 @@ public abstract class MongoOperationsUnitTests { converter = new AbstractMongoConverter(null) { - public void write(Object t, Bson dbo) { - ((Document) dbo).put("firstName", person.getFirstName()); + public void write(Object t, Bson bson) { + ((Document) bson).put("firstName", person.getFirstName()); } @SuppressWarnings("unchecked") - public S read(Class clazz, Bson dbo) { + public S read(Class clazz, Bson bson) { return (S) person; } @@ -202,16 +202,6 @@ public abstract class MongoOperationsUnitTests { }.assertDataAccessException(); } - @Test - public void convertsExceptionForExecuteInSession() { - new Execution() { - @Override - public void doWith(MongoOperations operations) { - operations.executeInSession(dbCallback); - } - }.assertDataAccessException(); - } - @Test public void convertsExceptionForGetCollection() { new Execution() { diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateMappingTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateMappingTests.java index f59053f51..86e04a003 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateMappingTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateMappingTests.java @@ -83,8 +83,8 @@ public class MongoTemplateMappingTests { private void checkPersonPersisted(MongoTemplate template) { template.execute(Person.class, new CollectionCallback() { public Object doInCollection(MongoCollection collection) throws MongoException, DataAccessException { - Document dbo = collection.find(new Document()).first(); - assertThat((String) dbo.get("name"), is("Oliver")); + Document document = collection.find(new Document()).first(); + assertThat((String) document.get("name"), is("Oliver")); return null; } }); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java index 814efc7f1..7e36593f6 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java @@ -351,7 +351,7 @@ public class MongoTemplateTests { p2.setAge(40); template.insert(p2); - template.indexOps(Person.class).ensureIndex(new Index().on("age", Direction.DESC).unique(Duplicates.DROP)); + template.indexOps(Person.class).ensureIndex(new Index().on("age", Direction.DESC).unique()); MongoCollection coll = template.getCollection(template.getCollectionName(Person.class)); List indexInfo = new ArrayList(); @@ -1238,8 +1238,8 @@ public class MongoTemplateTests { template.insert(new Person("Harry")); final List names = new ArrayList(); template.executeQuery(new Query(), template.getCollectionName(Person.class), new DocumentCallbackHandler() { - public void processDocument(org.bson.Document dbObject) { - String name = (String) dbObject.get("firstName"); + public void processDocument(org.bson.Document document) { + String name = (String) document.get("firstName"); if (name != null) { names.add(name); } @@ -1259,8 +1259,8 @@ public class MongoTemplateTests { template.insert(new Person("Harry")); final List names = new ArrayList(); template.executeQuery(new Query(), template.getCollectionName(Person.class), new DocumentCallbackHandler() { - public void processDocument(org.bson.Document dbObject) { - String name = (String) dbObject.get("firstName"); + public void processDocument(org.bson.Document document) { + String name = (String) document.get("firstName"); if (name != null) { names.add(name); } @@ -2102,11 +2102,11 @@ public class MongoTemplateTests { new DocumentCallbackHandler() { @Override - public void processDocument(org.bson.Document dbObject) throws MongoException, DataAccessException { + public void processDocument(org.bson.Document document) throws MongoException, DataAccessException { - assertThat(dbObject, is(notNullValue())); + assertThat(document, is(notNullValue())); - ObjectWithEnumValue result = template.getConverter().read(ObjectWithEnumValue.class, dbObject); + ObjectWithEnumValue result = template.getConverter().read(ObjectWithEnumValue.class, document); assertThat(result.value, is(EnumValue.VALUE2)); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java index 157121e80..e6ef278ab 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java @@ -365,7 +365,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests { template.executeQuery(query, "collection1", new DocumentCallbackHandler() { @Override - public void processDocument(Document dbObject) throws MongoException, DataAccessException { + public void processDocument(Document document) throws MongoException, DataAccessException { // nothing to do - just a test } }); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/UnwrapAndReadDbObjectCallbackUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/UnwrapAndReadDbObjectCallbackUnitTests.java index 22f6cba8c..e184cd410 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/UnwrapAndReadDbObjectCallbackUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/UnwrapAndReadDbObjectCallbackUnitTests.java @@ -25,13 +25,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.data.mongodb.MongoDbFactory; -import org.springframework.data.mongodb.core.MongoTemplate.UnwrapAndReadDbObjectCallback; +import org.springframework.data.mongodb.core.MongoTemplate.UnwrapAndReadDocumentCallback; import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; import org.springframework.data.mongodb.core.convert.MappingMongoConverter; import org.springframework.data.mongodb.core.mapping.MongoMappingContext; /** - * Unit tests for {@link UnwrapAndReadDbObjectCallback}. + * Unit tests for {@link UnwrapAndReadDocumentCallback}. * * @author Oliver Gierke */ @@ -40,7 +40,7 @@ public class UnwrapAndReadDbObjectCallbackUnitTests { @Mock MongoDbFactory factory; - UnwrapAndReadDbObjectCallback callback; + UnwrapAndReadDocumentCallback callback; @Before public void setUp() { @@ -49,7 +49,7 @@ public class UnwrapAndReadDbObjectCallbackUnitTests { MappingMongoConverter converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), new MongoMappingContext()); - this.callback = template.new UnwrapAndReadDbObjectCallback(converter, Target.class, "collection-1"); + this.callback = template.new UnwrapAndReadDocumentCallback(converter, Target.class, "collection-1"); } @Test diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationOptionsTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationOptionsTests.java index c71c0a362..516570f29 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationOptionsTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationOptionsTests.java @@ -56,7 +56,7 @@ public class AggregationOptionsTests { */ @Test public void aggregationOptionsToString() { - assertThat(aggregationOptions.toDbObject(), + assertThat(aggregationOptions.toDocument(), is(Document.parse("{ \"allowDiskUse\" : true , \"explain\" : true , \"cursor\" : { \"foo\" : 1}}"))); } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationUnitTests.java index 414a52f70..bb6037b08 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationUnitTests.java @@ -32,7 +32,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.mongodb.core.DBObjectTestUtils; import org.springframework.data.mongodb.core.query.Criteria; /** @@ -81,7 +80,7 @@ public class AggregationUnitTests { project("a", "b"), // group("a").count().as("cnt"), // a was introduced to the context by the project operation project("cnt", "b") // b was removed from the context by the group operation - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); // -> triggers IllegalArgumentException + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); // -> triggers IllegalArgumentException } /** @@ -94,7 +93,7 @@ public class AggregationUnitTests { project("a", "b"), // unwind("a"), // project("a", "b") // b should still be available - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); } /** @@ -107,7 +106,7 @@ public class AggregationUnitTests { project("a", "b"), // unwind("a", "x"), // project("a", "b") // b should still be available - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); } /** @@ -120,7 +119,7 @@ public class AggregationUnitTests { project("a", "b"), // unwind("a", "x"), // project("a", "x") // b should still be available - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); } /** @@ -130,7 +129,7 @@ public class AggregationUnitTests { public void fullUnwindOperationShouldBuildCorrectClause() { Document agg = newAggregation( // - unwind("a", "x", true)).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + unwind("a", "x", true)).toDocument("foo", Aggregation.DEFAULT_CONTEXT); @SuppressWarnings("unchecked") Document unwind = ((List) agg.get("pipeline")).get(0); @@ -147,7 +146,7 @@ public class AggregationUnitTests { public void unwindOperationWithPreserveNullShouldBuildCorrectClause() { Document agg = newAggregation( // - unwind("a", true)).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + unwind("a", true)).toDocument("foo", Aggregation.DEFAULT_CONTEXT); @SuppressWarnings("unchecked") Document unwind = ((List) agg.get("pipeline")).get(0); @@ -165,7 +164,7 @@ public class AggregationUnitTests { project("a", "b"), // match(where("a").gte(1)), // project("a", "b") // b should still be available - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); } /** @@ -178,7 +177,7 @@ public class AggregationUnitTests { project("a"), // group("a").count().as("aCnt"), // project("aCnt", "a") // - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); @SuppressWarnings("unchecked") Document secondProjection = ((List) agg.get("pipeline")).get(2); @@ -198,7 +197,7 @@ public class AggregationUnitTests { ops.add(group("a").count().as("aCnt")); ops.add(project("aCnt", "a")); - Document agg = newAggregation(ops).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + Document agg = newAggregation(ops).toDocument("foo", Aggregation.DEFAULT_CONTEXT); @SuppressWarnings("unchecked") Document secondProjection = ((List) agg.get("pipeline")).get(2); @@ -218,7 +217,7 @@ public class AggregationUnitTests { ops.add(group("a").count().as("aCnt")); ops.add(project("aCnt", "a")); - Document agg = newAggregation(Document.class, ops).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + Document agg = newAggregation(Document.class, ops).toDocument("foo", Aggregation.DEFAULT_CONTEXT); @SuppressWarnings("unchecked") Document secondProjection = ((List) agg.get("pipeline")).get(2); @@ -236,7 +235,7 @@ public class AggregationUnitTests { Document agg = newAggregation( // project("a").andExpression("b+c").as("foo"), // group("a").sum("foo").as("foosum") // - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); @SuppressWarnings("unchecked") Document secondProjection = ((List) agg.get("pipeline")).get(1); @@ -254,7 +253,7 @@ public class AggregationUnitTests { project("cmsParameterId", "rules"), // unwind("rules"), // group("cmsParameterId", "rules.ruleType").count().as("totol") // - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); assertThat(agg, is(notNullValue())); @@ -274,7 +273,7 @@ public class AggregationUnitTests { Document agg = newAggregation( // project().and("foo.bar").as("ba") // , project().and("ba").as("b") // - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document projection0 = extractPipelineElement(agg, 0, "$project"); assertThat(projection0, is((Document) new Document("ba", "$foo.bar"))); @@ -291,7 +290,7 @@ public class AggregationUnitTests { Document agg = newAggregation( // project().and("a").as("aa") // - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); assertThat(agg, is(Document.parse("{ \"aggregate\" : \"foo\" , \"pipeline\" : [ { \"$project\" : { \"aa\" : \"$a\"}}]}"))); @@ -310,7 +309,7 @@ public class AggregationUnitTests { project().and("a").as("aa") // ) // .withOptions(aggregationOptions) // - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); assertThat(agg, is(Document.parse("{ \"aggregate\" : \"foo\" , " // @@ -333,7 +332,7 @@ public class AggregationUnitTests { .and(Aggregation.CURRENT + ".a").as("a2") // , sort(Direction.DESC, "a") // , group("someKey").first(Aggregation.ROOT).as("doc") // - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document projection0 = extractPipelineElement(agg, 0, "$project"); assertThat(projection0, is((Document) new Document("someKey", 1).append("a1", "$a").append("a2", "$$CURRENT.a"))); @@ -356,7 +355,7 @@ public class AggregationUnitTests { .and("tags").minus(10).as("tags_count")// , group("date")// .sum("tags_count").as("count")// - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document group = extractPipelineElement(agg, 1, "$group"); assertThat(getAsDocument(group, "count"), is(new Document().append("$sum", "$tags_count"))); @@ -373,7 +372,7 @@ public class AggregationUnitTests { .andExpression("tags-10")// , group("date")// .sum("tags_count").as("count")// - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document group = extractPipelineElement(agg, 1, "$group"); assertThat(getAsDocument(group, "count"), is(new Document().append("$sum", "$tags_count"))); @@ -387,7 +386,7 @@ public class AggregationUnitTests { Document agg = newAggregation( // project("a"), // group("a").first(conditional(Criteria.where("a").gte(42), "answer", "no-answer")).as("foosum") // - ).toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + ).toDocument("foo", Aggregation.DEFAULT_CONTEXT); @SuppressWarnings("unchecked") Document secondProjection = ((List) agg.get("pipeline")).get(1); @@ -408,7 +407,7 @@ public class AggregationUnitTests { .when("isYellow") // .then("bright") // .otherwise("dark")).as("color")) - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document project = extractPipelineElement(agg, 0, "$project"); Document expectedCondition = new Document() // @@ -431,7 +430,7 @@ public class AggregationUnitTests { .when("isYellow") // .then("bright") // .otherwise("dark"))) - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document project = extractPipelineElement(agg, 0, "$project"); Document expectedCondition = new Document() // @@ -452,7 +451,7 @@ public class AggregationUnitTests { .newAggregation(project()// .and("color")// .applyCondition(conditional(Criteria.where("key").gt(5), "bright", "dark"))) // - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document project = extractPipelineElement(agg, 0, "$project"); Document expectedCondition = new Document() // @@ -474,7 +473,7 @@ public class AggregationUnitTests { project().and("color").as("chroma"), project().and("luminosity") // .applyCondition(conditional(field("chroma"), "bright", "dark"))) // - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document project = extractPipelineElement(agg, 1, "$project"); Document expectedCondition = new Document() // @@ -496,7 +495,7 @@ public class AggregationUnitTests { project().and("color").as("chroma"), project().and("luminosity") // .applyCondition(conditional(Criteria.where("chroma").is(100), "bright", "dark"))) // - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document project = extractPipelineElement(agg, 1, "$project"); Document expectedCondition = new Document() // @@ -518,7 +517,7 @@ public class AggregationUnitTests { project().and("color"), // project().and("luminosity") // .applyCondition(ifNull(field("chroma"), "unknown"))) // - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document project = extractPipelineElement(agg, 1, "$project"); @@ -537,7 +536,7 @@ public class AggregationUnitTests { project("fallback").and("color").as("chroma"), project().and("luminosity") // .applyCondition(ifNull(field("chroma"), field("fallback")))) // - .toDbObject("foo", Aggregation.DEFAULT_CONTEXT); + .toDocument("foo", Aggregation.DEFAULT_CONTEXT); Document project = extractPipelineElement(agg, 1, "$project"); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperatorUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperatorUnitTests.java index 5435a1085..165a16c8f 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperatorUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ConditionalOperatorUnitTests.java @@ -25,7 +25,6 @@ import org.bson.Document; import org.junit.Test; import org.springframework.data.mongodb.core.query.Criteria; -import com.mongodb.BasicDBObject; import com.mongodb.DBObject; /** @@ -73,7 +72,7 @@ public class ConditionalOperatorUnitTests { */ @Test(expected = IllegalArgumentException.class) public void builderRejectsNullFieldName() { - newBuilder().when((DBObject) null); + newBuilder().when((Document) null); } /** @@ -99,7 +98,7 @@ public class ConditionalOperatorUnitTests { public void simpleBuilderShouldRenderCorrectly() { ConditionalOperator operator = newBuilder().when("isYellow").then("bright").otherwise("dark"); - Document dbObject = operator.toDbObject(Aggregation.DEFAULT_CONTEXT); + Document dbObject = operator.toDocument(Aggregation.DEFAULT_CONTEXT); Document expectedCondition = new Document() // .append("if", "$isYellow") // @@ -117,7 +116,7 @@ public class ConditionalOperatorUnitTests { ConditionalOperator operator = newBuilder().when(Criteria.where("luminosity").gte(100)).then("bright") .otherwise("dark"); - Document dbObject = operator.toDbObject(Aggregation.DEFAULT_CONTEXT); + Document dbObject = operator.toDocument(Aggregation.DEFAULT_CONTEXT); Document expectedCondition = new Document () // .append("if", new Document ("$gte", Arrays. asList("$luminosity", 100))) // @@ -139,7 +138,7 @@ public class ConditionalOperatorUnitTests { Criteria.where("saturation").lt(11))) .then("bright").otherwise("dark"); - Document dbObject = operator.toDbObject(Aggregation.DEFAULT_CONTEXT); + Document dbObject = operator.toDocument(Aggregation.DEFAULT_CONTEXT); Document luminosity = new Document ("$gte", Arrays. asList("$luminosity", 100)); Document hue = new Document ("$eq", Arrays. asList("$hue", 50)); @@ -163,7 +162,7 @@ public class ConditionalOperatorUnitTests { .and("saturation").and("chroma").is(200); ConditionalOperator operator = newBuilder().when(criteria).then("bright").otherwise("dark"); - Document dbObject = operator.toDbObject(Aggregation.DEFAULT_CONTEXT); + Document dbObject = operator.toDocument(Aggregation.DEFAULT_CONTEXT); Document gte = new Document ("$gte", Arrays. asList("$luminosity", 100)); Document is = new Document ("$eq", Arrays. asList("$chroma", 200)); @@ -193,7 +192,7 @@ public class ConditionalOperatorUnitTests { .then("very-dark") // .otherwise("not-so-dark")); - Document dbObject = operator.toDbObject(Aggregation.DEFAULT_CONTEXT); + Document dbObject = operator.toDocument(Aggregation.DEFAULT_CONTEXT); Document trueCondition = new Document () // .append("if", new Document ("$gte", Arrays. asList("$luminosity", 200))) // diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/IfNullOperatorUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/IfNullOperatorUnitTests.java index c03defd2e..660a1e27f 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/IfNullOperatorUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/IfNullOperatorUnitTests.java @@ -24,8 +24,6 @@ import java.util.Arrays; import org.bson.Document; import org.junit.Test; -import com.mongodb.DBObject; - /** * Unit tests for {@link IfNullOperator}. * @@ -60,7 +58,7 @@ public class IfNullOperatorUnitTests { .ifNull("optional") // .thenReplaceWith("a more sophisticated value"); - Document dbObject = operator.toDbObject(Aggregation.DEFAULT_CONTEXT); + Document dbObject = operator.toDocument(Aggregation.DEFAULT_CONTEXT); assertThat(dbObject, isBsonObject().containing("$ifNull", Arrays. asList("$optional", "a more sophisticated value"))); @@ -76,7 +74,7 @@ public class IfNullOperatorUnitTests { .ifNull(Fields.field("optional")) // .thenReplaceWith(Fields.field("never-null")); - Document dbObject = operator.toDbObject(Aggregation.DEFAULT_CONTEXT); + Document dbObject = operator.toDocument(Aggregation.DEFAULT_CONTEXT); assertThat(dbObject, isBsonObject().containing("$ifNull", Arrays. asList("$optional", "$never-null"))); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContextUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContextUnitTests.java index 365b93087..4f6b483d3 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContextUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContextUnitTests.java @@ -24,7 +24,6 @@ import static org.springframework.data.mongodb.test.util.IsBsonObject.*; import java.util.Arrays; import java.util.List; -import com.mongodb.DBObject; import org.bson.Document; import org.bson.types.ObjectId; import org.junit.Before; @@ -121,7 +120,7 @@ public class TypeBasedAggregationOperationContextUnitTests { MatchOperation matchStage = match(Criteria.where("age").is(new Age(10))); ProjectionOperation projectStage = project("age", "name"); - org.bson.Document agg = newAggregation(matchStage, projectStage).toDbObject("test", context); + org.bson.Document agg = newAggregation(matchStage, projectStage).toDocument("test", context); org.bson.Document age = getValue( (org.bson.Document) getValue(getPipelineElementFromAggregationAt(agg, 0), "$match"), "age"); @@ -143,7 +142,7 @@ public class TypeBasedAggregationOperationContextUnitTests { MatchOperation matchStage = match(Criteria.where("age").is(new Age(10))); ProjectionOperation projectStage = project("age", "name"); - org.bson.Document agg = newAggregation(projectStage, matchStage).toDbObject("test", context); + org.bson.Document agg = newAggregation(projectStage, matchStage).toDocument("test", context); org.bson.Document age = getValue( (org.bson.Document) getValue(getPipelineElementFromAggregationAt(agg, 1), "$match"), "age"); @@ -161,7 +160,7 @@ public class TypeBasedAggregationOperationContextUnitTests { .withOptions( newAggregationOptions().allowDiskUse(true).explain(true).cursor(new org.bson.Document("foo", 1)).build()); - org.bson.Document dbo = agg.toDbObject("person", context); + org.bson.Document dbo = agg.toDocument("person", context); org.bson.Document projection = getPipelineElementFromAggregationAt(dbo, 0); assertThat(projection.containsKey("$project"), is(true)); @@ -183,7 +182,7 @@ public class TypeBasedAggregationOperationContextUnitTests { TypedAggregation agg = newAggregation(MeterData.class, group("counterName").sum("counterVolume").as("totalCounterVolume")); - org.bson.Document dbo = agg.toDbObject("meterData", context); + org.bson.Document dbo = agg.toDocument("meterData", context); org.bson.Document group = getPipelineElementFromAggregationAt(dbo, 0); org.bson.Document definition = (org.bson.Document) group.get("$group"); @@ -201,7 +200,7 @@ public class TypeBasedAggregationOperationContextUnitTests { TypedAggregation agg = newAggregation(MeterData.class, lookup("OtherCollection", "resourceId", "otherId", "lookup"), sort(Direction.ASC, "resourceId")); - org.bson.Document dbo = agg.toDbObject("meterData", context); + org.bson.Document dbo = agg.toDocument("meterData", context); org.bson.Document sort = getPipelineElementFromAggregationAt(dbo, 1); org.bson.Document definition = (org.bson.Document) sort.get("$sort"); @@ -219,7 +218,7 @@ public class TypeBasedAggregationOperationContextUnitTests { TypedAggregation agg = newAggregation(MeterData.class, group().min("resourceId").as("foreignKey"), lookup("OtherCollection", "foreignKey", "otherId", "lookup"), sort(Direction.ASC, "foreignKey")); - org.bson.Document dbo = agg.toDbObject("meterData", context); + org.bson.Document dbo = agg.toDocument("meterData", context); org.bson.Document sort = getPipelineElementFromAggregationAt(dbo, 2); org.bson.Document definition = (org.bson.Document) sort.get("$sort"); @@ -238,7 +237,7 @@ public class TypeBasedAggregationOperationContextUnitTests { lookup("OtherCollection", "resourceId", "otherId", "lookup"), group().min("lookup.otherkey").as("something_totally_different")); - org.bson.Document dbo = agg.toDbObject("meterData", context); + org.bson.Document dbo = agg.toDocument("meterData", context); org.bson.Document group = getPipelineElementFromAggregationAt(dbo, 1); org.bson.Document definition = (org.bson.Document) group.get("$group"); @@ -259,7 +258,7 @@ public class TypeBasedAggregationOperationContextUnitTests { group().min("lookup.otherkey").as("something_totally_different"), sort(Direction.ASC, "something_totally_different")); - org.bson.Document dbo = agg.toDbObject("meterData", context); + org.bson.Document dbo = agg.toDocument("meterData", context); org.bson.Document sort = getPipelineElementFromAggregationAt(dbo, 2); org.bson.Document definition = (org.bson.Document) sort.get("$sort"); @@ -278,7 +277,7 @@ public class TypeBasedAggregationOperationContextUnitTests { lookup("OtherCollection", "resourceId", "otherId", "lookup"), group().min("lookup.otherkey").as("something_totally_different"), sort(Direction.ASC, "resourceId")); - agg.toDbObject("meterData", context); + agg.toDocument("meterData", context); } /** @@ -294,7 +293,7 @@ public class TypeBasedAggregationOperationContextUnitTests { .applyCondition(conditional(Criteria.where("age.value").lt(10), new Age(0), field("age"))) // ); - Document dbo = agg.toDbObject("person", context); + Document dbo = agg.toDocument("person", context); Document projection = getPipelineElementFromAggregationAt(dbo, 0); assertThat(projection.containsKey("$project"), is(true)); @@ -320,7 +319,7 @@ public class TypeBasedAggregationOperationContextUnitTests { .applyCondition(ifNull("age", new Age(0))) // ); - Document dbo = agg.toDbObject("person", context); + Document dbo = agg.toDocument("person", context); Document projection = getPipelineElementFromAggregationAt(dbo, 0); assertThat(projection.containsKey("$project"), is(true)); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoConvertersUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoConvertersUnitTests.java index c77f0344e..da37beb9d 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoConvertersUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoConvertersUnitTests.java @@ -29,17 +29,17 @@ import org.springframework.data.geo.Distance; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; import org.springframework.data.geo.Polygon; -import org.springframework.data.mongodb.core.convert.GeoConverters.BoxToDbObjectConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.CircleToDbObjectConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToBoxConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToCircleConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToPointConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToPolygonConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToSphereConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.GeoCommandToDbObjectConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.PointToDbObjectConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.PolygonToDbObjectConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.SphereToDbObjectConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.BoxToDocumentConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.CircleToDocumentConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToBoxConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToCircleConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToPointConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToPolygonConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToSphereConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.GeoCommandToDocumentConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.PointToDocumentConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.PolygonToDocumentConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.SphereToDocumentConverter; import org.springframework.data.mongodb.core.geo.Sphere; import org.springframework.data.mongodb.core.query.GeoCommand; @@ -60,8 +60,8 @@ public class GeoConvertersUnitTests { Box box = new Box(new Point(1, 2), new Point(3, 4)); - Document dbo = BoxToDbObjectConverter.INSTANCE.convert(box); - Box result = DbObjectToBoxConverter.INSTANCE.convert(dbo); + Document dbo = BoxToDocumentConverter.INSTANCE.convert(box); + Box result = DocumentToBoxConverter.INSTANCE.convert(dbo); assertThat(result, is(box)); assertThat(result.getClass().equals(Box.class), is(true)); @@ -75,8 +75,8 @@ public class GeoConvertersUnitTests { Circle circle = new Circle(new Point(1, 2), 3); - Document dbo = CircleToDbObjectConverter.INSTANCE.convert(circle); - Circle result = DbObjectToCircleConverter.INSTANCE.convert(dbo); + Document dbo = CircleToDocumentConverter.INSTANCE.convert(circle); + Circle result = DocumentToCircleConverter.INSTANCE.convert(dbo); assertThat(result, is(circle)); } @@ -90,8 +90,8 @@ public class GeoConvertersUnitTests { Distance radius = new Distance(3, Metrics.MILES); Circle circle = new Circle(new Point(1, 2), radius); - Document dbo = CircleToDbObjectConverter.INSTANCE.convert(circle); - Circle result = DbObjectToCircleConverter.INSTANCE.convert(dbo); + Document dbo = CircleToDocumentConverter.INSTANCE.convert(circle); + Circle result = DocumentToCircleConverter.INSTANCE.convert(dbo); assertThat(result, is(circle)); assertThat(result.getRadius(), is(radius)); @@ -105,8 +105,8 @@ public class GeoConvertersUnitTests { Polygon polygon = new Polygon(new Point(1, 2), new Point(2, 3), new Point(3, 4), new Point(5, 6)); - Document dbo = PolygonToDbObjectConverter.INSTANCE.convert(polygon); - Polygon result = DbObjectToPolygonConverter.INSTANCE.convert(dbo); + Document dbo = PolygonToDocumentConverter.INSTANCE.convert(polygon); + Polygon result = DocumentToPolygonConverter.INSTANCE.convert(dbo); assertThat(result, is(polygon)); assertThat(result.getClass().equals(Polygon.class), is(true)); @@ -120,8 +120,8 @@ public class GeoConvertersUnitTests { Sphere sphere = new Sphere(new Point(1, 2), 3); - Document dbo = SphereToDbObjectConverter.INSTANCE.convert(sphere); - Sphere result = DbObjectToSphereConverter.INSTANCE.convert(dbo); + Document dbo = SphereToDocumentConverter.INSTANCE.convert(sphere); + Sphere result = DocumentToSphereConverter.INSTANCE.convert(dbo); assertThat(result, is(sphere)); assertThat(result.getClass().equals(Sphere.class), is(true)); @@ -136,8 +136,8 @@ public class GeoConvertersUnitTests { Distance radius = new Distance(3, Metrics.KILOMETERS); Sphere sphere = new Sphere(new Point(1, 2), radius); - Document dbo = SphereToDbObjectConverter.INSTANCE.convert(sphere); - Sphere result = DbObjectToSphereConverter.INSTANCE.convert(dbo); + Document dbo = SphereToDocumentConverter.INSTANCE.convert(sphere); + Sphere result = DocumentToSphereConverter.INSTANCE.convert(dbo); assertThat(result, is(sphere)); assertThat(result.getRadius(), is(radius)); @@ -152,8 +152,8 @@ public class GeoConvertersUnitTests { Point point = new Point(1, 2); - Document dbo = PointToDbObjectConverter.INSTANCE.convert(point); - Point result = DbObjectToPointConverter.INSTANCE.convert(dbo); + Document dbo = PointToDocumentConverter.INSTANCE.convert(point); + Point result = DocumentToPointConverter.INSTANCE.convert(dbo); assertThat(result, is(point)); assertThat(result.getClass().equals(Point.class), is(true)); @@ -168,7 +168,7 @@ public class GeoConvertersUnitTests { Box box = new Box(new double[] { 1, 2 }, new double[] { 3, 4 }); GeoCommand cmd = new GeoCommand(box); - Document dbo = GeoCommandToDbObjectConverter.INSTANCE.convert(cmd); + Document dbo = GeoCommandToDocumentConverter.INSTANCE.convert(cmd); assertThat(dbo, is(notNullValue())); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoJsonConverterUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoJsonConverterUnitTests.java index 38a316996..275146681 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoJsonConverterUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/GeoJsonConverterUnitTests.java @@ -29,13 +29,13 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; import org.springframework.data.geo.Point; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToGeoJsonLineStringConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToGeoJsonMultiLineStringConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToGeoJsonMultiPointConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToGeoJsonMultiPolygonConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToGeoJsonPointConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.DbObjectToGeoJsonPolygonConverter; -import org.springframework.data.mongodb.core.convert.GeoConverters.GeoJsonToDbObjectConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToGeoJsonLineStringConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToGeoJsonMultiLineStringConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToGeoJsonMultiPointConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToGeoJsonMultiPolygonConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToGeoJsonPointConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.DocumentToGeoJsonPolygonConverter; +import org.springframework.data.mongodb.core.convert.GeoConverters.GeoJsonToDocumentConverter; import org.springframework.data.mongodb.core.geo.GeoJson; import org.springframework.data.mongodb.core.geo.GeoJsonGeometryCollection; import org.springframework.data.mongodb.core.geo.GeoJsonLineString; @@ -47,8 +47,6 @@ import org.springframework.data.mongodb.core.geo.GeoJsonPolygon; import org.springframework.data.mongodb.test.util.BasicDbListBuilder; import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObjectBuilder; -import com.mongodb.DBObject; /** * @author Christoph Strobl @@ -178,7 +176,7 @@ public class GeoJsonConverterUnitTests { */ public static class DbObjectToGeoJsonPolygonConverterUnitTests { - DbObjectToGeoJsonPolygonConverter converter = DbObjectToGeoJsonPolygonConverter.INSTANCE; + DocumentToGeoJsonPolygonConverter converter = DocumentToGeoJsonPolygonConverter.INSTANCE; public @Rule ExpectedException expectedException = ExpectedException.none(); /** @@ -224,7 +222,7 @@ public class GeoJsonConverterUnitTests { */ public static class DbObjectToGeoJsonPointConverterUnitTests { - DbObjectToGeoJsonPointConverter converter = DbObjectToGeoJsonPointConverter.INSTANCE; + DocumentToGeoJsonPointConverter converter = DocumentToGeoJsonPointConverter.INSTANCE; public @Rule ExpectedException expectedException = ExpectedException.none(); /** @@ -261,7 +259,7 @@ public class GeoJsonConverterUnitTests { */ public static class DbObjectToGeoJsonLineStringConverterUnitTests { - DbObjectToGeoJsonLineStringConverter converter = DbObjectToGeoJsonLineStringConverter.INSTANCE; + DocumentToGeoJsonLineStringConverter converter = DocumentToGeoJsonLineStringConverter.INSTANCE; public @Rule ExpectedException expectedException = ExpectedException.none(); /** @@ -298,7 +296,7 @@ public class GeoJsonConverterUnitTests { */ public static class DbObjectToGeoJsonMultiLineStringConverterUnitTests { - DbObjectToGeoJsonMultiLineStringConverter converter = DbObjectToGeoJsonMultiLineStringConverter.INSTANCE; + DocumentToGeoJsonMultiLineStringConverter converter = DocumentToGeoJsonMultiLineStringConverter.INSTANCE; public @Rule ExpectedException expectedException = ExpectedException.none(); /** @@ -335,7 +333,7 @@ public class GeoJsonConverterUnitTests { */ public static class DbObjectToGeoJsonMultiPointConverterUnitTests { - DbObjectToGeoJsonMultiPointConverter converter = DbObjectToGeoJsonMultiPointConverter.INSTANCE; + DocumentToGeoJsonMultiPointConverter converter = DocumentToGeoJsonMultiPointConverter.INSTANCE; public @Rule ExpectedException expectedException = ExpectedException.none(); /** @@ -372,7 +370,7 @@ public class GeoJsonConverterUnitTests { */ public static class DbObjectToGeoJsonMultiPolygonConverterUnitTests { - DbObjectToGeoJsonMultiPolygonConverter converter = DbObjectToGeoJsonMultiPolygonConverter.INSTANCE; + DocumentToGeoJsonMultiPolygonConverter converter = DocumentToGeoJsonMultiPolygonConverter.INSTANCE; public @Rule ExpectedException expectedException = ExpectedException.none(); /** @@ -409,7 +407,7 @@ public class GeoJsonConverterUnitTests { */ public static class GeoJsonToDbObjectConverterUnitTests { - GeoJsonToDbObjectConverter converter = GeoJsonToDbObjectConverter.INSTANCE; + GeoJsonToDocumentConverter converter = GeoJsonToDocumentConverter.INSTANCE; /** * @see DATAMONGO-1135 diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java index 92b01ff3d..d63caf642 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java @@ -42,7 +42,6 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; -import com.mongodb.BasicDBObject; import org.bson.types.ObjectId; import org.hamcrest.Matcher; import org.hamcrest.Matchers; @@ -2087,7 +2086,7 @@ public class MappingMongoConverterUnitTests { @Test public void readsEmptyEnumSet() { - DBObject source = new BasicDBObject("enumSet", new BasicDBList()); + org.bson.Document source = new org.bson.Document("enumSet", Collections.emptyList()); assertThat(converter.read(ClassWithEnumProperty.class, source).enumSet, is(EnumSet.noneOf(SampleEnum.class))); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MongoConvertersUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MongoConvertersUnitTests.java index 84005583c..3e311ff0f 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MongoConvertersUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MongoConvertersUnitTests.java @@ -69,8 +69,8 @@ public class MongoConvertersUnitTests { Box box = new Box(new Point(1, 2), new Point(3, 4)); - Document dbo = GeoConverters.BoxToDbObjectConverter.INSTANCE.convert(box); - Shape shape = GeoConverters.DbObjectToBoxConverter.INSTANCE.convert(dbo); + Document dbo = GeoConverters.BoxToDocumentConverter.INSTANCE.convert(box); + Shape shape = GeoConverters.DocumentToBoxConverter.INSTANCE.convert(dbo); assertThat(shape, is((org.springframework.data.geo.Shape) box)); } @@ -83,8 +83,8 @@ public class MongoConvertersUnitTests { Circle circle = new Circle(new Point(1, 2), 3); - Document dbo = GeoConverters.CircleToDbObjectConverter.INSTANCE.convert(circle); - Shape shape = GeoConverters.DbObjectToCircleConverter.INSTANCE.convert(dbo); + Document dbo = GeoConverters.CircleToDocumentConverter.INSTANCE.convert(circle); + Shape shape = GeoConverters.DocumentToCircleConverter.INSTANCE.convert(dbo); assertThat(shape, is((org.springframework.data.geo.Shape) circle)); } @@ -97,8 +97,8 @@ public class MongoConvertersUnitTests { Polygon polygon = new Polygon(new Point(1, 2), new Point(2, 3), new Point(3, 4), new Point(5, 6)); - Document dbo = GeoConverters.PolygonToDbObjectConverter.INSTANCE.convert(polygon); - Shape shape = GeoConverters.DbObjectToPolygonConverter.INSTANCE.convert(dbo); + Document dbo = GeoConverters.PolygonToDocumentConverter.INSTANCE.convert(polygon); + Shape shape = GeoConverters.DocumentToPolygonConverter.INSTANCE.convert(dbo); assertThat(shape, is((org.springframework.data.geo.Shape) polygon)); } @@ -111,8 +111,8 @@ public class MongoConvertersUnitTests { Sphere sphere = new Sphere(new Point(1, 2), 3); - Document dbo = GeoConverters.SphereToDbObjectConverter.INSTANCE.convert(sphere); - org.springframework.data.geo.Shape shape = GeoConverters.DbObjectToSphereConverter.INSTANCE.convert(dbo); + Document dbo = GeoConverters.SphereToDocumentConverter.INSTANCE.convert(sphere); + org.springframework.data.geo.Shape shape = GeoConverters.DocumentToSphereConverter.INSTANCE.convert(dbo); assertThat(shape, is((org.springframework.data.geo.Shape) sphere)); } @@ -125,8 +125,8 @@ public class MongoConvertersUnitTests { Point point = new Point(1, 2); - Document dbo = GeoConverters.PointToDbObjectConverter.INSTANCE.convert(point); - org.springframework.data.geo.Point converted = GeoConverters.DbObjectToPointConverter.INSTANCE.convert(dbo); + Document dbo = GeoConverters.PointToDocumentConverter.INSTANCE.convert(point); + org.springframework.data.geo.Point converted = GeoConverters.DocumentToPointConverter.INSTANCE.convert(dbo); assertThat(converted, is((org.springframework.data.geo.Point) point)); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java index a92cf8969..569cd5b50 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java @@ -20,7 +20,6 @@ import static org.junit.Assert.*; import org.junit.Test; import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.mongodb.core.query.Order; /** * Unit tests for {@link IndexField}. @@ -37,7 +36,6 @@ public class IndexFieldUnitTests { assertThat(field.getKey(), is("foo")); assertThat(field.getDirection(), is(Direction.ASC)); - assertThat(field.getOrder(), is(Order.ASCENDING)); assertThat(field.isGeo(), is(false)); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java index cf4bdb828..2b9926c32 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java @@ -36,7 +36,7 @@ public class IndexInfoUnitTests { IndexField fooField = IndexField.create("foo", Direction.ASC); IndexField barField = IndexField.create("bar", Direction.DESC); - IndexInfo info = new IndexInfo(Arrays.asList(fooField, barField), "myIndex", false, false, false); + IndexInfo info = new IndexInfo(Arrays.asList(fooField, barField), "myIndex", false, false, false, ""); assertThat(info.isIndexForFields(Arrays.asList("foo", "bar")), is(true)); } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java index 209af85b0..05ef3436e 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java @@ -143,21 +143,10 @@ public class MongoPersistentEntityIndexResolverUnitTests { IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); assertThat(indexDefinition.getIndexOptions(), equalTo( - new org.bson.Document().append("name", "indexedProperty").append("unique", true).append("dropDups", true) + new org.bson.Document().append("name", "indexedProperty").append("unique", true) .append("sparse", true).append("background", true).append("expireAfterSeconds", 10L))); } - /** - * @see DATAMONGO-899 - */ - @Test - public void resolvesIndexCollectionNameCorrectlyWhenDefinedInAnnotation() { - - List indexDefinitions = prepareMappingContextAndResolveIndexForType( - WithOptionsOnIndexedProperty.class); - assertThat(indexDefinitions.get(0).getCollection(), equalTo("CollectionOverride")); - } - /** * @see DATAMONGO-1297 */ @@ -254,7 +243,7 @@ public class MongoPersistentEntityIndexResolverUnitTests { @Document(collection = "WithOptionsOnIndexedProperty") static class WithOptionsOnIndexedProperty { - @Indexed(background = true, collection = "CollectionOverride", direction = IndexDirection.DESCENDING, + @Indexed(background = true, direction = IndexDirection.DESCENDING, dropDups = true, expireAfterSeconds = 10, sparse = true, unique = true) // String indexedProperty; } @@ -435,7 +424,7 @@ public class MongoPersistentEntityIndexResolverUnitTests { @Document(collection = "WithOptionsOnGeoSpatialIndexProperty") static class WithOptionsOnGeoSpatialIndexProperty { - @GeoSpatialIndexed(collection = "CollectionOverride", bits = 2, max = 100, min = 1, + @GeoSpatialIndexed(bits = 2, max = 100, min = 1, type = GeoSpatialIndexType.GEO_2D) // Point location; } @@ -498,7 +487,7 @@ public class MongoPersistentEntityIndexResolverUnitTests { IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("name", "compound_index") - .append("unique", true).append("dropDups", true).append("sparse", true).append("background", true))); + .append("unique", true).append("sparse", true).append("background", true))); assertThat(indexDefinition.getIndexKeys(), equalTo(new org.bson.Document().append("foo", 1).append("bar", -1))); } @@ -513,7 +502,7 @@ public class MongoPersistentEntityIndexResolverUnitTests { IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("name", "compound_index") - .append("unique", true).append("dropDups", true).append("sparse", true).append("background", true))); + .append("unique", true).append("sparse", true).append("background", true))); assertThat(indexDefinition.getIndexKeys(), equalTo(new org.bson.Document().append("foo", 1).append("bar", -1))); } @@ -528,7 +517,7 @@ public class MongoPersistentEntityIndexResolverUnitTests { IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("unique", true) - .append("dropDups", true).append("sparse", true).append("background", true))); + .append("sparse", true).append("background", true))); assertThat(indexDefinition.getIndexKeys(), equalTo(new org.bson.Document().append("foo", 1).append("bar", -1))); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/GeoLocation.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/GeoLocation.java index 59552a97c..7c5f59310 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/GeoLocation.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/GeoLocation.java @@ -29,7 +29,7 @@ public class GeoLocation { @Id private ObjectId id; - @GeoSpatialIndexed(collection = "geolocation") + @GeoSpatialIndexed private double[] location; public GeoLocation(double[] location) { diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListenerUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListenerUnitTests.java index 55c70d497..80f0cccb6 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListenerUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListenerUnitTests.java @@ -126,7 +126,7 @@ public class AbstractMongoEventListenerUnitTests { public void handlesUntypedImplementations() { UntypedEventListener listener = new UntypedEventListener(); - listener.onApplicationEvent(new MongoMappingEvent(new Object(), new Document())); + listener.onApplicationEvent(new MongoMappingEvent(new Object(), new Document(), "collection-1")); } /** diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexUnitTests.java index 1389ee8e0..8be5cd4b3 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexUnitTests.java @@ -54,14 +54,6 @@ public class IndexUnitTests { assertEquals(Document.parse("{ \"name\" : \"test\" , \"unique\" : true}"), i.getIndexOptions()); } - @Test - public void testWithDropDuplicates() { - Index i = new Index().on("name", Direction.ASC); - i.unique(Duplicates.DROP); - assertEquals(Document.parse("{ \"name\" : 1}"), i.getIndexKeys()); - assertEquals(Document.parse("{ \"unique\" : true , \"dropDups\" : true}"), i.getIndexOptions()); - } - @Test public void testWithSparse() { Index i = new Index().on("name", Direction.ASC); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessorUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessorUnitTests.java index 4692b0ef2..71895b1b2 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessorUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessorUnitTests.java @@ -63,12 +63,6 @@ public class ConvertingParameterAccessorUnitTests { this.converter = new MappingMongoConverter(resolver, context); } - @SuppressWarnings("deprecation") - @Test(expected = IllegalArgumentException.class) - public void rejectsNullMongoDbFactory() { - new MappingMongoConverter((MongoDbFactory) null, context); - } - @Test(expected = IllegalArgumentException.class) public void rejectsNullDbRefResolver() { new MappingMongoConverter((DbRefResolver) null, context); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java index bba8388d0..9d838c0c2 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java @@ -260,7 +260,7 @@ public class MongoQueryMethodUnitTests { @Meta List emptyMetaAnnotation(); - @Meta(maxExcecutionTime = 100) + @Meta(maxExecutionTimeMs = 100) List metaWithMaxExecutionTime(); @Meta(maxExecutionTimeMs = 100)