[gatein-commits] gatein SVN: r1990 - in portal/trunk/component/portal/src/main/java/org/exoplatform/portal: pom/config/cache and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Mar 4 17:56:11 EST 2010
Author: julien_viet
Date: 2010-03-04 17:56:10 -0500 (Thu, 04 Mar 2010)
New Revision: 1990
Added:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/NullObject.java
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/OwnerKey.java
Log:
improving getAllPortalNames() performances
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java 2010-03-04 22:21:40 UTC (rev 1989)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java 2010-03-04 22:56:10 UTC (rev 1990)
@@ -136,4 +136,12 @@
public Dashboard loadDashboard(String dashboardId) throws Exception;
public void saveDashboard(Dashboard dashboard) throws Exception;
+
+ /**
+ * Returns the list of all portal names.
+ *
+ * @return the portal names
+ * @throws Exception any exception
+ */
+ public List<String> getAllPortalNames() throws Exception;
}
\ No newline at end of file
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java 2010-03-04 22:21:40 UTC (rev 1989)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java 2010-03-04 22:56:10 UTC (rev 1990)
@@ -42,11 +42,7 @@
import org.exoplatform.services.listener.ListenerService;
import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
/**
* @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
@@ -230,8 +226,6 @@
tmpList.add(list.get(i));
}
Collections.sort(tmpList, new Comparator<D>() {
-
- @Override
public int compare(D d1, D d2)
{
if (comparator == null) {
@@ -247,6 +241,18 @@
}
}
+ public List<String> getAllPortalNames() throws Exception {
+
+ Query<PortalKey> q = new Query<PortalKey>("portal", null,PortalKey.class);
+ List<PortalKey> keys = delegate.find(q).getAll();
+ LinkedList<String> list = new LinkedList<String>();
+ for (PortalKey key : keys)
+ {
+ list.add(key.getId());
+ }
+ return list;
+ }
+
public <T> ListAccess<T> find2(Query<T> q) throws Exception
{
return find2(q, null);
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java 2010-03-04 22:21:40 UTC (rev 1989)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java 2010-03-04 22:56:10 UTC (rev 1990)
@@ -253,14 +253,14 @@
}
/**
- * This method is equivalent to <code>hasEditPermission(PortalConfig)</code>. That allows us
+ * This method is equivalent to <code>hasEditPermission(PortalConfig)</code>. That allows us
* to check edit permission on a UIPortal, without converting UIPortal into PortalConfig via
* PortalDataMapper.
*
- * @param ownerType
- * @param ownerId
- * @param editPermExpression
- * @return
+ * @param ownerType the owner type
+ * @param ownerId the owner id
+ * @param editPermExpression the permission expression
+ * @return true or false
*/
public boolean hasEditPermissionOnPortal(String ownerType, String ownerId, String editPermExpression)
{
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2010-03-04 22:21:40 UTC (rev 1989)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2010-03-04 22:56:10 UTC (rev 1990)
@@ -20,7 +20,6 @@
package org.exoplatform.portal.config;
import org.exoplatform.commons.utils.LazyPageList;
-import org.exoplatform.commons.utils.PageList;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.component.RequestLifeCycle;
@@ -39,13 +38,7 @@
import org.exoplatform.services.organization.OrganizationService;
import org.picocontainer.Startable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
/**
* Created by The eXo Platform SAS Apr 19, 2007 This service is used to load the PortalConfig, Page config and
@@ -586,15 +579,14 @@
*/
public List<String> getAllPortalNames() throws Exception
{
- List<String> list = new ArrayList<String>();
- Query<PortalConfig> query = new Query<PortalConfig>(PortalConfig.PORTAL_TYPE, null, null, null, PortalConfig.class);
- PageList<PortalConfig> pageList = storage_.find(query);
- List<PortalConfig> configs = pageList.getAll();
- for (PortalConfig ele : configs)
+ List<String> list = storage_.getAllPortalNames();
+ for (Iterator<String> i = list.iterator();i.hasNext();)
{
- if (userACL_.hasPermission(ele))
+ String name = i.next();
+ PortalConfig config = storage_.getPortalConfig(name);
+ if (config == null || !userACL_.hasPermission(config))
{
- list.add(ele.getName());
+ i.remove();
}
}
return list;
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java 2010-03-04 22:21:40 UTC (rev 1989)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java 2010-03-04 22:56:10 UTC (rev 1990)
@@ -99,11 +99,18 @@
V v = null;
if (o != null)
{
- Class<V> type = task.getValueType();
- if (type.isInstance(o))
+ if (o == NullObject.get())
{
- v = type.cast(o);
+ return null;
}
+ else
+ {
+ Class<V> type = task.getValueType();
+ if (type.isInstance(o))
+ {
+ v = type.cast(o);
+ }
+ }
}
//
@@ -119,8 +126,12 @@
v = super.execute(session, task);
//
- if (v != null)
+ if (v == null)
{
+ session.putInCache(key, NullObject.get());
+ }
+ else
+ {
session.putInCache(key, v);
}
Added: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/NullObject.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/NullObject.java (rev 0)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/NullObject.java 2010-03-04 22:56:10 UTC (rev 1990)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.pom.config.cache;
+
+import java.io.*;
+
+/**
+ * A serializable object that is a private marker representing a null value.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class NullObject implements Serializable
+{
+
+ /** VM singleton. */
+ private static final NullObject instance = new NullObject();
+
+ public static NullObject get()
+ {
+ return instance;
+ }
+
+ private Object readResolve() throws ObjectStreamException
+ {
+ return instance;
+ }
+
+ private void writeObject(ObjectOutputStream out) throws IOException
+ {
+ // Nothing to do
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException
+ {
+ // Nothing to do
+ }
+}
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/OwnerKey.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/OwnerKey.java 2010-03-04 22:21:40 UTC (rev 1989)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/OwnerKey.java 2010-03-04 22:56:10 UTC (rev 1990)
@@ -70,11 +70,15 @@
{
return true;
}
- if (getClass().isInstance(obj))
+
+ // We need to use class equality here
+ if (obj != null && getClass().equals(obj.getClass()))
{
OwnerKey that = (OwnerKey)obj;
return type.equals(that.type) && id.equals(that.id);
}
+
+ //
return false;
}
}
More information about the gatein-commits
mailing list