context.rebind(dataSourceName, ref);
} catch (NamingException e) {
String msg = " Error binding name ' " + dataSourceName + " ' to " +
"the DataSource(BasicDataSource) reference";
throw new SynapseCommonsException(msg, e, log);
}
} else if (DataSourceInformation.PER_USER_POOL_DATA_SOURCE.equals(dsType)) {
// Construct DriverAdapterCPDS reference
String className = (String) information.getParameter(
DataSourceConstants.PROP_CPDS_ADAPTER +
DataSourceConstants.DOT_STRING +
DataSourceConstants.PROP_CPDS_CLASS_NAME);
String factory = (String) information.getParameter(
DataSourceConstants.PROP_CPDS_ADAPTER +
DataSourceConstants.DOT_STRING +
DataSourceConstants.PROP_CPDS_FACTORY);
String name = (String) information.getParameter(
DataSourceConstants.PROP_CPDS_ADAPTER +
DataSourceConstants.DOT_STRING +
DataSourceConstants.PROP_CPDS_NAME);
Reference cpdsRef =
new Reference(className, factory, null);
cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_DRIVER, driver));
cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_URL, url));
cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_USER, user));
cpdsRef.add(new StringRefAddr(SecurityConstants.PROP_PASSWORD,
password));
try {
context.rebind(name, cpdsRef);
} catch (NamingException e) {
String msg = "Error binding name '" + name + "' to " +
"the DriverAdapterCPDS reference";
throw new SynapseCommonsException(msg, e, log);
}
// Construct PerUserPoolDataSource reference
Reference ref =
new Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource",
"org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory",
null);
ref.add(new BinaryRefAddr(
DataSourceConstants.PROP_JNDI_ENV,
MiscellaneousUtil.serialize(jndiEvn)));
ref.add(new StringRefAddr(
DataSourceConstants.PROP_DATA_SOURCE_NAME, name));
ref.add(new StringRefAddr(
DataSourceConstants.PROP_DEFAULT_MAX_ACTIVE, maxActive));
ref.add(new StringRefAddr(
DataSourceConstants.PROP_DEFAULT_MAX_IDLE, maxIdle));
ref.add(new StringRefAddr(
DataSourceConstants.PROP_DEFAULT_MAX_WAIT, maxWait));
//set default jndiProperties for reference
setCommonParameters(ref, information);
try {
if (log.isDebugEnabled()) {
log.debug("Registering a DataSource with name : " +
dataSourceName + " in the JNDI tree with jndiProperties : " + jndiEvn);
}
context.rebind(dataSourceName, ref);
} catch (NamingException e) {
String msg = "Error binding name ' " + dataSourceName + " ' to " +
"the PerUserPoolDataSource reference";
throw new SynapseCommonsException(msg, e, log);
}
} else {
throw new SynapseCommonsException("Unsupported data source type : " + dsType, log);
}
cachedNameList.add(dataSourceName);
}