String strval = null;
//Choose the mapper in according to the connection factory (JCA or JDBC)
String cfName = getProperty(props, JDO_OPTION_CONNECTION_FACTORY_NAME, null, true);
useConnectionFactory = cfName != null && cfName.length() > 0;
Object o = Fractal.getAttributeController(component);
MapperAttributes ma = (MapperAttributes) o;
if (useConnectionFactory) {
Object cf = null;
//There is a connection factory
try {
InitialContext ic = new InitialContext();
cf = ic.lookup(cfName);
} catch (NamingException e) {
throw new SpeedoException(
"Problem to get the connection factory in JNDI ("
+ cfName + ")", e);
}
if (cf == null) {
throw new SpeedoException(
"No connection factory registered in JNDI with the name "
+ cfName);
} else if (cf instanceof ConnectionSpecJDBC) {
// Use the JDBC Mapper ==> nothing to do
} else if (cf instanceof javax.sql.DataSource) {
// Use the JDBC Mapper ==> nothing to do
} else if (cf instanceof javax.resource.cci.ConnectionFactory) {
throw new SpeedoException("JCA datasource no yet supported");
} else {
throw new SpeedoException("The connection factory registered "
+ "in JNDI is not supported by Speedo " + cfName + " => "
+ cf);
}
boolean ignoring = removeProps(props, new String[]{
JDO_OPTION_CONNECTION_DRIVER_NAME_OLD,
JDO_OPTION_CONNECTION_DRIVER_NAME_OLD2,
JDO_OPTION_CONNECTION_DRIVER_NAME,
JDO_OPTION_CONNECTION_URL,
JDO_OPTION_CONNECTION_USER_NAME,
JDO_OPTION_CONNECTION_PASSWORD});
if (ignoring) {
logger.log(BasicLevel.WARN,
LocaleHelper.getSpeedoRB().getString("ignjdbcinfo"));
}
ignoring = removeProps(props, new String[]{
CONNECTION_POOL_MIN,
CONNECTION_POOL_MAX,
CONNECTION_POOL_TTL,
CONNECTION_POOL_TIMEOUT});
if (ignoring) {
logger.log(BasicLevel.WARN,
LocaleHelper.getSpeedoRB().getString("ignconninfo"));
}
//Assign the connection factory to the mapper
logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB().getString("connfact")
+ LocaleHelper.getSpeedoRB().getString("jndinm") + cfName
+ LocaleHelper.getSpeedoRB().getString("factfound") + cf
+ LocaleHelper.getSpeedoRB().getString("mappernm") + mapperName);
PMapper mapper = (PMapper) component.getFcInterface("mapper");
mapper.setMapperName(mapperName);
mapper.setConnectionFactory(cf);
} else {
JDBCMapperAttributes jdbcma = (JDBCMapperAttributes) ma;
//deprecated properties
strval = getProperty(props, JDO_OPTION_CONNECTION_DRIVER_NAME_OLD, "", true);
if (strval.length()>0) {
logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB().getString("property")
+ " " + JDO_OPTION_CONNECTION_DRIVER_NAME_OLD
+ LocaleHelper.getSpeedoRB().getString("deprecuse") + JDO_OPTION_CONNECTION_DRIVER_NAME);
if (getProperty(props, JDO_OPTION_CONNECTION_DRIVER_NAME, null, false) == null) {
props.put(JDO_OPTION_CONNECTION_DRIVER_NAME, strval);
}
}
strval = getProperty(props, JDO_OPTION_CONNECTION_DRIVER_NAME_OLD2, "", true);
if (strval.length()>0) {
logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB().getString("property")
+ " " + JDO_OPTION_CONNECTION_DRIVER_NAME_OLD2
+ LocaleHelper.getSpeedoRB().getString("deprecuse") + JDO_OPTION_CONNECTION_DRIVER_NAME);
if (getProperty(props, JDO_OPTION_CONNECTION_DRIVER_NAME, null, false) == null) {
props.put(JDO_OPTION_CONNECTION_DRIVER_NAME, strval);
}
}
String jdbcDriverCN = getProperty(props, JDO_OPTION_CONNECTION_DRIVER_NAME, null, true);
String jdbcUser = getProperty(props, JDO_OPTION_CONNECTION_USER_NAME, null, true);
String jdbcUrl = getProperty(props, JDO_OPTION_CONNECTION_URL, null, true);
String jdbcPass = getProperty(props, JDO_OPTION_CONNECTION_PASSWORD, null, true);
logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB().getString("jdbcdrv")
+ LocaleHelper.getSpeedoRB().getString("driver") + jdbcDriverCN
+ LocaleHelper.getSpeedoRB().getString("url") + jdbcUrl
+ LocaleHelper.getSpeedoRB().getString("user") + jdbcUser
+ LocaleHelper.getSpeedoRB().getString("mappernm") + mapperName);
jdbcma.setMapperName(mapperName);
jdbcma.setDriverClassName(jdbcDriverCN);
jdbcma.setURL(jdbcUrl);
jdbcma.setUserName(jdbcUser);
jdbcma.setPassword(jdbcPass);
jdbcma.setPoolConnection(true);
//configure the pool of connection
configurePool(getSubComponent(speedo, CONNECTION_POOL_PATH),
"Connection pool: ",
CONNECTION_POOL_MIN,
CONNECTION_POOL_MAX,
CONNECTION_POOL_TTL,
CONNECTION_POOL_INACTIVETTL,
CONNECTION_POOL_TIMEOUT,
props);
}
strval = (String) props.remove(CONNECTION_CHECK);
if (strval != null) {
boolean v = BooleanHelper.parse(strval, false);
ma.setCheckConnectivityAtStartup(v);
if (!v) {
logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB().getString("noconnchk"));
}
}