public interface CloudSpannerJdbcConnection extends Connection
JdbcDriver will implement this interface.
Calling Wrapper.unwrap(Class) with CloudSpannerJdbcConnection#getClass() as
input on a Connection returned by the Cloud Spanner JDBC Driver will return a CloudSpannerJdbcConnection instance.
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Modifier and Type | Method and Description |
|---|---|
void |
addTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener listener) |
void |
addTransactionRetryListener(TransactionRetryListener listener)
Deprecated.
|
void |
bufferedWrite(Iterable<com.google.cloud.spanner.Mutation> mutations)
Buffers the given mutations locally on the current transaction of this
Connection. |
void |
bufferedWrite(com.google.cloud.spanner.Mutation mutation)
Buffers the given mutation locally on the current transaction of this
Connection. |
com.google.cloud.spanner.connection.AutocommitDmlMode |
getAutocommitDmlMode() |
Timestamp |
getCommitTimestamp() |
String |
getConnectionUrl() |
String |
getOptimizerVersion()
Gets the current query optimizer version of this connection.
|
com.google.cloud.spanner.TimestampBound |
getReadOnlyStaleness() |
Timestamp |
getReadTimestamp() |
com.google.cloud.spanner.connection.TransactionMode |
getTransactionMode() |
Iterator<TransactionRetryListener> |
getTransactionRetryListeners()
Deprecated.
|
Iterator<com.google.cloud.spanner.connection.TransactionRetryListener> |
getTransactionRetryListenersFromConnection() |
boolean |
isInTransaction() |
boolean |
isRetryAbortsInternally() |
boolean |
isTransactionStarted() |
boolean |
removeTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener listener) |
boolean |
removeTransactionRetryListener(TransactionRetryListener listener)
Deprecated.
|
void |
setAutocommitDmlMode(com.google.cloud.spanner.connection.AutocommitDmlMode mode)
Sets the mode for executing DML statements in autocommit mode for this connection.
|
void |
setOptimizerVersion(String optimizerVersion)
Sets the query optimizer version to use for this connection.
|
void |
setReadOnlyStaleness(com.google.cloud.spanner.TimestampBound staleness)
Sets the staleness to use for the current read-only transaction.
|
void |
setRetryAbortsInternally(boolean retryAbortsInternally)
Sets whether this connection will internally retry read/write transactions that abort.
|
void |
setTransactionMode(com.google.cloud.spanner.connection.TransactionMode transactionMode)
Sets the transaction mode to use for current transaction.
|
void |
write(Iterable<com.google.cloud.spanner.Mutation> mutations)
Writes the specified mutations directly to the database and commits the changes.
|
void |
write(com.google.cloud.spanner.Mutation mutation)
Writes the specified mutation directly to the database and commits the change.
|
abort, clearWarnings, close, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMapisWrapperFor, unwrapvoid setTransactionMode(com.google.cloud.spanner.connection.TransactionMode transactionMode)
throws SQLException
transactionMode - The transaction mode to use for the current transaction.
TransactionMode.READ_ONLY_TRANSACTION will create a read-only transaction and
prevent any changes to written to the database through this transaction. The read
timestamp to be used will be determined based on the current readOnlyStaleness
setting of this connection. It is recommended to use TransactionMode.READ_ONLY_TRANSACTION instead of TransactionMode.READ_WRITE_TRANSACTION when possible, as read-only transactions do
not acquire locks on Cloud Spanner, and read-only transactions never abort.
TransactionMode.READ_WRITE_TRANSACTION this value is only allowed when the
connection is not in read-only mode and will create a read-write transaction. If
Connection#isRetryAbortsInternally() is true, each read/write
transaction will keep track of a running SHA256 checksum for each ResultSet
that is returned in order to be able to retry the transaction in case the transaction
is aborted by Spanner.
SQLExceptioncom.google.cloud.spanner.connection.TransactionMode getTransactionMode()
throws SQLException
SQLExceptionvoid setAutocommitDmlMode(com.google.cloud.spanner.connection.AutocommitDmlMode mode)
throws SQLException
AutocommitDmlMode.TRANSACTIONAL when
autocommit mode is changed on the connection.mode - The DML autocommit mode to use
AutocommitDmlMode.TRANSACTIONAL DML statements are executed as single
read-write transaction. After successful execution, the DML statement is guaranteed
to have been applied exactly once to the database
AutocommitDmlMode.PARTITIONED_NON_ATOMIC DML statements are executed as
partitioned DML transactions. If an error occurs during the execution of the DML
statement, it is possible that the statement has been applied to some but not all of
the rows specified in the statement.
SQLExceptioncom.google.cloud.spanner.connection.AutocommitDmlMode getAutocommitDmlMode()
throws SQLException
AutocommitDmlMode setting for this connection. This method may only
be called on a connection that is in autocommit mode and not while in a temporary
transaction.SQLExceptionvoid setReadOnlyStaleness(com.google.cloud.spanner.TimestampBound staleness)
throws SQLException
TransactionMode.READ_ONLY_TRANSACTION and there is no transaction that has started, or when
the connection is in read-only and autocommit mode.staleness - The staleness to use for the current but not yet started read-only transactionSQLExceptioncom.google.cloud.spanner.TimestampBound getReadOnlyStaleness()
throws SQLException
SQLExceptionvoid setOptimizerVersion(String optimizerVersion) throws SQLException
optimizerVersion - The query optimizer version to use. Must be a valid optimizer version
number, the string LATEST or an empty string. The empty string will instruct
the connection to use the optimizer version that is defined in the environment variable
SPANNER_OPTIMIZER_VERSION. If no value is specified in the environment
variable, the default query optimizer of Cloud Spanner is used.SQLExceptionString getOptimizerVersion() throws SQLException
SQLExceptionboolean isInTransaction()
throws SQLException
true if this connection has a transaction (that has not necessarily
started). This method will only return false when the Connection is in autocommit
mode and no explicit transaction has been started by calling Connection#beginTransaction(). If the Connection is not in autocommit mode, there
will always be a transaction.SQLExceptionboolean isTransactionStarted()
throws SQLException
true if this connection has a transaction that has started. A transaction
is automatically started by the first statement that is executed in the transaction.SQLExceptionTimestamp getCommitTimestamp() throws SQLException
Timestamp of the last read/write transaction. If the last
transaction was not a read/write transaction, or a read/write transaction that did not
return a commit timestamp because the transaction was not committed, the method will throw
a SQLException.SQLExceptionTimestamp getReadTimestamp() throws SQLException
Timestamp of the last read-only transaction. If the last transaction
was not a read-only transaction, or a read-only transaction that did not return a read
timestamp because no data was read, the method will throw a SQLException.SQLExceptionboolean isRetryAbortsInternally()
throws SQLException
true if this connection will automatically retry read/write transactions
that abort. This method may only be called when the connection is in read/write
transactional mode and no transaction has been started yet.SQLExceptionvoid setRetryAbortsInternally(boolean retryAbortsInternally)
throws SQLException
true. When internal retry is enabled, the Connection will keep
track of a running SHA256 checksum of all ResultSets that have been returned from Cloud
Spanner. If the checksum that is calculated during an internal retry differs from the original
checksum, the transaction will abort with an AbortedDueToConcurrentModificationException.
Note that retries of a read/write transaction that calls a non-deterministic function on Cloud Spanner, such as CURRENT_TIMESTAMP(), will never be successful, as the data returned during the retry will always be different from the original transaction.
It is also highly recommended that all queries in a read/write transaction have an ORDER BY clause that guarantees that the data is returned in the same order as in the original transaction if the transaction is internally retried. The most efficient way to achieve this is to always include the primary key columns at the end of the ORDER BY clause.
This method may only be called when the connection is in read/write transactional mode and no transaction has been started yet.
retryAbortsInternally - Set to true to internally retry transactions that are
aborted by Spanner. When set to false, any database call on a transaction that
has been aborted by Cloud Spanner will throw an AbortedException instead of being
retried. Set this to false if your application already uses retry loops to handle AbortedExceptions.SQLExceptionvoid write(com.google.cloud.spanner.Mutation mutation)
throws SQLException
write(Iterable).
Calling this method is only allowed in autocommit mode. See bufferedWrite(Iterable) for writing mutations in transactions.
mutation - The Mutation to write to the database.SQLException - if the Connection is not in autocommit mode or if the Connection is closed.void write(Iterable<com.google.cloud.spanner.Mutation> mutations) throws SQLException
Calling this method is only allowed in autocommit mode. See bufferedWrite(Iterable) for writing mutations in transactions.
mutations - The Mutations to write to the database.SQLException - if the Connection is not in autocommit mode or if the Connection is closed.void bufferedWrite(com.google.cloud.spanner.Mutation mutation)
throws SQLException
Connection. The
mutation will be written to the database at the next call to Connection.commit(). The
value will not be readable on this Connection before the transaction is committed.
Calling this method is only allowed when not in autocommit mode. See write(Mutation) for writing mutations in autocommit mode.
mutation - the Mutation to buffer for writing to the database on the next commit.SQLException - if the Connection is in autocommit mode or the Connection
is closed.void bufferedWrite(Iterable<com.google.cloud.spanner.Mutation> mutations) throws SQLException
Connection. The
mutations will be written to the database at the next call to Connection.commit(). The
values will not be readable on this Connection before the transaction is committed.
Calling this method is only allowed when not in autocommit mode. See write(Iterable) for writing mutations in autocommit mode.
mutations - the Mutations to buffer for writing to the database on the next
commit.SQLException - if the Connection is in autocommit mode or the Connection
is closed.String getConnectionUrl()
Connection that is equal to
the initial state of this connection. If this connection was initially opened in read-only
mode, and later changed to read-write, this will not be reflected in the connection URL
that is returned.void addTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener listener)
throws SQLException
SQLException - if the Connection is closed.Connection.addTransactionRetryListener(TransactionRetryListener)@Deprecated void addTransactionRetryListener(TransactionRetryListener listener) throws SQLException
SQLExceptionboolean removeTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener listener)
throws SQLException
SQLException - if the Connection is closed.Connection.removeTransactionRetryListener(TransactionRetryListener)@Deprecated boolean removeTransactionRetryListener(TransactionRetryListener listener) throws SQLException
SQLException@Deprecated Iterator<TransactionRetryListener> getTransactionRetryListeners() throws SQLException
SQLExceptionIterator<com.google.cloud.spanner.connection.TransactionRetryListener> getTransactionRetryListenersFromConnection() throws SQLException
SQLException - if the Connection is closed.Connection.getTransactionRetryListeners()Copyright © 2021 Google LLC. All rights reserved.