Search in sources :

Example 1 with DbcpDataSourceCreator

use of org.apache.openejb.resource.jdbc.dbcp.DbcpDataSourceCreator in project tomee by apache.

the class DataSourceFactory method creator.

public static DataSourceCreator creator(final Object creatorName, final boolean willBeProxied) {
    final DataSourceCreator defaultCreator = SystemInstance.get().getComponent(DataSourceCreator.class);
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    if (creatorName != null && creatorName instanceof String && (defaultCreator == null || !creatorName.equals(defaultCreator.getClass().getName()))) {
        String clazz = KNOWN_CREATORS.get(creatorName);
        if (clazz == null) {
            clazz = (String) creatorName;
        }
        if (willBeProxied && clazz.equals(DefaultDataSourceCreator.class.getName())) {
            clazz = DbcpDataSourceCreator.class.getName();
        }
        try {
            return (DataSourceCreator) loader.loadClass(clazz).newInstance();
        } catch (final Throwable e) {
            LOGGER.error("can't create '" + creatorName + "', the default one will be used: " + defaultCreator, e);
        }
    }
    if (defaultCreator instanceof DefaultDataSourceCreator && willBeProxied) {
        // this one is proxiable, not the default one (legacy)
        return new DbcpDataSourceCreator();
    }
    return defaultCreator;
}
Also used : DefaultDataSourceCreator(org.apache.openejb.resource.jdbc.pool.DefaultDataSourceCreator) DbcpDataSourceCreator(org.apache.openejb.resource.jdbc.dbcp.DbcpDataSourceCreator) DataSourceCreator(org.apache.openejb.resource.jdbc.pool.DataSourceCreator) DefaultDataSourceCreator(org.apache.openejb.resource.jdbc.pool.DefaultDataSourceCreator) DbcpDataSourceCreator(org.apache.openejb.resource.jdbc.dbcp.DbcpDataSourceCreator)

Aggregations

DbcpDataSourceCreator (org.apache.openejb.resource.jdbc.dbcp.DbcpDataSourceCreator)1 DataSourceCreator (org.apache.openejb.resource.jdbc.pool.DataSourceCreator)1 DefaultDataSourceCreator (org.apache.openejb.resource.jdbc.pool.DefaultDataSourceCreator)1