24
24
import java .util .concurrent .TimeUnit ;
25
25
import java .util .stream .Collectors ;
26
26
27
+ import org .apache .commons .logging .Log ;
28
+ import org .apache .commons .logging .LogFactory ;
27
29
import org .bson .Document ;
28
30
import org .bson .conversions .Bson ;
29
- import org .slf4j .Logger ;
30
- import org .slf4j .LoggerFactory ;
31
31
32
32
import org .springframework .beans .BeansException ;
33
33
import org .springframework .context .ApplicationContext ;
163
163
*/
164
164
public class MongoTemplate implements MongoOperations , ApplicationContextAware , IndexOperationsProvider {
165
165
166
- private static final Logger LOGGER = LoggerFactory . getLogger (MongoTemplate .class );
166
+ private static final Log LOGGER = LogFactory . getLog (MongoTemplate .class );
167
167
private static final WriteResultChecking DEFAULT_WRITE_RESULT_CHECKING = WriteResultChecking .NONE ;
168
168
169
169
private final MongoConverter mongoConverter ;
@@ -507,8 +507,8 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback
507
507
Document fieldsObject = query .getFieldsObject ();
508
508
509
509
if (LOGGER .isDebugEnabled ()) {
510
- LOGGER .debug ("Executing query: {} sort: {} fields: {} in collection: {}" , serializeToJsonSafely ( queryObject ) ,
511
- sortObject , fieldsObject , collectionName );
510
+ LOGGER .debug (String . format ( "Executing query: %s sort: %s fields: %s in collection: %s" ,
511
+ serializeToJsonSafely ( queryObject ), sortObject , fieldsObject , collectionName ) );
512
512
}
513
513
514
514
this .executeQueryInternal (new FindCallback (queryObject , fieldsObject , null ),
@@ -700,8 +700,8 @@ public void dropCollection(String collectionName) {
700
700
execute (collectionName , (CollectionCallback <Void >) collection -> {
701
701
collection .drop ();
702
702
if (LOGGER .isDebugEnabled ()) {
703
- LOGGER .debug ("Dropped collection [{} ]" ,
704
- collection .getNamespace () != null ? collection .getNamespace ().getCollectionName () : collectionName );
703
+ LOGGER .debug (String . format ( "Dropped collection [%s ]" ,
704
+ collection .getNamespace () != null ? collection .getNamespace ().getCollectionName () : collectionName )) ;
705
705
}
706
706
return null ;
707
707
});
@@ -903,8 +903,8 @@ public <T> List<T> findDistinct(Query query, String field, String collectionName
903
903
MongoIterable <?> result = execute (collectionName , (collection ) -> {
904
904
905
905
if (LOGGER .isDebugEnabled ()) {
906
- LOGGER .debug ("Executing findDistinct using query {} for field: {} in collection: {} " ,
907
- serializeToJsonSafely (mappedQuery ), field , collectionName );
906
+ LOGGER .debug (String . format ( "Executing findDistinct using query %s for field: %s in collection: %s " ,
907
+ serializeToJsonSafely (mappedQuery ), field , collectionName )) ;
908
908
}
909
909
910
910
QueryCursorPreparer preparer = new QueryCursorPreparer (query , entityClass );
@@ -1126,7 +1126,8 @@ public long count(Query query, @Nullable Class<?> entityClass, String collection
1126
1126
protected long doCount (String collectionName , Document filter , CountOptions options ) {
1127
1127
1128
1128
if (LOGGER .isDebugEnabled ()) {
1129
- LOGGER .debug ("Executing count: {} in collection: {}" , serializeToJsonSafely (filter ), collectionName );
1129
+ LOGGER
1130
+ .debug (String .format ("Executing count: %s in collection: %s" , serializeToJsonSafely (filter ), collectionName ));
1130
1131
}
1131
1132
1132
1133
return execute (collectionName ,
@@ -1453,7 +1454,8 @@ protected <T> T doSave(String collectionName, T objectToSave, MongoWriter<T> wri
1453
1454
protected Object insertDocument (String collectionName , Document document , Class <?> entityClass ) {
1454
1455
1455
1456
if (LOGGER .isDebugEnabled ()) {
1456
- LOGGER .debug ("Inserting Document containing fields: {} in collection: {}" , document .keySet (), collectionName );
1457
+ LOGGER .debug (String .format ("Inserting Document containing fields: %s in collection: %s" , document .keySet (),
1458
+ collectionName ));
1457
1459
}
1458
1460
1459
1461
return execute (collectionName , collection -> {
@@ -1478,7 +1480,7 @@ protected List<Object> insertDocumentList(String collectionName, List<Document>
1478
1480
}
1479
1481
1480
1482
if (LOGGER .isDebugEnabled ()) {
1481
- LOGGER .debug ("Inserting list of Documents containing {} items" , documents .size ());
1483
+ LOGGER .debug (String . format ( "Inserting list of Documents containing %s items" , documents .size () ));
1482
1484
}
1483
1485
1484
1486
execute (collectionName , collection -> {
@@ -1502,7 +1504,7 @@ protected List<Object> insertDocumentList(String collectionName, List<Document>
1502
1504
protected Object saveDocument (String collectionName , Document dbDoc , Class <?> entityClass ) {
1503
1505
1504
1506
if (LOGGER .isDebugEnabled ()) {
1505
- LOGGER .debug ("Saving Document containing fields: {} " , dbDoc .keySet ());
1507
+ LOGGER .debug (String . format ( "Saving Document containing fields: %s " , dbDoc .keySet () ));
1506
1508
}
1507
1509
1508
1510
return execute (collectionName , collection -> {
@@ -1607,8 +1609,8 @@ protected UpdateResult doUpdate(String collectionName, Query query, UpdateDefini
1607
1609
1608
1610
if (query .isSorted () && LOGGER .isWarnEnabled ()) {
1609
1611
1610
- LOGGER .warn ("{} does not support sort ('{} '). Please use findAndModify() instead." ,
1611
- upsert ? "Upsert" : "UpdateFirst" , serializeToJsonSafely (query .getSortObject ()));
1612
+ LOGGER .warn (String . format ( "%s does not support sort ('%s '). Please use findAndModify() instead." ,
1613
+ upsert ? "Upsert" : "UpdateFirst" , serializeToJsonSafely (query .getSortObject ()))) ;
1612
1614
}
1613
1615
1614
1616
MongoPersistentEntity <?> entity = entityClass == null ? null : getPersistentEntity (entityClass );
@@ -1630,8 +1632,8 @@ protected UpdateResult doUpdate(String collectionName, Query query, UpdateDefini
1630
1632
return execute (collectionName , collection -> {
1631
1633
1632
1634
if (LOGGER .isDebugEnabled ()) {
1633
- LOGGER .debug ("Calling update using query: {} and update: {} in collection: {} " ,
1634
- serializeToJsonSafely (queryObj ), serializeToJsonSafely (pipeline ), collectionName );
1635
+ LOGGER .debug (String . format ( "Calling update using query: %s and update: %s in collection: %s " ,
1636
+ serializeToJsonSafely (queryObj ), serializeToJsonSafely (pipeline ), collectionName )) ;
1635
1637
}
1636
1638
1637
1639
collection = writeConcernToUse != null ? collection .withWriteConcern (writeConcernToUse ) : collection ;
@@ -1648,8 +1650,8 @@ protected UpdateResult doUpdate(String collectionName, Query query, UpdateDefini
1648
1650
return execute (collectionName , collection -> {
1649
1651
1650
1652
if (LOGGER .isDebugEnabled ()) {
1651
- LOGGER .debug ("Calling update using query: {} and update: {} in collection: {}" , serializeToJsonSafely ( queryObj ) ,
1652
- serializeToJsonSafely (updateObj ), collectionName );
1653
+ LOGGER .debug (String . format ( "Calling update using query: %s and update: %s in collection: %s" ,
1654
+ serializeToJsonSafely (queryObj ), serializeToJsonSafely ( updateObj ), collectionName ) );
1653
1655
}
1654
1656
1655
1657
collection = writeConcernToUse != null ? collection .withWriteConcern (writeConcernToUse ) : collection ;
@@ -1739,8 +1741,8 @@ protected <T> DeleteResult doRemove(String collectionName, Query query, @Nullabl
1739
1741
Document removeQuery = queryObject ;
1740
1742
1741
1743
if (LOGGER .isDebugEnabled ()) {
1742
- LOGGER .debug ("Remove using query: {} in collection: {}." ,
1743
- new Object [] { serializeToJsonSafely ( removeQuery ), collectionName } );
1744
+ LOGGER .debug (String . format ( "Remove using query: %s in collection: %s." , serializeToJsonSafely ( removeQuery ) ,
1745
+ collectionName ) );
1744
1746
}
1745
1747
1746
1748
if (query .getLimit () > 0 || query .getSkip () > 0 ) {
@@ -1954,13 +1956,13 @@ public <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputColl
1954
1956
Document commandObject = new Document ("group" , document );
1955
1957
1956
1958
if (LOGGER .isDebugEnabled ()) {
1957
- LOGGER .debug ("Executing Group with Document [{} ]" , serializeToJsonSafely (commandObject ));
1959
+ LOGGER .debug (String . format ( "Executing Group with Document [%s ]" , serializeToJsonSafely (commandObject ) ));
1958
1960
}
1959
1961
1960
1962
Document commandResult = executeCommand (commandObject , this .readPreference );
1961
1963
1962
1964
if (LOGGER .isDebugEnabled ()) {
1963
- LOGGER .debug ("Group command result = [{} ]" , commandResult );
1965
+ LOGGER .debug (String . format ( "Group command result = [%s ]" , commandResult ) );
1964
1966
}
1965
1967
1966
1968
@ SuppressWarnings ("unchecked" )
@@ -2132,7 +2134,7 @@ protected <O> AggregationResults<O> doAggregate(Aggregation aggregation, String
2132
2134
Document command = aggregationUtil .createCommand (collectionName , aggregation , context );
2133
2135
2134
2136
if (LOGGER .isDebugEnabled ()) {
2135
- LOGGER .debug ("Executing aggregation: {} " , serializeToJsonSafely (command ));
2137
+ LOGGER .debug (String . format ( "Executing aggregation: %s " , serializeToJsonSafely (command ) ));
2136
2138
}
2137
2139
2138
2140
Document commandResult = executeCommand (command );
@@ -2143,7 +2145,8 @@ protected <O> AggregationResults<O> doAggregate(Aggregation aggregation, String
2143
2145
List <Document > pipeline = aggregationUtil .createPipeline (aggregation , context );
2144
2146
2145
2147
if (LOGGER .isDebugEnabled ()) {
2146
- LOGGER .debug ("Executing aggregation: {} in collection {}" , serializeToJsonSafely (pipeline ), collectionName );
2148
+ LOGGER .debug (
2149
+ String .format ("Executing aggregation: %s in collection %s" , serializeToJsonSafely (pipeline ), collectionName ));
2147
2150
}
2148
2151
2149
2152
return execute (collectionName , collection -> {
@@ -2209,7 +2212,8 @@ protected <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, Stri
2209
2212
List <Document > pipeline = aggregationDefinition .getAggregationPipeline ();
2210
2213
2211
2214
if (LOGGER .isDebugEnabled ()) {
2212
- LOGGER .debug ("Streaming aggregation: {} in collection {}" , serializeToJsonSafely (pipeline ), collectionName );
2215
+ LOGGER .debug (
2216
+ String .format ("Streaming aggregation: %s in collection %s" , serializeToJsonSafely (pipeline ), collectionName ));
2213
2217
}
2214
2218
2215
2219
ReadDocumentCallback <O > readCallback = new ReadDocumentCallback <>(mongoConverter , outputType , collectionName );
@@ -2455,8 +2459,8 @@ protected MongoCollection<Document> doCreateCollection(String collectionName, Do
2455
2459
2456
2460
// TODO: Emit a collection created event
2457
2461
if (LOGGER .isDebugEnabled ()) {
2458
- LOGGER .debug ("Created collection [{} ]" ,
2459
- coll .getNamespace () != null ? coll .getNamespace ().getCollectionName () : collectionName );
2462
+ LOGGER .debug (String . format ( "Created collection [%s ]" ,
2463
+ coll .getNamespace () != null ? coll .getNamespace ().getCollectionName () : collectionName )) ;
2460
2464
}
2461
2465
return coll ;
2462
2466
});
@@ -2499,8 +2503,8 @@ protected <T> T doFindOne(String collectionName, Document query, Document fields
2499
2503
Document mappedQuery = queryContext .getMappedQuery (entity );
2500
2504
2501
2505
if (LOGGER .isDebugEnabled ()) {
2502
- LOGGER .debug ("findOne using query: {} fields: {} for class: {} in collection: {}" , serializeToJsonSafely ( query ) ,
2503
- mappedFields , entityClass , collectionName );
2506
+ LOGGER .debug (String . format ( "findOne using query: %s fields: %s for class: %s in collection: %s" ,
2507
+ serializeToJsonSafely ( query ), mappedFields , entityClass , collectionName ) );
2504
2508
}
2505
2509
2506
2510
return executeFindOneInternal (new FindOneCallback (mappedQuery , mappedFields , preparer ),
@@ -2551,8 +2555,8 @@ protected <S, T> List<T> doFind(String collectionName, Document query, Document
2551
2555
Document mappedQuery = queryContext .getMappedQuery (entity );
2552
2556
2553
2557
if (LOGGER .isDebugEnabled ()) {
2554
- LOGGER .debug ("find using query: {} fields: {} for class: {} in collection: {} " ,
2555
- serializeToJsonSafely (mappedQuery ), mappedFields , entityClass , collectionName );
2558
+ LOGGER .debug (String . format ( "find using query: %s fields: %s for class: %s in collection: %s " ,
2559
+ serializeToJsonSafely (mappedQuery ), mappedFields , entityClass , collectionName )) ;
2556
2560
}
2557
2561
2558
2562
return executeFindMultiInternal (new FindCallback (mappedQuery , mappedFields , null ),
@@ -2575,8 +2579,8 @@ <S, T> List<T> doFind(String collectionName, Document query, Document fields, Cl
2575
2579
Document mappedQuery = queryContext .getMappedQuery (entity );
2576
2580
2577
2581
if (LOGGER .isDebugEnabled ()) {
2578
- LOGGER .debug ("find using query: {} fields: {} for class: {} in collection: {} " ,
2579
- serializeToJsonSafely (mappedQuery ), mappedFields , sourceClass , collectionName );
2582
+ LOGGER .debug (String . format ( "find using query: %s fields: %s for class: %s in collection: %s " ,
2583
+ serializeToJsonSafely (mappedQuery ), mappedFields , sourceClass , collectionName )) ;
2580
2584
}
2581
2585
2582
2586
return executeFindMultiInternal (new FindCallback (mappedQuery , mappedFields , null ), preparer ,
@@ -2678,8 +2682,8 @@ protected <T> T doFindAndRemove(String collectionName, Document query, Document
2678
2682
EntityReader <? super T , Bson > readerToUse = this .mongoConverter ;
2679
2683
2680
2684
if (LOGGER .isDebugEnabled ()) {
2681
- LOGGER .debug ("findAndRemove using query: {} fields: {} sort: {} for class: {} in collection: {} " ,
2682
- serializeToJsonSafely (query ), fields , sort , entityClass , collectionName );
2685
+ LOGGER .debug (String . format ( "findAndRemove using query: %s fields: %s sort: %s for class: %s in collection: %s " ,
2686
+ serializeToJsonSafely (query ), fields , sort , entityClass , collectionName )) ;
2683
2687
}
2684
2688
2685
2689
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (entityClass );
@@ -2709,10 +2713,10 @@ protected <T> T doFindAndModify(String collectionName, Document query, Document
2709
2713
: updateContext .getMappedUpdate (entity );
2710
2714
2711
2715
if (LOGGER .isDebugEnabled ()) {
2712
- LOGGER .debug (
2713
- "findAndModify using query: {} fields: {} sort: {} for class: {} and update: {} " + " in collection: {} " ,
2716
+ LOGGER .debug (String . format (
2717
+ "findAndModify using query: %s fields: %s sort: %s for class: %s and update: %s in collection: %s " ,
2714
2718
serializeToJsonSafely (mappedQuery ), fields , sort , entityClass , serializeToJsonSafely (mappedUpdate ),
2715
- collectionName );
2719
+ collectionName )) ;
2716
2720
}
2717
2721
2718
2722
return executeFindOneInternal (
@@ -2742,10 +2746,10 @@ protected <T> T doFindAndReplace(String collectionName, Document mappedQuery, Do
2742
2746
Document replacement , FindAndReplaceOptions options , Class <T > resultType ) {
2743
2747
2744
2748
if (LOGGER .isDebugEnabled ()) {
2745
- LOGGER .debug (
2746
- "findAndReplace using query: {} fields: {} sort: {} for class: {} and replacement: {} " + "in collection: {} " ,
2749
+ LOGGER .debug (String . format (
2750
+ "findAndReplace using query: %s fields: %s sort: %s for class: %s and replacement: %s " + "in collection: %s " ,
2747
2751
serializeToJsonSafely (mappedQuery ), serializeToJsonSafely (mappedFields ), serializeToJsonSafely (mappedSort ),
2748
- entityType , serializeToJsonSafely (replacement ), collectionName );
2752
+ entityType , serializeToJsonSafely (replacement ), collectionName )) ;
2749
2753
}
2750
2754
2751
2755
return executeFindOneInternal (
@@ -2937,9 +2941,10 @@ public Document doInCollection(MongoCollection<Document> collection) throws Mong
2937
2941
2938
2942
if (LOGGER .isDebugEnabled ()) {
2939
2943
2940
- LOGGER .debug ("findOne using query: {} fields: {} in db.collection: {}" , serializeToJsonSafely (query ),
2944
+ LOGGER .debug (String .format ("findOne using query: %s fields: %s in db.collection: %s" ,
2945
+ serializeToJsonSafely (query ),
2941
2946
serializeToJsonSafely (fields .orElseGet (Document ::new )),
2942
- collection .getNamespace () != null ? collection .getNamespace ().getFullName () : "n/a" );
2947
+ collection .getNamespace () != null ? collection .getNamespace ().getFullName () : "n/a" )) ;
2943
2948
}
2944
2949
2945
2950
if (fields .isPresent ()) {
0 commit comments