}
private void initialize(Map props) {
try {
if (props == null) {
throw new NestedRuntimeException("SimpleDataSource: The properties map passed to the initializer was null.");
}
if (!(props.containsKey(PROP_JDBC_DRIVER)
&& props.containsKey(PROP_JDBC_URL)
&& props.containsKey(PROP_JDBC_USERNAME)
&& props.containsKey(PROP_JDBC_PASSWORD))) {
throw new NestedRuntimeException("SimpleDataSource: Some properties were not set.");
} else {
jdbcDriver = (String) props.get(PROP_JDBC_DRIVER);
jdbcUrl = (String) props.get(PROP_JDBC_URL);
jdbcUsername = (String) props.get(PROP_JDBC_USERNAME);
jdbcPassword = (String) props.get(PROP_JDBC_PASSWORD);
poolMaximumActiveConnections =
props.containsKey(PROP_POOL_MAX_ACTIVE_CONN)
? Integer.parseInt((String) props.get(PROP_POOL_MAX_ACTIVE_CONN))
: 10;
poolMaximumIdleConnections =
props.containsKey(PROP_POOL_MAX_IDLE_CONN)
? Integer.parseInt((String) props.get(PROP_POOL_MAX_IDLE_CONN))
: 5;
poolMaximumCheckoutTime =
props.containsKey(PROP_POOL_MAX_CHECKOUT_TIME)
? Integer.parseInt((String) props.get(PROP_POOL_MAX_CHECKOUT_TIME))
: 20000;
poolTimeToWait =
props.containsKey(PROP_POOL_TIME_TO_WAIT)
? Integer.parseInt((String) props.get(PROP_POOL_TIME_TO_WAIT))
: 20000;
poolPingEnabled =
props.containsKey(PROP_POOL_PING_ENABLED)
? Boolean.valueOf((String) props.get(PROP_POOL_PING_ENABLED)).booleanValue()
: false;
poolPingQuery =
props.containsKey(PROP_POOL_PING_QUERY)
? (String) props.get(PROP_POOL_PING_QUERY)
: "NO PING QUERY SET";
poolPingConnectionsOlderThan =
props.containsKey(PROP_POOL_PING_CONN_OLDER_THAN)
? Integer.parseInt((String) props.get(PROP_POOL_PING_CONN_OLDER_THAN))
: 0;
poolPingConnectionsNotUsedFor =
props.containsKey(PROP_POOL_PING_CONN_NOT_USED_FOR)
? Integer.parseInt((String) props.get(PROP_POOL_PING_CONN_NOT_USED_FOR))
: 0;
jdbcDefaultAutoCommit =
props.containsKey(PROP_JDBC_DEFAULT_AUTOCOMMIT)
? Boolean.valueOf((String) props.get(PROP_JDBC_DEFAULT_AUTOCOMMIT)).booleanValue()
: false;
useDriverProps = false;
Iterator propIter = props.keySet().iterator();
driverProps = new Properties();
driverProps.put("user", jdbcUsername);
driverProps.put("password", jdbcPassword);
while (propIter.hasNext()) {
String name = (String) propIter.next();
String value = (String) props.get(name);
if (name.startsWith(ADD_DRIVER_PROPS_PREFIX)) {
driverProps.put(name.substring(ADD_DRIVER_PROPS_PREFIX_LENGTH), value);
useDriverProps = true;
}
}
expectedConnectionTypeCode = assembleConnectionTypeCode(jdbcUrl, jdbcUsername, jdbcPassword);
Resources.instantiate(jdbcDriver);
}
} catch (Exception e) {
log.error("SimpleDataSource: Error while loading properties. Cause: " + e.toString(), e);
throw new NestedRuntimeException("SimpleDataSource: Error while loading properties. Cause: " + e, e);
}
}