-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add methods for unwrapping Spanner client #1914
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,13 @@ | |
import com.google.cloud.spanner.AbortedException; | ||
import com.google.cloud.spanner.CommitResponse; | ||
import com.google.cloud.spanner.CommitStats; | ||
import com.google.cloud.spanner.DatabaseClient; | ||
import com.google.cloud.spanner.DatabaseId; | ||
import com.google.cloud.spanner.Dialect; | ||
import com.google.cloud.spanner.Mutation; | ||
import com.google.cloud.spanner.Options.QueryOption; | ||
import com.google.cloud.spanner.PartitionOptions; | ||
import com.google.cloud.spanner.Spanner; | ||
import com.google.cloud.spanner.TimestampBound; | ||
import com.google.cloud.spanner.connection.AutocommitDmlMode; | ||
import com.google.cloud.spanner.connection.SavepointSupport; | ||
|
@@ -47,6 +50,28 @@ | |
*/ | ||
public interface CloudSpannerJdbcConnection extends Connection { | ||
|
||
/** | ||
* Returns the {@link DatabaseId} of the database that this {@link Connection} is connected to. | ||
*/ | ||
default DatabaseId getDatabaseId() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** | ||
* Returns the underlying {@link DatabaseClient} that is used by this connection. Operations that | ||
* are executed on the {@link DatabaseClient} that is returned has no impact on this {@link | ||
* Connection}, e.g. starting a read/write transaction on the {@link DatabaseClient} will not | ||
* start a transaction on this connection. | ||
*/ | ||
default DatabaseClient getDatabaseClient() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can customer do something like below?
Is there any difference between this and the exposed method? I mean do we need to expose a seperate method for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment, there is no difference, as the only key that is used to determine which |
||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** Returns the underlying {@link Spanner} instance that is used by this connection. */ | ||
default Spanner getSpanner() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** | ||
* Sets the transaction tag to use for the current transaction. This method may only be called | ||
* when in a transaction, and before the transaction is actually started, i.e. before any | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interested to understand if there is a customer usecase where they would like to use databaseclient directly instead of using the connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is more of an 'escape hatch'. We try to support most features directly in the JDBC driver, but some Spanner features don't have a good equivalent in JDBC. In those cases, it can be easier to just use the database client directly. One such example could for example be
BatchWrite
. Although we can also create a method in the JDBC Connection that just delegates the call directly to the underlying database client, giving the option of just unwrapping the client ensures that all features are usable, even if there is no such delegate method.