Skip to content

Commit a0b2dc4

Browse files
authored
Merge pull request #23 from sharding-sphere/dev
update from origin
2 parents f00b037 + 3c35015 commit a0b2dc4

File tree

8 files changed

+166
-17
lines changed

8 files changed

+166
-17
lines changed

sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecuteCallback.java

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import io.shardingsphere.core.constant.SQLType;
2121

22+
import java.util.Map;
23+
2224
/**
2325
* Statement execute callback interface.
2426
*
@@ -35,4 +37,18 @@ public interface ExecuteCallback<T> extends ShardingExecuteCallback<BaseStatemen
3537
* @return SQL type
3638
*/
3739
SQLType getSQLType();
40+
41+
/**
42+
* Judge is exception thrown or not.
43+
*
44+
* @return is exception thrown or not
45+
*/
46+
boolean isExceptionThrown();
47+
48+
/**
49+
* Get data map.
50+
*
51+
* @return data map
52+
*/
53+
Map<String, Object> getDataMap();
3854
}

sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.Collections;
3535
import java.util.LinkedList;
3636
import java.util.List;
37-
import java.util.Map;
3837
import java.util.concurrent.ExecutorService;
3938
import java.util.concurrent.Executors;
4039
import java.util.concurrent.TimeUnit;
@@ -97,10 +96,10 @@ public <T> List<T> execute(final Collection<? extends BaseStatementUnit> baseSta
9796
protected abstract <T> List<T> getExecuteResults(Collection<? extends BaseStatementUnit> baseStatementUnits, ExecuteCallback<T> executeCallback) throws Exception;
9897

9998
protected final <T> T executeInternal(
100-
final BaseStatementUnit baseStatementUnit, final ExecuteCallback<T> executeCallback, final boolean isExceptionThrown, final Map<String, Object> dataMap) throws Exception {
99+
final BaseStatementUnit baseStatementUnit, final ExecuteCallback<T> executeCallback) throws Exception {
101100
T result;
102-
ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown);
103-
ExecutorDataMap.setDataMap(dataMap);
101+
ExecutorExceptionHandler.setExceptionThrown(executeCallback.isExceptionThrown());
102+
ExecutorDataMap.setDataMap(executeCallback.getDataMap());
104103
List<SQLExecutionEvent> events = new LinkedList<>();
105104
for (List<Object> each : baseStatementUnit.getSqlExecutionUnit().getSqlUnit().getParameterSets()) {
106105
SQLExecutionEvent event = SQLExecutionEventFactory.createEvent(executeCallback.getSQLType(), baseStatementUnit, each);

sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/batch/BatchPreparedStatementExecutor.java

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import io.shardingsphere.core.executor.BaseStatementUnit;
2323
import io.shardingsphere.core.executor.ExecuteCallback;
2424
import io.shardingsphere.core.executor.ExecutorEngine;
25+
import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap;
26+
import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler;
2527
import lombok.RequiredArgsConstructor;
2628

2729
import java.sql.SQLException;
@@ -55,6 +57,8 @@ public final class BatchPreparedStatementExecutor {
5557
* @throws SQLException SQL exception
5658
*/
5759
public int[] executeBatch() throws SQLException {
60+
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
61+
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
5862
return accumulate(executorEngine.execute(batchPreparedStatementUnits, new ExecuteCallback<int[]>() {
5963

6064
@Override
@@ -66,6 +70,16 @@ public int[] execute(final BaseStatementUnit baseStatementUnit) throws Exception
6670
public SQLType getSQLType() {
6771
return sqlType;
6872
}
73+
74+
@Override
75+
public boolean isExceptionThrown() {
76+
return isExceptionThrown;
77+
}
78+
79+
@Override
80+
public Map<String, Object> getDataMap() {
81+
return dataMap;
82+
}
6983
}));
7084
}
7185

sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import io.shardingsphere.core.executor.BaseStatementUnit;
2222
import io.shardingsphere.core.executor.ExecuteCallback;
2323
import io.shardingsphere.core.executor.ExecutorEngine;
24-
import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap;
25-
import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler;
2624

2725
import java.util.ArrayList;
2826
import java.util.Collection;
@@ -66,16 +64,14 @@ private Map<String, Collection<BaseStatementUnit>> getBaseStatementUnitGroups(fi
6664

6765
private <T> Collection<ListenableFuture<Collection<T>>> asyncExecute(final Map<String, Collection<BaseStatementUnit>> baseStatementUnitGroups, final ExecuteCallback<T> executeCallback) {
6866
Collection<ListenableFuture<Collection<T>>> result = new ArrayList<>(baseStatementUnitGroups.size());
69-
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
70-
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
7167
for (Map.Entry<String, Collection<BaseStatementUnit>> entry : baseStatementUnitGroups.entrySet()) {
7268
final Collection<BaseStatementUnit> baseStatementUnits = entry.getValue();
7369
result.add(getExecutorService().submit(new Callable<Collection<T>>() {
7470
@Override
7571
public Collection<T> call() throws Exception {
7672
Collection<T> result = new LinkedList<>();
7773
for (BaseStatementUnit each : baseStatementUnits) {
78-
result.add(executeInternal(each, executeCallback, isExceptionThrown, dataMap));
74+
result.add(executeInternal(each, executeCallback));
7975
}
8076
return result;
8177
}
@@ -87,7 +83,7 @@ public Collection<T> call() throws Exception {
8783
private <T> Collection<T> syncExecute(final Collection<? extends BaseStatementUnit> baseStatementUnits, final ExecuteCallback<T> executeCallback) throws Exception {
8884
Collection<T> result = new LinkedList<>();
8985
for (BaseStatementUnit each : baseStatementUnits) {
90-
result.add(executeInternal(each, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap()));
86+
result.add(executeInternal(each, executeCallback));
9187
}
9288
return result;
9389
}

sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@
2222
import io.shardingsphere.core.executor.BaseStatementUnit;
2323
import io.shardingsphere.core.executor.ExecuteCallback;
2424
import io.shardingsphere.core.executor.ExecutorEngine;
25-
import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap;
26-
import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler;
2725

2826
import java.util.ArrayList;
2927
import java.util.Collection;
3028
import java.util.Iterator;
3129
import java.util.LinkedList;
3230
import java.util.List;
33-
import java.util.Map;
3431
import java.util.concurrent.Callable;
3532
import java.util.concurrent.ExecutionException;
3633

@@ -55,22 +52,20 @@ protected <T> List<T> getExecuteResults(final Collection<? extends BaseStatement
5552

5653
private <T> Collection<ListenableFuture<T>> asyncExecute(final Collection<BaseStatementUnit> baseStatementUnits, final ExecuteCallback<T> executeCallback) {
5754
List<ListenableFuture<T>> result = new ArrayList<>(baseStatementUnits.size());
58-
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
59-
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
6055
for (final BaseStatementUnit each : baseStatementUnits) {
6156
result.add(getExecutorService().submit(new Callable<T>() {
6257

6358
@Override
6459
public T call() throws Exception {
65-
return executeInternal(each, executeCallback, isExceptionThrown, dataMap);
60+
return executeInternal(each, executeCallback);
6661
}
6762
}));
6863
}
6964
return result;
7065
}
7166

7267
private <T> T syncExecute(final BaseStatementUnit baseStatementUnit, final ExecuteCallback<T> executeCallback) throws Exception {
73-
return executeInternal(baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap());
68+
return executeInternal(baseStatementUnit, executeCallback);
7469
}
7570

7671
private <T> List<T> getResultList(final T firstOutput, final Collection<ListenableFuture<T>> restResultFutures) throws ExecutionException, InterruptedException {

sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/prepared/PreparedStatementExecutor.java

+39
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
import io.shardingsphere.core.executor.BaseStatementUnit;
2222
import io.shardingsphere.core.executor.ExecuteCallback;
2323
import io.shardingsphere.core.executor.ExecutorEngine;
24+
import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap;
25+
import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler;
2426
import lombok.RequiredArgsConstructor;
2527

2628
import java.sql.PreparedStatement;
2729
import java.sql.ResultSet;
2830
import java.sql.SQLException;
2931
import java.util.Collection;
3032
import java.util.List;
33+
import java.util.Map;
3134

3235
/**
3336
* PreparedStatement Executor for multiple threads.
@@ -52,6 +55,8 @@ public final class PreparedStatementExecutor {
5255
* @throws SQLException SQL exception
5356
*/
5457
public List<ResultSet> executeQuery() throws SQLException {
58+
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
59+
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
5560
return executorEngine.execute(preparedStatementUnits, new ExecuteCallback<ResultSet>() {
5661

5762
@Override
@@ -63,6 +68,16 @@ public ResultSet execute(final BaseStatementUnit baseStatementUnit) throws Excep
6368
public SQLType getSQLType() {
6469
return sqlType;
6570
}
71+
72+
@Override
73+
public boolean isExceptionThrown() {
74+
return isExceptionThrown;
75+
}
76+
77+
@Override
78+
public Map<String, Object> getDataMap() {
79+
return dataMap;
80+
}
6681
});
6782
}
6883

@@ -73,6 +88,8 @@ public SQLType getSQLType() {
7388
* @throws SQLException SQL exception
7489
*/
7590
public int executeUpdate() throws SQLException {
91+
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
92+
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
7693
List<Integer> results = executorEngine.execute(preparedStatementUnits, new ExecuteCallback<Integer>() {
7794

7895
@Override
@@ -84,6 +101,16 @@ public Integer execute(final BaseStatementUnit baseStatementUnit) throws Excepti
84101
public SQLType getSQLType() {
85102
return sqlType;
86103
}
104+
105+
@Override
106+
public boolean isExceptionThrown() {
107+
return isExceptionThrown;
108+
}
109+
110+
@Override
111+
public Map<String, Object> getDataMap() {
112+
return dataMap;
113+
}
87114
});
88115
return accumulate(results);
89116
}
@@ -103,6 +130,8 @@ private int accumulate(final List<Integer> results) {
103130
* @throws SQLException SQL exception
104131
*/
105132
public boolean execute() throws SQLException {
133+
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
134+
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
106135
List<Boolean> result = executorEngine.execute(preparedStatementUnits, new ExecuteCallback<Boolean>() {
107136

108137
@Override
@@ -114,6 +143,16 @@ public Boolean execute(final BaseStatementUnit baseStatementUnit) throws Excepti
114143
public SQLType getSQLType() {
115144
return sqlType;
116145
}
146+
147+
@Override
148+
public boolean isExceptionThrown() {
149+
return isExceptionThrown;
150+
}
151+
152+
@Override
153+
public Map<String, Object> getDataMap() {
154+
return dataMap;
155+
}
117156
});
118157
if (null == result || result.isEmpty() || null == result.get(0)) {
119158
return false;

sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/statement/StatementExecutor.java

+39
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
import io.shardingsphere.core.executor.BaseStatementUnit;
2222
import io.shardingsphere.core.executor.ExecuteCallback;
2323
import io.shardingsphere.core.executor.ExecutorEngine;
24+
import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap;
25+
import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler;
2426
import lombok.RequiredArgsConstructor;
2527

2628
import java.sql.ResultSet;
2729
import java.sql.SQLException;
2830
import java.sql.Statement;
2931
import java.util.Collection;
3032
import java.util.List;
33+
import java.util.Map;
3134

3235
/**
3336
* Statement Executor for multiple threads.
@@ -53,6 +56,8 @@ public final class StatementExecutor {
5356
* @throws SQLException SQL exception
5457
*/
5558
public List<ResultSet> executeQuery() throws SQLException {
59+
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
60+
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
5661
return executorEngine.execute(statementUnits, new ExecuteCallback<ResultSet>() {
5762

5863
@Override
@@ -64,6 +69,16 @@ public ResultSet execute(final BaseStatementUnit baseStatementUnit) throws Excep
6469
public SQLType getSQLType() {
6570
return sqlType;
6671
}
72+
73+
@Override
74+
public boolean isExceptionThrown() {
75+
return isExceptionThrown;
76+
}
77+
78+
@Override
79+
public Map<String, Object> getDataMap() {
80+
return dataMap;
81+
}
6782
});
6883
}
6984

@@ -135,6 +150,8 @@ public int executeUpdate(final Statement statement, final String sql) throws SQL
135150
}
136151

137152
private int executeUpdate(final Updater updater) throws SQLException {
153+
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
154+
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
138155
List<Integer> results = executorEngine.execute(statementUnits, new ExecuteCallback<Integer>() {
139156

140157
@Override
@@ -146,6 +163,16 @@ public Integer execute(final BaseStatementUnit baseStatementUnit) throws Excepti
146163
public SQLType getSQLType() {
147164
return sqlType;
148165
}
166+
167+
@Override
168+
public boolean isExceptionThrown() {
169+
return isExceptionThrown;
170+
}
171+
172+
@Override
173+
public Map<String, Object> getDataMap() {
174+
return dataMap;
175+
}
149176
});
150177
return accumulate(results);
151178
}
@@ -226,6 +253,8 @@ public boolean execute(final Statement statement, final String sql) throws SQLEx
226253
}
227254

228255
private boolean execute(final Executor executor) throws SQLException {
256+
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
257+
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
229258
List<Boolean> result = executorEngine.execute(statementUnits, new ExecuteCallback<Boolean>() {
230259

231260
@Override
@@ -237,6 +266,16 @@ public Boolean execute(final BaseStatementUnit baseStatementUnit) throws SQLExce
237266
public SQLType getSQLType() {
238267
return sqlType;
239268
}
269+
270+
@Override
271+
public boolean isExceptionThrown() {
272+
return isExceptionThrown;
273+
}
274+
275+
@Override
276+
public Map<String, Object> getDataMap() {
277+
return dataMap;
278+
}
240279
});
241280
if (null == result || result.isEmpty() || null == result.get(0)) {
242281
return false;

0 commit comments

Comments
 (0)