throw new DeploymentException("Could not construct Reference for datasource " + dsDescription, e);
}
}
private DataSource processDefinition(DataSourceDefinition dsDefinition, JndiConsumer annotatedApp) {
DataSource dataSource = findDataSource(dsDefinition, annotatedApp);
boolean existing = dataSource != null;
if (!existing) {
dataSource = new DataSource();
dataSource.setName(dsDefinition.name());
}
if (dataSource.getClassName() == null) {
dataSource.setClassName(dsDefinition.className());
}
if (dataSource.getDescription() == null && dsDefinition.description().trim().length() > 0) {
dataSource.setDescriptions(new Text[]{new Text(null, dsDefinition.description().trim())});
}
if (dataSource.getUser() == null && dsDefinition.user().trim().length() > 0) {
dataSource.setUser(dsDefinition.user().trim());
}
if (dataSource.getPassword() == null && dsDefinition.password().trim().length() > 0) {
dataSource.setPassword(dsDefinition.password().trim());
}
if (dataSource.getDatabaseName() == null && dsDefinition.databaseName().trim().length() > 0) {
dataSource.setDatabaseName(dsDefinition.databaseName().trim());
}
if (dataSource.getPortNumber() == null && dsDefinition.portNumber() != -1) {
dataSource.setPortNumber(dsDefinition.portNumber());
}
if (dataSource.getServerName() == null && dsDefinition.serverName().trim().length() > 0) {
dataSource.setServerName(dsDefinition.serverName().trim());
}
if (dataSource.getUrl() == null && dsDefinition.url().trim().length() > 0) {
dataSource.setUrl(dsDefinition.url().trim());
}
if (dataSource.getInitialPoolSize() == null && dsDefinition.initialPoolSize() != -1) {
dataSource.setInitialPoolSize(dsDefinition.initialPoolSize());
}
if (dataSource.getMaxPoolSize() == null && dsDefinition.maxPoolSize() != -1) {
dataSource.setMaxPoolSize(dsDefinition.maxPoolSize());
}
if (dataSource.getMinPoolSize() == null && dsDefinition.minPoolSize() != -1) {
dataSource.setMinPoolSize(dsDefinition.minPoolSize());
}
if (dataSource.getMaxIdleTime() == null && dsDefinition.maxIdleTime() != -1) {
dataSource.setMaxIdleTime(dsDefinition.maxIdleTime());
}
if (dataSource.getMaxStatements() == null && dsDefinition.maxStatements() != -1) {
dataSource.setMaxStatements(dsDefinition.maxStatements());
}
if (dataSource.getLoginTimeout() == null && dsDefinition.loginTimeout() != 0) {
dataSource.setLoginTimeout(dsDefinition.loginTimeout());
}
if (dataSource.getIsolationLevel() == null) {
dataSource.setIsolationLevel(IsolationLevel.fromFlag(dsDefinition.isolationLevel()));
}
if (dataSource.getTransactional() == null) {
dataSource.setTransactional(dsDefinition.transactional());
}
if (dataSource.getProperty().size() == 0) {
String[] properties = dsDefinition.properties();
if (properties != null) {
for (String property : properties) {
String[] tokens = property.split("=");
Property prop = new Property();
prop.setName(tokens[0]);
prop.setValue(tokens[1]);
dataSource.getProperty().add(prop);
}
}
}
if (!existing) {
annotatedApp.getDataSource().add(dataSource);