Class TransactionTemplate
ConnectionCallbacks inside a managed JDBC transaction.
The template opens a connection, sets the requested Isolation,
applies follower-read staleness from CrdbContext (via
SET TRANSACTION AS OF SYSTEM TIME), applies Cockroach vCluster tagging
from CrdbContext — SET LOCAL application_name for the vCluster
name and SET LOCAL default_transaction_quality_of_service for the
workload QoS (HIGH→critical, NORMAL→regular, LOW→background) —
runs the callback, and commits. SET LOCAL scopes the tags to this
transaction so pooled connections are not polluted for the next borrower.
On a serialization conflict it rolls back and — when retry is enabled —
replays the whole transaction through RetryEngine, realizing
CockroachDB's cockroach_restart retry semantics as a full-transaction
restart.
vCluster scope (v1): this is workload tagging and QoS assignment. Routing a workload to a different vCluster endpoint is platform-dependent and is not performed here.
-
Constructor Summary
ConstructorsConstructorDescriptionTransactionTemplate(DataSource dataSource) TransactionTemplate(DataSource dataSource, RetryPolicy retryPolicy, RetryEngine retryEngine) -
Method Summary
Modifier and TypeMethodDescription<T> Texecute(Isolation iso, boolean retry, ConnectionCallback<T> work) Executeworkin a transaction.
-
Constructor Details
-
TransactionTemplate
-
TransactionTemplate
-
-
Method Details
-
execute
Executeworkin a transaction.- Parameters:
iso- the isolation level to setretry- whether to retry on serialization conflictswork- the work to run against the transactional connection
-