Author: chris.laprun(a)jboss.com
Date: 2009-02-26 08:18:28 -0500 (Thu, 26 Feb 2009)
New Revision: 12898
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
Log:
- JBPORTAL-2040:
+ Re-wrote PortalObject.getChild to use container directly instead of going through
ObjectNode.getChildren
to avoid having to retrieve all the children just to get one. This should yield a
massive reduction in DB
requests.
+ Removed unused instances and pages SelectedItems in PortalObjectManagerBean
- Added PortalObjectId.getChildId to efficiently get a child's id from a parent and
use ParameterValidation.
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-02-26
13:07:23 UTC (rev 12897)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-02-26
13:18:28 UTC (rev 12898)
@@ -88,7 +88,7 @@
public PortalObjectImpl(boolean initState)
{
- this.declaredPropertyMap = new HashMap();
+ this.declaredPropertyMap = new HashMap<String, String>();
this.listener = null;
//
@@ -408,17 +408,18 @@
public PortalObject getChild(String name)
{
- ParameterValidation.throwIllegalArgExceptionIfNull(name, "child name");
- ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
- if (childNode != null)
+ if (name == null)
{
- PortalObjectImpl childObject = childNode.getObject();
+ throw new IllegalArgumentException();
+ }
- // Track it
- getAccessedChildren().add(childObject);
-
- //
- return childObject;
+ // use container directly instead of going through children to avoid having to
retrieve all of them just for one
+ // this leads to major perfomance improvement by dramatically reducing the number
of DB requests
+ PortalObject portalObject =
objectNode.getContext().getContainer().getObject(getId().getChildId(name));
+ if (portalObject != null)
+ {
+ getAccessedChildren().add(portalObject);
+ return portalObject;
}
else
{
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java 2009-02-26
13:07:23 UTC (rev 12897)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java 2009-02-26
13:18:28 UTC (rev 12898)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.core.model.portal;
+import org.jboss.portal.common.util.ParameterValidation;
+
import java.io.Serializable;
/**
@@ -60,14 +62,8 @@
*/
public PortalObjectId(String namespace, PortalObjectPath path) throws
IllegalArgumentException
{
- if (namespace == null)
- {
- throw new IllegalArgumentException();
- }
- if (path == null)
- {
- throw new IllegalArgumentException();
- }
+ ParameterValidation.throwIllegalArgExceptionIfNull(namespace,
"namespace");
+ ParameterValidation.throwIllegalArgExceptionIfNull(path, "path");
this.namespace = namespace;
this.path = path;
}
@@ -125,10 +121,7 @@
*/
public static PortalObjectId parse(String idValue, PortalObjectPath.Format format)
throws IllegalArgumentException
{
- if (idValue == null)
- {
- throw new IllegalArgumentException("No null id value accepted");
- }
+ ParameterValidation.throwIllegalArgExceptionIfNull(idValue, "id");
int pos = idValue.indexOf(NAMESPACE_SEPARATOR);
//
@@ -144,6 +137,12 @@
}
}
+ public PortalObjectId getChildId(String name)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(name, "child name");
+ return new PortalObjectId(getNamespace(), getPath().getChild(name));
+ }
+
/**
* Parse a portal object id given the namespace and the path string representation.
*
@@ -177,10 +176,7 @@
*/
public String toString(PortalObjectPath.Format format) throws
IllegalArgumentException
{
- if (format == null)
- {
- throw new IllegalArgumentException("No null format accepted");
- }
+ ParameterValidation.throwIllegalArgExceptionIfNull(format, "format");
//
if (format == PortalObjectPath.LEGACY_FORMAT)
@@ -216,14 +212,8 @@
*/
public static String toString(String namespace, PortalObjectPath path,
PortalObjectPath.Format format) throws IllegalArgumentException
{
- if (namespace == null)
- {
- throw new IllegalArgumentException("No null namespace accepted");
- }
- if (path == null)
- {
- throw new IllegalArgumentException("No null path accepted");
- }
+ ParameterValidation.throwIllegalArgExceptionIfNull(namespace,
"namespace");
+ ParameterValidation.throwIllegalArgExceptionIfNull(path, "path");
if (namespace.length() > 0)
{
return namespace + NAMESPACE_SEPARATOR + path.toString(format);
@@ -240,4 +230,4 @@
int order = namespace.compareTo(that.namespace);
return order != 0 ? order : path.compareTo(that.path);
}
-}
+}
\ No newline at end of file
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2009-02-26
13:07:23 UTC (rev 12897)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2009-02-26
13:18:28 UTC (rev 12898)
@@ -36,7 +36,6 @@
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.content.spi.ContentProvider;
import org.jboss.portal.core.model.content.spi.portlet.ContentPortlet;
-import org.jboss.portal.core.model.instance.Instance;
import org.jboss.portal.core.model.instance.InstanceContainer;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.PortalObject;
@@ -66,7 +65,6 @@
import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@@ -141,12 +139,6 @@
private final AuthorizationBean auth = new PortalObjectAuthorizationBean();
/** . */
- private SelectItem[] instanceItems;
-
- /** . */
- private SelectItem[] portalPageItems;
-
- /** . */
private List selectedObjectPath;
/** . */
@@ -368,16 +360,6 @@
return auth;
}
- public SelectItem[] getInstanceItems()
- {
- return instanceItems;
- }
-
- public SelectItem[] getPortalPageItems()
- {
- return portalPageItems;
- }
-
public List getSelectedObjectPath()
{
return selectedObjectPath;
@@ -653,8 +635,6 @@
public void refresh()
{
propertyAction = null;
- instanceItems = null;
- portalPageItems = null;
selectedObjectPath = null;
selectedObject = null;
selectedProperties = null;
@@ -693,18 +673,6 @@
//
theme = new ThemeBean(selectedObject);
- //
- Collection<PortalObject> pages =
getSelectedObject().getChildren(PortalObject.PAGE_MASK);
- ArrayList<SelectItem> list = new ArrayList<SelectItem>(pages.size() +
1);
- for (PortalObject page : pages)
- {
- SelectItem item = new SelectItem(page.getName());
- list.add(item);
- }
- list.add(new SelectItem("", "no selection"));
- portalPageItems = list.toArray(new SelectItem[list.size()]);
-
- //
PortalObject o = getSelectedObject();
ArrayList<PortalObject> path = new ArrayList<PortalObject>();
while (o != null)
@@ -714,17 +682,6 @@
}
Collections.reverse(path);
selectedObjectPath = path;
-
- // rather dirty code...
- List tmp = new ArrayList(instanceContainer.getDefinitions());
- Collections.sort(tmp, InstanceManagerBean.INSTANCE_COMPARATOR);
- for (int i = 0; i < tmp.size(); i++)
- {
- Instance instance = (Instance)tmp.get(i);
- SelectItem item = new SelectItem(instance.getId());
- tmp.set(i, item);
- }
- instanceItems = (SelectItem[])tmp.toArray(new SelectItem[tmp.size()]);
}
public void processEvent(ActionEvent event)