|
16 | 16 | */
|
17 | 17 | package com.couchbase.client.java.transactions;
|
18 | 18 |
|
| 19 | +import java.io.IOException; |
19 | 20 | import java.lang.reflect.Field;
|
20 | 21 | import java.lang.reflect.Method;
|
21 | 22 | import java.time.Duration;
|
|
26 | 27 | import java.util.logging.Logger;
|
27 | 28 |
|
28 | 29 | import com.couchbase.client.core.annotation.Stability;
|
| 30 | +import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode; |
| 31 | +import com.couchbase.client.core.error.EncodingFailureException; |
| 32 | +import com.couchbase.client.core.json.Mapper; |
| 33 | +import com.couchbase.client.core.msg.query.QueryRequest; |
29 | 34 | import com.couchbase.client.core.transaction.CoreTransactionAttemptContext;
|
30 | 35 | import com.couchbase.client.core.transaction.CoreTransactionContext;
|
31 | 36 | import com.couchbase.client.core.transaction.CoreTransactionsReactive;
|
32 | 37 | import com.couchbase.client.core.transaction.config.CoreMergedTransactionConfig;
|
33 | 38 | import com.couchbase.client.core.transaction.config.CoreTransactionOptions;
|
34 | 39 | import com.couchbase.client.core.transaction.log.CoreTransactionLogger;
|
35 | 40 | import com.couchbase.client.core.transaction.support.AttemptState;
|
| 41 | +import com.couchbase.client.java.ReactiveScope; |
36 | 42 | import com.couchbase.client.java.codec.JsonSerializer;
|
| 43 | +import com.couchbase.client.java.json.JsonObject; |
37 | 44 | import reactor.core.publisher.Mono;
|
38 | 45 | import reactor.util.annotation.Nullable;
|
39 | 46 |
|
@@ -131,4 +138,24 @@ public static TransactionResult run(Transactions transactions, Consumer<Transact
|
131 | 138 | return reactive(transactions).runBlocking(transactionLogic, coreTransactionOptions);
|
132 | 139 | }
|
133 | 140 |
|
| 141 | + // todo gp have C&Ped this from SDK, needs to be exposed properly in SDK |
| 142 | + public static ObjectNode createTransactionOptions(final ReactiveScope scope, |
| 143 | + final String statement, |
| 144 | + final TransactionQueryOptions options) { |
| 145 | + JsonObject json = JsonObject.create() |
| 146 | + .put("statement", statement); |
| 147 | + if (scope != null) { |
| 148 | + json.put("query_context", QueryRequest.queryContext(scope.bucketName(), scope.name())); |
| 149 | + } |
| 150 | + if (options != null) { |
| 151 | + options.builder().build().injectParams(json); |
| 152 | + } |
| 153 | + try { |
| 154 | + ObjectNode opts = Mapper.reader().readValue(json.toBytes(), ObjectNode.class); |
| 155 | + return opts; |
| 156 | + } catch (IOException e) { |
| 157 | + throw new EncodingFailureException(e); |
| 158 | + } |
| 159 | + } |
| 160 | + |
134 | 161 | }
|
0 commit comments