Example usage for org.apache.commons.dbcp PoolableConnection getInnermostDelegate

List of usage examples for org.apache.commons.dbcp PoolableConnection getInnermostDelegate

Introduction

In this page you can find the example usage for org.apache.commons.dbcp PoolableConnection getInnermostDelegate.

Prototype

public Connection getInnermostDelegate() 

Source Link

Document

If my underlying Connection is not a DelegatingConnection, returns it, otherwise recursively invokes this method on my delegate.

Usage

From source file:org.ofbiz.tenant.util.TenantUtil.java

/**
 * is connection available// ww w .  j a  v a2 s  .com
 * @param tenantId
 * @param delegator
 * @return
 */
public static boolean isConnectionAvailable(String tenantId, Delegator delegator) {
    try {
        List<GenericValue> tenantDataSources = delegator.findByAnd("TenantDataSource",
                UtilMisc.toMap("tenantId", tenantId), null, false);
        for (GenericValue tenantDataSource : tenantDataSources) {
            String entityGroupName = tenantDataSource.getString("entityGroupName");
            String jdbcUri = tenantDataSource.getString("jdbcUri");
            String jdbcUsername = tenantDataSource.getString("jdbcUsername");
            String jdbcPassword = tenantDataSource.getString("jdbcPassword");

            GenericHelperInfo helperInfo = delegator.getGroupHelperInfo(entityGroupName);
            Connection connection = ConnectionFactory.getConnection(jdbcUri, jdbcUsername, jdbcPassword);
            ManagedConnection managedConn = (ManagedConnection) ConnectionFactory.getConnection(helperInfo);
            PoolableConnection poolConn = (PoolableConnection) managedConn.getDelegate();
            Connection innermostDelegate = poolConn.getInnermostDelegate();
            if (UtilValidate.isNotEmpty(connection)) {
                if (!innermostDelegate.getClass().getName().equals(connection.getClass().getName())) {
                    return false;
                }
            } else {
                return false;
            }
        }
    } catch (Exception e) {
        Debug.logWarning(e, module);
        return false;
    }
    return true;
}