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

cq.database.use.PoolUser Maven / Gradle / Ivy

The newest version!
package cq.database.use;

import cq.database.exception.DBException;
import cq.database.helper.DBConfig;
import cq.database.helper.DBHelper;
import cq.database.pool.ConnectionPool;
import cq.database.pool.ConnectionPoolConfig;

import java.sql.SQLException;

public class PoolUser {
    private static ConnectionPool pool = ConnectionPool.getInstance();

    private PoolUser() {
    }

    public static void initPool(ConnectionPoolConfig poolConfig, DBConfig dbConfig) {
        pool.init(poolConfig, dbConfig);
    }

    public static  T handle(Result result) {
        DBHelper dbHelper;
        try {
            dbHelper = pool.getDBHelper();
        } catch (SQLException e) {
            throw new DBException(e);
        }
        T rst;
        try {
            rst = result.handle(dbHelper);
        } finally {
            dbHelper.setAutoCommit(true);
            pool.recovery(dbHelper);
        }
        return rst;
    }
  
    public static void destroy() {
        pool.destroy();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy