com.litongjava.model.db.IAtom Maven / Gradle / Ivy
package com.litongjava.model.db;
import java.sql.SQLException;
/**
* IAtom support transaction of database.
* It can be invoked in Db.tx(IAtom atom) method.
*
* Example:
* Db.tx(new IAtom(){
* public boolean run() throws SQLException {
* int result1 = Db.update("update account set cash = cash - ? where id = ?", 100, 123);
* int result2 = Db.update("update account set cash = cash + ? where id = ?", 100, 456);
* return result1 == 1 && result2 == 1;
* }});
*/
@FunctionalInterface
public interface IAtom {
/**
* Place codes here that need transaction support.
* @return true if you want to commit the transaction otherwise roll back transaction
*/
boolean run() throws SQLException;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy