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