@@ -396,15 +396,15 @@ public Mono<Document> executeCommand(String jsonCommand) {
396
396
* (non-Javadoc)
397
397
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#executeCommand(org.bson.Document)
398
398
*/
399
- public Mono <Document > executeCommand (final Document command ) {
399
+ public Mono <Document > executeCommand (Document command ) {
400
400
return executeCommand (command , null );
401
401
}
402
402
403
403
/*
404
404
* (non-Javadoc)
405
405
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#executeCommand(org.bson.Document, com.mongodb.ReadPreference)
406
406
*/
407
- public Mono <Document > executeCommand (final Document command , @ Nullable ReadPreference readPreference ) {
407
+ public Mono <Document > executeCommand (Document command , @ Nullable ReadPreference readPreference ) {
408
408
409
409
Assert .notNull (command , "Command must not be null!" );
410
410
@@ -553,7 +553,7 @@ public <T> Flux<T> createFlux(ReactiveDatabaseCallback<T> callback) {
553
553
* @param callback must not be {@literal null}
554
554
* @return a {@link Mono} wrapping the {@link ReactiveDatabaseCallback}.
555
555
*/
556
- public <T > Mono <T > createMono (final ReactiveDatabaseCallback <T > callback ) {
556
+ public <T > Mono <T > createMono (ReactiveDatabaseCallback <T > callback ) {
557
557
558
558
Assert .notNull (callback , "ReactiveDatabaseCallback must not be null!" );
559
559
@@ -638,7 +638,7 @@ public Mono<MongoCollection<Document>> createCollection(String collectionName,
638
638
* (non-Javadoc)
639
639
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#getCollection(java.lang.String)
640
640
*/
641
- public MongoCollection <Document > getCollection (final String collectionName ) {
641
+ public MongoCollection <Document > getCollection (String collectionName ) {
642
642
return execute ((MongoDatabaseCallback <MongoCollection <Document >>) db -> db .getCollection (collectionName ));
643
643
}
644
644
@@ -654,7 +654,7 @@ public <T> Mono<Boolean> collectionExists(Class<T> entityClass) {
654
654
* (non-Javadoc)
655
655
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#collectionExists(java.lang.String)
656
656
*/
657
- public Mono <Boolean > collectionExists (final String collectionName ) {
657
+ public Mono <Boolean > collectionExists (String collectionName ) {
658
658
return createMono (db -> Flux .from (db .listCollectionNames ()) //
659
659
.filter (s -> s .equals (collectionName )) //
660
660
.map (s -> true ) //
@@ -673,7 +673,7 @@ public <T> Mono<Void> dropCollection(Class<T> entityClass) {
673
673
* (non-Javadoc)
674
674
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#dropCollection(java.lang.String)
675
675
*/
676
- public Mono <Void > dropCollection (final String collectionName ) {
676
+ public Mono <Void > dropCollection (String collectionName ) {
677
677
678
678
return createMono (collectionName , MongoCollection ::drop ).doOnSuccess (success -> {
679
679
if (LOGGER .isDebugEnabled ()) {
@@ -1006,15 +1006,15 @@ protected <T> Flux<GeoResult<T>> geoNear(NearQuery near, Class<?> entityClass, S
1006
1006
}
1007
1007
1008
1008
String collection = StringUtils .hasText (collectionName ) ? collectionName : determineCollectionName (entityClass );
1009
- Document nearDbObject = near .toDocument ();
1009
+ Document nearDocument = near .toDocument ();
1010
1010
1011
1011
Document command = new Document ("geoNear" , collection );
1012
- command .putAll (nearDbObject );
1012
+ command .putAll (nearDocument );
1013
1013
1014
1014
return Flux .defer (() -> {
1015
1015
1016
- if (nearDbObject .containsKey ("query" )) {
1017
- Document query = (Document ) nearDbObject .get ("query" );
1016
+ if (nearDocument .containsKey ("query" )) {
1017
+ Document query = (Document ) nearDocument .get ("query" );
1018
1018
command .put ("query" , queryMapper .getMappedObject (query , getPersistentEntity (entityClass )));
1019
1019
}
1020
1020
@@ -1023,7 +1023,7 @@ protected <T> Flux<GeoResult<T>> geoNear(NearQuery near, Class<?> entityClass, S
1023
1023
entityClass , collectionName );
1024
1024
}
1025
1025
1026
- GeoNearResultDbObjectCallback <T > callback = new GeoNearResultDbObjectCallback <>(
1026
+ GeoNearResultDocumentCallback <T > callback = new GeoNearResultDocumentCallback <>(
1027
1027
new ProjectingReadCallback <>(mongoConverter , entityClass , returnType , collectionName ), near .getMetric ());
1028
1028
1029
1029
return executeCommand (command , this .readPreference ).flatMapMany (document -> {
@@ -1144,7 +1144,7 @@ public Mono<Long> count(Query query, Class<?> entityClass) {
1144
1144
* (non-Javadoc)
1145
1145
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#count(org.springframework.data.mongodb.core.query.Query, java.lang.String)
1146
1146
*/
1147
- public Mono <Long > count (final Query query , String collectionName ) {
1147
+ public Mono <Long > count (Query query , String collectionName ) {
1148
1148
return count (query , null , collectionName );
1149
1149
}
1150
1150
@@ -1247,7 +1247,7 @@ protected <T> Mono<T> doInsert(String collectionName, T objectToSave, MongoWrite
1247
1247
1248
1248
maybeEmitEvent (new BeforeSaveEvent <>(initialized , dbDoc , collectionName ));
1249
1249
1250
- Mono <T > afterInsert = insertDBObject (collectionName , dbDoc , initialized .getClass ()).map (id -> {
1250
+ Mono <T > afterInsert = insertDocument (collectionName , dbDoc , initialized .getClass ()).map (id -> {
1251
1251
1252
1252
T saved = entity .populateIdIfNecessary (id );
1253
1253
maybeEmitEvent (new AfterSaveEvent <>(initialized , dbDoc , collectionName ));
@@ -1293,7 +1293,7 @@ public <T> Flux<T> insertAll(Mono<? extends Collection<? extends T>> objectsToSa
1293
1293
1294
1294
protected <T > Flux <T > doInsertAll (Collection <? extends T > listToSave , MongoWriter <Object > writer ) {
1295
1295
1296
- final Map <String , List <T >> elementsByCollection = new HashMap <>();
1296
+ Map <String , List <T >> elementsByCollection = new HashMap <>();
1297
1297
1298
1298
listToSave .forEach (element -> {
1299
1299
@@ -1309,8 +1309,8 @@ protected <T> Flux<T> doInsertAll(Collection<? extends T> listToSave, MongoWrite
1309
1309
.flatMap (collectionName -> doInsertBatch (collectionName , elementsByCollection .get (collectionName ), writer ));
1310
1310
}
1311
1311
1312
- protected <T > Flux <T > doInsertBatch (final String collectionName , final Collection <? extends T > batchToSave ,
1313
- final MongoWriter <Object > writer ) {
1312
+ protected <T > Flux <T > doInsertBatch (String collectionName , Collection <? extends T > batchToSave ,
1313
+ MongoWriter <Object > writer ) {
1314
1314
1315
1315
Assert .notNull (writer , "MongoWriter must not be null!" );
1316
1316
@@ -1330,9 +1330,9 @@ protected <T> Flux<T> doInsertBatch(final String collectionName, final Collectio
1330
1330
1331
1331
Flux <Tuple2 <AdaptibleEntity <T >, Document >> insertDocuments = prepareDocuments .flatMapMany (tuples -> {
1332
1332
1333
- List <Document > dbObjects = tuples .stream ().map (Tuple2 ::getT2 ).collect (Collectors .toList ());
1333
+ List <Document > documents = tuples .stream ().map (Tuple2 ::getT2 ).collect (Collectors .toList ());
1334
1334
1335
- return insertDocumentList (collectionName , dbObjects ).thenMany (Flux .fromIterable (tuples ));
1335
+ return insertDocumentList (collectionName , documents ).thenMany (Flux .fromIterable (tuples ));
1336
1336
});
1337
1337
1338
1338
return insertDocuments .map (tuple -> {
@@ -1445,7 +1445,7 @@ protected <T> Mono<T> doSave(String collectionName, T objectToSave, MongoWriter<
1445
1445
});
1446
1446
}
1447
1447
1448
- protected Mono <Object > insertDBObject ( final String collectionName , final Document dbDoc , final Class <?> entityClass ) {
1448
+ protected Mono <Object > insertDocument ( String collectionName , Document dbDoc , Class <?> entityClass ) {
1449
1449
1450
1450
if (LOGGER .isDebugEnabled ()) {
1451
1451
LOGGER .debug ("Inserting Document containing fields: " + dbDoc .keySet () + " in collection: " + collectionName );
@@ -1467,17 +1467,17 @@ protected Mono<Object> insertDBObject(final String collectionName, final Documen
1467
1467
return Flux .from (execute ).last ().map (success -> MappedDocument .of (document ).getId ());
1468
1468
}
1469
1469
1470
- protected Flux <ObjectId > insertDocumentList (final String collectionName , final List <Document > dbDocList ) {
1470
+ protected Flux <ObjectId > insertDocumentList (String collectionName , List <Document > dbDocList ) {
1471
1471
1472
1472
if (dbDocList .isEmpty ()) {
1473
1473
return Flux .empty ();
1474
1474
}
1475
1475
1476
1476
if (LOGGER .isDebugEnabled ()) {
1477
- LOGGER .debug ("Inserting list of DBObjects containing " + dbDocList .size () + " items" );
1477
+ LOGGER .debug ("Inserting list of Documents containing " + dbDocList .size () + " items" );
1478
1478
}
1479
1479
1480
- final List <Document > documents = new ArrayList <>();
1480
+ List <Document > documents = new ArrayList <>();
1481
1481
1482
1482
return execute (collectionName , collection -> {
1483
1483
@@ -1509,8 +1509,7 @@ private MongoCollection<Document> prepareCollection(MongoCollection<Document> co
1509
1509
return collectionToUse ;
1510
1510
}
1511
1511
1512
- protected Mono <Object > saveDocument (final String collectionName , final Document document ,
1513
- final Class <?> entityClass ) {
1512
+ protected Mono <Object > saveDocument (String collectionName , Document document , Class <?> entityClass ) {
1514
1513
1515
1514
if (LOGGER .isDebugEnabled ()) {
1516
1515
LOGGER .debug ("Saving Document containing fields: " + document .keySet ());
@@ -1572,7 +1571,7 @@ public Mono<UpdateResult> updateFirst(Query query, Update update, Class<?> entit
1572
1571
* (non-Javadoc)
1573
1572
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#updateFirst(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, java.lang.String)
1574
1573
*/
1575
- public Mono <UpdateResult > updateFirst (final Query query , final Update update , final String collectionName ) {
1574
+ public Mono <UpdateResult > updateFirst (Query query , Update update , String collectionName ) {
1576
1575
return doUpdate (collectionName , query , update , null , false , false );
1577
1576
}
1578
1577
@@ -1596,21 +1595,20 @@ public Mono<UpdateResult> updateMulti(Query query, Update update, Class<?> entit
1596
1595
* (non-Javadoc)
1597
1596
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#updateMulti(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, java.lang.String)
1598
1597
*/
1599
- public Mono <UpdateResult > updateMulti (final Query query , final Update update , String collectionName ) {
1598
+ public Mono <UpdateResult > updateMulti (Query query , Update update , String collectionName ) {
1600
1599
return doUpdate (collectionName , query , update , null , false , true );
1601
1600
}
1602
1601
1603
1602
/*
1604
1603
* (non-Javadoc)
1605
1604
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#updateMulti(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, java.lang.Class, java.lang.String)
1606
1605
*/
1607
- public Mono <UpdateResult > updateMulti (final Query query , final Update update , Class <?> entityClass ,
1608
- String collectionName ) {
1606
+ public Mono <UpdateResult > updateMulti (Query query , Update update , Class <?> entityClass , String collectionName ) {
1609
1607
return doUpdate (collectionName , query , update , entityClass , false , true );
1610
1608
}
1611
1609
1612
- protected Mono <UpdateResult > doUpdate (final String collectionName , Query query , @ Nullable Update update ,
1613
- @ Nullable Class <?> entityClass , final boolean upsert , final boolean multi ) {
1610
+ protected Mono <UpdateResult > doUpdate (String collectionName , Query query , @ Nullable Update update ,
1611
+ @ Nullable Class <?> entityClass , boolean upsert , boolean multi ) {
1614
1612
1615
1613
MongoPersistentEntity <?> entity = entityClass == null ? null : getPersistentEntity (entityClass );
1616
1614
@@ -1656,7 +1654,7 @@ protected Mono<UpdateResult> doUpdate(final String collectionName, Query query,
1656
1654
: queryMapper .getMappedObject (query .getQueryObject (), entity );
1657
1655
Document updateObj = update == null ? new Document ()
1658
1656
: updateMapper .getMappedObject (update .getUpdateObject (), entity );
1659
- if (dbObjectContainsVersionProperty (queryObj , entity ))
1657
+ if (containsVersionProperty (queryObj , entity ))
1660
1658
throw new OptimisticLockingFailureException ("Optimistic lock exception on saving entity: "
1661
1659
+ updateObj .toString () + " to collection " + collectionName );
1662
1660
}
@@ -1676,8 +1674,7 @@ private void increaseVersionForUpdateIfNecessary(@Nullable MongoPersistentEntity
1676
1674
}
1677
1675
}
1678
1676
1679
- private boolean dbObjectContainsVersionProperty (Document document ,
1680
- @ Nullable MongoPersistentEntity <?> persistentEntity ) {
1677
+ private boolean containsVersionProperty (Document document , @ Nullable MongoPersistentEntity <?> persistentEntity ) {
1681
1678
1682
1679
if (persistentEntity == null || !persistentEntity .hasVersionProperty ()) {
1683
1680
return false ;
@@ -1780,8 +1777,8 @@ protected <T> Mono<DeleteResult> doRemove(String collectionName, Query query, @N
1780
1777
1781
1778
Assert .hasText (collectionName , "Collection name must not be null or empty!" );
1782
1779
1783
- final Document queryObject = query .getQueryObject ();
1784
- final MongoPersistentEntity <?> entity = getPersistentEntity (entityClass );
1780
+ Document queryObject = query .getQueryObject ();
1781
+ MongoPersistentEntity <?> entity = getPersistentEntity (entityClass );
1785
1782
1786
1783
return execute (collectionName , collection -> {
1787
1784
@@ -1792,7 +1789,7 @@ protected <T> Mono<DeleteResult> doRemove(String collectionName, Query query, @N
1792
1789
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .REMOVE , collectionName , entityClass ,
1793
1790
null , removeQuey );
1794
1791
1795
- final DeleteOptions deleteOptions = new DeleteOptions ();
1792
+ DeleteOptions deleteOptions = new DeleteOptions ();
1796
1793
query .getCollation ().map (Collation ::toMongoCollation ).ifPresent (deleteOptions ::collation );
1797
1794
1798
1795
WriteConcern writeConcernToUse = prepareWriteConcern (mongoAction );
@@ -2148,8 +2145,8 @@ protected <T> Flux<T> doFindAndDelete(String collectionName, Query query, Class<
2148
2145
* @param collectionOptions
2149
2146
* @return the collection that was created
2150
2147
*/
2151
- protected Mono <MongoCollection <Document >> doCreateCollection (final String collectionName ,
2152
- final CreateCollectionOptions collectionOptions ) {
2148
+ protected Mono <MongoCollection <Document >> doCreateCollection (String collectionName ,
2149
+ CreateCollectionOptions collectionOptions ) {
2153
2150
2154
2151
return createMono (db -> db .createCollection (collectionName , collectionOptions )).map (success -> {
2155
2152
@@ -2586,17 +2583,6 @@ private MongoPersistentEntity<?> getPersistentEntity(@Nullable Class<?> type) {
2586
2583
return type == null ? null : mappingContext .getPersistentEntity (type );
2587
2584
}
2588
2585
2589
- @ Nullable
2590
- private MongoPersistentProperty getIdPropertyFor (@ Nullable Class <?> type ) {
2591
-
2592
- if (type == null ) {
2593
- return null ;
2594
- }
2595
-
2596
- MongoPersistentEntity <?> persistentEntity = mappingContext .getPersistentEntity (type );
2597
- return persistentEntity != null ? persistentEntity .getIdProperty () : null ;
2598
- }
2599
-
2600
2586
private <T > String determineEntityCollectionName (@ Nullable T obj ) {
2601
2587
2602
2588
if (null != obj ) {
@@ -2689,6 +2675,7 @@ public Publisher<Document> doInCollection(MongoCollection<Document> collection)
2689
2675
*
2690
2676
* @author Mark Paluch
2691
2677
*/
2678
+ @ RequiredArgsConstructor
2692
2679
private static class FindCallback implements ReactiveCollectionQueryCallback <Document > {
2693
2680
2694
2681
private final @ Nullable Document query ;
@@ -2698,11 +2685,6 @@ private static class FindCallback implements ReactiveCollectionQueryCallback<Doc
2698
2685
this (query , null );
2699
2686
}
2700
2687
2701
- FindCallback (Document query , Document fields ) {
2702
- this .query = query ;
2703
- this .fields = fields ;
2704
- }
2705
-
2706
2688
@ Override
2707
2689
public FindPublisher <Document > doInCollection (MongoCollection <Document > collection ) {
2708
2690
@@ -2756,6 +2738,7 @@ public Publisher<Document> doInCollection(MongoCollection<Document> collection)
2756
2738
/**
2757
2739
* @author Mark Paluch
2758
2740
*/
2741
+ @ RequiredArgsConstructor
2759
2742
private static class FindAndModifyCallback implements ReactiveCollectionCallback <Document > {
2760
2743
2761
2744
private final Document query ;
@@ -2764,16 +2747,6 @@ private static class FindAndModifyCallback implements ReactiveCollectionCallback
2764
2747
private final Document update ;
2765
2748
private final FindAndModifyOptions options ;
2766
2749
2767
- FindAndModifyCallback (Document query , Document fields , Document sort , Document update ,
2768
- FindAndModifyOptions options ) {
2769
-
2770
- this .query = query ;
2771
- this .fields = fields ;
2772
- this .sort = sort ;
2773
- this .update = update ;
2774
- this .options = options ;
2775
- }
2776
-
2777
2750
@ Override
2778
2751
public Publisher <Document > doInCollection (MongoCollection <Document > collection )
2779
2752
throws MongoException , DataAccessException {
@@ -2981,18 +2954,18 @@ public T doWith(@Nullable Document object) {
2981
2954
*
2982
2955
* @author Mark Paluch
2983
2956
*/
2984
- static class GeoNearResultDbObjectCallback <T > implements DocumentCallback <GeoResult <T >> {
2957
+ static class GeoNearResultDocumentCallback <T > implements DocumentCallback <GeoResult <T >> {
2985
2958
2986
2959
private final DocumentCallback <T > delegate ;
2987
2960
private final Metric metric ;
2988
2961
2989
2962
/**
2990
- * Creates a new {@link GeoNearResultDbObjectCallback } using the given {@link DocumentCallback} delegate for
2963
+ * Creates a new {@link GeoNearResultDocumentCallback } using the given {@link DocumentCallback} delegate for
2991
2964
* {@link GeoResult} content unmarshalling.
2992
2965
*
2993
2966
* @param delegate must not be {@literal null}.
2994
2967
*/
2995
- GeoNearResultDbObjectCallback (DocumentCallback <T > delegate , Metric metric ) {
2968
+ GeoNearResultDocumentCallback (DocumentCallback <T > delegate , Metric metric ) {
2996
2969
2997
2970
Assert .notNull (delegate , "DocumentCallback must not be null!" );
2998
2971
@@ -3105,7 +3078,7 @@ public <T> FindPublisher<T> prepare(FindPublisher<T> findPublisher) {
3105
3078
}
3106
3079
}
3107
3080
3108
- private static List <? extends Document > toDocuments (final Collection <? extends Document > documents ) {
3081
+ private static List <? extends Document > toDocuments (Collection <? extends Document > documents ) {
3109
3082
return new ArrayList <>(documents );
3110
3083
}
3111
3084
0 commit comments