Transaction
The Transaction class wraps a set of operations into an atomic unit. Changes made within a transaction are only applied when committed, and can be rolled back by cancelling. Transactions are created by calling .beginTransaction() on a Surreal instance.
Source: surrealdb.java
Methods
Note
.query(sql)
Executes a SurrealQL query within the transaction. The query results are not visible outside the transaction until it is committed.
| Parameter | Type | Description |
|---|---|---|
sql | String | The SurrealQL query string to execute within the transaction. |
Returns: Response
.commit()
Commits the transaction, applying all changes made within it to the database. After committing, the transaction object should not be reused.
Returns: void
.cancel()
Cancels the transaction, discarding all changes made within it. No data is written to the database. After cancelling, the transaction object should not be reused.
Returns: void
Complete Example
See Also
Surreal — Connection and method reference
Response — Query response reference
Transactions — Transaction concepts and patterns
SurrealQL BEGIN — Server-side transaction syntax