Skip to content

Commit d0de490

Browse files
committed
chore(spanner): support for TransactionManager
1 parent 7270c9b commit d0de490

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedTransactionManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public TransactionContext begin() {
4949
return getTransactionManager().begin();
5050
}
5151

52+
@Override
53+
public TransactionContext begin(AbortedException exception) {
54+
return getTransactionManager().begin(exception);
55+
}
56+
5257
@Override
5358
public void commit() {
5459
getTransactionManager().commit();

google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ enum TransactionState {
6161
*/
6262
TransactionContext begin();
6363

64+
TransactionContext begin(AbortedException exception);
65+
6466
/**
6567
* Commits the currently active transaction. If the transaction was already aborted, then this
6668
* would throw an {@link AbortedException}.

google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManagerImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,19 @@ public void setSpan(ISpan span) {
5353
@Override
5454
public TransactionContext begin() {
5555
Preconditions.checkState(txn == null, "begin can only be called once");
56+
return begin(ByteString.EMPTY);
57+
}
58+
59+
@Override
60+
public TransactionContext begin(AbortedException exception) {
61+
Preconditions.checkState(txn == null, "begin can only be called once");
62+
ByteString previousAbortedTransactionID = exception.getTransactionID() != null ? exception.getTransactionID() : ByteString.EMPTY;
63+
return begin(previousAbortedTransactionID);
64+
}
65+
66+
TransactionContext begin(ByteString previousTransactionId) {
5667
try (IScope s = tracer.withSpan(span)) {
57-
txn = session.newTransaction(options, /* previousTransactionId = */ ByteString.EMPTY);
68+
txn = session.newTransaction(options, /* previousTransactionId = */ previousTransactionId);
5869
session.setActive(this);
5970
txnState = TransactionState.STARTED;
6071
return txn;

0 commit comments

Comments
 (0)