@@ -242,29 +242,30 @@ OperationResult executeListCollections(final BsonDocument operation) {
242
242
ListCollectionsIterable <BsonDocument > iterable = session == null
243
243
? database .listCollections (BsonDocument .class )
244
244
: database .listCollections (session , BsonDocument .class );
245
- for (Map .Entry <String , BsonValue > cur : arguments .entrySet ()) {
246
- switch (cur .getKey ()) {
247
- case "session" :
248
- break ;
249
- case "filter" :
250
- iterable .filter (cur .getValue ().asDocument ());
251
- break ;
252
- case "batchSize" :
253
- iterable .batchSize (cur .getValue ().asNumber ().intValue ());
254
- break ;
255
- case "timeoutMode" :
256
- setTimeoutMode (iterable , cur );
257
- break ;
258
- case "maxTimeMS" :
259
- iterable .maxTime (cur .getValue ().asNumber ().longValue (), TimeUnit .MILLISECONDS );
260
- break ;
261
- default :
262
- throw new UnsupportedOperationException ("Unsupported argument: " + cur .getKey ());
245
+ return resultOf (() -> {
246
+ for (Map .Entry <String , BsonValue > cur : arguments .entrySet ()) {
247
+ switch (cur .getKey ()) {
248
+ case "session" :
249
+ break ;
250
+ case "filter" :
251
+ iterable .filter (cur .getValue ().asDocument ());
252
+ break ;
253
+ case "batchSize" :
254
+ iterable .batchSize (cur .getValue ().asNumber ().intValue ());
255
+ break ;
256
+ case "timeoutMode" :
257
+ setTimeoutMode (iterable , cur );
258
+ break ;
259
+ case "maxTimeMS" :
260
+ iterable .maxTime (cur .getValue ().asNumber ().longValue (), TimeUnit .MILLISECONDS );
261
+ break ;
262
+ default :
263
+ throw new UnsupportedOperationException ("Unsupported argument: " + cur .getKey ());
264
+ }
263
265
}
264
- }
265
266
266
- return resultOf (() ->
267
- new BsonArray ( iterable . into ( new ArrayList <>())) );
267
+ return new BsonArray ( iterable . into ( new ArrayList <>()));
268
+ } );
268
269
}
269
270
270
271
OperationResult executeListCollectionNames (final BsonDocument operation ) {
@@ -298,17 +299,17 @@ OperationResult executeListCollectionNames(final BsonDocument operation) {
298
299
}
299
300
300
301
OperationResult executeListIndexes (final BsonDocument operation ) {
301
- ListIndexesIterable < BsonDocument > iterable = createListIndexesIterable ( operation );
302
-
303
- return resultOf (() ->
304
- new BsonArray ( iterable . into ( new ArrayList <>())) );
302
+ return resultOf (() -> {
303
+ ListIndexesIterable < BsonDocument > iterable = createListIndexesIterable ( operation );
304
+ return new BsonArray ( iterable . into ( new ArrayList <>()));
305
+ } );
305
306
}
306
307
307
308
OperationResult executeListIndexNames (final BsonDocument operation ) {
308
- ListIndexesIterable < BsonDocument > iterable = createListIndexesIterable ( operation );
309
-
310
- return resultOf (() ->
311
- new BsonArray ( iterable . into ( new ArrayList <>()). stream (). map ( document -> document . getString ( "name" )). collect ( toList ())) );
309
+ return resultOf (() -> {
310
+ ListIndexesIterable < BsonDocument > iterable = createListIndexesIterable ( operation );
311
+ return new BsonArray ( iterable . into ( new ArrayList <>()). stream (). map ( document -> document . getString ( "name" )). collect ( toList ()));
312
+ } );
312
313
}
313
314
314
315
private ListIndexesIterable <BsonDocument > createListIndexesIterable (final BsonDocument operation ) {
@@ -339,19 +340,19 @@ private ListIndexesIterable<BsonDocument> createListIndexesIterable(final BsonDo
339
340
}
340
341
341
342
OperationResult executeFind (final BsonDocument operation ) {
342
- FindIterable <BsonDocument > iterable = createFindIterable (operation );
343
- return resultOf (() ->
344
- new BsonArray (iterable .into (new ArrayList <>())));
343
+ return resultOf (() -> {
344
+ FindIterable <BsonDocument > iterable = createFindIterable (operation );
345
+ return new BsonArray (iterable .into (new ArrayList <>()));
346
+ });
345
347
}
346
348
347
349
OperationResult executeFindOne (final BsonDocument operation ) {
348
- FindIterable <BsonDocument > iterable = createFindIterable (operation );
349
- return resultOf (iterable ::first );
350
+ return resultOf (() -> createFindIterable (operation ).first ());
350
351
}
351
352
352
353
OperationResult createFindCursor (final BsonDocument operation ) {
353
- FindIterable <BsonDocument > iterable = createFindIterable (operation );
354
354
return resultOf (() -> {
355
+ FindIterable <BsonDocument > iterable = createFindIterable (operation );
355
356
entities .addCursor (operation .getString ("saveResultAsEntity" , new BsonString (createRandomEntityId ())).getValue (),
356
357
iterable .cursor ());
357
358
return null ;
@@ -647,40 +648,40 @@ OperationResult executeAggregate(final BsonDocument operation) {
647
648
} else {
648
649
throw new UnsupportedOperationException ("Unsupported entity type with name: " + entityName );
649
650
}
650
- for (Map .Entry <String , BsonValue > cur : arguments .entrySet ()) {
651
- switch (cur .getKey ()) {
652
- case "pipeline" :
653
- case "session" :
654
- break ;
655
- case "batchSize" :
656
- iterable .batchSize (cur .getValue ().asNumber ().intValue ());
657
- break ;
658
- case "allowDiskUse" :
659
- iterable .allowDiskUse (cur .getValue ().asBoolean ().getValue ());
660
- break ;
661
- case "let" :
662
- iterable .let (cur .getValue ().asDocument ());
663
- break ;
664
- case "comment" :
665
- iterable .comment (cur .getValue ());
666
- break ;
667
- case "timeoutMode" :
668
- setTimeoutMode (iterable , cur );
669
- break ;
670
- case "maxTimeMS" :
671
- iterable .maxTime (cur .getValue ().asNumber ().longValue (), TimeUnit .MILLISECONDS );
672
- break ;
673
- case "maxAwaitTimeMS" :
674
- iterable .maxAwaitTime (cur .getValue ().asNumber ().longValue (), TimeUnit .MILLISECONDS );
675
- break ;
676
- default :
677
- throw new UnsupportedOperationException ("Unsupported argument: " + cur .getKey ());
678
- }
679
- }
680
- String lastStageName = pipeline .isEmpty () ? null : pipeline .get (pipeline .size () - 1 ).getFirstKey ();
681
- boolean useToCollection = Objects .equals (lastStageName , "$out" ) || Objects .equals (lastStageName , "$merge" );
682
651
683
652
return resultOf (() -> {
653
+ for (Map .Entry <String , BsonValue > cur : arguments .entrySet ()) {
654
+ switch (cur .getKey ()) {
655
+ case "pipeline" :
656
+ case "session" :
657
+ break ;
658
+ case "batchSize" :
659
+ iterable .batchSize (cur .getValue ().asNumber ().intValue ());
660
+ break ;
661
+ case "allowDiskUse" :
662
+ iterable .allowDiskUse (cur .getValue ().asBoolean ().getValue ());
663
+ break ;
664
+ case "let" :
665
+ iterable .let (cur .getValue ().asDocument ());
666
+ break ;
667
+ case "comment" :
668
+ iterable .comment (cur .getValue ());
669
+ break ;
670
+ case "timeoutMode" :
671
+ setTimeoutMode (iterable , cur );
672
+ break ;
673
+ case "maxTimeMS" :
674
+ iterable .maxTime (cur .getValue ().asNumber ().longValue (), TimeUnit .MILLISECONDS );
675
+ break ;
676
+ case "maxAwaitTimeMS" :
677
+ iterable .maxAwaitTime (cur .getValue ().asNumber ().longValue (), TimeUnit .MILLISECONDS );
678
+ break ;
679
+ default :
680
+ throw new UnsupportedOperationException ("Unsupported argument: " + cur .getKey ());
681
+ }
682
+ }
683
+ String lastStageName = pipeline .isEmpty () ? null : pipeline .get (pipeline .size () - 1 ).getFirstKey ();
684
+ boolean useToCollection = Objects .equals (lastStageName , "$out" ) || Objects .equals (lastStageName , "$merge" );
684
685
if (!pipeline .isEmpty () && useToCollection ) {
685
686
iterable .toCollection ();
686
687
return null ;
@@ -1834,8 +1835,14 @@ private static void invokeTimeoutMode(final MongoIterable<BsonDocument> iterable
1834
1835
timeoutModeMethod .invoke (iterable , timeoutMode );
1835
1836
} catch (NoSuchMethodException e ) {
1836
1837
throw new UnsupportedOperationException ("Unsupported timeoutMode method for class: " + iterable .getClass (), e );
1837
- } catch (InvocationTargetException | IllegalAccessException e ) {
1838
+ } catch (IllegalAccessException e ) {
1838
1839
throw new UnsupportedOperationException ("Unable to set timeoutMode method for class: " + iterable .getClass (), e );
1840
+ } catch (InvocationTargetException e ) {
1841
+ Throwable targetException = e .getTargetException ();
1842
+ if (targetException instanceof IllegalArgumentException ) {
1843
+ throw (IllegalArgumentException ) targetException ;
1844
+ }
1845
+ throw new UnsupportedOperationException ("Unable to set timeoutMode method for class: " + iterable .getClass (), targetException );
1839
1846
}
1840
1847
}
1841
1848
}
0 commit comments