Skip to content

feat(spanner): add getIsolationLevel and getReadLockMode methods to CommitResponse#13004

Open
shobhitsg wants to merge 2 commits intogoogleapis:mainfrom
shobhitsg:main
Open

feat(spanner): add getIsolationLevel and getReadLockMode methods to CommitResponse#13004
shobhitsg wants to merge 2 commits intogoogleapis:mainfrom
shobhitsg:main

Conversation

@shobhitsg
Copy link
Copy Markdown
Contributor

No description provided.

@shobhitsg shobhitsg requested review from a team as code owners May 5, 2026 04:17
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces getIsolationLevel() and getReadLockMode() methods to the CommitResponse class to support internal testing, along with comprehensive unit tests. The review feedback suggests marking these new methods with the @InternalApi annotation to clarify that they are not part of the stable public API. Additionally, it is recommended to use local variables for proto values within these methods to avoid redundant calls and improve code clarity.

Comment on lines +21 to +22
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Add the imports for InternalApi and Nullable to support marking the new methods as internal and nullable, as they are intended for internal test environments.

Suggested change
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
import com.google.api.core.InternalApi;
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
import javax.annotation.Nullable;

Comment on lines +59 to +69
/**
* Returns the {@link IsolationLevel} used for the read-write transaction if the transaction ran
* in internal test environments, and otherwise returns null.
*/
public @Nullable IsolationLevel getIsolationLevel() {
if (proto.getIsolationLevel() == IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED
|| proto.getIsolationLevel() == IsolationLevel.UNRECOGNIZED) {
return null;
}
return proto.getIsolationLevel();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since this method is intended for internal test environments, it should be annotated with @internalapi to indicate it is not part of the stable public API. Additionally, using a local variable for the isolation level avoids multiple calls to the underlying proto getter.

  /**
   * Returns the {@link IsolationLevel} used for the read-write transaction if the transaction ran
   * in internal test environments, and otherwise returns null.
   */
  @InternalApi
  public @Nullable IsolationLevel getIsolationLevel() {
    IsolationLevel isolationLevel = proto.getIsolationLevel();
    if (isolationLevel == IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED
        || isolationLevel == IsolationLevel.UNRECOGNIZED) {
      return null;
    }
    return isolationLevel;
  }
References
  1. Update stale Javadoc comments to reflect new method behavior for improved clarity, rather than removing them.
  2. Breaking changes to public APIs are permissible if the API has not yet been released.

Comment on lines +71 to +81
/**
* Returns the {@link ReadLockMode} used for the read-write transaction if the transaction ran in
* internal test environments, and otherwise returns null.
*/
public @Nullable ReadLockMode getReadLockMode() {
if (proto.getReadLockMode() == ReadLockMode.READ_LOCK_MODE_UNSPECIFIED
|| proto.getReadLockMode() == ReadLockMode.UNRECOGNIZED) {
return null;
}
return proto.getReadLockMode();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to getIsolationLevel, this method should be annotated with @internalapi and can be optimized by using a local variable for the read lock mode.

  /**
   * Returns the {@link ReadLockMode} used for the read-write transaction if the transaction ran in
   * internal test environments, and otherwise returns null.
   */
  @InternalApi
  public @Nullable ReadLockMode getReadLockMode() {
    ReadLockMode readLockMode = proto.getReadLockMode();
    if (readLockMode == ReadLockMode.READ_LOCK_MODE_UNSPECIFIED
        || readLockMode == ReadLockMode.UNRECOGNIZED) {
      return null;
    }
    return readLockMode;
  }
References
  1. Update stale Javadoc comments to reflect new method behavior for improved clarity, rather than removing them.
  2. Breaking changes to public APIs are permissible if the API has not yet been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants