File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
main/java/com/google/cloud/spanner
test/java/com/google/cloud/spanner Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1919import com .google .cloud .Timestamp ;
2020import com .google .common .base .Preconditions ;
2121import java .util .Objects ;
22+ import javax .annotation .Nullable ;
2223
2324/** Represents a response from a commit operation. */
2425public class CommitResponse {
@@ -41,6 +42,18 @@ public Timestamp getCommitTimestamp() {
4142 return Timestamp .fromProto (proto .getCommitTimestamp ());
4243 }
4344
45+ /**
46+ * Returns a {@link Timestamp} representing the timestamp at which all reads in the transaction
47+ * ran at, if the transaction ran at repeatable read isolation in internal test environments, and
48+ * otherwise returns null.
49+ */
50+ public @ Nullable Timestamp getSnapshotTimestamp () {
51+ if (proto .getSnapshotTimestamp () == com .google .protobuf .Timestamp .getDefaultInstance ()) {
52+ return null ;
53+ }
54+ return Timestamp .fromProto (proto .getSnapshotTimestamp ());
55+ }
56+
4457 /**
4558 * @return true if the {@link CommitResponse} includes {@link CommitStats}
4659 */
Original file line number Diff line number Diff line change @@ -101,4 +101,22 @@ public void testHasCommitStats() {
101101 CommitResponse responseWithCommitStats = new CommitResponse (protoWithCommitStats );
102102 assertTrue (responseWithCommitStats .hasCommitStats ());
103103 }
104+
105+ @ Test
106+ public void testGetSnapshotTimestamp () {
107+ com .google .spanner .v1 .CommitResponse protoWithoutSnapshotTimestamp =
108+ com .google .spanner .v1 .CommitResponse .getDefaultInstance ();
109+ CommitResponse responseWithoutSnapshotTimestamp =
110+ new CommitResponse (protoWithoutSnapshotTimestamp );
111+ assertEquals (null , responseWithoutSnapshotTimestamp .getSnapshotTimestamp ());
112+
113+ com .google .protobuf .Timestamp timestamp =
114+ com .google .protobuf .Timestamp .newBuilder ().setSeconds (123L ).setNanos (456 ).build ();
115+ com .google .spanner .v1 .CommitResponse protoWithSnapshotTimestamp =
116+ com .google .spanner .v1 .CommitResponse .newBuilder ().setSnapshotTimestamp (timestamp ).build ();
117+ CommitResponse responseWithSnapshotTimestamp = new CommitResponse (protoWithSnapshotTimestamp );
118+ assertEquals (
119+ Timestamp .ofTimeSecondsAndNanos (123L , 456 ),
120+ responseWithSnapshotTimestamp .getSnapshotTimestamp ());
121+ }
104122}
You can’t perform that action at this time.
0 commit comments