Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Transactions
- Object
- Transactions
The transaction a @Transactional method runs in, bound to the calling
thread.
The build rewrites every @Transactional method into a call to
begin, the original body, then commit – or
afterThrow with the rollback decision it worked out from the
annotation. Propagation, isolation, read-only and timeout arrive as constants.
This class binds the connection, completion hooks and scoped resources to
the physical transaction on the calling thread.
Joining
Nothing has to be handed the transaction. DataSource.borrow asks this
class first, and a thread inside a transaction gets the transaction’s
connection back instead of a pooled one – so the pool’s own methods, an
EntityManager’s daos and a managed session all join it. The connection
is borrowed, and BEGIN sent, only when the transaction first needs it: a
@Transactional method that returns before touching the database costs
only an in-memory scope, with no database round trip.
A thread that has never begun a transaction does not even read the
thread-local: used is set by the first begin of the process,
on the thread that is then inside it, so every other thread reading a stale
false is correct – none of them is in a transaction.
Propagation
Spring’s seven, one for one; the constants below are the ordinals of
com.codename1.backend.annotations.Propagation. A method that joins a
transaction and fails with a rollback-worthy exception marks the whole
transaction rollback-only, and the method that began it then rolls back and
throws TransactionException.UnexpectedRollback rather than reporting
a commit that did not happen.
Nested types
enum Transactions.Outcome | Final outcome. |
class Transactions.Synchronization | Hooks run synchronously in registration order, once per physical transaction (including a scope that never borrowed a connection). |
interface Transactions.Work | A programmatic transaction body. |
Methods
Inherited methods
Method details
execute
public static Object execute(Transactions.Work work)
throws ExceptionThrows
execute
public static Object execute(Propagation propagation, boolean readOnly, int timeoutSeconds, Isolation isolation, Transactions.Work work)
throws Exception@Transactional. Unlike annotation rollback rules, every body failure rolls back.Throws
registerSynchronization
public static void registerSynchronization(Transactions.Synchronization synchronization)bindResource
public static void bindResource(Object key, Object value)getResource
public static Object getResource(Object key)unbindResource
public static Object unbindResource(Object key)isActive
public static boolean isActive()isRollbackOnly
public static boolean isRollbackOnly()setRollbackOnly
public static void setRollbackOnly()