attribute = entry.getKey();
} else {
poolName = entry.getKey().substring(0, entry.getKey().indexOf("."));
attribute = entry.getKey().substring(entry.getKey().indexOf(".") + 1, entry.getKey().length());
}
ConnectionPool pool = null;
if (poolName.equals("write")) {
poolName = "default";
}
if (poolName.equals("read")) {
pool = serverSession.getReadConnectionPool();
// By default there is no connection pool, so if the default, create a new one.
if ((pool == null) || (pool == serverSession.getDefaultConnectionPool())) {
if (this.session.getDatasourceLogin().shouldUseExternalConnectionPooling()) {
pool = new ExternalConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
} else {
pool = new ConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
}
serverSession.setReadConnectionPool(pool);
}
} else if (poolName.equals("sequence")) {
pool = getDatabaseSession().getSequencingControl().getConnectionPool();
if (pool == null) {
if (this.session.getDatasourceLogin().shouldUseExternalConnectionPooling()) {
pool = new ExternalConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
} else {
pool = new ConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
}
getDatabaseSession().getSequencingControl().setConnectionPool(pool);
}
} else {
pool = serverSession.getConnectionPool(poolName);
if (pool == null) {
if (this.session.getDatasourceLogin().shouldUseExternalConnectionPooling()) {
pool = new ExternalConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
} else {
pool = new ConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
}
serverSession.addConnectionPool(pool);
}
}
if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_INITIAL)) {
pool.setInitialNumberOfConnections(Integer.parseInt((String)entry.getValue()));
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_MIN)) {
pool.setMinNumberOfConnections(Integer.parseInt((String)entry.getValue()));
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_MAX)) {
pool.setMaxNumberOfConnections(Integer.parseInt((String)entry.getValue()));
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_URL)) {
pool.setLogin(pool.getLogin().clone());
((DatabaseLogin)pool.getLogin()).setURL((String)entry.getValue());
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_NON_JTA_DATA_SOURCE)) {
pool.setLogin(pool.getLogin().clone());
((DatabaseLogin)pool.getLogin()).useDataSource((String)entry.getValue());
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_JTA_DATA_SOURCE)) {
pool.setLogin(pool.getLogin().clone());
((DatabaseLogin)pool.getLogin()).useDataSource((String)entry.getValue());
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_USER)) {
pool.setLogin(pool.getLogin().clone());
((DatabaseLogin)pool.getLogin()).setUserName((String)entry.getValue());
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_PASSWORD)) {
pool.setLogin(pool.getLogin().clone());
((DatabaseLogin)pool.getLogin()).setPassword((String)entry.getValue());
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_WAIT)) {
pool.setWaitTimeout(Integer.parseInt((String)entry.getValue()));
} else if (attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_FAILOVER)) {
String failoverPools = (String)entry.getValue();
if ((failoverPools.indexOf(',') != -1) || (failoverPools.indexOf(' ') != -1)) {
StringTokenizer tokenizer = new StringTokenizer(failoverPools, " ,");
while (tokenizer.hasMoreTokens()) {
pool.addFailoverConnectionPool(tokenizer.nextToken());
}
} else {
pool.addFailoverConnectionPool((String)entry.getValue());
}
} else if (poolName.equals("read") && attribute.equals(PersistenceUnitProperties.CONNECTION_POOL_SHARED)) {
boolean shared = Boolean.parseBoolean((String)entry.getValue());
if (shared) {
ReadConnectionPool readPool = new ReadConnectionPool(poolName, serverSession.getDatasourceLogin(), serverSession);
readPool.setInitialNumberOfConnections(pool.getInitialNumberOfConnections());
readPool.setMinNumberOfConnections(pool.getMinNumberOfConnections());
readPool.setMaxNumberOfConnections(pool.getMaxNumberOfConnections());
readPool.setWaitTimeout(pool.getWaitTimeout());
readPool.setLogin(pool.getLogin());
serverSession.setReadConnectionPool(readPool);
}
}
} catch (RuntimeException exception) {
this.session.handleException(ValidationException.invalidValueForProperty(entry.getValue(), entry.getKey(), exception));