Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.cloud.Timestamp;
import com.google.common.base.Preconditions;
import java.util.Objects;
import javax.annotation.Nullable;

/** Represents a response from a commit operation. */
public class CommitResponse {
Expand All @@ -41,6 +42,18 @@ public Timestamp getCommitTimestamp() {
return Timestamp.fromProto(proto.getCommitTimestamp());
}

/**
* Returns a {@link Timestamp} representing the timestamp at which all reads in the transaction
* ran at, if the transaction ran at repeatable read isolation in internal test environments, and
* otherwise returns null.
*/
public @Nullable Timestamp getSnapshotTimestamp() {
Comment thread
skuruppu marked this conversation as resolved.
if (proto.getSnapshotTimestamp() == com.google.protobuf.Timestamp.getDefaultInstance()) {
return null;
}
return Timestamp.fromProto(proto.getSnapshotTimestamp());
}

/**
* @return true if the {@link CommitResponse} includes {@link CommitStats}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,22 @@ public void testHasCommitStats() {
CommitResponse responseWithCommitStats = new CommitResponse(protoWithCommitStats);
assertTrue(responseWithCommitStats.hasCommitStats());
}

@Test
public void testGetSnapshotTimestamp() {
com.google.spanner.v1.CommitResponse protoWithoutSnapshotTimestamp =
com.google.spanner.v1.CommitResponse.getDefaultInstance();
CommitResponse responseWithoutSnapshotTimestamp =
new CommitResponse(protoWithoutSnapshotTimestamp);
assertEquals(null, responseWithoutSnapshotTimestamp.getSnapshotTimestamp());

com.google.protobuf.Timestamp timestamp =
com.google.protobuf.Timestamp.newBuilder().setSeconds(123L).setNanos(456).build();
com.google.spanner.v1.CommitResponse protoWithSnapshotTimestamp =
com.google.spanner.v1.CommitResponse.newBuilder().setSnapshotTimestamp(timestamp).build();
CommitResponse responseWithSnapshotTimestamp = new CommitResponse(protoWithSnapshotTimestamp);
assertEquals(
Timestamp.ofTimeSecondsAndNanos(123L, 456),
responseWithSnapshotTimestamp.getSnapshotTimestamp());
}
}
Loading