}
if (platform != null && platform.length() == 0) {
platform = null;
}
DataSource ds = null;
JdbcMetadataUtils jdbcMetadataUtils = new JdbcMetadataUtils ();
if (jndiName != null) {
// using "preconfigured" data source
if (connectionFactoryClass == null) {
connectionFactoryClass = ConnectionFactoryManagedImpl.class.getName ();
}
Context initialContext = new InitialContext();
ds = (DataSource) initialContext.lookup(jndiName);
jcd.setDatasourceName(jndiName);
} else {
// have to get data source ourselves
if (connectionFactoryClass == null) {
connectionFactoryClass = ConnectionFactoryDBCPImpl.class.getName ();
}
jcd.setDriver(driverClassName);
HashMap conData = jdbcMetadataUtils.parseConnectionUrl(url);
jcd.setDbms(platform);
jcd.setProtocol((String)conData.get(JdbcMetadataUtils.PROPERTY_PROTOCOL));
jcd.setSubProtocol((String)conData.get(JdbcMetadataUtils.PROPERTY_SUBPROTOCOL));
jcd.setDbAlias((String)conData.get(JdbcMetadataUtils.PROPERTY_DBALIAS));
jcd.setUserName(username);
jcd.setPassWord(password);
// Wrapping the connection factory in a DataSource introduces a bit
// of redundancy (url is parsed again and platform determined again).
// But although JdbcMetadataUtils exposes the methods used in
// fillJCDFromDataSource as public (and these do not require a DataSource)
// the method itself does more than is made available by the exposed methods.
ds = new MinimalDataSource (jcd);
}
ConnectionPoolDescriptor cpd = jcd.getConnectionPoolDescriptor();
if (cpd == null)
{
cpd = new ConnectionPoolDescriptor();
jcd.setConnectionPoolDescriptor(cpd);
}
Class conFacCls = ClassHelper.getClass(connectionFactoryClass);
cpd.setConnectionFactory(conFacCls);
jdbcMetadataUtils.fillJCDFromDataSource(jcd, ds, null, null);
if (platform == null && JdbcMetadataUtils.PLATFORM_ORACLE.equals(jcd.getDbms())) {
// Postprocess to find Oracle version.
updateOraclePlatform (jcd, ds);
}