-
Notifications
You must be signed in to change notification settings - Fork 46
Transaction
王爵nice edited this page Apr 11, 2018
·
2 revisions
Anima puts the transaction operation in a lambda
expression, so that you don't care how it is done. By default, the transaction will automatically roll back when a certain add/delete operation encounters RuntimeException
. Let's see one example.
Anima.atomic(() -> {
int a = 1 / 0;
new User("apple", 666).save();
}).catchException(e -> {
e.printStackTrace();
});
In this example we do a divide by 0 operation, which produces an ArithmeticException
which is a runtime exception, so the following save
operation will not be executed and the transaction will be rolled back.
You can get this exception with the catchException
post operation and do some custom actions.
Using Anima.open
method returns the Anima
objects have a rollbackException
method, you can call it specified rollback Exception type.
Contributing
Documentation
- Getting started
- Create Model
- Query DB
- Save to DB
- Updates and Deletes
- Transaction
- Integration with Spring
- Advanced Usage
Other resources
中文文档