Interface Connection
-
- All Superinterfaces:
AutoCloseable
@InternalApi public interface Connection extends AutoCloseable
Internal connection API for Google Cloud Spanner. This interface may introduce breaking changes without prior notice.A connection to a Cloud Spanner database. Connections are not designed to be thread-safe. The only exception is the
cancel()
method that may be called by any other thread to stop the execution of the current statement on the connection.All -Async methods on
Connection
are guaranteed to be executed in the order that they are issued on theConnection
. Mixing synchronous and asynchronous method calls is also supported, and these are also guaranteed to be executed in the order that they are issued.Connections accept a number of additional SQL statements for setting or changing the state of a
Connection
. These statements can only be executed using theexecute(Statement)
method:SHOW AUTOCOMMIT
: Returns the current value ofAUTOCOMMIT
of this connection as aResultSet
SET AUTOCOMMIT=TRUE|FALSE
: Sets the value ofAUTOCOMMIT
for this connectionSHOW READONLY
: Returns the current value ofREADONLY
of this connection as aResultSet
SET READONLY=TRUE|FALSE
: Sets the value ofREADONLY
for this connectionSHOW RETRY_ABORTS_INTERNALLY
: Returns the current value ofRETRY_ABORTS_INTERNALLY
of this connection as aResultSet
SET RETRY_ABORTS_INTERNALLY=TRUE|FALSE
: Sets the value ofRETRY_ABORTS_INTERNALLY
for this connectionSHOW AUTOCOMMIT_DML_MODE
: Returns the current value ofAUTOCOMMIT_DML_MODE
of this connection as aResultSet
SET AUTOCOMMIT_DML_MODE='TRANSACTIONAL' | 'PARTITIONED_NON_ATOMIC'
: Sets the value ofAUTOCOMMIT_DML_MODE
for this connectionSHOW STATEMENT_TIMEOUT
: Returns the current value ofSTATEMENT_TIMEOUT
of this connection as aResultSet
SET STATEMENT_TIMEOUT='<int64>s|ms|us|ns' | NULL
: Sets the value ofSTATEMENT_TIMEOUT
for this connection. The supportedTimeUnit
s are:- s - Seconds
- ms - Milliseconds
- us - Microseconds
- ns - Nanoseconds
SHOW READ_TIMESTAMP
: Returns the lastREAD_TIMESTAMP
of this connection as aResultSet
SHOW COMMIT_TIMESTAMP
: Returns the lastCOMMIT_TIMESTAMP
of this connection as aResultSet
SHOW READ_ONLY_STALENESS
: Returns the current value ofREAD_ONLY_STALENESS
of this connection as aResultSet
SET READ_ONLY_STALENESS='STRONG' | 'MIN_READ_TIMESTAMP <timestamp>' | 'READ_TIMESTAMP <timestamp>' | 'MAX_STALENESS <int64>s|ms|mus|ns' | 'EXACT_STALENESS (<int64>s|ms|mus|ns)'
: Sets the value ofREAD_ONLY_STALENESS
for this connection.SHOW OPTIMIZER_VERSION
: Returns the current value ofOPTIMIZER_VERSION
of this connection as aResultSet
SET OPTIMIZER_VERSION='<version>' | 'LATEST'
: Sets the value ofOPTIMIZER_VERSION
for this connection.SHOW OPTIMIZER_STATISTICS_PACKAGE
: Returns the current value ofOPTIMIZER_STATISTICS_PACKAGE
of this connection as aResultSet
SET OPTIMIZER_STATISTICS_PACKAGE='<package>' | ''
: Sets the value ofOPTIMIZER_STATISTICS_PACKAGE
for this connection.BEGIN [TRANSACTION]
: Begins a new transaction. This statement is optional when the connection is not in autocommit mode, as a new transaction will automatically be started when a query or update statement is issued. In autocommit mode, this statement will temporarily put the connection in transactional mode, and return the connection to autocommit mode whenCOMMIT [TRANSACTION]
orROLLBACK [TRANSACTION]
is executedCOMMIT [TRANSACTION]
: Commits the current transactionROLLBACK [TRANSACTION]
: Rollbacks the current transactionSET TRANSACTION READ ONLY|READ WRITE
: Sets the type for the current transaction. May only be executed before a transaction is actually running (i.e. before any statements have been executed in the transaction)START BATCH DDL
: Starts a batch of DDL statements. May only be executed when no transaction has been started and the connection is in read/write mode. The connection will only accept DDL statements while a DDL batch is active.START BATCH DML
: Starts a batch of DML statements. May only be executed when the connection is in read/write mode. The connection will only accept DML statements while a DML batch is active.RUN BATCH
: Ends the current batch, sends the batched DML or DDL statements to Spanner and blocks until all statements have been executed or an error occurs. May only be executed when a (possibly empty) batch is active. The statement will return the update counts of the batched statements asResultSet
with an ARRAY<INT64> column. In case of a DDL batch, this array will always be empty.ABORT BATCH
: Ends the current batch and removes any DML or DDL statements from the buffer without sending any statements to Spanner. May only be executed when a (possibly empty) batch is active.
AbortedException
. This also includes calls toResultSet.next()
.If
isRetryAbortsInternally()
istrue
, then the connection will silently handle anyAbortedException
s by internally re-acquiring all transactional locks and verifying (via the use of cryptographic checksums) that no underlying data has changed. If a change to the underlying data is detected, then anAbortedDueToConcurrentModificationException
error will be thrown. If your application already uses retry loops to handle these Aborted errors, then it will be most efficient to setisRetryAbortsInternally()
tofalse
.Use
ConnectionOptions
to create aConnection
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Connection.InternalMetadataQuery
This query option is used internally to indicate that a query is executed by the library itself to fetch metadata.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
abortBatch()
Clears all buffered statements in the current batch and ends the batch.void
addTransactionRetryListener(TransactionRetryListener listener)
Add aTransactionRetryListener
to thisConnection
for testing and logging purposes.ResultSet
analyzeQuery(Statement query, ReadContext.QueryAnalyzeMode queryMode)
Analyzes a query or a DML statement and returns query plan and/or query execution statistics information.default ResultSetStats
analyzeUpdate(Statement update, ReadContext.QueryAnalyzeMode analyzeMode)
Deprecated.default ResultSet
analyzeUpdateStatement(Statement statement, ReadContext.QueryAnalyzeMode analyzeMode, Options.UpdateOption... options)
Analyzes a DML statement and returns execution plan, undeclared parameters and optionally execution statistics information.void
beginTransaction()
Begins a new transaction for this connection.com.google.api.core.ApiFuture<Void>
beginTransactionAsync()
Begins a new transaction for this connection.void
bufferedWrite(Mutation mutation)
Buffers the given mutation locally on the current transaction of thisConnection
.void
bufferedWrite(Iterable<Mutation> mutations)
Buffers the given mutations locally on the current transaction of thisConnection
.void
cancel()
Cancels the currently running statement on thisConnection
(if any).void
clearStatementTimeout()
Clears the statement timeout value for this connection.void
close()
Closes this connection.com.google.api.core.ApiFuture<Void>
closeAsync()
Closes this connection without blocking.void
commit()
Commits the current transaction of this connection.com.google.api.core.ApiFuture<Void>
commitAsync()
Commits the current transaction of this connection.StatementResult
execute(Statement statement)
Executes the given statement if allowed in the currentTransactionMode
and connection state.AsyncStatementResult
executeAsync(Statement statement)
Executes the given statement if allowed in the currentTransactionMode
and connection state asynchronously.long[]
executeBatchUpdate(Iterable<Statement> updates)
Executes a list of DML statements (can be simple DML statements or DML statements with returning clause) in a single request.com.google.api.core.ApiFuture<long[]>
executeBatchUpdateAsync(Iterable<Statement> updates)
Executes a list of DML statements (can be simple DML statements or DML statements with returning clause) in a single request.ResultSet
executeQuery(Statement query, Options.QueryOption... options)
Executes the given statement (a query or a DML statement with returning clause) and returns the result as aResultSet
.AsyncResultSet
executeQueryAsync(Statement query, Options.QueryOption... options)
Executes the given statement (a query or a DML statement with returning clause) asynchronously and returns the result as anAsyncResultSet
.long
executeUpdate(Statement update)
Executes the given statement as a simple DML statement.com.google.api.core.ApiFuture<Long>
executeUpdateAsync(Statement update)
Executes the given statement asynchronously as a simple DML statement.AutocommitDmlMode
getAutocommitDmlMode()
CommitResponse
getCommitResponse()
com.google.cloud.Timestamp
getCommitTimestamp()
default DatabaseClient
getDatabaseClient()
TheDatabaseClient
that is used by thisConnection
.default Dialect
getDialect()
TheDialect
that is used by thisConnection
.default String
getOptimizerStatisticsPackage()
Gets the current query optimizer statistics package of this connection.String
getOptimizerVersion()
Gets the current query optimizer version of this connection.TimestampBound
getReadOnlyStaleness()
com.google.cloud.Timestamp
getReadTimestamp()
Returns the read timestamp of the current/lastTransactionMode.READ_ONLY_TRANSACTION
transaction, or the read timestamp of the last query in autocommit mode.default Options.RpcPriority
getRPCPriority()
Gets the current RPC priority of this connection.default String
getStatementTag()
long
getStatementTimeout(TimeUnit unit)
TransactionMode
getTransactionMode()
Iterator<TransactionRetryListener>
getTransactionRetryListeners()
default String
getTransactionTag()
boolean
hasStatementTimeout()
boolean
isAutocommit()
boolean
isClosed()
boolean
isDdlBatchActive()
boolean
isDmlBatchActive()
boolean
isInTransaction()
boolean
isReadOnly()
boolean
isRetryAbortsInternally()
boolean
isReturnCommitStats()
boolean
isTransactionStarted()
boolean
removeTransactionRetryListener(TransactionRetryListener listener)
Removes one existingTransactionRetryListener
from thisConnection
, if it is present (optional operation).void
rollback()
Rollbacks the current transaction of this connection.com.google.api.core.ApiFuture<Void>
rollbackAsync()
Rollbacks the current transaction of this connection.long[]
runBatch()
Sends all buffered DML or DDL statements of the current batch to the database, waits for these to be executed and ends the current batch.com.google.api.core.ApiFuture<long[]>
runBatchAsync()
Sends all buffered DML or DDL statements of the current batch to the database, waits for these to be executed and ends the current batch.void
setAutocommit(boolean autocommit)
Sets autocommit on/off for thisConnection
.void
setAutocommitDmlMode(AutocommitDmlMode mode)
Sets the mode for executing DML statements in autocommit mode for this connection.default void
setOptimizerStatisticsPackage(String optimizerStatisticsPackage)
Sets the query optimizer statistics packagevoid
setOptimizerVersion(String optimizerVersion)
Sets the query optimizer version to use for this connection.void
setReadOnly(boolean readOnly)
Sets this connection to read-only or read-write.void
setReadOnlyStaleness(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
setReturnCommitStats(boolean returnCommitStats)
Sets whether this connection should request commit statistics from Cloud Spanner for read/write transactions and DML statements in autocommit mode.default void
setRPCPriority(Options.RpcPriority rpcPriority)
Sets the priority to use for RPCs executed by this connection..default void
setStatementTag(String tag)
Sets the statement tag to use for the next statement that is executed.void
setStatementTimeout(long timeout, TimeUnit unit)
Sets the duration the connection should wait before automatically aborting the execution of a statement.void
setTransactionMode(TransactionMode transactionMode)
Sets the transaction mode to use for current transaction.default void
setTransactionTag(String tag)
Sets the transaction tag to use for the current transaction.void
startBatchDdl()
Starts a new DDL batch on this connection.void
startBatchDml()
Starts a new DML batch on this connection.void
write(Mutation mutation)
Writes the specified mutation directly to the database and commits the change.void
write(Iterable<Mutation> mutations)
Writes the specified mutations directly to the database and commits the changes.com.google.api.core.ApiFuture<Void>
writeAsync(Mutation mutation)
Writes the specified mutation directly to the database and commits the change.com.google.api.core.ApiFuture<Void>
writeAsync(Iterable<Mutation> mutations)
Writes the specified mutations directly to the database and commits the changes.
-
-
-
Method Detail
-
close
void close()
Closes this connection. This is a no-op if theConnection
has already been closed.- Specified by:
close
in interfaceAutoCloseable
-
closeAsync
com.google.api.core.ApiFuture<Void> closeAsync()
Closes this connection without blocking. This is a no-op if theConnection
has already been closed. TheConnection
is no longer usable directly after calling this method. The returnedApiFuture
is done when the running statement(s) (if any) on the connection have finished.
-
isClosed
boolean isClosed()
- Returns:
true
if this connection has been closed.
-
setAutocommit
void setAutocommit(boolean autocommit)
Sets autocommit on/off for thisConnection
. Connections in autocommit mode will apply any changes to the database directly without waiting for an explicit commit. DDL- and DML statements as well asMutation
s are sent directly to Spanner, and committed automatically unless the statement caused an error. The statement is retried in case of anAbortedException
. All other errors will cause the underlying transaction to be rolled back.A
Connection
that is in autocommit and read/write mode will allow all types of statements: Queries, DML, DDL, and Mutations (writes). If the connection is in read-only mode, only queries will be allowed.Connection
s in autocommit mode may also accept partitioned DML statements. SeesetAutocommitDmlMode(AutocommitDmlMode)
for more information.- Parameters:
autocommit
- true/false to turn autocommit on/off
-
isAutocommit
boolean isAutocommit()
- Returns:
true
if this connection is in autocommit mode
-
setReadOnly
void setReadOnly(boolean readOnly)
Sets this connection to read-only or read-write. This method may only be called when no transaction is active. A connection that is in read-only mode, will never allow any kind of changes to the database to be submitted.- Parameters:
readOnly
- true/false to turn read-only mode on/off
-
isReadOnly
boolean isReadOnly()
- Returns:
true
if this connection is in read-only mode
-
setStatementTimeout
void setStatementTimeout(long timeout, TimeUnit unit)
Sets the duration the connection should wait before automatically aborting the execution of a statement. The default is no timeout. Statement timeouts are applied all types of statements, both in autocommit and transactional mode. They also apply tocommit()
androllback()
statements.A DML statement in autocommit mode may or may not have actually been applied to the database, depending on when the timeout occurred.
A DML statement in a transaction that times out may still have been applied to the transaction. If you still decide to commit the transaction after such a timeout, the DML statement may or may not have been part of the transaction, depending on whether the timeout occurred before or after the statement was (successfully) sent to Spanner. You should therefore either always rollback a transaction that had a DML statement that timed out, or you should accept that the timed out statement still might have been applied to the database.
DDL statements and DML statements in
AutocommitDmlMode.PARTITIONED_NON_ATOMIC
mode cannot be rolled back. If such a statement times out, it may or may not have been applied to the database. The same applies to commit and rollback statements.Statements that time out will throw a
SpannerException
with error codeErrorCode.DEADLINE_EXCEEDED
.- Parameters:
timeout
- The number ofTimeUnit
s before a statement is automatically aborted by the connection. Zero or negative values are not allowed. The maximum allowed value is 315,576,000,000 seconds. UseclearStatementTimeout()
to remove a timeout value that has been set.unit
- TheTimeUnit
to specify the timeout value in. Must be one ofTimeUnit.NANOSECONDS
,TimeUnit.MICROSECONDS
,TimeUnit.MILLISECONDS
,TimeUnit.SECONDS
.
-
clearStatementTimeout
void clearStatementTimeout()
Clears the statement timeout value for this connection. This is a no-op if there is currently no statement timeout set on this connection.
-
getStatementTimeout
long getStatementTimeout(TimeUnit unit)
- Parameters:
unit
- TheTimeUnit
to get the timeout value in. Must be one ofTimeUnit.NANOSECONDS
,TimeUnit.MICROSECONDS
,TimeUnit.MILLISECONDS
,TimeUnit.SECONDS
- Returns:
- the current statement timeout value or 0 if no timeout value has been set.
-
hasStatementTimeout
boolean hasStatementTimeout()
- Returns:
true
if thisConnection
has a statement timeout value.
-
cancel
void cancel()
Cancels the currently running statement on thisConnection
(if any). If canceling the statement execution succeeds, the statement will be terminated and aSpannerException
with codeErrorCode.CANCELLED
will be thrown. The result of the statement will be the same as when a statement times out (seesetStatementTimeout(long, TimeUnit)
for more information).Canceling a DDL statement in autocommit mode or a RUN BATCH statement of a DDL batch will cause the connection to try to cancel the execution of the DDL statement(s). This is not guaranteed to cancel the execution of the statement(s) on Cloud Spanner. See https://cloud.google.com/spanner/docs/reference/rpc/google.longrunning#google.longrunning.Operations.CancelOperation for more information.
Canceling a DML statement that is running in
AutocommitDmlMode.PARTITIONED_NON_ATOMIC
mode will not cancel a statement on Cloud Spanner that is already being executed, and its effects will still be applied to the database.
-
beginTransaction
void beginTransaction()
Begins a new transaction for this connection.- Calling this method on a connection that has no transaction and that is not in autocommit mode, will register a new transaction that has not yet started on this connection
- Calling this method on a connection that has no transaction and that is in autocommit mode, will register a new transaction that has not yet started on this connection, and temporarily turn off autocommit mode until the next commit/rollback
- Calling this method on a connection that already has a transaction that has not yet
started, will cause a
SpannerException
- Calling this method on a connection that already has a transaction that has started, will
cause a
SpannerException
(no nested transactions)
-
beginTransactionAsync
com.google.api.core.ApiFuture<Void> beginTransactionAsync()
Begins a new transaction for this connection. This method is guaranteed to be non-blocking. The returnedApiFuture
will be done when the transaction has been initialized.- Calling this method on a connection that has no transaction and that is not in autocommit mode, will register a new transaction that has not yet started on this connection
- Calling this method on a connection that has no transaction and that is in autocommit mode, will register a new transaction that has not yet started on this connection, and temporarily turn off autocommit mode until the next commit/rollback
- Calling this method on a connection that already has a transaction that has not yet
started, will cause a
SpannerException
- Calling this method on a connection that already has a transaction that has started, will
cause a
SpannerException
(no nested transactions)
-
setTransactionMode
void setTransactionMode(TransactionMode transactionMode)
Sets the transaction mode to use for current transaction. This method may only be called when in a transaction, and before the transaction is actually started, i.e. before any statements have been executed in the transaction.- Parameters:
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 useTransactionMode.READ_ONLY_TRANSACTION
instead ofTransactionMode.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. IfisRetryAbortsInternally()
istrue
, each read/write transaction will keep track of a running SHA256 checksum for eachResultSet
that is returned in order to be able to retry the transaction in case the transaction is aborted by Spanner.
-
getTransactionMode
TransactionMode getTransactionMode()
- Returns:
- the transaction mode of the current transaction. This method may only be called when the connection is in a transaction.
-
setTransactionTag
default void setTransactionTag(String tag)
Sets the transaction tag to use for the current transaction. This method may only be called when in a transaction and before any statements have been executed in the transaction.The tag will be set as the transaction tag of all statements during the transaction, and as the transaction tag of the commit.
The transaction tag will automatically be cleared after the transaction has ended.
- Parameters:
tag
- The tag to use.
-
getTransactionTag
default String getTransactionTag()
- Returns:
- The transaction tag of the current transaction.
-
setStatementTag
default void setStatementTag(String tag)
Sets the statement tag to use for the next statement that is executed. The tag is automatically cleared after the statement is executed. Statement tags can be used both with autocommit=true and autocommit=false, and can be used for partitioned DML.Statement tags are not allowed before COMMIT and ROLLBACK statements.
Statement tags are allowed before START BATCH DML statements and will be included in the
ExecuteBatchDmlRequest
that is sent to Spanner. Statement tags are not allowed inside a batch.- Parameters:
tag
- The statement tag to use with the next statement that will be executed on this connection.
-
getStatementTag
default String getStatementTag()
- Returns:
- The statement tag that will be used with the next statement that is executed on this connection.
-
isRetryAbortsInternally
boolean isRetryAbortsInternally()
- Returns:
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.
-
setRetryAbortsInternally
void setRetryAbortsInternally(boolean retryAbortsInternally)
Sets whether this connection will internally retry read/write transactions that abort. The default istrue
. When internal retry is enabled, theConnection
will keep track of a running SHA256 checksum of allResultSet
s 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 anAbortedDueToConcurrentModificationException
.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.
- Parameters:
retryAbortsInternally
- Set totrue
to internally retry transactions that are aborted by Spanner. When set tofalse
, any database call on a transaction that has been aborted by Cloud Spanner will throw anAbortedException
instead of being retried. Set this to false if your application already uses retry loops to handleAbortedException
s.
-
addTransactionRetryListener
void addTransactionRetryListener(TransactionRetryListener listener)
Add aTransactionRetryListener
to thisConnection
for testing and logging purposes. The methodTransactionRetryListener.retryStarting(Timestamp, long, int)
will be called before an automatic retry is started for a read/write transaction on this connection. The methodTransactionRetryListener.retryFinished(Timestamp, long, int, TransactionRetryListener.RetryResult)
will be called after the retry has finished.- Parameters:
listener
- The listener to add to this connection.
-
removeTransactionRetryListener
boolean removeTransactionRetryListener(TransactionRetryListener listener)
Removes one existingTransactionRetryListener
from thisConnection
, if it is present (optional operation).- Parameters:
listener
- The listener to remove from the connection.- Returns:
true
if a listener was removed from the connection.
-
getTransactionRetryListeners
Iterator<TransactionRetryListener> getTransactionRetryListeners()
- Returns:
- an unmodifiable iterator of the
TransactionRetryListener
s registered for this connection.
-
setAutocommitDmlMode
void setAutocommitDmlMode(AutocommitDmlMode mode)
Sets the mode for executing DML statements in autocommit mode for this connection. This setting is only used when the connection is in autocommit mode, and may only be set while the transaction is in autocommit mode and not in a temporary transaction. The autocommit transaction mode is reset to its default value ofAutocommitDmlMode.TRANSACTIONAL
when autocommit mode is changed on the connection.- Parameters:
mode
- The DML autocommit mode to useAutocommitDmlMode.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 databaseAutocommitDmlMode.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.
-
getAutocommitDmlMode
AutocommitDmlMode getAutocommitDmlMode()
- Returns:
- the current
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.
-
setReadOnlyStaleness
void setReadOnlyStaleness(TimestampBound staleness)
Sets the staleness to use for the current read-only transaction. This method may only be called when the transaction mode of the current transaction isTransactionMode.READ_ONLY_TRANSACTION
and there is no transaction that has started, or when the connection is in read-only and autocommit mode.- Parameters:
staleness
- The staleness to use for the current but not yet started read-only transaction
-
getReadOnlyStaleness
TimestampBound getReadOnlyStaleness()
- Returns:
- the read-only staleness setting for the current read-only transaction. This method may only be called when the current transaction is a read-only transaction, or when the connection is in read-only and autocommit mode.
-
setOptimizerVersion
void setOptimizerVersion(String optimizerVersion)
Sets the query optimizer version to use for this connection.- Parameters:
optimizerVersion
- The query optimizer version to use. Must be a valid optimizer version number, the stringLATEST
or an empty string. The empty string will instruct the connection to use the optimizer version that is defined in the environment variableSPANNER_OPTIMIZER_VERSION
. If no value is specified in the environment variable, the default query optimizer of Cloud Spanner is used.
-
getOptimizerVersion
String getOptimizerVersion()
Gets the current query optimizer version of this connection.- Returns:
- The query optimizer version that is currently used by this connection.
-
setOptimizerStatisticsPackage
default void setOptimizerStatisticsPackage(String optimizerStatisticsPackage)
Sets the query optimizer statistics package- Parameters:
optimizerStatisticsPackage
- The query optimizer statistics package to use. Must be a string composed of letters, numbers, dashes and underscores or an empty string. The empty string will instruct the connection to use the optimizer statistics package that is defined the environment variableSPANNER_OPTIMIZER_STATISTICS_PACKAGE
. If no value is specified in the environment variable, the client level query optimizer is used. If none is set, the default query optimizer of Cloud Spanner is used.
-
getOptimizerStatisticsPackage
default String getOptimizerStatisticsPackage()
Gets the current query optimizer statistics package of this connection.- Returns:
- The query optimizer statistics package that is currently used by this connection.
-
setReturnCommitStats
void setReturnCommitStats(boolean returnCommitStats)
Sets whether this connection should request commit statistics from Cloud Spanner for read/write transactions and DML statements in autocommit mode.
-
isReturnCommitStats
boolean isReturnCommitStats()
- Returns:
- true if this connection requests commit statistics from Cloud Spanner
-
setRPCPriority
default void setRPCPriority(Options.RpcPriority rpcPriority)
Sets the priority to use for RPCs executed by this connection..- Parameters:
rpcPriority
- The RPC priority to use.Options.RpcPriority.HIGH
This specifies that the RPC's invocation will be of high priority.Options.RpcPriority.MEDIUM
This specifies that the RPC's invocation will be of medium priority.Options.RpcPriority.LOW
This specifies that the RPC's invocation will be of low priority.
-
getRPCPriority
default Options.RpcPriority getRPCPriority()
Gets the current RPC priority of this connection.- Returns:
- The RPC priority that is currently used by this connection.
-
commit
void commit()
Commits the current transaction of this connection. All mutations that have been buffered during the current transaction will be written to the database.If the connection is in autocommit mode, and there is a temporary transaction active on this connection, calling this method will cause the connection to go back to autocommit mode after calling this method.
This method will throw a
SpannerException
with codeErrorCode.DEADLINE_EXCEEDED
if a statement timeout has been set on this connection, and the commit operation takes longer than this timeout.- Calling this method on a connection in autocommit mode and with no temporary transaction, will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end
that transaction and any properties that might have been set on that transaction, and
return the connection to its previous state. This means that if a transaction is created
and set to read-only, and then committed before any statements have been executed, the
read-only transaction is ended and any subsequent statements will be executed in a new
transaction. If the connection is in read-write mode, the default for new transactions
will be
TransactionMode.READ_WRITE_TRANSACTION
. Committing an empty transaction also does not generate a read timestamp or a commit timestamp, and calling one of the methodsgetReadTimestamp()
orgetCommitTimestamp()
will cause an exception. - Calling this method on a connection with a
TransactionMode.READ_ONLY_TRANSACTION
transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be aTransactionMode.READ_WRITE_TRANSACTION
transaction, unless any following transaction is explicitly set toTransactionMode.READ_ONLY_TRANSACTION
- Calling this method on a connection with a
TransactionMode.READ_WRITE_TRANSACTION
transaction will send all buffered mutations to the database, commit any DML statements that have been executed during this transaction and end the transaction.
-
commitAsync
com.google.api.core.ApiFuture<Void> commitAsync()
Commits the current transaction of this connection. All mutations that have been buffered during the current transaction will be written to the database.This method is guaranteed to be non-blocking. The returned
ApiFuture
will be done when the transaction has committed or the commit has failed.Calling this method will always end the current transaction and start a new transaction when the next statement is executed, regardless whether this commit call succeeded or failed. If the next statement(s) rely on the results of the transaction that is being committed, it is recommended to check the status of this commit by inspecting the value of the returned
ApiFuture
before executing the next statement, to ensure that the commit actually succeeded.If the connection is in autocommit mode, and there is a temporary transaction active on this connection, calling this method will cause the connection to go back to autocommit mode after calling this method.
This method will throw a
SpannerException
with codeErrorCode.DEADLINE_EXCEEDED
if a statement timeout has been set on this connection, and the commit operation takes longer than this timeout.- Calling this method on a connection in autocommit mode and with no temporary transaction, will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end
that transaction and any properties that might have been set on that transaction, and
return the connection to its previous state. This means that if a transaction is created
and set to read-only, and then committed before any statements have been executed, the
read-only transaction is ended and any subsequent statements will be executed in a new
transaction. If the connection is in read-write mode, the default for new transactions
will be
TransactionMode.READ_WRITE_TRANSACTION
. Committing an empty transaction also does not generate a read timestamp or a commit timestamp, and calling one of the methodsgetReadTimestamp()
orgetCommitTimestamp()
will cause an exception. - Calling this method on a connection with a
TransactionMode.READ_ONLY_TRANSACTION
transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be aTransactionMode.READ_WRITE_TRANSACTION
transaction, unless any following transaction is explicitly set toTransactionMode.READ_ONLY_TRANSACTION
- Calling this method on a connection with a
TransactionMode.READ_WRITE_TRANSACTION
transaction will send all buffered mutations to the database, commit any DML statements that have been executed during this transaction and end the transaction.
-
rollback
void rollback()
Rollbacks the current transaction of this connection. All mutations or DDL statements that have been buffered during the current transaction will be removed from the buffer.If the connection is in autocommit mode, and there is a temporary transaction active on this connection, calling this method will cause the connection to go back to autocommit mode after calling this method.
- Calling this method on a connection in autocommit mode and with no temporary transaction will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end
that transaction and any properties that might have been set on that transaction, and
return the connection to its previous state. This means that if a transaction is created
and set to read-only, and then rolled back before any statements have been executed, the
read-only transaction is ended and any subsequent statements will be executed in a new
transaction. If the connection is in read-write mode, the default for new transactions
will be
TransactionMode.READ_WRITE_TRANSACTION
. - Calling this method on a connection with a
TransactionMode.READ_ONLY_TRANSACTION
transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be aTransactionMode.READ_WRITE_TRANSACTION
transaction, unless any following transaction is explicitly set toTransactionMode.READ_ONLY_TRANSACTION
- Calling this method on a connection with a
TransactionMode.READ_WRITE_TRANSACTION
transaction will clear all buffered mutations, rollback any DML statements that have been executed during this transaction and end the transaction.
-
rollbackAsync
com.google.api.core.ApiFuture<Void> rollbackAsync()
Rollbacks the current transaction of this connection. All mutations or DDL statements that have been buffered during the current transaction will be removed from the buffer.This method is guaranteed to be non-blocking. The returned
ApiFuture
will be done when the transaction has been rolled back.If the connection is in autocommit mode, and there is a temporary transaction active on this connection, calling this method will cause the connection to go back to autocommit mode after calling this method.
- Calling this method on a connection in autocommit mode and with no temporary transaction will cause an exception
- Calling this method while a DDL batch is active will cause an exception
- Calling this method on a connection with a transaction that has not yet started, will end
that transaction and any properties that might have been set on that transaction, and
return the connection to its previous state. This means that if a transaction is created
and set to read-only, and then rolled back before any statements have been executed, the
read-only transaction is ended and any subsequent statements will be executed in a new
transaction. If the connection is in read-write mode, the default for new transactions
will be
TransactionMode.READ_WRITE_TRANSACTION
. - Calling this method on a connection with a
TransactionMode.READ_ONLY_TRANSACTION
transaction will end that transaction. If the connection is in read-write mode, any subsequent transaction will by default be aTransactionMode.READ_WRITE_TRANSACTION
transaction, unless any following transaction is explicitly set toTransactionMode.READ_ONLY_TRANSACTION
- Calling this method on a connection with a
TransactionMode.READ_WRITE_TRANSACTION
transaction will clear all buffered mutations, rollback any DML statements that have been executed during this transaction and end the transaction.
-
isInTransaction
boolean isInTransaction()
- Returns:
true
if this connection has a transaction (that has not necessarily started). This method will only return false when theConnection
is in autocommit mode and no explicit transaction has been started by callingbeginTransaction()
. If theConnection
is not in autocommit mode, there will always be a transaction.
-
isTransactionStarted
boolean isTransactionStarted()
- Returns:
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.
-
getReadTimestamp
com.google.cloud.Timestamp getReadTimestamp()
Returns the read timestamp of the current/lastTransactionMode.READ_ONLY_TRANSACTION
transaction, or the read timestamp of the last query in autocommit mode.- When in autocommit mode: The method will return the read timestamp of the last statement if the last statement was a query.
- When in a
TransactionMode.READ_ONLY_TRANSACTION
transaction that has started (a query has been executed), or that has just committed: The read timestamp of the transaction. If the read-only transaction was committed without ever executing a query, calling this method after the commit will also throw aSpannerException
- In all other cases the method will throw a
SpannerException
.
- Returns:
- the read timestamp of the current/last read-only transaction.
-
getCommitTimestamp
com.google.cloud.Timestamp getCommitTimestamp()
- Returns:
- the commit timestamp of the last
TransactionMode.READ_WRITE_TRANSACTION
transaction. This method throws aSpannerException
if there is no lastTransactionMode.READ_WRITE_TRANSACTION
transaction. That is, if the last transaction was aTransactionMode.READ_ONLY_TRANSACTION
), or if the lastTransactionMode.READ_WRITE_TRANSACTION
transaction rolled back. It also throws aSpannerException
if the lastTransactionMode.READ_WRITE_TRANSACTION
transaction was empty when committed.
-
getCommitResponse
CommitResponse getCommitResponse()
- Returns:
- the
CommitResponse
of the lastTransactionMode.READ_WRITE_TRANSACTION
transaction. This method throws aSpannerException
if there is no lastTransactionMode.READ_WRITE_TRANSACTION
transaction. That is, if the last transaction was aTransactionMode.READ_ONLY_TRANSACTION
), or if the lastTransactionMode.READ_WRITE_TRANSACTION
transaction rolled back. It also throws aSpannerException
if the lastTransactionMode.READ_WRITE_TRANSACTION
transaction was empty when committed.
-
startBatchDdl
void startBatchDdl()
Starts a new DDL batch on this connection. A DDL batch allows several DDL statements to be grouped into a batch that can be executed as a group. DDL statements that are issued during the batch are buffered locally and will return immediately with an OK. It is not guaranteed that a DDL statement that has been issued during a batch will eventually succeed when running the batch. Aborting a DDL batch will clear the DDL buffer and will have made no changes to the database. Running a DDL batch will send all buffered DDL statements to Spanner, and Spanner will try to execute these. The result will be OK if all the statements executed successfully. If a statement cannot be executed, Spanner will stop execution at that point and return an error message for the statement that could not be executed. Preceding statements of the batch may have been executed.This method may only be called when the connection is in read/write mode, autocommit mode is enabled or no read/write transaction has been started, and there is not already another batch active. The connection will only accept DDL statements while a DDL batch is active.
-
startBatchDml
void startBatchDml()
Starts a new DML batch on this connection. A DML batch allows several DML statements to be grouped into a batch that can be executed as a group. DML statements that are issued during the batch are buffered locally and will return immediately with an OK. It is not guaranteed that a DML statement that has been issued during a batch will eventually succeed when running the batch. Aborting a DML batch will clear the DML buffer and will have made no changes to the database. Running a DML batch will send all buffered DML statements to Spanner, and Spanner will try to execute these. The result will be OK if all the statements executed successfully. If a statement cannot be executed, Spanner will stop execution at that point and returnSpannerBatchUpdateException
for the statement that could not be executed. Preceding statements of the batch will have been executed, and the update counts of those statements can be retrieved throughSpannerBatchUpdateException.getUpdateCounts()
.This method may only be called when the connection is in read/write mode, autocommit mode is enabled or no read/write transaction has been started, and there is not already another batch active. The connection will only accept DML statements while a DML batch is active.
-
runBatch
long[] runBatch()
Sends all buffered DML or DDL statements of the current batch to the database, waits for these to be executed and ends the current batch. The method will throw an exception for the first statement that cannot be executed, or return successfully if all statements could be executed. If an exception is thrown for a statement in the batch, the preceding statements in the same batch may still have been applied to the database.This method may only be called when a (possibly empty) batch is active.
- Returns:
- the update counts in case of a DML batch. Returns an array containing 1 for each successful statement and 0 for each failed statement or statement that was not executed in case of a DDL batch.
-
runBatchAsync
com.google.api.core.ApiFuture<long[]> runBatchAsync()
Sends all buffered DML or DDL statements of the current batch to the database, waits for these to be executed and ends the current batch. The method will throw an exception for the first statement that cannot be executed, or return successfully if all statements could be executed. If an exception is thrown for a statement in the batch, the preceding statements in the same batch may still have been applied to the database.This method is guaranteed to be non-blocking. The returned
ApiFuture
will be done when the batch has been successfully applied, or when one or more of the statements in the batch has failed and the further execution of the batch has been halted.This method may only be called when a (possibly empty) batch is active.
- Returns:
- an
ApiFuture
containing the update counts in case of a DML batch. TheApiFuture
contains an array containing 1 for each successful statement and 0 for each failed statement or statement that was not executed in case of a DDL batch.
-
abortBatch
void abortBatch()
Clears all buffered statements in the current batch and ends the batch.This method may only be called when a (possibly empty) batch is active.
-
isDdlBatchActive
boolean isDdlBatchActive()
- Returns:
true
if a DDL batch is active on this connection.
-
isDmlBatchActive
boolean isDmlBatchActive()
- Returns:
true
if a DML batch is active on this connection.
-
execute
StatementResult execute(Statement statement)
Executes the given statement if allowed in the currentTransactionMode
and connection state. The returned value depends on the type of statement:- Queries and DML statements with returning clause will return a
ResultSet
. - Simple DML statements will return an update count
- DDL statements will return a
StatementResult.ResultType.NO_RESULT
- Connection and transaction statements (SET AUTOCOMMIT=TRUE|FALSE, SHOW AUTOCOMMIT, SET
TRANSACTION READ ONLY, etc) will return either a
ResultSet
orStatementResult.ResultType.NO_RESULT
, depending on the type of statement (SHOW or SET)
- Parameters:
statement
- The statement to execute- Returns:
- the result of the statement
- Queries and DML statements with returning clause will return a
-
executeAsync
AsyncStatementResult executeAsync(Statement statement)
Executes the given statement if allowed in the currentTransactionMode
and connection state asynchronously. The returned value depends on the type of statement:- Queries and DML statements with returning clause will return an
AsyncResultSet
. - Simple DML statements will return an
ApiFuture
with an update count that is done when the DML statement has been applied successfully, or that throws anExecutionException
if the DML statement failed. - DDL statements will return an
ApiFuture
containing aVoid
that is done when the DDL statement has been applied successfully, or that throws anExecutionException
if the DDL statement failed. - Connection and transaction statements (SET AUTOCOMMIT=TRUE|FALSE, SHOW AUTOCOMMIT, SET
TRANSACTION READ ONLY, etc) will return either a
ResultSet
orStatementResult.ResultType.NO_RESULT
, depending on the type of statement (SHOW or SET)
- Parameters:
statement
- The statement to execute- Returns:
- the result of the statement
- Queries and DML statements with returning clause will return an
-
executeQuery
ResultSet executeQuery(Statement query, Options.QueryOption... options)
Executes the given statement (a query or a DML statement with returning clause) and returns the result as aResultSet
. This method blocks and waits for a response from Spanner. If the statement does not contain a valid query or a DML statement with returning clause, the method will throw aSpannerException
.- Parameters:
query
- The query statement or DML statement with returning clause to executeoptions
- the options to configure the query- Returns:
- a
ResultSet
with the results of the statement
-
executeQueryAsync
AsyncResultSet executeQueryAsync(Statement query, Options.QueryOption... options)
Executes the given statement (a query or a DML statement with returning clause) asynchronously and returns the result as anAsyncResultSet
. This method is guaranteed to be non-blocking. If the statement does not contain a valid query or a DML statement with returning clause, the method will throw aSpannerException
.See
AsyncResultSet.setCallback(java.util.concurrent.Executor, com.google.cloud.spanner.AsyncResultSet.ReadyCallback)
for more information on how to consume the results of the statement asynchronously.It is also possible to consume the returned
AsyncResultSet
in the same way as a normalResultSet
, i.e. in a while-loop callingResultSet.next()
.- Parameters:
query
- The query statement or DML statement with returning clause to executeoptions
- the options to configure the query- Returns:
- an
AsyncResultSet
with the results of the statement
-
analyzeQuery
ResultSet analyzeQuery(Statement query, ReadContext.QueryAnalyzeMode queryMode)
Analyzes a query or a DML statement and returns query plan and/or query execution statistics information.The query plan and query statistics information is contained in
ResultSetStats
that can be accessed by callingResultSet.getStats()
on the returnedResultSet
.ResultSet resultSet = connection.analyzeQuery( Statement.of("SELECT SingerId, AlbumId, MarketingBudget FROM Albums"), ReadContext.QueryAnalyzeMode.PROFILE); while (resultSet.next()) { // Discard the results. We're only processing because getStats() below requires it. } ResultSetStats stats = resultSet.getStats();
- Parameters:
query
- the query statement to executequeryMode
- the mode in which to execute the query
-
executeUpdate
long executeUpdate(Statement update)
Executes the given statement as a simple DML statement. If the statement does not contain a valid DML statement, the method will throw aSpannerException
.- Parameters:
update
- The update statement to execute- Returns:
- the number of records that were inserted/updated/deleted by this statement
-
analyzeUpdate
@Deprecated default ResultSetStats analyzeUpdate(Statement update, ReadContext.QueryAnalyzeMode analyzeMode)
Deprecated.Analyzes a DML statement and returns query plan and/or execution statistics information.ReadContext.QueryAnalyzeMode.PLAN
only returns the plan for the statement.ReadContext.QueryAnalyzeMode.PROFILE
executes the DML statement, returns the modified row count and execution statistics, and the effects of the DML statement will be visible to subsequent operations in the transaction.
-
analyzeUpdateStatement
default ResultSet analyzeUpdateStatement(Statement statement, ReadContext.QueryAnalyzeMode analyzeMode, Options.UpdateOption... options)
Analyzes a DML statement and returns execution plan, undeclared parameters and optionally execution statistics information.ReadContext.QueryAnalyzeMode.PLAN
only returns the plan and undeclared parameters for the statement.ReadContext.QueryAnalyzeMode.PROFILE
also executes the DML statement, returns the modified row count and execution statistics, and the effects of the DML statement will be visible to subsequent operations in the transaction.
-
executeUpdateAsync
com.google.api.core.ApiFuture<Long> executeUpdateAsync(Statement update)
Executes the given statement asynchronously as a simple DML statement. If the statement does not contain a simple DML statement, the method will throw aSpannerException
. A DML statement with returning clause will throw aSpannerException
.This method is guaranteed to be non-blocking.
- Parameters:
update
- The update statement to execute- Returns:
- an
ApiFuture
containing the number of records that were inserted/updated/deleted by this statement
-
executeBatchUpdate
long[] executeBatchUpdate(Iterable<Statement> updates)
Executes a list of DML statements (can be simple DML statements or DML statements with returning clause) in a single request. The statements will be executed in order and the semantics is the same as if each statement is executed byexecuteUpdate(Statement)
in a loop. This method returns an array of long integers, each representing the number of rows modified by each statement.If an individual statement fails, execution stops and a
SpannerBatchUpdateException
is returned, which includes the error and the number of rows affected by the statements that are run prior to the error.For example, if statements contains 3 statements, and the 2nd one is not a valid DML. This method throws a
SpannerBatchUpdateException
that contains the error message from the 2nd statement, and an array of length 1 that contains the number of rows modified by the 1st statement. The 3rd statement will not run. Executes the given statements as DML statements in one batch. If one of the statements does not contain a valid DML statement, the method will throw aSpannerException
.- Parameters:
updates
- The update statements that will be executed as one batch.- Returns:
- an array containing the update counts per statement.
-
executeBatchUpdateAsync
com.google.api.core.ApiFuture<long[]> executeBatchUpdateAsync(Iterable<Statement> updates)
Executes a list of DML statements (can be simple DML statements or DML statements with returning clause) in a single request. The statements will be executed in order and the semantics is the same as if each statement is executed byexecuteUpdate(Statement)
in a loop. This method returns anApiFuture
that contains an array of long integers, each representing the number of rows modified by each statement.This method is guaranteed to be non-blocking.
If an individual statement fails, execution stops and a
SpannerBatchUpdateException
is returned, which includes the error and the number of rows affected by the statements that are run prior to the error.For example, if statements contains 3 statements, and the 2nd one is not a valid DML. This method throws a
SpannerBatchUpdateException
that contains the error message from the 2nd statement, and an array of length 1 that contains the number of rows modified by the 1st statement. The 3rd statement will not run. Executes the given statements as DML statements in one batch. If one of the statements does not contain a valid DML statement, the method will throw aSpannerException
.- Parameters:
updates
- The update statements that will be executed as one batch.- Returns:
- an
ApiFuture
containing an array with the update counts per statement.
-
write
void write(Mutation mutation)
Writes the specified mutation directly to the database and commits the change. The value is readable after the successful completion of this method. Writing multiple mutations to a database by calling this method multiple times mode is inefficient, as each call will need a round trip to the database. Instead, you should consider writing the mutations together by callingwrite(Iterable)
.Calling this method is only allowed in autocommit mode. See
bufferedWrite(Iterable)
for writing mutations in transactions.- Parameters:
mutation
- TheMutation
to write to the database- Throws:
SpannerException
- if theConnection
is not in autocommit mode
-
writeAsync
com.google.api.core.ApiFuture<Void> writeAsync(Mutation mutation)
Writes the specified mutation directly to the database and commits the change. The value is readable after the successful completion of the returnedApiFuture
. Writing multiple mutations to a database by calling this method multiple times mode is inefficient, as each call will need a round trip to the database. Instead, you should consider writing the mutations together by callingwriteAsync(Iterable)
.This method is guaranteed to be non-blocking.
Calling this method is only allowed in autocommit mode. See
bufferedWrite(Iterable)
for writing mutations in transactions.- Parameters:
mutation
- TheMutation
to write to the database- Throws:
SpannerException
- if theConnection
is not in autocommit mode
-
write
void write(Iterable<Mutation> mutations)
Writes the specified mutations directly to the database and commits the changes. The values are readable after the successful completion of this method.Calling this method is only allowed in autocommit mode. See
bufferedWrite(Iterable)
for writing mutations in transactions.- Parameters:
mutations
- TheMutation
s to write to the database- Throws:
SpannerException
- if theConnection
is not in autocommit mode
-
writeAsync
com.google.api.core.ApiFuture<Void> writeAsync(Iterable<Mutation> mutations)
Writes the specified mutations directly to the database and commits the changes. The values are readable after the successful completion of the returnedApiFuture
.This method is guaranteed to be non-blocking.
Calling this method is only allowed in autocommit mode. See
bufferedWrite(Iterable)
for writing mutations in transactions.- Parameters:
mutations
- TheMutation
s to write to the database- Throws:
SpannerException
- if theConnection
is not in autocommit mode
-
bufferedWrite
void bufferedWrite(Mutation mutation)
Buffers the given mutation locally on the current transaction of thisConnection
. The mutation will be written to the database at the next call tocommit()
. The value will not be readable on thisConnection
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.- Parameters:
mutation
- theMutation
to buffer for writing to the database on the next commit- Throws:
SpannerException
- if theConnection
is in autocommit mode
-
bufferedWrite
void bufferedWrite(Iterable<Mutation> mutations)
Buffers the given mutations locally on the current transaction of thisConnection
. The mutations will be written to the database at the next call tocommit()
. The values will not be readable on thisConnection
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.- Parameters:
mutations
- theMutation
s to buffer for writing to the database on the next commit- Throws:
SpannerException
- if theConnection
is in autocommit mode
-
getDialect
default Dialect getDialect()
TheDialect
that is used by thisConnection
.
-
getDatabaseClient
@InternalApi default DatabaseClient getDatabaseClient()
TheDatabaseClient
that is used by thisConnection
.
-
-