|
23 | 23 | import tech.ydb.jdbc.impl.YdbStaticResultSet; |
24 | 24 | import tech.ydb.jdbc.query.QueryType; |
25 | 25 | import tech.ydb.jdbc.query.YdbQuery; |
| 26 | +import tech.ydb.jdbc.settings.YdbOperationProperties; |
26 | 27 | import tech.ydb.query.QueryClient; |
27 | 28 | import tech.ydb.query.QuerySession; |
28 | 29 | import tech.ydb.query.QueryStream; |
|
42 | 43 | * @author Aleksandr Gorshenin |
43 | 44 | */ |
44 | 45 | public class QueryServiceExecutor extends BaseYdbExecutor { |
45 | | - protected final Duration sessionTimeout; |
46 | | - protected final QueryClient queryClient; |
| 46 | + private final Duration sessionTimeout; |
| 47 | + private final QueryClient queryClient; |
47 | 48 | private final boolean useStreamResultSet; |
48 | 49 |
|
49 | | - protected int transactionLevel; |
50 | | - protected boolean isReadOnly; |
51 | | - protected boolean isAutoCommit; |
52 | | - protected TxMode txMode; |
| 50 | + private int transactionLevel; |
| 51 | + private boolean isReadOnly; |
| 52 | + private boolean isAutoCommit; |
| 53 | + private TxMode txMode; |
53 | 54 |
|
54 | | - protected final AtomicReference<QueryTransaction> tx = new AtomicReference<>(); |
55 | | - protected volatile boolean isClosed; |
| 55 | + private final AtomicReference<QueryTransaction> tx = new AtomicReference<>(); |
| 56 | + private volatile boolean isClosed; |
56 | 57 |
|
57 | | - public QueryServiceExecutor(YdbContext ctx, int transactionLevel, boolean autoCommit) throws SQLException { |
| 58 | + public QueryServiceExecutor(YdbContext ctx) throws SQLException { |
58 | 59 | super(ctx); |
59 | | - this.sessionTimeout = ctx.getOperationProperties().getSessionTimeout(); |
| 60 | + YdbOperationProperties options = ctx.getOperationProperties(); |
| 61 | + this.sessionTimeout = options.getSessionTimeout(); |
60 | 62 | this.queryClient = ctx.getQueryClient(); |
61 | | - this.useStreamResultSet = ctx.getOperationProperties().getUseStreamResultSets(); |
| 63 | + this.useStreamResultSet = options.getUseStreamResultSets(); |
62 | 64 |
|
63 | | - this.transactionLevel = transactionLevel; |
| 65 | + this.transactionLevel = options.getTransactionLevel(); |
| 66 | + this.isAutoCommit = options.isAutoCommit(); |
64 | 67 | this.isReadOnly = transactionLevel != Connection.TRANSACTION_SERIALIZABLE; |
65 | | - this.isAutoCommit = autoCommit; |
66 | 68 | this.txMode = txMode(transactionLevel, isReadOnly); |
67 | 69 | this.isClosed = false; |
68 | 70 | } |
@@ -179,22 +181,26 @@ public void commit(YdbContext ctx, YdbValidator validator) throws SQLException { |
179 | 181 | return; |
180 | 182 | } |
181 | 183 |
|
182 | | - YdbTracer tracer = ctx.getTracer(); |
183 | | - tracer.trace("--> commit"); |
184 | | - tracer.query(null); |
185 | | - |
186 | | - CommitTransactionSettings settings = ctx.withRequestTimeout(CommitTransactionSettings.newBuilder()).build(); |
187 | 184 | try { |
188 | | - validator.clearWarnings(); |
189 | | - validator.call("Commit TxId: " + localTx.getId(), tracer, () -> localTx.commit(settings)); |
| 185 | + commitImpl(ctx, validator, localTx); |
190 | 186 | } finally { |
191 | 187 | if (tx.compareAndSet(localTx, null)) { |
192 | 188 | localTx.getSession().close(); |
193 | 189 | } |
194 | | - tracer.close(); |
| 190 | + ctx.getTracer().close(); |
195 | 191 | } |
196 | 192 | } |
197 | 193 |
|
| 194 | + protected void commitImpl(YdbContext ctx, YdbValidator validator, QueryTransaction tx) throws SQLException { |
| 195 | + YdbTracer tracer = ctx.getTracer(); |
| 196 | + tracer.trace("--> commit"); |
| 197 | + tracer.query(null); |
| 198 | + |
| 199 | + CommitTransactionSettings settings = ctx.withRequestTimeout(CommitTransactionSettings.newBuilder()).build(); |
| 200 | + validator.clearWarnings(); |
| 201 | + validator.call("Commit TxId: " + tx.getId(), tracer, () -> tx.commit(settings)); |
| 202 | + } |
| 203 | + |
198 | 204 | @Override |
199 | 205 | public void rollback(YdbContext ctx, YdbValidator validator) throws SQLException { |
200 | 206 | ensureOpened(); |
@@ -223,9 +229,8 @@ public void rollback(YdbContext ctx, YdbValidator validator) throws SQLException |
223 | 229 | } |
224 | 230 |
|
225 | 231 | @Override |
226 | | - public YdbQueryResult executeDataQuery( |
227 | | - YdbStatement statement, YdbQuery query, String preparedYql, Params params, long timeout, boolean keepInCache |
228 | | - ) throws SQLException { |
| 232 | + public YdbQueryResult executeDataQuery(YdbStatement statement, YdbQuery query, String preparedYql, Params params, |
| 233 | + long timeout, boolean keepInCache) throws SQLException { |
229 | 234 | ensureOpened(); |
230 | 235 |
|
231 | 236 | YdbValidator validator = statement.getValidator(); |
|
0 commit comments