All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.centit.support.database.transaction.DatabaseWorkHandler Maven / Gradle / Ivy

There is a newer version: 5.3.2302
Show newest version
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