Skip to content

Commit 31aa533

Browse files
GH-37 Reorganize StoredProcedure private members
1 parent 686aa1e commit 31aa533

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ class StoredProcedure {
7272

7373
private final Class<?> returnType;
7474

75+
private final VirtualShardKeyStrategy shardStrategy;
76+
private final List<ShardKeyParameter> shardKeyParameters;
77+
private final boolean autoPartition;
78+
7579
// whether the result type is a collection (List)
7680
private final boolean collectionResult;
7781
private final boolean runOnAllShards;
7882
private final boolean searchShards;
79-
private final boolean autoPartition;
8083
private final boolean parallel;
8184
private final boolean readOnly;
8285
private final WriteTransaction writeTransaction;
8386

8487
private final Executor executor;
8588

86-
private final VirtualShardKeyStrategy shardStrategy;
87-
private final List<ShardKeyParameter> shardKeyParameters;
88-
8989
private static final Executor MULTI_ROW_SIMPLE_TYPE_EXECUTOR = new MultiRowSimpleTypeExecutor();
9090
private static final Executor MULTI_ROW_TYPE_MAPPER_EXECUTOR = new MultiRowTypeMapperExecutor();
9191
private static final Executor SINGLE_ROW_SIMPLE_TYPE_EXECUTOR = new SingleRowSimpleTypeExecutor();
@@ -106,6 +106,10 @@ public StoredProcedure(final String name, final String query, final List<StoredP
106106
this.sqlParameterList = createSqlParameterList(params);
107107
this.query = (query != null ? query : defaultQuery(name, sqlParameterList));
108108

109+
this.shardStrategy = sStrategy;
110+
this.shardKeyParameters = new ArrayList<>(shardKeyParameters);
111+
this.autoPartition = isAutoPartition(shardKeyParameters);
112+
109113
this.runOnAllShards = runOnAllShards;
110114
this.searchShards = searchShards;
111115
this.parallel = parallel;
@@ -115,11 +119,6 @@ public StoredProcedure(final String name, final String query, final List<StoredP
115119
this.adivsoryLock = advisoryLock;
116120
this.timeout = timeout;
117121

118-
this.shardStrategy = sStrategy;
119-
this.shardKeyParameters = new ArrayList<>(shardKeyParameters);
120-
121-
this.autoPartition = isAutoPartition(shardKeyParameters);
122-
123122
ValueTransformer<?, ?> valueTransformerForClass = null;
124123
Executor exec;
125124
if (genericType instanceof ParameterizedType) {
@@ -246,6 +245,10 @@ public String getSqlParameterList() {
246245
return sqlParameterList;
247246
}
248247

248+
public String getQuery() {
249+
return query;
250+
}
251+
249252
private static String createSqlParameterList(final List<StoredProcedureParameter> params) {
250253
String s = "";
251254
boolean first = true;
@@ -262,14 +265,19 @@ private static String createSqlParameterList(final List<StoredProcedureParameter
262265
return s;
263266
}
264267

265-
public String getQuery() {
266-
return query;
267-
}
268-
269268
private static String defaultQuery(final String name, final String sqlParameterList) {
270269
return "SELECT * FROM " + name + " ( " + sqlParameterList + " )";
271270
}
272271

272+
private static boolean isAutoPartition(final List<ShardKeyParameter> shardKeyParameters) {
273+
for (ShardKeyParameter p : shardKeyParameters) {
274+
if (List.class.isAssignableFrom(p.getType())) {
275+
return true;
276+
}
277+
}
278+
return false;
279+
}
280+
273281
/**
274282
* build execution string like create_or_update_multiple_objects({"(a,b)","(c,d)" }).
275283
*
@@ -376,15 +384,6 @@ private Map<Integer, Object[]> partitionArguments(final DataSourceProvider dataS
376384
return argumentsByShardId;
377385
}
378386

379-
private boolean isAutoPartition(final List<ShardKeyParameter> shardKeyParameters) {
380-
for (ShardKeyParameter p : shardKeyParameters) {
381-
if (List.class.isAssignableFrom(p.getType())) {
382-
return true;
383-
}
384-
}
385-
return false;
386-
}
387-
388387
@Immutable
389388
private static final class Call implements Callable<Object> {
390389

0 commit comments

Comments
 (0)