@@ -91,6 +91,8 @@ class StoredProcedure {
91
91
private static final Executor SINGLE_ROW_SIMPLE_TYPE_EXECUTOR = new SingleRowSimpleTypeExecutor ();
92
92
private static final Executor SINGLE_ROW_TYPE_MAPPER_EXECUTOR = new SingleRowTypeMapperExecutor ();
93
93
94
+ private static final ExecutorService PARALLEL_THREAD_POOL = Executors .newCachedThreadPool ();
95
+
94
96
private final long timeout ;
95
97
private final AdvisoryLock adivsoryLock ;
96
98
@@ -376,18 +378,6 @@ private Map<Integer, Object[]> partitionArguments(final DataSourceProvider dataS
376
378
return argumentsByShardId ;
377
379
}
378
380
379
- private Callable <Object > with (final DataSource shardDs , final Object [] params , final InvocationContext invocation ) {
380
- final StoredProcedure sproc = this ;
381
- return new Callable <Object >() {
382
- @ Override
383
- public Object call () throws Exception {
384
- return sproc .executor .executeSProc (shardDs , sproc .query , params , sproc .types , invocation , sproc .returnType );
385
- }
386
- };
387
- }
388
-
389
- private static ExecutorService parallelThreadPool = Executors .newCachedThreadPool ();
390
-
391
381
public Object execute (final DataSourceProvider dp , final InvocationContext invocation ) {
392
382
393
383
List <Integer > shardIds = null ;
@@ -443,7 +433,7 @@ public Object execute(final DataSourceProvider dp, final InvocationContext invoc
443
433
}
444
434
445
435
// most common case: only one shard and no argument partitioning
446
- return executor . executeSProc (firstDs , query , paramValues .get (0 ), types , invocation , returnType );
436
+ return execute (firstDs , paramValues .get (0 ), invocation );
447
437
} else {
448
438
Map <Integer , SameConnectionDatasource > transactionalDatasources = null ;
449
439
try {
@@ -528,8 +518,7 @@ private Object executeSequential(final DataSourceProvider dp, final InvocationCo
528
518
529
519
sprocResult = null ;
530
520
try {
531
- sprocResult = executor .executeSProc (shardDs , query , paramValues .get (i ), types , invocation ,
532
- returnType );
521
+ sprocResult = execute (shardDs , paramValues .get (i ), invocation );
533
522
} catch (final Exception e ) {
534
523
535
524
// remember all exceptions and go on
@@ -569,7 +558,7 @@ private Object executeInParallel(final DataSourceProvider dp, final InvocationCo
569
558
570
559
final FutureTask <Object > task = new FutureTask <>(with (shardDs , paramValues .get (i ), invocation ));
571
560
tasks .put (shardId , task );
572
- parallelThreadPool .execute (task );
561
+ PARALLEL_THREAD_POOL .execute (task );
573
562
i ++;
574
563
}
575
564
@@ -605,6 +594,19 @@ private Object executeInParallel(final DataSourceProvider dp, final InvocationCo
605
594
return sprocResult ;
606
595
}
607
596
597
+ private Callable <Object > with (final DataSource shardDs , final Object [] params , final InvocationContext invocation ) {
598
+ return new Callable <Object >() {
599
+ @ Override
600
+ public Object call () throws Exception {
601
+ return StoredProcedure .this .execute (shardDs , params , invocation );
602
+ }
603
+ };
604
+ }
605
+
606
+ private Object execute (final DataSource shardDs , final Object [] params , final InvocationContext invocation ) {
607
+ return executor .executeSProc (shardDs , query , params , types , invocation , returnType );
608
+ }
609
+
608
610
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
609
611
private boolean addResultsBreakWhenSharded (final Collection results , final Object sprocResult ) {
610
612
boolean breakSearch = false ;
0 commit comments