diff --git a/pom.xml b/pom.xml index 79e5353b7f..c553a34dde 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 4.0.0-SNAPSHOT + 4.0.0-GH-4061-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml index c28a240d2c..a7b8bb1074 100644 --- a/spring-data-mongodb-benchmarks/pom.xml +++ b/spring-data-mongodb-benchmarks/pom.xml @@ -7,7 +7,7 @@ org.springframework.data spring-data-mongodb-parent - 4.0.0-SNAPSHOT + 4.0.0-GH-4061-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index 5dedcf81ed..115388e3fe 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -15,7 +15,7 @@ org.springframework.data spring-data-mongodb-parent - 4.0.0-SNAPSHOT + 4.0.0-GH-4061-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index b26a926c7a..2e0e8ac71a 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -12,7 +12,7 @@ org.springframework.data spring-data-mongodb-parent - 4.0.0-SNAPSHOT + 4.0.0-GH-4061-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java index ca13e57f68..2cbd6721eb 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java @@ -174,7 +174,11 @@ public String determineCollectionName(@Nullable Class entityClass) { "No class parameter provided, entity collection can't be determined!"); } - return context.getRequiredPersistentEntity(entityClass).getCollection(); + MongoPersistentEntity persistentEntity = context.getPersistentEntity(entityClass); + if(persistentEntity == null) { + throw new MappingException(String.format("Collection name cannot be derived for type %s. Is it a store native type?", entityClass)); + } + return persistentEntity.getCollection(); } public Query getByIdInQuery(Collection entities) { 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 69c1745f89..975f806690 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 @@ -77,6 +77,7 @@ public interface MongoOperations extends FluentMongoOperations { * * @param entityClass must not be {@literal null}. * @return never {@literal null}. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be derived from the type. */ String getCollectionName(Class entityClass); @@ -918,6 +919,8 @@ T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions o * fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @return the converted object that was updated or {@literal null}, if not found. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given replacement value. * @since 2.1 */ @Nullable @@ -959,6 +962,8 @@ default T findAndReplace(Query query, T replacement, String collectionName) * @return the converted object that was updated or {@literal null}, if not found. Depending on the value of * {@link FindAndReplaceOptions#isReturnNew()} this will either be the object as it was before the update or * as it is after the update. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given replacement value. * @since 2.1 */ @Nullable @@ -1032,6 +1037,8 @@ default T findAndReplace(Query query, T replacement, FindAndReplaceOptions o * @return the converted object that was updated or {@literal null}, if not found. Depending on the value of * {@link FindAndReplaceOptions#isReturnNew()} this will either be the object as it was before the update or * as it is after the update. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given replacement value. * @since 2.1 */ @Nullable @@ -1115,6 +1122,8 @@ T findAndReplace(Query query, S replacement, FindAndReplaceOptions option * {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the count of matching documents. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @see #exactCount(Query, Class) * @see #estimatedCount(Class) */ @@ -1170,6 +1179,8 @@ T findAndReplace(Query query, S replacement, FindAndReplaceOptions option * * @param entityClass must not be {@literal null}. * @return the estimated number of documents. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @since 3.1 */ default long estimatedCount(Class entityClass) { @@ -1206,6 +1217,8 @@ default long estimatedCount(Class entityClass) { * {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the count of matching documents. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @since 3.4 */ default long exactCount(Query query, Class entityClass) { @@ -1273,6 +1286,8 @@ default long exactCount(Query query, String collectionName) { * @param objectToSave the object to store in the collection. Must not be {@literal null}. * @return the inserted object. * @throws IllegalArgumentException in case the {@code objectToSave} is collection-like. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ T insert(T objectToSave); @@ -1297,6 +1312,8 @@ default long exactCount(Query query, String collectionName) { * @param batchToSave the batch of objects to save. Must not be {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the inserted objects that. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. */ Collection insert(Collection batchToSave, Class entityClass); @@ -1315,6 +1332,8 @@ default long exactCount(Query query, String collectionName) { * * @param objectsToSave the list of objects to save. Must not be {@literal null}. * @return the inserted objects. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} for the given objects. */ Collection insertAll(Collection objectsToSave); @@ -1333,6 +1352,8 @@ default long exactCount(Query query, String collectionName) { * @param objectToSave the object to store in the collection. Must not be {@literal null}. * @return the saved object. * @throws IllegalArgumentException in case the {@code objectToSave} is collection-like. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ T save(T objectToSave); @@ -1367,9 +1388,11 @@ default long exactCount(Query query, String collectionName) { * the existing object. Must not be {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the {@link UpdateResult} which lets you access the results of the previous write. - * @since 3.0 * @see Update * @see AggregationUpdate + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. + * @since 3.0 */ UpdateResult upsert(Query query, UpdateDefinition update, Class entityClass); @@ -1421,9 +1444,11 @@ default long exactCount(Query query, String collectionName) { * the existing. Must not be {@literal null}. * @param entityClass class that determines the collection to use. * @return the {@link UpdateResult} which lets you access the results of the previous write. - * @since 3.0 * @see Update * @see AggregationUpdate + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. + * @since 3.0 */ UpdateResult updateFirst(Query query, UpdateDefinition update, Class entityClass); @@ -1475,9 +1500,11 @@ default long exactCount(Query query, String collectionName) { * the existing. Must not be {@literal null}. * @param entityClass class of the pojo to be operated on. Must not be {@literal null}. * @return the {@link UpdateResult} which lets you access the results of the previous write. - * @since 3.0 + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @see Update * @see AggregationUpdate + * @since 3.0 */ UpdateResult updateMulti(Query query, UpdateDefinition update, Class entityClass); @@ -1525,6 +1552,8 @@ default long exactCount(Query query, String collectionName) { * * @param object must not be {@literal null}. * @return the {@link DeleteResult} which lets you access the results of the previous delete. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ DeleteResult remove(Object object); @@ -1548,6 +1577,8 @@ default long exactCount(Query query, String collectionName) { * @param entityClass class that determines the collection to use. * @return the {@link DeleteResult} which lets you access the results of the previous delete. * @throws IllegalArgumentException when {@literal query} or {@literal entityClass} is {@literal null}. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. */ DeleteResult remove(Query query, Class entityClass); @@ -1595,6 +1626,8 @@ default long exactCount(Query query, String collectionName) { * @param query the query document that specifies the criteria used to find and remove documents. * @param entityClass class of the pojo to be operated on. * @return the {@link List} converted objects deleted by this operation. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @since 1.5 */ List findAllAndRemove(Query query, Class entityClass); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java index d35727b232..7b13829c9f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java @@ -693,6 +693,8 @@ Mono findAndModify(Query query, UpdateDefinition update, FindAndModifyOpt * fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @return the converted object that was updated or {@link Mono#empty()}, if not found. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given replacement value. * @since 2.1 */ default Mono findAndReplace(Query query, T replacement) { @@ -732,6 +734,8 @@ default Mono findAndReplace(Query query, T replacement, String collection * @return the converted object that was updated or {@link Mono#empty()}, if not found. Depending on the value of * {@link FindAndReplaceOptions#isReturnNew()} this will either be the object as it was before the update or * as it is after the update. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given replacement value. * @since 2.1 */ default Mono findAndReplace(Query query, T replacement, FindAndReplaceOptions options) { @@ -802,6 +806,8 @@ default Mono findAndReplace(Query query, T replacement, FindAndReplaceOpt * @return the converted object that was updated or {@link Mono#empty()}, if not found. Depending on the value of * {@link FindAndReplaceOptions#isReturnNew()} this will either be the object as it was before the update or * as it is after the update. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given replacement value. * @since 2.1 */ default Mono findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class entityType, @@ -882,6 +888,8 @@ Mono findAndReplace(Query query, S replacement, FindAndReplaceOptions * {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the count of matching documents. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @see #exactCount(Query, Class) * @see #estimatedCount(Class) */ @@ -937,6 +945,8 @@ Mono findAndReplace(Query query, S replacement, FindAndReplaceOptions * * @param entityClass must not be {@literal null}. * @return a {@link Mono} emitting the estimated number of documents. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @since 3.1 */ default Mono estimatedCount(Class entityClass) { @@ -973,6 +983,8 @@ default Mono estimatedCount(Class entityClass) { * {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the count of matching documents. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @since 3.4 */ default Mono exactCount(Query query, Class entityClass) { @@ -1040,6 +1052,8 @@ default Mono exactCount(Query query, String collectionName) { * @param objectToSave the object to store in the collection. Must not be {@literal null}. * @return the inserted object. * @throws IllegalArgumentException in case the {@code objectToSave} is collection-like. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ Mono insert(T objectToSave); @@ -1063,7 +1077,9 @@ default Mono exactCount(Query query, String collectionName) { * * @param batchToSave the batch of objects to save. Must not be {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. - * @return the inserted objects . + * @return the inserted objects. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. */ Flux insert(Collection batchToSave, Class entityClass); @@ -1082,6 +1098,8 @@ default Mono exactCount(Query query, String collectionName) { * * @param objectsToSave the list of objects to save. Must not be {@literal null}. * @return the saved objects. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} for the given objects. */ Flux insertAll(Collection objectsToSave); @@ -1106,6 +1124,8 @@ default Mono exactCount(Query query, String collectionName) { * @param batchToSave the publisher which provides objects to save. Must not be {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the inserted objects. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} for the type. */ Flux insertAll(Mono> batchToSave, Class entityClass); @@ -1142,6 +1162,8 @@ default Mono exactCount(Query query, String collectionName) { * @param objectToSave the object to store in the collection. Must not be {@literal null}. * @return the saved object. * @throws IllegalArgumentException in case the {@code objectToSave} is collection-like. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ Mono save(T objectToSave); @@ -1176,6 +1198,8 @@ default Mono exactCount(Query query, String collectionName) { * * @param objectToSave the object to store in the collection. Must not be {@literal null}. * @return the saved object. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ Mono save(Mono objectToSave); @@ -1208,6 +1232,8 @@ default Mono exactCount(Query query, String collectionName) { * the existing object. Must not be {@literal null}. * @param entityClass class that determines the collection to use. Must not be {@literal null}. * @return the {@link UpdateResult} which lets you access the results of the previous write. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @since 3.0 * @see Update * @see AggregationUpdate @@ -1262,6 +1288,8 @@ default Mono exactCount(Query query, String collectionName) { * the existing. Must not be {@literal null}. * @param entityClass class that determines the collection to use. * @return the {@link UpdateResult} which lets you access the results of the previous write. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @since 3.0 * @see Update * @see AggregationUpdate @@ -1317,6 +1345,8 @@ default Mono exactCount(Query query, String collectionName) { * @param entityClass class of the pojo to be operated on. Must not be {@literal null}. * @return the {@link UpdateResult} which lets you access the results of the previous write. * @since 3.0 + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. * @see Update * @see AggregationUpdate */ @@ -1363,6 +1393,8 @@ default Mono exactCount(Query query, String collectionName) { * * @param object must not be {@literal null}. * @return the {@link DeleteResult} which lets you access the results of the previous delete. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ Mono remove(Object object); @@ -1380,6 +1412,8 @@ default Mono exactCount(Query query, String collectionName) { * * @param objectToRemove must not be {@literal null}. * @return the {@link DeleteResult} which lets you access the results of the previous delete. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given object type. */ Mono remove(Mono objectToRemove); @@ -1399,6 +1433,8 @@ default Mono exactCount(Query query, String collectionName) { * @param query the query document that specifies the criteria used to remove a record. * @param entityClass class that determines the collection to use. * @return the {@link DeleteResult} which lets you access the results of the previous delete. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. */ Mono remove(Query query, Class entityClass); @@ -1442,6 +1478,8 @@ default Mono exactCount(Query query, String collectionName) { * @param query the query document that specifies the criteria used to find and remove documents. * @param entityClass class of the pojo to be operated on. * @return the {@link Flux} converted objects deleted by this operation. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. */ Flux findAllAndRemove(Query query, Class entityClass); @@ -1471,6 +1509,8 @@ default Mono exactCount(Query query, String collectionName) { * specification. * @param entityClass the parametrized type of the returned {@link Flux}. * @return the {@link Flux} of converted objects. + * @throws org.springframework.data.mapping.MappingException if the target collection name cannot be + * {@link #getCollectionName(Class) derived} from the given type. */ Flux tail(Query query, Class entityClass); @@ -1611,6 +1651,7 @@ Flux mapReduce(Query filterQuery, Class domainType, String inputCollec * * @param entityClass must not be {@literal null}. * @return never {@literal null}. + * @throws org.springframework.data.mapping.MappingException if the collection name cannot be derived from the type. * @since 2.1 */ String getCollectionName(Class entityClass);