|
19 | 19 | import java.util.concurrent.FutureTask;
|
20 | 20 |
|
21 | 21 | import javax.sql.DataSource;
|
| 22 | +import javax.annotation.concurrent.Immutable; |
22 | 23 |
|
23 | 24 | import org.slf4j.Logger;
|
24 | 25 | import org.slf4j.LoggerFactory;
|
@@ -383,24 +384,37 @@ private Map<Integer, Object[]> partitionArguments(final DataSourceProvider dataS
|
383 | 384 | return argumentsByShardId;
|
384 | 385 | }
|
385 | 386 |
|
386 |
| - private static class Call implements Callable<Object> { |
387 |
| - private final StoredProcedure sproc; |
| 387 | + @Immutable |
| 388 | + private static final class Call implements Callable<Object> { |
| 389 | + |
| 390 | + private final Executor executor; |
388 | 391 | private final DataSource shardDs;
|
| 392 | + private final String query; |
389 | 393 | private final Object[] params;
|
| 394 | + private final int[] types; |
390 | 395 | private final InvocationContext invocation;
|
| 396 | + private final Class<?> returnType; |
| 397 | + |
| 398 | + Call(final Executor executor, |
| 399 | + final DataSource shardDs, |
| 400 | + final String query, |
| 401 | + final Object[] params, |
| 402 | + final int[] types, |
| 403 | + final InvocationContext invocation, |
| 404 | + final Class<?> returnType) { |
391 | 405 |
|
392 |
| - public Call(final StoredProcedure sproc, final DataSource shardDs, final Object[] params, |
393 |
| - final InvocationContext invocation) { |
394 |
| - this.sproc = sproc; |
| 406 | + this.executor = executor; |
395 | 407 | this.shardDs = shardDs;
|
| 408 | + this.query = query; |
396 | 409 | this.params = params;
|
| 410 | + this.types = types; |
397 | 411 | this.invocation = invocation;
|
| 412 | + this.returnType = returnType; |
398 | 413 | }
|
399 | 414 |
|
400 | 415 | @Override
|
401 | 416 | public Object call() throws Exception {
|
402 |
| - return sproc.executor.executeSProc(shardDs, sproc.getQuery(), params, sproc.getTypes(), invocation, |
403 |
| - sproc.returnType); |
| 417 | + return executor.executeSProc(shardDs, query, params, types, invocation, returnType); |
404 | 418 | }
|
405 | 419 |
|
406 | 420 | }
|
@@ -576,18 +590,25 @@ private Object executeInParallel(final DataSourceProvider dp, final InvocationCo
|
576 | 590 | final List<Integer> shardIds, final List<Object[]> paramValues,
|
577 | 591 | final Map<Integer, SameConnectionDatasource> transactionalDatasources, final List<?> results,
|
578 | 592 | Object sprocResult) {
|
579 |
| - DataSource shardDs; |
| 593 | + |
580 | 594 | final Map<Integer, FutureTask<Object>> tasks = Maps.newHashMapWithExpectedSize(shardIds.size());
|
581 |
| - FutureTask<Object> task; |
582 | 595 | int i = 0;
|
583 | 596 |
|
584 | 597 | for (final int shardId : shardIds) {
|
585 |
| - shardDs = getShardDs(dp, transactionalDatasources, shardId); |
| 598 | + final DataSource shardDs = getShardDs(dp, transactionalDatasources, shardId); |
586 | 599 | if (LOG.isDebugEnabled()) {
|
587 | 600 | LOG.debug(getDebugLog(paramValues.get(i)));
|
588 | 601 | }
|
589 | 602 |
|
590 |
| - task = new FutureTask<Object>(new Call(this, shardDs, paramValues.get(i), invocation)); |
| 603 | + final FutureTask<Object> task = new FutureTask<>(new Call( |
| 604 | + executor, |
| 605 | + shardDs, |
| 606 | + getQuery(), |
| 607 | + paramValues.get(i), |
| 608 | + getTypes(), |
| 609 | + invocation, |
| 610 | + returnType |
| 611 | + )); |
591 | 612 | tasks.put(shardId, task);
|
592 | 613 | parallelThreadPool.execute(task);
|
593 | 614 | i++;
|
|
0 commit comments