@@ -398,13 +398,11 @@ public CommandResult doInDB(DB db) throws MongoException, DataAccessException {
398
398
}
399
399
400
400
protected void logCommandExecutionError (final DBObject command , CommandResult result ) {
401
+
401
402
String error = result .getErrorMessage ();
403
+
402
404
if (error != null ) {
403
- // TODO: DATADOC-204 allow configuration of logging level / throw
404
- // throw new
405
- // InvalidDataAccessApiUsageException("Command execution of " +
406
- // command.toString() + " failed: " + error);
407
- LOGGER .warn ("Command execution of " + command .toString () + " failed: " + error );
405
+ LOGGER .warn ("Command execution of {} failed: {}" , command .toString (), error );
408
406
}
409
407
}
410
408
@@ -433,8 +431,8 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback
433
431
DBObject fieldsObject = query .getFieldsObject ();
434
432
435
433
if (LOGGER .isDebugEnabled ()) {
436
- LOGGER .debug (String . format ( "Executing query: %s sort: %s fields: %s in collection: %s" ,
437
- serializeToJsonSafely ( queryObject ), sortObject , fieldsObject , collectionName ) );
434
+ LOGGER .debug ("Executing query: {} sort: {} fields: {} in collection: {}" , serializeToJsonSafely ( queryObject ) ,
435
+ sortObject , fieldsObject , collectionName );
438
436
}
439
437
440
438
this .executeQueryInternal (new FindCallback (queryObject , fieldsObject ), preparer , dch , collectionName );
@@ -532,7 +530,7 @@ public void dropCollection(String collectionName) {
532
530
public Void doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
533
531
collection .drop ();
534
532
if (LOGGER .isDebugEnabled ()) {
535
- LOGGER .debug ("Dropped collection [" + collection .getFullName () + "]" );
533
+ LOGGER .debug ("Dropped collection [{}]" , collection .getFullName ());
536
534
}
537
535
return null ;
538
536
}
@@ -666,8 +664,8 @@ public <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass, String co
666
664
}
667
665
668
666
if (LOGGER .isDebugEnabled ()) {
669
- LOGGER .debug (String . format ( "Executing geoNear using: %s for class: %s in collection: %s" ,
670
- serializeToJsonSafely ( command ), entityClass , collectionName ) );
667
+ LOGGER .debug ("Executing geoNear using: {} for class: {} in collection: {}" , serializeToJsonSafely ( command ) ,
668
+ entityClass , collectionName );
671
669
}
672
670
673
671
CommandResult commandResult = executeCommand (command , this .readPreference );
@@ -1022,9 +1020,11 @@ protected <T> void doSave(String collectionName, T objectToSave, MongoWriter<T>
1022
1020
}
1023
1021
1024
1022
protected Object insertDBObject (final String collectionName , final DBObject dbDoc , final Class <?> entityClass ) {
1023
+
1025
1024
if (LOGGER .isDebugEnabled ()) {
1026
- LOGGER .debug ("Inserting DBObject containing fields: " + dbDoc . keySet () + " in collection: " + collectionName );
1025
+ LOGGER .debug ("Inserting DBObject containing fields: {} in collection: {}" , dbDoc . keySet (), collectionName );
1027
1026
}
1027
+
1028
1028
return execute (collectionName , new CollectionCallback <Object >() {
1029
1029
public Object doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
1030
1030
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .INSERT , collectionName ,
@@ -1044,8 +1044,9 @@ protected List<ObjectId> insertDBObjectList(final String collectionName, final L
1044
1044
}
1045
1045
1046
1046
if (LOGGER .isDebugEnabled ()) {
1047
- LOGGER .debug ("Inserting list of DBObjects containing " + dbDocList .size () + " items" );
1047
+ LOGGER .debug ("Inserting list of DBObjects containing {} items" , dbDocList .size ());
1048
1048
}
1049
+
1049
1050
execute (collectionName , new CollectionCallback <Void >() {
1050
1051
public Void doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
1051
1052
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .INSERT_LIST , collectionName , null ,
@@ -1072,9 +1073,11 @@ public Void doInCollection(DBCollection collection) throws MongoException, DataA
1072
1073
}
1073
1074
1074
1075
protected Object saveDBObject (final String collectionName , final DBObject dbDoc , final Class <?> entityClass ) {
1076
+
1075
1077
if (LOGGER .isDebugEnabled ()) {
1076
- LOGGER .debug ("Saving DBObject containing fields: " + dbDoc .keySet ());
1078
+ LOGGER .debug ("Saving DBObject containing fields: {}" , dbDoc .keySet ());
1077
1079
}
1080
+
1078
1081
return execute (collectionName , new CollectionCallback <Object >() {
1079
1082
public Object doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
1080
1083
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .SAVE , collectionName , entityClass ,
@@ -1140,8 +1143,8 @@ public WriteResult doInCollection(DBCollection collection) throws MongoException
1140
1143
: updateMapper .getMappedObject (update .getUpdateObject (), entity );
1141
1144
1142
1145
if (LOGGER .isDebugEnabled ()) {
1143
- LOGGER .debug (String . format ( "Calling update using query: %s and update: %s in collection: %s " ,
1144
- serializeToJsonSafely (queryObj ), serializeToJsonSafely (updateObj ), collectionName )) ;
1146
+ LOGGER .debug ("Calling update using query: {} and update: {} in collection: {} " ,
1147
+ serializeToJsonSafely (queryObj ), serializeToJsonSafely (updateObj ), collectionName );
1145
1148
}
1146
1149
1147
1150
MongoAction mongoAction = new MongoAction (writeConcern , MongoActionOperation .UPDATE , collectionName ,
@@ -1376,8 +1379,8 @@ public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName
1376
1379
copyMapReduceOptionsToCommand (query , mapReduceOptions , command );
1377
1380
1378
1381
if (LOGGER .isDebugEnabled ()) {
1379
- LOGGER .debug ("Executing MapReduce on collection [" + command . getInput () + " ], mapFunction [" + mapFunc
1380
- + "], reduceFunction [" + reduceFunc + "]" );
1382
+ LOGGER .debug ("Executing MapReduce on collection [{}], mapFunction [{} ], reduceFunction [{}]" , command . getInput (),
1383
+ mapFunc , reduceFunc );
1381
1384
}
1382
1385
1383
1386
MapReduceOutput mapReduceOutput = inputCollection .mapReduce (command );
@@ -1703,8 +1706,8 @@ protected <T> T doFindOne(String collectionName, DBObject query, DBObject fields
1703
1706
DBObject mappedFields = fields == null ? null : queryMapper .getMappedObject (fields , entity );
1704
1707
1705
1708
if (LOGGER .isDebugEnabled ()) {
1706
- LOGGER .debug (String . format ( "findOne using query: %s fields: %s for class: %s in collection: %s" ,
1707
- serializeToJsonSafely ( query ), mappedFields , entityClass , collectionName ) );
1709
+ LOGGER .debug ("findOne using query: {} fields: {} for class: {} in collection: {}" , serializeToJsonSafely ( query ) ,
1710
+ mappedFields , entityClass , collectionName );
1708
1711
}
1709
1712
1710
1713
return executeFindOneInternal (new FindOneCallback (mappedQuery , mappedFields ),
@@ -1754,8 +1757,8 @@ protected <S, T> List<T> doFind(String collectionName, DBObject query, DBObject
1754
1757
DBObject mappedQuery = queryMapper .getMappedObject (query , entity );
1755
1758
1756
1759
if (LOGGER .isDebugEnabled ()) {
1757
- LOGGER .debug (String . format ( "find using query: %s fields: %s for class: %s in collection: %s " ,
1758
- serializeToJsonSafely (mappedQuery ), mappedFields , entityClass , collectionName )) ;
1760
+ LOGGER .debug ("find using query: {} fields: {} for class: {} in collection: {} " ,
1761
+ serializeToJsonSafely (mappedQuery ), mappedFields , entityClass , collectionName );
1759
1762
}
1760
1763
1761
1764
return executeFindMultiInternal (new FindCallback (mappedQuery , mappedFields ), preparer , objectCallback ,
@@ -1791,12 +1794,16 @@ protected DBObject convertToDbObject(CollectionOptions collectionOptions) {
1791
1794
*/
1792
1795
protected <T > T doFindAndRemove (String collectionName , DBObject query , DBObject fields , DBObject sort ,
1793
1796
Class <T > entityClass ) {
1797
+
1794
1798
EntityReader <? super T , DBObject > readerToUse = this .mongoConverter ;
1799
+
1795
1800
if (LOGGER .isDebugEnabled ()) {
1796
- LOGGER .debug (String . format ( "findAndRemove using query: %s fields: %s sort: %s for class: %s in collection: %s " ,
1797
- serializeToJsonSafely (query ), fields , sort , entityClass , collectionName )) ;
1801
+ LOGGER .debug ("findAndRemove using query: {} fields: {} sort: {} for class: {} in collection: {} " ,
1802
+ serializeToJsonSafely (query ), fields , sort , entityClass , collectionName );
1798
1803
}
1804
+
1799
1805
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (entityClass );
1806
+
1800
1807
return executeFindOneInternal (new FindAndRemoveCallback (queryMapper .getMappedObject (query , entity ), fields , sort ),
1801
1808
new ReadDbObjectCallback <T >(readerToUse , entityClass , collectionName ), collectionName );
1802
1809
}
@@ -1818,13 +1825,10 @@ protected <T> T doFindAndModify(String collectionName, DBObject query, DBObject
1818
1825
DBObject mappedUpdate = updateMapper .getMappedObject (update .getUpdateObject (), entity );
1819
1826
1820
1827
if (LOGGER .isDebugEnabled ()) {
1821
- LOGGER
1822
- .debug (
1823
- String .format (
1824
- "findAndModify using query: %s fields: %s sort: %s for class: %s and update: %s "
1825
- + "in collection: %s" ,
1826
- serializeToJsonSafely (mappedQuery ), fields , sort , entityClass , serializeToJsonSafely (mappedUpdate ),
1827
- collectionName ));
1828
+ LOGGER .debug (
1829
+ "findAndModify using query: {} fields: {} sort: {} for class: {} and update: {} " + "in collection: {}" ,
1830
+ serializeToJsonSafely (mappedQuery ), fields , sort , entityClass , serializeToJsonSafely (mappedUpdate ),
1831
+ collectionName );
1828
1832
}
1829
1833
1830
1834
return executeFindOneInternal (new FindAndModifyCallback (mappedQuery , fields , sort , mappedUpdate , options ),
@@ -2134,14 +2138,14 @@ public FindOneCallback(DBObject query, DBObject fields) {
2134
2138
public DBObject doInCollection (DBCollection collection ) throws MongoException , DataAccessException {
2135
2139
if (fields == null ) {
2136
2140
if (LOGGER .isDebugEnabled ()) {
2137
- LOGGER .debug (String . format ( "findOne using query: %s in db.collection: %s " , serializeToJsonSafely (query ),
2138
- collection .getFullName ())) ;
2141
+ LOGGER .debug ("findOne using query: {} in db.collection: {} " , serializeToJsonSafely (query ),
2142
+ collection .getFullName ());
2139
2143
}
2140
2144
return collection .findOne (query );
2141
2145
} else {
2142
2146
if (LOGGER .isDebugEnabled ()) {
2143
- LOGGER .debug (String . format ( "findOne using query: %s fields: %s in db.collection: %s" ,
2144
- serializeToJsonSafely ( query ), fields , collection .getFullName () ));
2147
+ LOGGER .debug ("findOne using query: {} fields: {} in db.collection: {}" , serializeToJsonSafely ( query ), fields ,
2148
+ collection .getFullName ());
2145
2149
}
2146
2150
return collection .findOne (query , fields );
2147
2151
}
0 commit comments