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

com.centit.support.database.transaction.ConnectThreadHolder 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.metadata.IDatabaseInfo;
import com.centit.support.database.utils.DataSourceDescription;

import java.sql.Connection;
import java.sql.SQLException;

public class ConnectThreadHolder {
    private static ConnectThreadLocal threadLocal = new ConnectThreadLocal();

    private ConnectThreadHolder() {
        super();
    }

    public static ConnectThreadWrapper getConnectThreadWrapper() {
        ConnectThreadWrapper wrapper = threadLocal.get();
        if (wrapper == null) {
            wrapper = new ConnectThreadWrapper();
            threadLocal.set(wrapper);
        }
        return wrapper;
    }

    public static Connection fetchConnect(DataSourceDescription description) throws SQLException {
        ConnectThreadWrapper wrapper = getConnectThreadWrapper();
        return wrapper.fetchConnect(description);
    }

    public static Connection fetchConnect(IDatabaseInfo description) throws SQLException {
        return fetchConnect(DataSourceDescription.valueOf(description));
    }

    public static void commitAndRelease() throws SQLException {
        ConnectThreadWrapper wrapper = getConnectThreadWrapper();
        try {
            wrapper.commitAllWork();
        } finally {
            wrapper.releaseAllConnect();
            threadLocal.superRemove();
        }
    }

    public static void rollbackAndRelease() throws SQLException {
        ConnectThreadWrapper wrapper = getConnectThreadWrapper();
        try {
            wrapper.rollbackAllWork();
        } finally {
            wrapper.releaseAllConnect();
            threadLocal.superRemove();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy