@@ -396,13 +396,11 @@ public CommandResult doInDB(DB db) throws MongoException, DataAccessException {
396
396
}
397
397
398
398
protected void logCommandExecutionError (final DBObject command , CommandResult result ) {
399
+
399
400
String error = result .getErrorMessage ();
401
+
400
402
if (error != null ) {
401
- // TODO: DATADOC-204 allow configuration of logging level / throw
402
- // throw new
403
- // InvalidDataAccessApiUsageException("Command execution of " +
404
- // command.toString() + " failed: " + error);
405
- LOGGER .warn ("Command execution of " + command .toString () + " failed: " + error );
403
+ LOGGER .warn ("Command execution of {} failed: {}" , command .toString (), error );
406
404
}
407
405
}
408
406
@@ -430,8 +428,8 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback
430
428
DBObject fieldsObject = query .getFieldsObject ();
431
429
432
430
if (LOGGER .isDebugEnabled ()) {
433
- LOGGER .debug (String . format ( "Executing query: %s sort: %s fields: %s in collection: %s" ,
434
- serializeToJsonSafely ( queryObject ), sortObject , fieldsObject , collectionName ) );
431
+ LOGGER .debug ("Executing query: {} sort: {} fields: {} in collection: {}" , serializeToJsonSafely ( queryObject ) ,
432
+ sortObject , fieldsObject , collectionName );
435
433
}
436
434
437
435
this .executeQueryInternal (new FindCallback (queryObject , fieldsObject ), preparer , dch , collectionName );
@@ -529,7 +527,7 @@ public void dropCollection(String collectionName) {
529
527
public Void doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
530
528
collection .drop ();
531
529
if (LOGGER .isDebugEnabled ()) {
532
- LOGGER .debug ("Dropped collection [" + collection .getFullName () + "]" );
530
+ LOGGER .debug ("Dropped collection [{}]" , collection .getFullName ());
533
531
}
534
532
return null ;
535
533
}
@@ -641,8 +639,8 @@ public <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass, String co
641
639
}
642
640
643
641
if (LOGGER .isDebugEnabled ()) {
644
- LOGGER .debug (String . format ( "Executing geoNear using: %s for class: %s in collection: %s" ,
645
- serializeToJsonSafely ( command ), entityClass , collectionName ) );
642
+ LOGGER .debug ("Executing geoNear using: {} for class: {} in collection: {}" , serializeToJsonSafely ( command ) ,
643
+ entityClass , collectionName );
646
644
}
647
645
648
646
CommandResult commandResult = executeCommand (command , this .readPreference );
@@ -996,9 +994,11 @@ protected <T> void doSave(String collectionName, T objectToSave, MongoWriter<T>
996
994
}
997
995
998
996
protected Object insertDBObject (final String collectionName , final DBObject dbDoc , final Class <?> entityClass ) {
997
+
999
998
if (LOGGER .isDebugEnabled ()) {
1000
- LOGGER .debug ("Inserting DBObject containing fields: " + dbDoc . keySet () + " in collection: " + collectionName );
999
+ LOGGER .debug ("Inserting DBObject containing fields: {} in collection: {}" , dbDoc . keySet (), collectionName );
1001
1000
}
1001
+
1002
1002
return execute (collectionName , new CollectionCallback <Object >() {
1003
1003
public Object doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
1004
1004
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .INSERT , collectionName ,
@@ -1018,8 +1018,9 @@ protected List<ObjectId> insertDBObjectList(final String collectionName, final L
1018
1018
}
1019
1019
1020
1020
if (LOGGER .isDebugEnabled ()) {
1021
- LOGGER .debug ("Inserting list of DBObjects containing " + dbDocList .size () + " items" );
1021
+ LOGGER .debug ("Inserting list of DBObjects containing {} items" , dbDocList .size ());
1022
1022
}
1023
+
1023
1024
execute (collectionName , new CollectionCallback <Void >() {
1024
1025
public Void doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
1025
1026
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .INSERT_LIST , collectionName , null ,
@@ -1046,9 +1047,11 @@ public Void doInCollection(DBCollection collection) throws MongoException, DataA
1046
1047
}
1047
1048
1048
1049
protected Object saveDBObject (final String collectionName , final DBObject dbDoc , final Class <?> entityClass ) {
1050
+
1049
1051
if (LOGGER .isDebugEnabled ()) {
1050
- LOGGER .debug ("Saving DBObject containing fields: " + dbDoc .keySet ());
1052
+ LOGGER .debug ("Saving DBObject containing fields: {}" , dbDoc .keySet ());
1051
1053
}
1054
+
1052
1055
return execute (collectionName , new CollectionCallback <Object >() {
1053
1056
public Object doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
1054
1057
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .SAVE , collectionName , entityClass ,
@@ -1114,8 +1117,8 @@ public WriteResult doInCollection(DBCollection collection) throws MongoException
1114
1117
update .getUpdateObject (), entity );
1115
1118
1116
1119
if (LOGGER .isDebugEnabled ()) {
1117
- LOGGER .debug (String . format ( "Calling update using query: %s and update: %s in collection: %s " ,
1118
- serializeToJsonSafely (queryObj ), serializeToJsonSafely (updateObj ), collectionName )) ;
1120
+ LOGGER .debug ("Calling update using query: {} and update: {} in collection: {} " ,
1121
+ serializeToJsonSafely (queryObj ), serializeToJsonSafely (updateObj ), collectionName );
1119
1122
}
1120
1123
1121
1124
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .UPDATE , collectionName ,
@@ -1350,8 +1353,8 @@ public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName
1350
1353
copyMapReduceOptionsToCommand (query , mapReduceOptions , command );
1351
1354
1352
1355
if (LOGGER .isDebugEnabled ()) {
1353
- LOGGER .debug ("Executing MapReduce on collection [" + command . getInput () + " ], mapFunction [" + mapFunc
1354
- + "], reduceFunction [" + reduceFunc + "]" );
1356
+ LOGGER .debug ("Executing MapReduce on collection [{}], mapFunction [{} ], reduceFunction [{}]" , command . getInput (),
1357
+ mapFunc , reduceFunc );
1355
1358
}
1356
1359
1357
1360
MapReduceOutput mapReduceOutput = inputCollection .mapReduce (command );
@@ -1675,8 +1678,8 @@ protected <T> T doFindOne(String collectionName, DBObject query, DBObject fields
1675
1678
DBObject mappedFields = fields == null ? null : queryMapper .getMappedObject (fields , entity );
1676
1679
1677
1680
if (LOGGER .isDebugEnabled ()) {
1678
- LOGGER .debug (String . format ( "findOne using query: %s fields: %s for class: %s in collection: %s" ,
1679
- serializeToJsonSafely ( query ), mappedFields , entityClass , collectionName ) );
1681
+ LOGGER .debug ("findOne using query: {} fields: {} for class: {} in collection: {}" , serializeToJsonSafely ( query ) ,
1682
+ mappedFields , entityClass , collectionName );
1680
1683
}
1681
1684
1682
1685
return executeFindOneInternal (new FindOneCallback (mappedQuery , mappedFields ), new ReadDbObjectCallback <T >(
@@ -1726,8 +1729,8 @@ protected <S, T> List<T> doFind(String collectionName, DBObject query, DBObject
1726
1729
DBObject mappedQuery = queryMapper .getMappedObject (query , entity );
1727
1730
1728
1731
if (LOGGER .isDebugEnabled ()) {
1729
- LOGGER .debug (String . format ( "find using query: %s fields: %s for class: %s in collection: %s " ,
1730
- serializeToJsonSafely (mappedQuery ), mappedFields , entityClass , collectionName )) ;
1732
+ LOGGER .debug ("find using query: {} fields: {} for class: {} in collection: {} " ,
1733
+ serializeToJsonSafely (mappedQuery ), mappedFields , entityClass , collectionName );
1731
1734
}
1732
1735
1733
1736
return executeFindMultiInternal (new FindCallback (mappedQuery , mappedFields ), preparer , objectCallback ,
@@ -1763,12 +1766,16 @@ protected DBObject convertToDbObject(CollectionOptions collectionOptions) {
1763
1766
*/
1764
1767
protected <T > T doFindAndRemove (String collectionName , DBObject query , DBObject fields , DBObject sort ,
1765
1768
Class <T > entityClass ) {
1769
+
1766
1770
EntityReader <? super T , DBObject > readerToUse = this .mongoConverter ;
1771
+
1767
1772
if (LOGGER .isDebugEnabled ()) {
1768
- LOGGER .debug (String . format ( "findAndRemove using query: %s fields: %s sort: %s for class: %s in collection: %s " ,
1769
- serializeToJsonSafely (query ), fields , sort , entityClass , collectionName )) ;
1773
+ LOGGER .debug ("findAndRemove using query: {} fields: {} sort: {} for class: {} in collection: {} " ,
1774
+ serializeToJsonSafely (query ), fields , sort , entityClass , collectionName );
1770
1775
}
1776
+
1771
1777
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (entityClass );
1778
+
1772
1779
return executeFindOneInternal (new FindAndRemoveCallback (queryMapper .getMappedObject (query , entity ), fields , sort ),
1773
1780
new ReadDbObjectCallback <T >(readerToUse , entityClass ), collectionName );
1774
1781
}
@@ -1790,9 +1797,10 @@ protected <T> T doFindAndModify(String collectionName, DBObject query, DBObject
1790
1797
DBObject mappedUpdate = updateMapper .getMappedObject (update .getUpdateObject (), entity );
1791
1798
1792
1799
if (LOGGER .isDebugEnabled ()) {
1793
- LOGGER .debug (String .format ("findAndModify using query: %s fields: %s sort: %s for class: %s and update: %s "
1794
- + "in collection: %s" , serializeToJsonSafely (mappedQuery ), fields , sort , entityClass ,
1795
- serializeToJsonSafely (mappedUpdate ), collectionName ));
1800
+ LOGGER .debug (
1801
+ "findAndModify using query: {} fields: {} sort: {} for class: {} and update: {} " + "in collection: {}" ,
1802
+ serializeToJsonSafely (mappedQuery ), fields , sort , entityClass , serializeToJsonSafely (mappedUpdate ),
1803
+ collectionName );
1796
1804
}
1797
1805
1798
1806
return executeFindOneInternal (new FindAndModifyCallback (mappedQuery , fields , sort , mappedUpdate , options ),
@@ -2102,14 +2110,14 @@ public FindOneCallback(DBObject query, DBObject fields) {
2102
2110
public DBObject doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
2103
2111
if (fields == null ) {
2104
2112
if (LOGGER .isDebugEnabled ()) {
2105
- LOGGER .debug (String . format ( "findOne using query: %s in db.collection: %s " , serializeToJsonSafely (query ),
2106
- collection .getFullName ())) ;
2113
+ LOGGER .debug ("findOne using query: {} in db.collection: {} " , serializeToJsonSafely (query ),
2114
+ collection .getFullName ());
2107
2115
}
2108
2116
return collection .findOne (query );
2109
2117
} else {
2110
2118
if (LOGGER .isDebugEnabled ()) {
2111
- LOGGER .debug (String . format ( "findOne using query: %s fields: %s in db.collection: %s" ,
2112
- serializeToJsonSafely ( query ), fields , collection .getFullName () ));
2119
+ LOGGER .debug ("findOne using query: {} fields: {} in db.collection: {}" , serializeToJsonSafely ( query ), fields ,
2120
+ collection .getFullName ());
2113
2121
}
2114
2122
return collection .findOne (query , fields );
2115
2123
}
0 commit comments