Skip to content

Commit 1d118ee

Browse files
GH-37 Refactor Call into anonymous class
1 parent 468009c commit 1d118ee

File tree

1 file changed

+9
-42
lines changed

1 file changed

+9
-42
lines changed

src/main/java/de/zalando/sprocwrapper/proxy/StoredProcedure.java

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -376,39 +376,14 @@ private Map<Integer, Object[]> partitionArguments(final DataSourceProvider dataS
376376
return argumentsByShardId;
377377
}
378378

379-
@Immutable
380-
private static final class Call implements Callable<Object> {
381-
382-
private final Executor executor;
383-
private final DataSource shardDs;
384-
private final String query;
385-
private final Object[] params;
386-
private final int[] types;
387-
private final InvocationContext invocation;
388-
private final Class<?> returnType;
389-
390-
Call(final Executor executor,
391-
final DataSource shardDs,
392-
final String query,
393-
final Object[] params,
394-
final int[] types,
395-
final InvocationContext invocation,
396-
final Class<?> returnType) {
397-
398-
this.executor = executor;
399-
this.shardDs = shardDs;
400-
this.query = query;
401-
this.params = params;
402-
this.types = types;
403-
this.invocation = invocation;
404-
this.returnType = returnType;
405-
}
406-
407-
@Override
408-
public Object call() throws Exception {
409-
return executor.executeSProc(shardDs, query, params, types, invocation, returnType);
410-
}
411-
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+
};
412387
}
413388

414389
private static ExecutorService parallelThreadPool = Executors.newCachedThreadPool();
@@ -592,15 +567,7 @@ private Object executeInParallel(final DataSourceProvider dp, final InvocationCo
592567
LOG.debug(getDebugLog(paramValues.get(i)));
593568
}
594569

595-
final FutureTask<Object> task = new FutureTask<>(new Call(
596-
executor,
597-
shardDs,
598-
query,
599-
paramValues.get(i),
600-
types,
601-
invocation,
602-
returnType
603-
));
570+
final FutureTask<Object> task = new FutureTask<>(with(shardDs, paramValues.get(i), invocation));
604571
tasks.put(shardId, task);
605572
parallelThreadPool.execute(task);
606573
i++;

0 commit comments

Comments
 (0)