setting.setValue(value == null ? "" : value);
}
}
ConnectionManager manager = instance.getConnectionManager();
manager.setTransactionLocal(true);
SinglePool pool = new SinglePool();
manager.setPoolSingle(pool);
pool.setMatchOne(true);
// Max Size needs to be set before the minimum. This is because
// the connection manager will constrain the minimum based on the
// current maximum value in the pool. We might consider adding a
// setPoolConstraints method to allow specifying both at the same time.
if (data.maxSize != null && !data.maxSize.equals("")) {
pool.setMaxSize(new Integer(data.maxSize));
}
if (data.minSize != null && !data.minSize.equals("")) {
pool.setMinSize(new Integer(data.minSize));
}
if (data.blockingTimeout != null && !data.blockingTimeout.equals("")) {
pool.setBlockingTimeoutMillis(new Integer(data.blockingTimeout));
}
if (data.idleTimeout != null && !data.idleTimeout.equals("")) {
pool.setIdleTimeoutMinutes(new Integer(data.idleTimeout));
}
if (planOnly) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
config.save(out);
out.close();
return new String(out.toByteArray(), "US-ASCII");
} else {
File tempFile = File.createTempFile("console-deployment", ".xml");
tempFile.deleteOnExit();
log.debug("Writing database pool deployment plan to " + tempFile.getAbsolutePath());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
config.save(out);
out.flush();
out.close();
Target[] targets = mgr.getTargets();
if (null == targets) {
throw new IllegalStateException("No target to distribute to");
}
targets = new Target[] {targets[0]};
ProgressObject po = mgr.distribute(targets, rarFile, tempFile);
waitForProgress(po);
if (po.getDeploymentStatus().isCompleted()) {
TargetModuleID[] ids = po.getResultTargetModuleIDs();
po = mgr.start(ids);
waitForProgress(po);
if (po.getDeploymentStatus().isCompleted()) {
ids = po.getResultTargetModuleIDs();
if (status != null) {
status.getCurrentPool().setName(data.getName());
status.getCurrentPool().setConfigurationName(ids[0].getModuleID());
status.getCurrentPool().setFinished(true);
response.setRenderParameter(MODE_KEY, IMPORT_STATUS_MODE);
}
log.info("Deployment completed successfully!");
}
} else if (po.getDeploymentStatus().isFailed()) {
data.deployError = "Unable to deploy: " + data.name;
response.setRenderParameter(MODE_KEY, EDIT_MODE);
log.info("Deployment Failed!");
}
}
} catch (Exception e) {
log.error("Unable to save connection pool", e);
} finally {
if (mgr != null) mgr.release();
}
} else { // We're saving updates to an existing pool
if (planOnly) {
throw new UnsupportedOperationException("Can't update a plan for an existing deployment");
}
try {
JCAManagedConnectionFactory factory = (JCAManagedConnectionFactory) PortletManager.getManagedBean(
request, new AbstractName(URI.create(data.getAbstractName())));
if (data.isGeneric()) {
factory.setConfigProperty("ConnectionURL", data.getUrl());
factory.setConfigProperty("UserName", data.getUser());
factory.setConfigProperty("Password", data.getPassword());
} else {
for (Map.Entry<String, String> entry : data.getProperties().entrySet()) {
factory.setConfigProperty(entry.getKey().substring("property-".length()),
entry.getValue());
}
}
//todo: push the lookup into ManagementHelper
PoolingAttributes pool = (PoolingAttributes) factory.getConnectionManagerContainer();
pool.setPartitionMinSize(
data.minSize == null || data.minSize.equals("") ? 0 : Integer.parseInt(data.minSize));
pool.setPartitionMaxSize(
data.maxSize == null || data.maxSize.equals("") ? 10 : Integer.parseInt(data.maxSize));
pool.setBlockingTimeoutMilliseconds(
data.blockingTimeout == null || data.blockingTimeout.equals("") ? 5000 : Integer.parseInt(
data.blockingTimeout));
pool.setIdleTimeoutMinutes(
data.idleTimeout == null || data.idleTimeout.equals("") ? 15 : Integer.parseInt(
data.idleTimeout));
} catch (Exception e) {
log.error("Unable to save connection pool", e);
}