优化 IAtom 接口。

This commit is contained in:
2023-06-25 09:14:27 +08:00
parent e61a393b93
commit 9d5fd0ff56
2 changed files with 19 additions and 65 deletions

View File

@@ -232,11 +232,11 @@ public class SimpleJdbcTemplate {
}
}
public void tx(final IAtom tx) throws Exception {
Assert.notNull(tx, "Tx can not be null.");
public <T extends Exception> void tx(final IAtom<T> atom) throws SQLException, T {
Assert.notNull(atom, "Tx can not be null.");
try {
this.conn.setAutoCommit(false);
tx.execute();
atom.execute();
conn.commit();
conn.setAutoCommit(true);
} catch (Exception e) {
@@ -247,9 +247,9 @@ public class SimpleJdbcTemplate {
}
@FunctionalInterface
public static interface IAtom {
public static interface IAtom<T extends Exception> {
@SuppressWarnings("all")
void execute() throws Exception;
void execute() throws SQLException, T;
}
}
}