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