
com.centit.support.database.transaction.DatabaseWorkHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of centit-database-transaction Show documentation
Show all versions of centit-database-transaction Show documentation
jdbc连接事务管理,通过ThreadHolder来保存数据库连接
package com.centit.support.database.transaction;
import com.centit.support.database.utils.DataSourceDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
public abstract class DatabaseWorkHandler {
private static final Logger logger = LoggerFactory.getLogger(DatabaseWorkHandler.class);
private DatabaseWorkHandler() {
throw new IllegalAccessError("Utility class");
}
public static T executeInTransaction(DataSourceDescription dataSourceDesc, ExecuteWork realWork)
throws SQLException {
Connection conn = ConnectThreadHolder.fetchConnect(dataSourceDesc);
return realWork.execute(conn);
}
public static T executeQueryInTransaction(DataSourceDescription dataSourceDesc, QueryWork realWork)
throws SQLException, IOException {
Connection conn = ConnectThreadHolder.fetchConnect(dataSourceDesc);
return realWork.execute(conn);
}
public interface ExecuteWork {
T execute(Connection conn) throws SQLException;
}
public interface QueryWork {
T execute(Connection conn) throws SQLException, IOException;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy