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 19
19
import com .google .cloud .Timestamp ;
20
20
import com .google .common .base .Preconditions ;
21
21
import java .util .Objects ;
22
+ import javax .annotation .Nullable ;
22
23
23
24
/** Represents a response from a commit operation. */
24
25
public class CommitResponse {
@@ -41,6 +42,18 @@ public Timestamp getCommitTimestamp() {
41
42
return Timestamp .fromProto (proto .getCommitTimestamp ());
42
43
}
43
44
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
+
44
57
/**
45
58
* @return true if the {@link CommitResponse} includes {@link CommitStats}
46
59
*/
Original file line number Diff line number Diff line change @@ -101,4 +101,22 @@ public void testHasCommitStats() {
101
101
CommitResponse responseWithCommitStats = new CommitResponse (protoWithCommitStats );
102
102
assertTrue (responseWithCommitStats .hasCommitStats ());
103
103
}
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
+ }
104
122
}
You can’t perform that action at this time.
0 commit comments