1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc;
19
20 import lombok.RequiredArgsConstructor;
21 import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
22 import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
23 import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
24 import org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorExceptionHandler;
25
26 import java.sql.SQLException;
27 import java.util.Collections;
28 import java.util.List;
29
30
31
32
33 @RequiredArgsConstructor
34 public final class JDBCExecutor {
35
36 private final ExecutorEngine executorEngine;
37
38 private final ConnectionContext connectionContext;
39
40
41
42
43
44
45
46
47
48
49 public <T> List<T> execute(final ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext, final JDBCExecutorCallback<T> callback) throws SQLException {
50 return execute(executionGroupContext, null, callback);
51 }
52
53
54
55
56
57
58
59
60
61
62
63 public <T> List<T> execute(final ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext,
64 final JDBCExecutorCallback<T> firstCallback, final JDBCExecutorCallback<T> callback) throws SQLException {
65 try {
66 return executorEngine.execute(executionGroupContext, firstCallback, callback, connectionContext.getTransactionContext().isInDistributedTransaction());
67 } catch (final SQLException ex) {
68 SQLExecutorExceptionHandler.handleException(ex);
69 return Collections.emptyList();
70 }
71 }
72 }