You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2007/08/17 02:33:01 UTC
svn commit: r566889 [2/3] - in /geronimo/server/trunk:
applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/
configs/webconsole-jetty6/src/plan/ configs/webconsole-tomcat/src/plan/
Modified: geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java?view=diff&rev=566889&r1=566888&r2=566889
==============================================================================
--- geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java (original)
+++ geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java Thu Aug 16 17:33:00 2007
@@ -42,11 +42,13 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.Iterator;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.SortedSet;
+
import javax.enterprise.deploy.model.DDBean;
import javax.enterprise.deploy.model.DDBeanRoot;
import javax.enterprise.deploy.shared.ModuleType;
@@ -67,6 +69,7 @@
import javax.portlet.WindowState;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.portlet.PortletFileUpload;
@@ -114,41 +117,60 @@
*/
public class DatabasePoolPortlet extends BasePortlet {
private final static Log log = LogFactory.getLog(DatabasePoolPortlet.class);
- private final static String[] SKIP_ENTRIES_WITH = new String[]{"geronimo", "tomcat", "tranql", "commons", "directory", "activemq"};
+ private final static Set<String> INCLUDE_ARTIFACTIDS = new HashSet<String>(Arrays.asList("system-database"));
+
+ private final static Set<String> EXCLUDE_GROUPIDS = new HashSet<String>(Arrays.asList("org.apache.geronimo.modules",
+ "org.apache.geronimo.configs",
+ "org.apache.geronimo.applications",
+ "org.apache.geronimo.assemblies",
+ "org.apache.cxf",
+ "org.apache.tomcat",
+ "org.tranql",
+ "commons-cli",
+ "commons-io",
+ "commons-logging",
+ "commons-lang",
+ "axis",
+ "org.apache.axis2",
+ "org.apache.directory",
+ "org.apache.activemq",
+ "org.apache.openejb",
+ "org.apache.myfaces",
+ "org.mortbay.jetty"));
private final static String DRIVER_SESSION_KEY = "org.apache.geronimo.console.dbpool.Drivers";
private final static String CONFIG_SESSION_KEY = "org.apache.geronimo.console.dbpool.ConfigParam";
- private final static String DRIVER_INFO_URL = "http://geronimo.apache.org/driver-downloads.properties";
- private static final String LIST_VIEW = "/WEB-INF/view/dbwizard/list.jsp";
- private static final String EDIT_VIEW = "/WEB-INF/view/dbwizard/edit.jsp";
- private static final String SELECT_RDBMS_VIEW = "/WEB-INF/view/dbwizard/selectDatabase.jsp";
- private static final String BASIC_PARAMS_VIEW = "/WEB-INF/view/dbwizard/basicParams.jsp";
- private static final String CONFIRM_URL_VIEW = "/WEB-INF/view/dbwizard/confirmURL.jsp";
+ private final static String DRIVER_INFO_URL = "http://geronimo.apache.org/driver-downloads.properties";
+ private static final String LIST_VIEW = "/WEB-INF/view/dbwizard/list.jsp";
+ private static final String EDIT_VIEW = "/WEB-INF/view/dbwizard/edit.jsp";
+ private static final String SELECT_RDBMS_VIEW = "/WEB-INF/view/dbwizard/selectDatabase.jsp";
+ private static final String BASIC_PARAMS_VIEW = "/WEB-INF/view/dbwizard/basicParams.jsp";
+ private static final String CONFIRM_URL_VIEW = "/WEB-INF/view/dbwizard/confirmURL.jsp";
private static final String TEST_CONNECTION_VIEW = "/WEB-INF/view/dbwizard/testConnection.jsp";
- private static final String DOWNLOAD_VIEW = "/WEB-INF/view/dbwizard/selectDownload.jsp";
+ private static final String DOWNLOAD_VIEW = "/WEB-INF/view/dbwizard/selectDownload.jsp";
private static final String DOWNLOAD_STATUS_VIEW = "/WEB-INF/view/dbwizard/downloadStatus.jsp";
- private static final String SHOW_PLAN_VIEW = "/WEB-INF/view/dbwizard/showPlan.jsp";
- private static final String IMPORT_UPLOAD_VIEW = "/WEB-INF/view/dbwizard/importUpload.jsp";
- private static final String IMPORT_STATUS_VIEW = "/WEB-INF/view/dbwizard/importStatus.jsp";
- private static final String USAGE_VIEW = "/WEB-INF/view/dbwizard/usage.jsp";
- private static final String LIST_MODE = "list";
- private static final String EDIT_MODE = "edit";
- private static final String SELECT_RDBMS_MODE = "rdbms";
- private static final String BASIC_PARAMS_MODE = "params";
- private static final String CONFIRM_URL_MODE = "url";
+ private static final String SHOW_PLAN_VIEW = "/WEB-INF/view/dbwizard/showPlan.jsp";
+ private static final String IMPORT_UPLOAD_VIEW = "/WEB-INF/view/dbwizard/importUpload.jsp";
+ private static final String IMPORT_STATUS_VIEW = "/WEB-INF/view/dbwizard/importStatus.jsp";
+ private static final String USAGE_VIEW = "/WEB-INF/view/dbwizard/usage.jsp";
+ private static final String LIST_MODE = "list";
+ private static final String EDIT_MODE = "edit";
+ private static final String SELECT_RDBMS_MODE = "rdbms";
+ private static final String BASIC_PARAMS_MODE = "params";
+ private static final String CONFIRM_URL_MODE = "url";
private static final String TEST_CONNECTION_MODE = "test";
- private static final String SHOW_PLAN_MODE = "plan";
- private static final String DOWNLOAD_MODE = "download";
+ private static final String SHOW_PLAN_MODE = "plan";
+ private static final String DOWNLOAD_MODE = "download";
private static final String DOWNLOAD_STATUS_MODE = "downloadStatus";
- private static final String EDIT_EXISTING_MODE = "editExisting";
- private static final String DELETE_MODE = "delete";
- private static final String SAVE_MODE = "save";
- private static final String IMPORT_START_MODE = "startImport";
- private static final String IMPORT_UPLOAD_MODE = "importUpload";
- private static final String IMPORT_STATUS_MODE = "importStatus";
+ private static final String EDIT_EXISTING_MODE = "editExisting";
+ private static final String DELETE_MODE = "delete";
+ private static final String SAVE_MODE = "save";
+ private static final String IMPORT_START_MODE = "startImport";
+ private static final String IMPORT_UPLOAD_MODE = "importUpload";
+ private static final String IMPORT_STATUS_MODE = "importStatus";
private static final String IMPORT_COMPLETE_MODE = "importComplete";
private static final String WEBLOGIC_IMPORT_MODE = "weblogicImport";
- private static final String USAGE_MODE = "usage";
- private static final String IMPORT_EDIT_MODE = "importEdit";
+ private static final String USAGE_MODE = "usage";
+ private static final String IMPORT_EDIT_MODE = "importEdit";
private static final String MODE_KEY = "mode";
private PortletRequestDispatcher listView;
@@ -198,8 +220,9 @@
public DriverDownloader.DriverInfo[] getDriverInfo(PortletRequest request) {
PortletSession session = request.getPortletSession(true);
- DriverDownloader.DriverInfo[] results = (DriverDownloader.DriverInfo[]) session.getAttribute(DRIVER_SESSION_KEY, PortletSession.APPLICATION_SCOPE);
- if(results == null) {
+ DriverDownloader.DriverInfo[] results = (DriverDownloader.DriverInfo[]) session.getAttribute(DRIVER_SESSION_KEY,
+ PortletSession.APPLICATION_SCOPE);
+ if (results == null) {
DriverDownloader downloader = new DriverDownloader();
try {
results = downloader.loadDriverInfo(new URL(DRIVER_INFO_URL));
@@ -215,26 +238,32 @@
/**
* Loads data about a resource adapter. Depending on what we already have, may load
* the name and description, but always loads the config property descriptions.
- * @param request Pass it or die
- * @param rarPath If we're creating a new RA, the path to identify it
- * @param displayName If we're editing an existing RA, its name
- * @param adapterAbstractName If we're editing an existing RA, its AbstractName
+ *
+ * @param request Pass it or die
+ * @param rarPath If we're creating a new RA, the path to identify it
+ * @param displayName If we're editing an existing RA, its name
+ * @param adapterAbstractName If we're editing an existing RA, its AbstractName
+ * @return resource adapter parameter data object
*/
public ResourceAdapterParams getRARConfiguration(PortletRequest request, String rarPath, String displayName, String adapterAbstractName) {
PortletSession session = request.getPortletSession(true);
- if(rarPath != null && !rarPath.equals("")) {
- ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute(CONFIG_SESSION_KEY+"-"+rarPath, PortletSession.APPLICATION_SCOPE);
- if(results == null) {
+ if (rarPath != null && !rarPath.equals("")) {
+ ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute(
+ CONFIG_SESSION_KEY + "-" + rarPath, PortletSession.APPLICATION_SCOPE);
+ if (results == null) {
results = loadConfigPropertiesByPath(request, rarPath);
- session.setAttribute(CONFIG_SESSION_KEY+"-"+rarPath, results, PortletSession.APPLICATION_SCOPE);
- session.setAttribute(CONFIG_SESSION_KEY+"-"+results.displayName, results, PortletSession.APPLICATION_SCOPE);
+ session.setAttribute(CONFIG_SESSION_KEY + "-" + rarPath, results, PortletSession.APPLICATION_SCOPE);
+ session.setAttribute(CONFIG_SESSION_KEY + "-" + results.displayName, results,
+ PortletSession.APPLICATION_SCOPE);
}
return results;
- } else if(displayName != null && !displayName.equals("") && adapterAbstractName != null && !adapterAbstractName.equals("")) {
- ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute(CONFIG_SESSION_KEY+"-"+displayName, PortletSession.APPLICATION_SCOPE);
- if(results == null) {
+ } else if (displayName != null && !displayName.equals(
+ "") && adapterAbstractName != null && !adapterAbstractName.equals("")) {
+ ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute(
+ CONFIG_SESSION_KEY + "-" + displayName, PortletSession.APPLICATION_SCOPE);
+ if (results == null) {
results = loadConfigPropertiesByAbstractName(request, adapterAbstractName);
- session.setAttribute(CONFIG_SESSION_KEY+"-"+displayName, results, PortletSession.APPLICATION_SCOPE);
+ session.setAttribute(CONFIG_SESSION_KEY + "-" + displayName, results, PortletSession.APPLICATION_SCOPE);
}
return results;
} else {
@@ -243,49 +272,43 @@
}
public void processAction(ActionRequest actionRequest,
- ActionResponse actionResponse) throws PortletException, IOException {
+ ActionResponse actionResponse) throws PortletException, IOException {
String mode = actionRequest.getParameter(MODE_KEY);
- if(mode.equals(IMPORT_UPLOAD_MODE)) {
+ if (mode.equals(IMPORT_UPLOAD_MODE)) {
processImportUpload(actionRequest, actionResponse);
actionResponse.setRenderParameter(MODE_KEY, IMPORT_STATUS_MODE);
return;
}
PoolData data = new PoolData();
data.load(actionRequest);
- if(mode.equals("process-"+SELECT_RDBMS_MODE)) {
- DatabaseDriver info = null;
- info = getDatabaseInfo(actionRequest, data);
- if(info != null) {
+ if (mode.equals("process-" + SELECT_RDBMS_MODE)) {
+ DatabaseDriver info = getDatabaseInfo(actionRequest, data);
+ if (info != null) {
data.rarPath = info.getRAR().toString();
- if(info.isXA()) {
- data.adapterDisplayName="Unknown"; // will pick these up when we process the RA type in the render request
- data.adapterDescription="Unknown";
+ if (info.isSpecific()) {
+ data.adapterDisplayName = "Unknown"; // will pick these up when we process the RA type in the render request
+ data.adapterDescription = "Unknown";
actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
} else {
- if(data.getDbtype().equals("Other")) {
- actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
- } else {
- data.driverClass = info.getDriverClassName();
- data.urlPrototype = info.getURLPrototype();
- actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE);
- }
+ data.driverClass = info.getDriverClassName();
+ data.urlPrototype = info.getURLPrototype();
+ actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE);
}
} else {
actionResponse.setRenderParameter(MODE_KEY, SELECT_RDBMS_MODE);
}
- } else if(mode.equals("process-"+DOWNLOAD_MODE)) {
+ } else if (mode.equals("process-" + DOWNLOAD_MODE)) {
String name = actionRequest.getParameter("driverName");
DriverDownloader.DriverInfo[] drivers = getDriverInfo(actionRequest);
DriverDownloader.DriverInfo found = null;
- for (int i = 0; i < drivers.length; i++) {
- DriverDownloader.DriverInfo driver = drivers[i];
- if(driver.getName().equals(name)) {
+ for (DriverDownloader.DriverInfo driver : drivers) {
+ if (driver.getName().equals(name)) {
found = driver;
break;
}
}
- if(found != null) {
- data.jars = new String[] {found.getRepositoryURI()};
+ if (found != null) {
+ data.jars = new String[]{found.getRepositoryURI()};
WriteableRepository repo = PortletManager.getCurrentServer(actionRequest).getWritableRepositories()[0];
final PortletSession session = actionRequest.getPortletSession();
ProgressInfo progressInfo = new ProgressInfo();
@@ -297,27 +320,27 @@
} else {
actionResponse.setRenderParameter(MODE_KEY, DOWNLOAD_MODE);
}
- } else if(mode.equals("process-"+DOWNLOAD_STATUS_MODE)) {
- if(data.getDbtype() == null || data.getDbtype().equals("Other")) {
+ } else if (mode.equals("process-" + DOWNLOAD_STATUS_MODE)) {
+ if (data.getDbtype() == null || data.getDbtype().equals("Other")) {
actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
} else {
actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE);
}
- } else if(mode.equals("process-"+BASIC_PARAMS_MODE)) {
- DatabaseDriver info = null;
+ } else if (mode.equals("process-" + BASIC_PARAMS_MODE)) {
+ DatabaseDriver info;
info = getDatabaseInfo(actionRequest, data);
- if(info != null) {
+ if (info != null) {
data.url = populateURL(info.getURLPrototype(), info.getURLParameters(), data.getUrlProperties());
}
- if(attemptDriverLoad(actionRequest, data) != null) {
+ if (attemptDriverLoad(actionRequest, data) != null) {
actionResponse.setRenderParameter(MODE_KEY, CONFIRM_URL_MODE);
} else {
- actionResponse.setRenderParameter("driverError", "Unable to load driver "+data.driverClass);
+ actionResponse.setRenderParameter("driverError", "Unable to load driver " + data.driverClass);
actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE);
}
- } else if(mode.equals("process-"+CONFIRM_URL_MODE)) {
+ } else if (mode.equals("process-" + CONFIRM_URL_MODE)) {
String test = actionRequest.getParameter("test");
- if(test == null || test.equals("true")) {
+ if (test == null || test.equals("true")) {
String result = null;
String stack = null;
try {
@@ -330,29 +353,29 @@
temp.close();
stack = writer.getBuffer().toString();
}
- if(result != null) actionResponse.setRenderParameter("connectResult", result);
+ if (result != null) actionResponse.setRenderParameter("connectResult", result);
actionRequest.getPortletSession(true).setAttribute("connectError", stack);
actionResponse.setRenderParameter(MODE_KEY, TEST_CONNECTION_MODE);
} else {
save(actionRequest, actionResponse, data, false);
}
- } else if(mode.equals(SAVE_MODE)) {
+ } else if (mode.equals(SAVE_MODE)) {
save(actionRequest, actionResponse, data, false);
- } else if(mode.equals(SHOW_PLAN_MODE)) {
+ } else if (mode.equals(SHOW_PLAN_MODE)) {
String plan = save(actionRequest, actionResponse, data, true);
actionRequest.getPortletSession(true).setAttribute("deploymentPlan", plan);
actionResponse.setRenderParameter(MODE_KEY, SHOW_PLAN_MODE);
- } else if(mode.equals(EDIT_EXISTING_MODE)) {
+ } else if (mode.equals(EDIT_EXISTING_MODE)) {
final String name = actionRequest.getParameter("adapterAbstractName");
loadConnectionFactory(actionRequest, name, data.getAbstractName(), data);
actionResponse.setRenderParameter("adapterAbstractName", name);
actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
- } else if(mode.equals(SELECT_RDBMS_MODE)) {
- if(data.getAdapterDisplayName() == null) { // Set a default for a new pool
+ } else if (mode.equals(SELECT_RDBMS_MODE)) {
+ if (data.getAdapterDisplayName() == null) { // Set a default for a new pool
data.adapterDisplayName = "TranQL Generic JDBC Resource Adapter";
}
actionResponse.setRenderParameter(MODE_KEY, mode);
- } else if(mode.equals(WEBLOGIC_IMPORT_MODE)) {
+ } else if (mode.equals(WEBLOGIC_IMPORT_MODE)) {
String domainDir = actionRequest.getParameter("weblogicDomainDir");
String libDir = actionRequest.getParameter("weblogicLibDir");
try {
@@ -364,24 +387,24 @@
actionResponse.setRenderParameter("from", actionRequest.getParameter("from"));
actionResponse.setRenderParameter(MODE_KEY, IMPORT_START_MODE);
}
- } else if(mode.equals(IMPORT_START_MODE)) {
+ } else if (mode.equals(IMPORT_START_MODE)) {
actionResponse.setRenderParameter("from", actionRequest.getParameter("from"));
actionResponse.setRenderParameter(MODE_KEY, mode);
- } else if(mode.equals(IMPORT_EDIT_MODE)) {
+ } else if (mode.equals(IMPORT_EDIT_MODE)) {
ImportStatus status = getImportStatus(actionRequest);
int index = Integer.parseInt(actionRequest.getParameter("importIndex"));
status.setCurrentPoolIndex(index);
loadImportedData(actionRequest, data, status.getCurrentPool());
actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
- } else if(mode.equals(IMPORT_COMPLETE_MODE)) {
+ } else if (mode.equals(IMPORT_COMPLETE_MODE)) {
ImportStatus status = getImportStatus(actionRequest);
log.warn("Import Results:"); //todo: create a screen for this
- log.warn(" "+status.getSkippedCount()+" ignored");
- log.warn(" "+status.getStartedCount()+" reviewed but not deployed");
- log.warn(" "+status.getPendingCount()+" not reviewed");
- log.warn(" "+status.getFinishedCount()+" deployed");
+ log.warn(" " + status.getSkippedCount() + " ignored");
+ log.warn(" " + status.getStartedCount() + " reviewed but not deployed");
+ log.warn(" " + status.getPendingCount() + " not reviewed");
+ log.warn(" " + status.getFinishedCount() + " deployed");
actionRequest.getPortletSession().removeAttribute("ImportStatus");
- } else if(mode.equals(DELETE_MODE)) {
+ } else if (mode.equals(DELETE_MODE)) {
String name = actionRequest.getParameter("adapterAbstractName");
loadConnectionFactory(actionRequest, name, data.getAbstractName(), data);
delete(actionRequest, actionResponse, data);
@@ -410,22 +433,22 @@
public void writeStarted(String fileDescription, int fileSize) {
this.fileSize = fileSize;
- log.info("Downloading "+fileDescription);
+ log.info("Downloading " + fileDescription);
}
public void writeProgress(int bytes) {
- int kbDownloaded = (int)Math.floor(bytes/1024);
+ int kbDownloaded = (int) Math.floor(bytes / 1024);
if (fileSize > 0) {
- int percent = (bytes*100)/fileSize;
+ int percent = (bytes * 100) / fileSize;
progressInfo.setProgressPercent(percent);
- progressInfo.setSubMessage(kbDownloaded + " / " + fileSize/1024 + " Kb downloaded");
+ progressInfo.setSubMessage(kbDownloaded + " / " + fileSize / 1024 + " Kb downloaded");
} else {
progressInfo.setSubMessage(kbDownloaded + " Kb downloaded");
}
}
public void writeComplete(int bytes) {
- log.info("Finished downloading "+bytes+" b");
+ log.info("Finished downloading " + bytes + " b");
}
});
} catch (IOException e) {
@@ -436,26 +459,28 @@
}
}
- private void loadImportedData(PortletRequest request, PoolData data, ImportStatus.PoolProgress progress) throws PortletException { if(!progress.getType().equals(ImportStatus.PoolProgress.TYPE_XA)) {
+ private void loadImportedData(PortletRequest request, PoolData data, ImportStatus.PoolProgress progress) throws PortletException {
+ if (!progress.getType().equals(ImportStatus.PoolProgress.TYPE_XA)) {
JDBCPool pool = (JDBCPool) progress.getPool();
data.dbtype = "Other";
data.adapterDisplayName = "TranQL Generic JDBC Resource Adapter";
data.blockingTimeout = getImportString(pool.getBlockingTimeoutMillis());
data.driverClass = pool.getDriverClass();
- data.idleTimeout = pool.getIdleTimeoutMillis() == null ? null : Integer.toString(pool.getIdleTimeoutMillis().intValue() / (60 * 1000));
+ data.idleTimeout = pool.getIdleTimeoutMillis() != null ? Integer.toString(
+ pool.getIdleTimeoutMillis().intValue() / (60 * 1000)) : null;
data.maxSize = getImportString(pool.getMaxSize());
data.minSize = getImportString(pool.getMinSize());
data.name = pool.getName();
data.password = pool.getPassword();
data.url = pool.getJdbcURL();
data.user = pool.getUsername();
- if(pool.getDriverClass() != null) {
+ if (pool.getDriverClass() != null) {
DatabaseDriver info = getDatabaseInfoFromDriver(request, data);
- if(info != null) {
+ if (info != null) {
data.rarPath = info.getRAR().toString();
data.urlPrototype = info.getURLPrototype();
} else {
- throw new PortletException("Don't recognize database driver "+data.driverClass+"!");
+ throw new PortletException("Don't recognize database driver " + data.driverClass + "!");
}
}
} else {
@@ -476,13 +501,12 @@
PortletFileUpload uploader = new PortletFileUpload(new DiskFileItemFactory());
try {
- List items = uploader.parseRequest(request);
- for (Iterator i = items.iterator(); i.hasNext();) {
- FileItem item = (FileItem) i.next();
+ List<FileItem> items = uploader.parseRequest(request);
+ for (FileItem item : items) {
if (!item.isFormField()) {
File file = File.createTempFile("geronimo-import", "");
file.deleteOnExit();
- log.debug("Writing database pool import file to "+file.getAbsolutePath());
+ log.debug("Writing database pool import file to " + file.getAbsolutePath());
item.write(file);
DatabaseConversionStatus status = processImport(file, type);
request.getPortletSession(true).setAttribute("ImportStatus", new ImportStatus(status));
@@ -491,21 +515,21 @@
throw new PortletException("Not expecting any form fields");
}
}
- } catch(PortletException e) {
+ } catch (PortletException e) {
throw e;
- } catch(Exception e) {
+ } catch (Exception e) {
throw new PortletException(e);
}
return false;
}
private DatabaseConversionStatus processImport(File importFile, String type) throws PortletException, IOException {
- if(type.equals("JBoss 4")) {
+ if (type.equals("JBoss 4")) {
return JBoss4DatabaseConverter.convert(new FileReader(importFile));
- } else if(type.equals("WebLogic 8.1")) {
+ } else if (type.equals("WebLogic 8.1")) {
return WebLogic81DatabaseConverter.convert(new FileReader(importFile));
} else {
- throw new PortletException("Unknown import type '"+type+"'");
+ throw new PortletException("Unknown import type '" + type + "'");
}
}
@@ -517,23 +541,22 @@
final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot();
String adapterName = null, adapterDesc = null;
String[] test = ddBeanRoot.getText("connector/display-name");
- if(test != null && test.length > 0) {
+ if (test != null && test.length > 0) {
adapterName = test[0];
}
test = ddBeanRoot.getText("connector/description");
- if(test != null && test.length > 0) {
+ if (test != null && test.length > 0) {
adapterDesc = test[0];
}
- DDBean[] definitions = ddBeanRoot.getChildBean("connector/resourceadapter/outbound-resourceadapter/connection-definition");
- List configs = new ArrayList();
- if(definitions != null) {
- for (int i = 0; i < definitions.length; i++) {
- DDBean definition = definitions[i];
+ DDBean[] definitions = ddBeanRoot.getChildBean(
+ "connector/resourceadapter/outbound-resourceadapter/connection-definition");
+ List<ConfigParam> configs = new ArrayList<ConfigParam>();
+ if (definitions != null) {
+ for (DDBean definition : definitions) {
String iface = definition.getText("connectionfactory-interface")[0];
- if(iface.equals("javax.sql.DataSource")) {
+ if (iface.equals("javax.sql.DataSource")) {
DDBean[] beans = definition.getChildBean("config-property");
- for (int j = 0; j < beans.length; j++) {
- DDBean bean = beans[j];
+ for (DDBean bean : beans) {
String name = bean.getText("config-property-name")[0].trim();
String type = bean.getText("config-property-type")[0].trim();
test = bean.getText("config-property-value");
@@ -545,17 +568,19 @@
}
}
}
- return new ResourceAdapterParams(adapterName, adapterDesc, (ConfigParam[]) configs.toArray(new ConfigParam[configs.size()]));
+ return new ResourceAdapterParams(adapterName, adapterDesc,
+ configs.toArray(new ConfigParam[configs.size()]));
} catch (Exception e) {
log.error("Unable to read configuration properties", e);
return null;
} finally {
- if(mgr != null) mgr.release();
+ if (mgr != null) mgr.release();
}
}
private ResourceAdapterParams loadConfigPropertiesByAbstractName(PortletRequest request, String abstractName) {
- ResourceAdapterModule module = (ResourceAdapterModule) PortletManager.getManagedBean(request, new AbstractName(URI.create(abstractName)));
+ ResourceAdapterModule module = (ResourceAdapterModule) PortletManager.getManagedBean(request,
+ new AbstractName(URI.create(abstractName)));
String dd = module.getDeploymentDescriptor();
DocumentBuilderFactory factory = XmlUtil.newDocumentBuilderFactory();
factory.setValidating(false);
@@ -571,13 +596,13 @@
elem = (Element) elem.getElementsByTagName("resourceadapter").item(0);
elem = (Element) elem.getElementsByTagName("outbound-resourceadapter").item(0);
NodeList defs = elem.getElementsByTagName("connection-definition");
- List all = new ArrayList();
- for(int i=0; i<defs.getLength(); i++) {
- final Element def = (Element)defs.item(i);
+ List<ConfigParam> all = new ArrayList<ConfigParam>();
+ for (int i = 0; i < defs.getLength(); i++) {
+ final Element def = (Element) defs.item(i);
String iface = getFirstText(def.getElementsByTagName("connectionfactory-interface")).trim();
- if(iface.equals("javax.sql.DataSource")) {
+ if (iface.equals("javax.sql.DataSource")) {
NodeList configs = def.getElementsByTagName("config-property");
- for(int j=0; j<configs.getLength(); j++) {
+ for (int j = 0; j < configs.getLength(); j++) {
Element config = (Element) configs.item(j);
String name = getFirstText(config.getElementsByTagName("config-property-name")).trim();
String type = getFirstText(config.getElementsByTagName("config-property-type")).trim();
@@ -589,7 +614,7 @@
}
}
}
- return new ResourceAdapterParams(displayName, description, (ConfigParam[]) all.toArray(new ConfigParam[all.size()]));
+ return new ResourceAdapterParams(displayName, description, all.toArray(new ConfigParam[all.size()]));
} catch (Exception e) {
log.error("Unable to read resource adapter DD", e);
return null;
@@ -597,15 +622,15 @@
}
private String getFirstText(NodeList list) {
- if(list.getLength() == 0) {
+ if (list.getLength() == 0) {
return null;
}
Element first = (Element) list.item(0);
StringBuffer buf = new StringBuffer();
NodeList all = first.getChildNodes();
- for(int i=0; i<all.getLength(); i++) {
+ for (int i = 0; i < all.getLength(); i++) {
Node node = all.item(i);
- if(node.getNodeType() == Node.TEXT_NODE) {
+ if (node.getNodeType() == Node.TEXT_NODE) {
buf.append(node.getNodeValue());
}
}
@@ -616,23 +641,26 @@
AbstractName abstractAdapterName = new AbstractName(URI.create(adapterName));
AbstractName abstractFactoryName = new AbstractName(URI.create(factoryName));
- ResourceAdapterModule adapter = (ResourceAdapterModule) PortletManager.getManagedBean(actionRequest,abstractAdapterName);
- JCAManagedConnectionFactory factory = (JCAManagedConnectionFactory) PortletManager.getManagedBean(actionRequest, abstractFactoryName);
+ ResourceAdapterModule adapter = (ResourceAdapterModule) PortletManager.getManagedBean(actionRequest,
+ abstractAdapterName);
+ JCAManagedConnectionFactory factory = (JCAManagedConnectionFactory) PortletManager.getManagedBean(actionRequest,
+ abstractFactoryName);
data.adapterDisplayName = adapter.getDisplayName();
data.adapterDescription = adapter.getDescription();
try {
- data.name = (String)abstractFactoryName.getName().get("name");
- if(data.isGeneric()) {
+ data.name = (String) abstractFactoryName.getName().get("name");
+ if (data.isGeneric()) {
data.url = (String) factory.getConfigProperty("ConnectionURL");
data.driverClass = (String) factory.getConfigProperty("Driver");
data.user = (String) factory.getConfigProperty("UserName");
data.password = (String) factory.getConfigProperty("Password");
} else {
- ResourceAdapterParams params = getRARConfiguration(actionRequest, data.getRarPath(), data.getAdapterDisplayName(), adapterName);
- for(int i=0; i<params.getConfigParams().length; i++) {
+ ResourceAdapterParams params = getRARConfiguration(actionRequest, data.getRarPath(),
+ data.getAdapterDisplayName(), adapterName);
+ for (int i = 0; i < params.getConfigParams().length; i++) {
ConfigParam cp = params.getConfigParams()[i];
Object value = factory.getConfigProperty(cp.getName());
- data.properties.put("property-"+cp.getName(), value == null ? null : value.toString());
+ data.properties.put("property-" + cp.getName(), value == null ? null : value.toString());
}
}
} catch (Exception e) {
@@ -657,37 +685,37 @@
data.load(renderRequest);
renderRequest.setAttribute("pool", data);
// If not headed anywhere in particular, send to list
- if(mode == null || mode.equals("")) {
+ if (mode == null || mode.equals("")) {
mode = LIST_MODE;
}
// If headed to list but there's an import in progress, redirect to import status
- if(mode.equals(LIST_MODE) && getImportStatus(renderRequest) != null) {
+ if (mode.equals(LIST_MODE) && getImportStatus(renderRequest) != null) {
mode = IMPORT_STATUS_MODE;
}
- if(mode.equals(LIST_MODE)) {
+ if (mode.equals(LIST_MODE)) {
renderList(renderRequest, renderResponse);
- } else if(mode.equals(EDIT_MODE)) {
+ } else if (mode.equals(EDIT_MODE)) {
renderEdit(renderRequest, renderResponse, data);
- } else if(mode.equals(SELECT_RDBMS_MODE)) {
+ } else if (mode.equals(SELECT_RDBMS_MODE)) {
renderSelectRDBMS(renderRequest, renderResponse);
- } else if(mode.equals(DOWNLOAD_MODE)) {
+ } else if (mode.equals(DOWNLOAD_MODE)) {
renderDownload(renderRequest, renderResponse);
- } else if(mode.equals(DOWNLOAD_STATUS_MODE)) {
+ } else if (mode.equals(DOWNLOAD_STATUS_MODE)) {
renderDownloadStatus(renderRequest, renderResponse);
- } else if(mode.equals(BASIC_PARAMS_MODE)) {
+ } else if (mode.equals(BASIC_PARAMS_MODE)) {
renderBasicParams(renderRequest, renderResponse, data);
- } else if(mode.equals(CONFIRM_URL_MODE)) {
+ } else if (mode.equals(CONFIRM_URL_MODE)) {
renderConfirmURL(renderRequest, renderResponse);
- } else if(mode.equals(TEST_CONNECTION_MODE)) {
+ } else if (mode.equals(TEST_CONNECTION_MODE)) {
renderTestConnection(renderRequest, renderResponse);
- } else if(mode.equals(SHOW_PLAN_MODE)) {
+ } else if (mode.equals(SHOW_PLAN_MODE)) {
renderPlan(renderRequest, renderResponse, data);
- } else if(mode.equals(IMPORT_START_MODE)) {
+ } else if (mode.equals(IMPORT_START_MODE)) {
renderImportUploadForm(renderRequest, renderResponse);
- } else if(mode.equals(IMPORT_STATUS_MODE)) {
+ } else if (mode.equals(IMPORT_STATUS_MODE)) {
renderImportStatus(renderRequest, renderResponse);
- } else if(mode.equals(USAGE_MODE)) {
+ } else if (mode.equals(USAGE_MODE)) {
renderUsage(renderRequest, renderResponse);
}
} catch (Throwable e) {
@@ -717,16 +745,16 @@
private void populatePoolList(PortletRequest renderRequest) {
ResourceAdapterModule[] modules = PortletManager.getOutboundRAModules(renderRequest, "javax.sql.DataSource");
- List list = new ArrayList();
- for (int i = 0; i < modules.length; i++) {
- ResourceAdapterModule module = modules[i];
+ List<ConnectionPool> list = new ArrayList<ConnectionPool>();
+ for (ResourceAdapterModule module : modules) {
AbstractName moduleName = PortletManager.getManagementHelper(renderRequest).getNameFor(module);
- JCAManagedConnectionFactory[] databases = PortletManager.getOutboundFactoriesForRA(renderRequest, module, "javax.sql.DataSource");
- for (int j = 0; j < databases.length; j++) {
- JCAManagedConnectionFactory db = databases[j];
- AbstractName dbName = PortletManager.getManagementHelper(renderRequest).getNameFor(db);
- list.add(new ConnectionPool(moduleName, dbName, (String)dbName.getName().get(NameFactory.J2EE_NAME), ((GeronimoManagedBean)db).getState()));
+ JCAManagedConnectionFactory[] databases = PortletManager.getOutboundFactoriesForRA(renderRequest, module,
+ "javax.sql.DataSource");
+ for (JCAManagedConnectionFactory db : databases) {
+ AbstractName dbName = PortletManager.getManagementHelper(renderRequest).getNameFor(db);
+ list.add(new ConnectionPool(moduleName, dbName, (String) dbName.getName().get(NameFactory.J2EE_NAME),
+ ((GeronimoManagedBean) db).getState()));
}
}
Collections.sort(list);
@@ -734,24 +762,25 @@
}
private void renderEdit(RenderRequest renderRequest, RenderResponse renderResponse, PoolData data) throws IOException, PortletException {
- if(data.abstractName == null || data.abstractName.equals("")) {
+ if (data.abstractName == null || data.abstractName.equals("")) {
loadDriverJARList(renderRequest);
}
- if(!data.isGeneric()) {
- ResourceAdapterParams params = getRARConfiguration(renderRequest, data.getRarPath(), data.getAdapterDisplayName(), renderRequest.getParameter("adapterAbstractName"));
+ if (!data.isGeneric()) {
+ ResourceAdapterParams params = getRARConfiguration(renderRequest, data.getRarPath(),
+ data.getAdapterDisplayName(), renderRequest.getParameter("adapterAbstractName"));
data.adapterDisplayName = params.getDisplayName();
data.adapterDescription = params.getDescription();
- Map map = new HashMap();
+ Map<String, ConfigParam> map = new HashMap<String, ConfigParam>();
boolean more = false;
for (int i = 0; i < params.getConfigParams().length; i++) {
ConfigParam param = params.getConfigParams()[i];
- if(!data.properties.containsKey("property-"+param.getName())) {
- data.properties.put("property-"+param.getName(), param.getDefaultValue());
+ if (!data.properties.containsKey("property-" + param.getName())) {
+ data.properties.put("property-" + param.getName(), param.getDefaultValue());
more = true;
}
- map.put("property-"+param.getName(), param);
+ map.put("property-" + param.getName(), param);
}
- if(more) {
+ if (more) {
data.loadPropertyNames();
}
renderRequest.setAttribute("ConfigParams", map);
@@ -777,13 +806,13 @@
loadDriverJARList(renderRequest);
// Make sure all properties available for the DB are listed
DatabaseDriver info = getDatabaseInfo(renderRequest, data);
- if(info != null) {
+ if (info != null) {
String[] params = info.getURLParameters();
- for (int i = 0; i < params.length; i++) {
- String param = params[i];
- final String key = "urlproperty-"+param;
- if(!data.getUrlProperties().containsKey(key)) {
- data.getUrlProperties().put(key, param.equalsIgnoreCase("port") && info.getDefaultPort() > 0 ? new Integer(info.getDefaultPort()) : null);
+ for (String param : params) {
+ final String key = "urlproperty-" + param;
+ if (!data.getUrlProperties().containsKey(key)) {
+ data.getUrlProperties().put(key,
+ param.equalsIgnoreCase("port") && info.getDefaultPort() > 0 ? info.getDefaultPort() : null);
}
}
}
@@ -795,24 +824,15 @@
private void loadDriverJARList(RenderRequest renderRequest) {
// List the available JARs
- List list = new ArrayList();
+ List<String> list = new ArrayList<String>();
ListableRepository[] repos = PortletManager.getCurrentServer(renderRequest).getRepositories();
- for (int i = 0; i < repos.length; i++) {
- ListableRepository repo = repos[i];
-
- SortedSet artifacts = repo.list();
- outer:
- for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
- Artifact artifact = (Artifact) iterator.next();
- String test = artifact.toString();
- // todo should only test groupId and should check for long (org.apache.geronimo) and short form
- for (int k = 0; k < SKIP_ENTRIES_WITH.length; k++) {
- String skip = SKIP_ENTRIES_WITH[k];
- if(test.indexOf(skip) > -1) {
- continue outer;
- }
+ for (ListableRepository repo : repos) {
+ SortedSet<Artifact> artifacts = repo.list();
+ for (Artifact artifact : artifacts) {
+ if (INCLUDE_ARTIFACTIDS.contains(artifact.getArtifactId())
+ || !EXCLUDE_GROUPIDS.contains(artifact.getGroupId())) {
+ list.add(artifact.toString());
}
- list.add(test);
}
}
Collections.sort(list);
@@ -836,14 +856,14 @@
// Digest the RAR URI
String path = PortletManager.getRepositoryEntry(renderRequest, data.getRarPath()).getPath();
String base = PortletManager.getCurrentServer(renderRequest).getServerInfo().getCurrentBaseDirectory();
- if(base != null && path.startsWith(base)) {
+ if (base != null && path.startsWith(base)) {
path = path.substring(base.length());
- if(path.startsWith("/")) {
+ if (path.startsWith("/")) {
path = path.substring(1);
}
} else {
int pos = path.lastIndexOf('/');
- path = path.substring(pos+1);
+ path = path.substring(pos + 1);
}
renderRequest.setAttribute("rarRelativePath", path);
@@ -853,32 +873,38 @@
private static String attemptConnect(PortletRequest request, PoolData data) throws SQLException, IllegalAccessException, InstantiationException {
Class driverClass = attemptDriverLoad(request, data);
Driver driver = (Driver) driverClass.newInstance();
- if(driver.acceptsURL(data.url)) {
+ if (driver.acceptsURL(data.url)) {
Properties props = new Properties();
- if(data.user != null) {
+ if (data.user != null) {
props.put("user", data.user);
}
- if(data.password != null) {
+ if (data.password != null) {
props.put("password", data.password);
}
Connection con = null;
try {
con = driver.connect(data.url, props);
final DatabaseMetaData metaData = con.getMetaData();
- return metaData.getDatabaseProductName()+" "+metaData.getDatabaseProductVersion();
+ return metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion();
} finally {
- if(con != null) try{con.close();}catch(SQLException e) {}
+ if (con != null) {
+ try {
+ con.close();
+ } catch (SQLException e) {
+ //ignore
+ }
+ }
}
- } else throw new SQLException("Driver "+data.getDriverClass()+" does not accept URL "+data.url);
+ } else throw new SQLException("Driver " + data.getDriverClass() + " does not accept URL " + data.url);
}
private void delete(PortletRequest request, ActionResponse response, PoolData data) {
// check to make sure the abstract name does not begin with 'org.apache.geronimo.configs'
// if it does not - then delete it -- otherwise it is a system database
- if(data.getAbstractName() != null) {
+ if (data.getAbstractName() != null) {
boolean isSystemDatabasePool = (data.getAbstractName().indexOf("org.apache.geronimo.configs") == 0);
- if(! isSystemDatabasePool) {
+ if (!isSystemDatabasePool) {
DeploymentManager mgr = PortletManager.getDeploymentManager(request);
try {
// retrieve all running modules
@@ -888,25 +914,25 @@
int index = -1;
// only keep module id that is associated with selected DB pool
- for(int i = 0; i < runningIds.length; i++) {
- if(data.getAbstractName().contains(runningIds[i].getModuleID())) {
+ for (int i = 0; i < runningIds.length; i++) {
+ if (data.getAbstractName().contains(runningIds[i].getModuleID())) {
index = i;
break;
}
}
- TargetModuleID[] ids = { runningIds[index] };
+ TargetModuleID[] ids = {runningIds[index]};
// undeploy the db pool
ProgressObject po = mgr.undeploy(ids);
waitForProgress(po);
- if(po.getDeploymentStatus().isCompleted()) {
+ if (po.getDeploymentStatus().isCompleted()) {
log.info("Undeployment completed successfully!");
}
- } catch(Exception e) {
+ } catch (Exception e) {
log.error("Undeployment unsuccessful!");
} finally {
- if(mgr != null) mgr.release();
+ if (mgr != null) mgr.release();
}
}
}
@@ -914,7 +940,7 @@
private static String save(PortletRequest request, ActionResponse response, PoolData data, boolean planOnly) {
ImportStatus status = getImportStatus(request);
- if(data.abstractName == null || data.abstractName.equals("")) { // we're creating a new pool
+ if (data.abstractName == null || data.abstractName.equals("")) { // we're creating a new pool
data.name = data.name.replaceAll("\\s", "");
DeploymentManager mgr = PortletManager.getDeploymentManager(request);
try {
@@ -923,7 +949,8 @@
DeploymentConfiguration config = mgr.createConfiguration(deployable);
final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot();
Connector15DCBRoot root = (Connector15DCBRoot) config.getDConfigBeanRoot(ddBeanRoot);
- ConnectorDCB connector = (ConnectorDCB) root.getDConfigBean(ddBeanRoot.getChildBean(root.getXpaths()[0])[0]);
+ ConnectorDCB connector = (ConnectorDCB) root.getDConfigBean(
+ ddBeanRoot.getChildBean(root.getXpaths()[0])[0]);
EnvironmentData environment = new EnvironmentData();
connector.setEnvironment(environment);
@@ -931,7 +958,7 @@
environment.setConfigId(configId);
configId.setGroupId("console.dbpool");
String artifactId = data.name;
- if(artifactId.indexOf('/') != -1) {
+ if (artifactId.indexOf('/') != -1) {
// slash in artifact-id results in invalid configuration-id and leads to deployment errors
artifactId = artifactId.replaceAll("/", "%2F");
}
@@ -940,18 +967,18 @@
configId.setType("rar");
String[] jars = data.getJars();
- int length = jars[jars.length - 1].length() ==0? jars.length -1: jars.length;
+ int length = jars[jars.length - 1].length() == 0 ? jars.length - 1 : jars.length;
org.apache.geronimo.deployment.service.jsr88.Artifact[] dependencies = new org.apache.geronimo.deployment.service.jsr88.Artifact[length];
- for (int i=0; i<dependencies.length; i++) {
+ for (int i = 0; i < dependencies.length; i++) {
dependencies[i] = new org.apache.geronimo.deployment.service.jsr88.Artifact();
}
environment.setDependencies(dependencies);
- for (int i=0; i<dependencies.length; i++) {
- Artifact tmp = Artifact.create(jars[i]);
- dependencies[i].setGroupId(tmp.getGroupId());
- dependencies[i].setArtifactId(tmp.getArtifactId());
- dependencies[i].setVersion(tmp.getVersion().toString());
- dependencies[i].setType(tmp.getType());
+ for (int i = 0; i < dependencies.length; i++) {
+ Artifact tmp = Artifact.create(jars[i]);
+ dependencies[i].setGroupId(tmp.getGroupId());
+ dependencies[i].setArtifactId(tmp.getArtifactId());
+ dependencies[i].setVersion(tmp.getVersion().toString());
+ dependencies[i].setType(tmp.getType());
}
ResourceAdapter adapter = connector.getResourceAdapter()[0];
@@ -962,23 +989,21 @@
definition.setConnectionInstance(new ConnectionDefinitionInstance[]{instance});
instance.setName(data.getName());
ConfigPropertySetting[] settings = instance.getConfigPropertySetting();
- if(data.isGeneric()) { // it's a generic TranQL JDBC pool
- for (int i = 0; i < settings.length; i++) {
- ConfigPropertySetting setting = settings[i];
- if(setting.getName().equals("UserName")) {
+ if (data.isGeneric()) { // it's a generic TranQL JDBC pool
+ for (ConfigPropertySetting setting : settings) {
+ if (setting.getName().equals("UserName")) {
setting.setValue(data.user);
- } else if(setting.getName().equals("Password")) {
+ } else if (setting.getName().equals("Password")) {
setting.setValue(data.password);
- } else if(setting.getName().equals("ConnectionURL")) {
+ } else if (setting.getName().equals("ConnectionURL")) {
setting.setValue(data.url);
- } else if(setting.getName().equals("Driver")) {
+ } else if (setting.getName().equals("Driver")) {
setting.setValue(data.driverClass);
}
}
} else { // it's an XA driver or non-TranQL RA
- for (int i = 0; i < settings.length; i++) {
- ConfigPropertySetting setting = settings[i];
- String value = (String) data.properties.get("property-"+setting.getName());
+ for (ConfigPropertySetting setting : settings) {
+ String value = (String) data.properties.get("property-" + setting.getName());
setting.setValue(value == null ? "" : value);
}
}
@@ -991,28 +1016,28 @@
// 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("")) {
+ if (data.maxSize != null && !data.maxSize.equals("")) {
pool.setMaxSize(new Integer(data.maxSize));
}
- if(data.minSize != null && !data.minSize.equals("")) {
+ if (data.minSize != null && !data.minSize.equals("")) {
pool.setMinSize(new Integer(data.minSize));
}
- if(data.blockingTimeout != null && !data.blockingTimeout.equals("")) {
+ if (data.blockingTimeout != null && !data.blockingTimeout.equals("")) {
pool.setBlockingTimeoutMillis(new Integer(data.blockingTimeout));
}
- if(data.idleTimeout != null && !data.idleTimeout.equals("")) {
+ if (data.idleTimeout != null && !data.idleTimeout.equals("")) {
pool.setIdleTimeoutMinutes(new Integer(data.idleTimeout));
}
- if(planOnly) {
+ 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");
+ File tempFile = File.createTempFile("console-deployment", ".xml");
tempFile.deleteOnExit();
- log.debug("Writing database pool deployment plan to "+tempFile.getAbsolutePath());
+ log.debug("Writing database pool deployment plan to " + tempFile.getAbsolutePath());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
config.save(out);
out.flush();
@@ -1020,13 +1045,13 @@
Target[] targets = mgr.getTargets();
ProgressObject po = mgr.distribute(targets, rarFile, tempFile);
waitForProgress(po);
- if(po.getDeploymentStatus().isCompleted()) {
+ if (po.getDeploymentStatus().isCompleted()) {
TargetModuleID[] ids = po.getResultTargetModuleIDs();
po = mgr.start(ids);
waitForProgress(po);
- if(po.getDeploymentStatus().isCompleted()) {
+ if (po.getDeploymentStatus().isCompleted()) {
ids = po.getResultTargetModuleIDs();
- if(status != null) {
+ if (status != null) {
status.getCurrentPool().setName(data.getName());
status.getCurrentPool().setConfigurationName(ids[0].getModuleID());
status.getCurrentPool().setFinished(true);
@@ -1035,7 +1060,7 @@
log.info("Deployment completed successfully!");
}
- } else if(po.getDeploymentStatus().isFailed()) {
+ } else if (po.getDeploymentStatus().isFailed()) {
data.deployError = "Unable to deploy: " + data.name;
response.setRenderParameter(MODE_KEY, EDIT_MODE);
log.info("Deployment Failed!");
@@ -1044,30 +1069,37 @@
} catch (Exception e) {
log.error("Unable to save connection pool", e);
} finally {
- if(mgr != null) mgr.release();
+ if (mgr != null) mgr.release();
}
} else { // We're saving updates to an existing pool
- if(planOnly) {
+ 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()) {
+ 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 (Iterator it = data.getProperties().entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- factory.setConfigProperty(((String) entry.getKey()).substring("property-".length()), entry.getValue());
+ 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));
+ 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);
}
@@ -1076,7 +1108,7 @@
}
private static void waitForProgress(ProgressObject po) {
- while(po.getDeploymentStatus().isRunning()) {
+ while (po.getDeploymentStatus().isRunning()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
@@ -1090,15 +1122,15 @@
}
private static File getRAR(PortletRequest request, String rarPath) {
- org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact.create(rarPath);
+ org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact.create(
+ rarPath);
ListableRepository[] repos = PortletManager.getCurrentServer(request).getRepositories();
- for (int i = 0; i < repos.length; i++) {
- ListableRepository repo = repos[i];
+ for (ListableRepository repo : repos) {
// if the artifact is not fully resolved then try to resolve it
if (!artifact.isResolved()) {
SortedSet results = repo.list(artifact);
if (!results.isEmpty()) {
- artifact = (org.apache.geronimo.kernel.repository.Artifact) results.first();
+ artifact = (Artifact) results.first();
}
}
File url = repo.getLocation(artifact);
@@ -1114,28 +1146,33 @@
/**
* WARNING: This method relies on having access to the same repository
* URLs as the server uses.
+ *
+ * @param request portlet request
+ * @param data info about jars to include
+ * @return driver class
*/
private static Class attemptDriverLoad(PortletRequest request, PoolData data) {
- List list = new ArrayList();
+ List<URL> list = new ArrayList<URL>();
try {
String[] jars = data.getJars();
- if(jars == null) {
+ if (jars == null) {
log.error("Driver load failed since no jar files were selected.");
return null;
}
ListableRepository[] repos = PortletManager.getCurrentServer(request).getRepositories();
- for (int i = 0; i < jars.length; i++) {
- org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact.create(jars[i]);
- for (int j = 0; j < repos.length; j++) {
- ListableRepository repo = repos[j];
+ for (String jar : jars) {
+ Artifact artifact = Artifact.create(
+ jar);
+ for (ListableRepository repo : repos) {
File url = repo.getLocation(artifact);
if (url != null) {
list.add(url.toURL());
}
}
}
- URLClassLoader loader = new URLClassLoader((URL[]) list.toArray(new URL[list.size()]), DatabasePoolPortlet.class.getClassLoader());
+ URLClassLoader loader = new URLClassLoader(list.toArray(new URL[list.size()]),
+ DatabasePoolPortlet.class.getClassLoader());
try {
return loader.loadClass(data.driverClass);
} catch (ClassNotFoundException e) {
@@ -1148,50 +1185,50 @@
}
private static String populateURL(String url, String[] keys, Map properties) {
- for (int i = 0; i < keys.length; i++) {
- String key = keys[i];
- String value = (String) properties.get("urlproperty-"+key);
- if(value == null || value.equals("")) {
- int begin = url.indexOf("{"+key+"}");
+ for (String key : keys) {
+ String value = (String) properties.get("urlproperty-" + key);
+ if (value == null || value.equals("")) {
+ int begin = url.indexOf("{" + key + "}");
int end = begin + key.length() + 2;
- for(int j=begin-1; j>=0; j--) {
+ for (int j = begin - 1; j >= 0; j--) {
char c = url.charAt(j);
- if(c == ';' || c == ':') {
+ if (c == ';' || c == ':') {
begin = j;
break;
- } else if(c == '/') {
- if(url.length() > end && url.charAt(end) == '/') {
+ } else if (c == '/') {
+ if (url.length() > end && url.charAt(end) == '/') {
begin = j; // Don't leave // if foo is null for /<foo>/
}
break;
}
}
- url = url.substring(0, begin)+url.substring(end);
+ url = url.substring(0, begin) + url.substring(end);
} else {
- if(value.indexOf('\\') != -1 || value.indexOf('$') != -1) {
+ if (value.indexOf('\\') != -1 || value.indexOf('$') != -1) {
// value contains backslash or dollar sign and needs preprocessing for replaceAll to work properly
StringBuffer temp = new StringBuffer();
char[] valueChars = value.toCharArray();
- for(int j = 0; j < valueChars.length; ++j) {
- if(valueChars[j] == '\\' || valueChars[j] == '$') {
+ for (int j = 0; j < valueChars.length; ++j) {
+ if (valueChars[j] == '\\' || valueChars[j] == '$') {
temp.append('\\');
}
temp.append(valueChars[j]);
}
value = temp.toString();
}
- url = url.replaceAll("\\{"+key+"\\}", value);
+ url = url.replaceAll("\\{" + key + "\\}", value);
}
}
return url;
}
private static DatabaseDriver[] getAllDrivers(PortletRequest request) {
- DatabaseDriver[] result = (DatabaseDriver[]) PortletManager.getGBeansImplementing(request, DatabaseDriver.class);
- Arrays.sort(result, new Comparator() {
- public int compare(Object o1, Object o2) {
- String name1 = ((DatabaseDriver) o1).getName();
- String name2 = ((DatabaseDriver) o2).getName();
+ DatabaseDriver[] result = (DatabaseDriver[]) PortletManager.getGBeansImplementing(request,
+ DatabaseDriver.class);
+ Arrays.sort(result, new Comparator<DatabaseDriver>() {
+ public int compare(DatabaseDriver o1, DatabaseDriver o2) {
+ String name1 = o1.getName();
+ String name2 = o2.getName();
if (name1.equals("Other")) name1 = "zzzOther";
if (name2.equals("Other")) name2 = "zzzOther";
return name1.compareTo(name2);
@@ -1203,8 +1240,7 @@
private static DatabaseDriver getDatabaseInfo(PortletRequest request, PoolData data) {
DatabaseDriver info = null;
DatabaseDriver[] all = getAllDrivers(request);
- for (int i = 0; i < all.length; i++) {
- DatabaseDriver next = all[i];
+ for (DatabaseDriver next : all) {
if (next.getName().equals(data.getDbtype())) {
info = next;
break;
@@ -1216,9 +1252,8 @@
private static DatabaseDriver getDatabaseInfoFromDriver(PortletRequest request, PoolData data) {
DatabaseDriver info = null;
DatabaseDriver[] all = getAllDrivers(request);
- for (int i = 0; i < all.length; i++) {
- DatabaseDriver next = all[i];
- if (next.getDriverClassName()!=null && next.getDriverClassName().equals(data.getDriverClass())) {
+ for (DatabaseDriver next : all) {
+ if (next.getDriverClassName() != null && next.getDriverClassName().equals(data.getDriverClass())) {
info = next;
break;
}
@@ -1232,9 +1267,9 @@
private String dbtype;
private String user;
private String password;
- private Map properties = new HashMap(); // Configuration for non-Generic drivers
- private Map urlProperties = new HashMap(); // URL substitution for Generic drivers
- private Map propertyNames; //todo: store these in the ConfigParam instead
+ private Map<String, String> properties = new HashMap<String, String>(); // Configuration for non-Generic drivers
+ private Map<String, Object> urlProperties = new HashMap<String, Object>(); // URL substitution for Generic drivers
+ private Map<String, String> propertyNames; //todo: store these in the ConfigParam instead
private String driverClass;
private String url;
private String urlPrototype;
@@ -1248,93 +1283,93 @@
private String adapterDescription;
private String rarPath;
private String importSource;
- private Map abstractNameMap; // generated as needed, don't need to read/write it
+ private Map<String, String> abstractNameMap; // generated as needed, don't need to read/write it
private String deployError;
public void load(PortletRequest request) {
name = request.getParameter("name");
- if(name != null && name.equals("")) name = null;
+ if (name != null && name.equals("")) name = null;
driverClass = request.getParameter("driverClass");
- if(driverClass != null && driverClass.equals("")) driverClass = null;
+ if (driverClass != null && driverClass.equals("")) driverClass = null;
dbtype = request.getParameter("dbtype");
- if(dbtype != null && dbtype.equals("")) dbtype = null;
+ if (dbtype != null && dbtype.equals("")) dbtype = null;
user = request.getParameter("user");
- if(user != null && user.equals("")) user = null;
+ if (user != null && user.equals("")) user = null;
password = request.getParameter("password");
- if(password != null && password.equals("")) password = null;
+ if (password != null && password.equals("")) password = null;
url = request.getParameter("url");
- if(url != null && url.equals("")) {
+ if (url != null && url.equals("")) {
url = null;
- } else if(url != null && url.startsWith("URLENCODED")) {
+ } else if (url != null && url.startsWith("URLENCODED")) {
try {
url = URLDecoder.decode(url.substring(10), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unable to decode URL", e);
- } catch(IllegalArgumentException e) { // not encoded after all??
+ } catch (IllegalArgumentException e) { // not encoded after all??
url = url.substring(10);
}
}
urlPrototype = request.getParameter("urlPrototype");
- if(urlPrototype != null && urlPrototype.equals("")) urlPrototype = null;
+ if (urlPrototype != null && urlPrototype.equals("")) urlPrototype = null;
jars = request.getParameterValues("jars");
minSize = request.getParameter("minSize");
- if(minSize != null && minSize.equals("")) minSize = null;
+ if (minSize != null && minSize.equals("")) minSize = null;
maxSize = request.getParameter("maxSize");
- if(maxSize != null && maxSize.equals("")) maxSize = null;
+ if (maxSize != null && maxSize.equals("")) maxSize = null;
blockingTimeout = request.getParameter("blockingTimeout");
- if(blockingTimeout != null && blockingTimeout.equals("")) blockingTimeout = null;
+ if (blockingTimeout != null && blockingTimeout.equals("")) blockingTimeout = null;
idleTimeout = request.getParameter("idleTimeout");
- if(idleTimeout != null && idleTimeout.equals("")) idleTimeout = null;
+ if (idleTimeout != null && idleTimeout.equals("")) idleTimeout = null;
abstractName = request.getParameter("abstractName");
- if(abstractName != null && abstractName.equals("")) abstractName = null;
+ if (abstractName != null && abstractName.equals("")) abstractName = null;
adapterDisplayName = request.getParameter("adapterDisplayName");
- if(adapterDisplayName != null && adapterDisplayName.equals("")) adapterDisplayName = null;
+ if (adapterDisplayName != null && adapterDisplayName.equals("")) adapterDisplayName = null;
adapterDescription = request.getParameter("adapterDescription");
- if(adapterDescription != null && adapterDescription.equals("")) adapterDescription = null;
+ if (adapterDescription != null && adapterDescription.equals("")) adapterDescription = null;
rarPath = request.getParameter("rarPath");
- if(rarPath != null && rarPath.equals("")) rarPath = null;
+ if (rarPath != null && rarPath.equals("")) rarPath = null;
importSource = request.getParameter("importSource");
- if(importSource != null && importSource.equals("")) importSource = null;
+ if (importSource != null && importSource.equals("")) importSource = null;
Map map = request.getParameterMap();
- propertyNames = new HashMap();
- for (Iterator it = map.keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
- if(key.startsWith("urlproperty-")) {
+ propertyNames = new HashMap<String, String>();
+ for (Object o : map.keySet()) {
+ String key = (String) o;
+ if (key.startsWith("urlproperty-")) {
urlProperties.put(key, request.getParameter(key));
- } else if(key.startsWith("property-")) {
+ } else if (key.startsWith("property-")) {
properties.put(key, request.getParameter(key));
propertyNames.put(key, getPropertyName(key));
}
}
deployError = request.getParameter("deployError");
- if(deployError != null && deployError.equals("")) deployError = null;
+ if (deployError != null && deployError.equals("")) deployError = null;
}
public void loadPropertyNames() {
- propertyNames = new HashMap();
- for (Iterator it = properties.keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
+ propertyNames = new HashMap<String, String>();
+ for (String key : properties.keySet()) {
propertyNames.put(key, getPropertyName(key));
}
}
private static String getPropertyName(String key) {
int pos = key.indexOf('-');
- key = Character.toUpperCase(key.charAt(pos+1))+key.substring(pos+2);
+ key = Character.toUpperCase(key.charAt(pos + 1)) + key.substring(pos + 2);
StringBuffer buf = new StringBuffer();
pos = 0;
- for(int i=1; i<key.length(); i++) {
- if(Character.isUpperCase(key.charAt(i))) {
- if(Character.isUpperCase(key.charAt(i-1))) { // ongoing capitalized word
+ for (int i = 1; i < key.length(); i++) {
+ if (Character.isUpperCase(key.charAt(i))) {
+ if (Character.isUpperCase(key.charAt(i - 1))) { // ongoing capitalized word
} else { // start of a new word
buf.append(key.substring(pos, i)).append(" ");
pos = i;
}
} else {
- if(Character.isUpperCase(key.charAt(i-1)) && i-pos > 1) { // first lower-case after a series of caps
- buf.append(key.substring(pos, i-1)).append(" ");
- pos = i-1;
+ if (Character.isUpperCase(
+ key.charAt(i - 1)) && i - pos > 1) { // first lower-case after a series of caps
+ buf.append(key.substring(pos, i - 1)).append(" ");
+ pos = i - 1;
}
}
}
@@ -1343,42 +1378,40 @@
}
public void store(ActionResponse response) {
- if(name != null) response.setRenderParameter("name", name);
- if(dbtype != null) response.setRenderParameter("dbtype", dbtype);
- if(driverClass != null) response.setRenderParameter("driverClass", driverClass);
- if(user != null) response.setRenderParameter("user", user);
- if(password != null) response.setRenderParameter("password", password);
- if(url != null) { // attempt to work around Pluto/Tomcat error with ; in a stored value
+ if (name != null) response.setRenderParameter("name", name);
+ if (dbtype != null) response.setRenderParameter("dbtype", dbtype);
+ if (driverClass != null) response.setRenderParameter("driverClass", driverClass);
+ if (user != null) response.setRenderParameter("user", user);
+ if (password != null) response.setRenderParameter("password", password);
+ if (url != null) { // attempt to work around Pluto/Tomcat error with ; in a stored value
try {
- response.setRenderParameter("url", "URLENCODED"+URLEncoder.encode(url, "UTF-8"));
+ response.setRenderParameter("url", "URLENCODED" + URLEncoder.encode(url, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unable to encode URL", e);
}
}
- if(urlPrototype != null) response.setRenderParameter("urlPrototype", urlPrototype);
- if(jars != null) response.setRenderParameter("jars", jars);
- if(minSize != null) response.setRenderParameter("minSize", minSize);
- if(maxSize != null) response.setRenderParameter("maxSize", maxSize);
- if(blockingTimeout != null) response.setRenderParameter("blockingTimeout", blockingTimeout);
- if(idleTimeout != null) response.setRenderParameter("idleTimeout", idleTimeout);
- if(abstractName != null) response.setRenderParameter("abstractName", abstractName);
- if(adapterDisplayName != null) response.setRenderParameter("adapterDisplayName", adapterDisplayName);
- if(adapterDescription != null) response.setRenderParameter("adapterDescription", adapterDescription);
- if(importSource != null) response.setRenderParameter("importSource", importSource);
- if(rarPath != null) response.setRenderParameter("rarPath", rarPath);
- for (Iterator it = urlProperties.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- if(entry.getValue() != null) {
- response.setRenderParameter((String)entry.getKey(), (String)entry.getValue());
- }
- }
- for (Iterator it = properties.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- if(entry.getValue() != null) {
- response.setRenderParameter((String)entry.getKey(), (String)entry.getValue());
+ if (urlPrototype != null) response.setRenderParameter("urlPrototype", urlPrototype);
+ if (jars != null) response.setRenderParameter("jars", jars);
+ if (minSize != null) response.setRenderParameter("minSize", minSize);
+ if (maxSize != null) response.setRenderParameter("maxSize", maxSize);
+ if (blockingTimeout != null) response.setRenderParameter("blockingTimeout", blockingTimeout);
+ if (idleTimeout != null) response.setRenderParameter("idleTimeout", idleTimeout);
+ if (abstractName != null) response.setRenderParameter("abstractName", abstractName);
+ if (adapterDisplayName != null) response.setRenderParameter("adapterDisplayName", adapterDisplayName);
+ if (adapterDescription != null) response.setRenderParameter("adapterDescription", adapterDescription);
+ if (importSource != null) response.setRenderParameter("importSource", importSource);
+ if (rarPath != null) response.setRenderParameter("rarPath", rarPath);
+ for (Map.Entry<String, Object> entry : urlProperties.entrySet()) {
+ if (entry.getValue() != null) {
+ response.setRenderParameter((String) entry.getKey(), (String) entry.getValue());
+ }
+ }
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ if (entry.getValue() != null) {
+ response.setRenderParameter((String) entry.getKey(), (String) entry.getValue());
}
}
- if(deployError != null) response.setRenderParameter("deployError", deployError);
+ if (deployError != null) response.setRenderParameter("deployError", deployError);
}
public String getName() {
@@ -1397,15 +1430,15 @@
return password;
}
- public Map getProperties() {
+ public Map<String, String> getProperties() {
return properties;
}
- public Map getPropertyNames() {
+ public Map<String, String> getPropertyNames() {
return propertyNames;
}
- public Map getUrlProperties() {
+ public Map<String, Object> getUrlProperties() {
return urlProperties;
}
@@ -1414,7 +1447,7 @@
}
public String[] getJars() {
- return jars;
+ return jars;
}
public String getMinSize() {
@@ -1466,11 +1499,11 @@
return importSource;
}
- public Map getAbstractNameMap() {
- if(abstractName == null) return Collections.EMPTY_MAP;
- if(abstractNameMap != null) return abstractNameMap;
+ public Map<String, String> getAbstractNameMap() {
+ if (abstractName == null) return Collections.emptyMap();
+ if (abstractNameMap != null) return abstractNameMap;
AbstractName name = new AbstractName(URI.create(abstractName));
- abstractNameMap = new HashMap(name.getName());
+ abstractNameMap = new HashMap<String, String>(name.getName());
abstractNameMap.put("domain", name.getObjectName().getDomain());
abstractNameMap.put("groupId", name.getArtifact().getGroupId());
abstractNameMap.put("artifactId", name.getArtifact().getArtifactId());
@@ -1494,8 +1527,8 @@
public ConnectionPool(AbstractName adapterAbstractName, AbstractName factoryAbstractName, String name, int state) {
this.adapterAbstractName = adapterAbstractName.toURI().toString();
- String parent = (String)adapterAbstractName.getName().get(NameFactory.J2EE_APPLICATION);
- if(parent != null && parent.equals("null")) {
+ String parent = (String) adapterAbstractName.getName().get(NameFactory.J2EE_APPLICATION);
+ if (parent != null && parent.equals("null")) {
parent = null;
}
parentName = parent;
@@ -1529,20 +1562,20 @@
}
public int compareTo(Object o) {
- final ConnectionPool pool = (ConnectionPool)o;
+ final ConnectionPool pool = (ConnectionPool) o;
int names = name.compareTo(pool.name);
- if(parentName == null) {
- if(pool.parentName == null) {
+ if (parentName == null) {
+ if (pool.parentName == null) {
return names;
} else {
return -1;
}
} else {
- if(pool.parentName == null) {
+ if (pool.parentName == null) {
return 1;
} else {
int test = parentName.compareTo(pool.parentName);
- if(test != 0) {
+ if (test != 0) {
return test;
} else {
return names;