String url = request.getParameter("url");
if (url == null || "".equals(url)) {
handleException(bundle.getString("ds.url.cannotfound.msg"));
}
DataSourceInformation dataSourceInformation = new DataSourceInformation();
dataSourceInformation.setAlias(alias.trim());
dataSourceInformation.setDriver(diver.trim());
dataSourceInformation.setUrl(url.trim());
String user = request.getParameter("user");
if (user != null && !"".equals(user)) {
SecretInformation secretInfo;
if (dataSourceInformation.getSecretInformation() == null) {
secretInfo = new SecretInformation();
} else {
secretInfo = dataSourceInformation.getSecretInformation();
}
secretInfo.setUser(user.trim());
dataSourceInformation.setSecretInformation(secretInfo);
}
String password = request.getParameter("password");
if (password != null && !"".equals(password)) {
SecretInformation secretInfo;
if (dataSourceInformation.getSecretInformation() == null) {
secretInfo = new SecretInformation();
} else {
secretInfo = dataSourceInformation.getSecretInformation();
}
secretInfo.setAliasSecret(password.trim());
dataSourceInformation.setSecretInformation(secretInfo);
}
String dstype = request.getParameter("dstype");
if ("peruserds".equals(dstype)) {
dataSourceInformation.setType("PerUserPoolDataSource");
}
String dsName = request.getParameter("dsName");
if (dsName != null && !"".equals(dsName)) {
dataSourceInformation.setDatasourceName(dsName.trim());
}
String dsrepotype = request.getParameter("dsrepotype");
if ("JNDI".equals(dsrepotype)) {
dataSourceInformation.setRepositoryType(DataSourceConstants.PROP_REGISTRY_JNDI);
StringBuffer buffer = new StringBuffer();
buffer.append(DataSourceConstants.PROP_SYNAPSE_PREFIX_DS);
buffer.append(DataSourceConstants.DOT_STRING);
buffer.append(alias.trim());
buffer.append(DataSourceConstants.DOT_STRING);
// The prefix for root level jndiProperties
String rootPrefix = buffer.toString();
// setting naming provider
Properties jndiEvn = new Properties();
String icFactory = request.getParameter("icFactory");
String providerUrl = request.getParameter("providerUrl");
String providerPort = request.getParameter("providerPort");
String providerType = request.getParameter("providerType");
if (icFactory != null && !"".equals(icFactory)) {
jndiEvn.setProperty(rootPrefix + DataSourceConstants.PROP_IC_FACTORY,
icFactory.trim());
}
if ("url".equals(providerType)) {
if (providerUrl != null && !"".equals(providerUrl)) {
jndiEvn.setProperty(rootPrefix +
DataSourceConstants.PROP_PROVIDER_URL, providerUrl.trim());
}
} else {
if (providerPort != null && !"".equals(providerPort)) {
jndiEvn.setProperty(rootPrefix +
DataSourceConstants.PROP_PROVIDER_PORT, providerPort.trim());
}
}
dataSourceInformation.setProperties(jndiEvn);
}
String autocommit = request.getParameter("autocommit");
if (autocommit != null && !"".equals(autocommit)) {
dataSourceInformation.setDefaultAutoCommit(Boolean.parseBoolean(autocommit.trim()));
}
String isolation = request.getParameter("isolation");
if (isolation != null && !"".equals(isolation)) {
if ("TRANSACTION_NONE".equals(isolation)) {
dataSourceInformation.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
} else if ("TRANSACTION_READ_COMMITTED".equals(isolation.trim())) {
dataSourceInformation.setDefaultTransactionIsolation(
Connection.TRANSACTION_READ_COMMITTED);
} else if ("TRANSACTION_READ_UNCOMMITTED".equals(isolation.trim())) {
dataSourceInformation.setDefaultTransactionIsolation(
Connection.TRANSACTION_READ_UNCOMMITTED);
} else if ("TRANSACTION_REPEATABLE_READ".equals(isolation.trim())) {
dataSourceInformation.setDefaultTransactionIsolation(
Connection.TRANSACTION_REPEATABLE_READ);
} else if ("TRANSACTION_SERIALIZABLE".equals(isolation.trim())) {
dataSourceInformation.setDefaultTransactionIsolation(
Connection.TRANSACTION_SERIALIZABLE);
}
}
String maxActive = request.getParameter("maxActive");
if (maxActive != null && !"".equals(maxActive) && !maxActive.contains("int")) {
try {
dataSourceInformation.setMaxActive(Integer.parseInt(maxActive.trim()));
} catch (NumberFormatException e) {
handleException(bundle.getString("invalid.maxActive"));
}
}
String maxIdle = request.getParameter("maxIdle");
if (maxIdle != null && !"".equals(maxIdle) && !maxIdle.contains("int")) {
try {
dataSourceInformation.setMaxIdle(Integer.parseInt(maxIdle.trim()));
} catch (NumberFormatException e) {
handleException(bundle.getString("invalid.maxidle"));
}
}
String maxopenstatements = request.getParameter("maxopenstatements");
if (maxopenstatements != null && !"".equals(maxopenstatements) &&
!maxopenstatements.contains("int")) {
try {
dataSourceInformation.setMaxOpenPreparedStatements(
Integer.parseInt(maxopenstatements.trim()));
} catch (NumberFormatException e) {
handleException(bundle.getString("invalid.MaxOpenStatements"));
}
}
String maxWait = request.getParameter("maxWait");
if (maxWait != null && !"".equals(maxWait) && !maxWait.contains("long")) {
try {
dataSourceInformation.setMaxWait(Long.parseLong(maxWait.trim()));
} catch (NumberFormatException e) {
handleException(bundle.getString("invalid.MaxWait"));
}
}
String minIdle = request.getParameter("minIdle");
if (minIdle != null && !"".equals(minIdle) && !minIdle.contains("int")) {
try {
dataSourceInformation.setMinIdle(Integer.parseInt(minIdle.trim()));
} catch (NumberFormatException e) {
handleException(bundle.getString("invalid.MinIdle"));
}
}
String initialsize = request.getParameter("initialsize");
if (initialsize != null && !"".equals(initialsize) && !initialsize.contains("int")) {
try {
dataSourceInformation.setInitialSize(Integer.parseInt(initialsize.trim()));
} catch (NumberFormatException e) {
handleException(bundle.getString("invalid.Initialsize"));
}
}
String poolstatements = request.getParameter("poolstatements");
if (poolstatements != null && !"".equals(poolstatements)) {
dataSourceInformation.setPoolPreparedStatements(
Boolean.parseBoolean(poolstatements.trim()));
}
String testonborrow = request.getParameter("testonborrow");
if (testonborrow != null && !"".equals(testonborrow)) {
dataSourceInformation.setTestOnBorrow(Boolean.parseBoolean(testonborrow.trim()));
}
String testwhileidle = request.getParameter("testwhileidle");
if (testwhileidle != null && !"".equals(testwhileidle)) {
dataSourceInformation.setTestWhileIdle(Boolean.parseBoolean(testwhileidle.trim()));
}
String validationquery = request.getParameter("validationquery");
if (validationquery != null && !"".equals(validationquery)) {
dataSourceInformation.setValidationQuery(validationquery.trim());
}
return dataSourceInformation;
}