Search in sources :

Example 1 with RepositoryBasedDataSourceFinder

use of org.apache.synapse.commons.datasource.RepositoryBasedDataSourceFinder in project wso2-synapse by wso2.

the class JDBCConfiguration method lookupDataSource.

/**
 * Lookup the DataSource on JNDI using the specified name and optional properties
 *
 * @return a DataSource looked up using the specified JNDI properties
 */
private DataSource lookupDataSource() {
    DataSource dataSource = null;
    RepositoryBasedDataSourceFinder finder = DataSourceRepositoryHolder.getInstance().getRepositoryBasedDataSourceFinder();
    if (finder.isInitialized()) {
        // First try a lookup based on the data source name only
        dataSource = finder.find(dataSourceName);
    }
    if (dataSource == null) {
        // Decrypt the password if needed
        String password = jndiProperties.getProperty(Context.SECURITY_CREDENTIALS);
        if (password != null && !"".equals(password)) {
            jndiProperties.put(Context.SECURITY_CREDENTIALS, getActualPassword(password));
        }
        // Lookup the data source using the specified jndi properties
        dataSource = DataSourceFinder.find(dataSourceName, jndiProperties);
        if (dataSource == null) {
            handleException("Cannot find a DataSource " + dataSourceName + " for given JNDI" + " properties :" + jndiProperties);
        }
    }
    if (dataSource != null) {
        log.info("Successfully looked up datasource " + dataSourceName);
    }
    return dataSource;
}
Also used : RepositoryBasedDataSourceFinder(org.apache.synapse.commons.datasource.RepositoryBasedDataSourceFinder) DataSource(javax.sql.DataSource)

Example 2 with RepositoryBasedDataSourceFinder

use of org.apache.synapse.commons.datasource.RepositoryBasedDataSourceFinder in project wso2-synapse by wso2.

the class AbstractDBMediator method lookupDataSource.

/**
 * Lookup the DataSource on JNDI using the specified name and optional properties
 *
 * @param dataSourceName the name of the data source to lookup
 * @param jndiProperties the JNDI properties identifying a data source provider
 * @return a DataSource looked up using the specified JNDI properties
 */
private DataSource lookupDataSource(String dataSourceName, Properties jndiProperties) {
    DataSource dataSource = null;
    RepositoryBasedDataSourceFinder finder = DataSourceRepositoryHolder.getInstance().getRepositoryBasedDataSourceFinder();
    if (finder.isInitialized()) {
        // first try a lookup based on the data source name only
        dataSource = finder.find(dataSourceName);
    }
    if (dataSource == null) {
        // decrypt the password if needed
        String password = jndiProperties.getProperty(Context.SECURITY_CREDENTIALS);
        if (password != null && !"".equals(password)) {
            jndiProperties.put(Context.SECURITY_CREDENTIALS, getActualPassword(password));
        }
        // lookup the data source using the specified jndi properties
        dataSource = DataSourceFinder.find(dataSourceName, jndiProperties);
    }
    if (dataSource != null) {
        MBeanRepository mBeanRepository = DatasourceMBeanRepository.getInstance();
        Object mBean = mBeanRepository.getMBean(dataSourceName);
        if (mBean instanceof DBPoolView) {
            setDbPoolView((DBPoolView) mBean);
        }
        log.info("Successfully looked up datasource " + dataSourceName + ".");
    }
    return dataSource;
}
Also used : DBPoolView(org.apache.synapse.commons.datasource.DBPoolView) RepositoryBasedDataSourceFinder(org.apache.synapse.commons.datasource.RepositoryBasedDataSourceFinder) MBeanRepository(org.apache.synapse.commons.jmx.MBeanRepository) DatasourceMBeanRepository(org.apache.synapse.commons.datasource.DatasourceMBeanRepository) PerUserPoolDataSource(org.apache.commons.dbcp.datasources.PerUserPoolDataSource) DataSource(javax.sql.DataSource) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

DataSource (javax.sql.DataSource)2 RepositoryBasedDataSourceFinder (org.apache.synapse.commons.datasource.RepositoryBasedDataSourceFinder)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 PerUserPoolDataSource (org.apache.commons.dbcp.datasources.PerUserPoolDataSource)1 DBPoolView (org.apache.synapse.commons.datasource.DBPoolView)1 DatasourceMBeanRepository (org.apache.synapse.commons.datasource.DatasourceMBeanRepository)1 MBeanRepository (org.apache.synapse.commons.jmx.MBeanRepository)1