[jboss-svn-commits] JBoss Portal SVN: r5656 - in branches/JBoss_Portal_Branch_2_4/core/src: main/org/jboss/portal/core/impl/model/instance main/org/jboss/portal/core/impl/model/portal resources/portal-core-sar/META-INF
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 14 20:06:15 EST 2006
Author: julien at jboss.com
Date: 2006-11-14 20:06:05 -0500 (Tue, 14 Nov 2006)
New Revision: 5656
Modified:
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java
branches/JBoss_Portal_Branch_2_4/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
Log:
backport 2.6 natural id optimizations to 2.4
Modified: branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
===================================================================
--- branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java 2006-11-15 00:50:54 UTC (rev 5655)
+++ branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java 2006-11-15 01:06:05 UTC (rev 5656)
@@ -57,6 +57,8 @@
import java.util.Iterator;
import java.util.Set;
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+
/**
* Instance Container that is persistent
*
@@ -93,6 +95,12 @@
/** If true clone the portlet on an instance creation. */
protected boolean cloneOnCreate;
+ /** . */
+ protected ConcurrentReaderHashMap cache;
+
+ /** . */
+ protected boolean cacheNaturalId;
+
public PersistentInstanceContainer()
{
ctx = new ContainerContext()
@@ -105,10 +113,31 @@
//
contextualizer = new ObjectContextualizer(ctx);
+ cache = new ConcurrentReaderHashMap();
}
- public boolean isCloneOnCreate()
+ public void flushNaturalIdCache()
{
+ cache.clear();
+ }
+
+ public int getNaturalIdCacheSize()
+ {
+ return cache.size();
+ }
+
+ public boolean getCacheNaturalId()
+ {
+ return cacheNaturalId;
+ }
+
+ public void setCacheNaturalId(boolean cacheNaturalId)
+ {
+ this.cacheNaturalId = cacheNaturalId;
+ }
+
+ public boolean getCloneOnCreate()
+ {
return cloneOnCreate;
}
@@ -324,6 +353,50 @@
private InstanceImpl lookup(Session session, String id)
{
+ // Get cached pk from natural id
+ Long pk = cacheNaturalId ? (Long)cache.get(id) : null;
+
+ //
+ InstanceImpl instance ;
+
+ //
+ if (pk == null)
+ {
+ // No pk
+ instance = lookupNoCache(session, id);
+ }
+ else
+ {
+ // Try lookup using the cached pk
+ instance = (InstanceImpl)session.get(InstanceImpl.class, pk);
+
+ // The pk may be invalid if the instance has been recreted under the same path with a different pk
+ if (instance == null)
+ {
+ // In that case we try a no cache
+ instance = lookupNoCache(session, id);
+ }
+ }
+
+ //
+ if (cacheNaturalId)
+ {
+ if (instance != null)
+ {
+ cache.put(id, instance.getKey());
+ }
+ else
+ {
+ cache.remove(id);
+ }
+ }
+
+ //
+ return instance;
+ }
+
+ private InstanceImpl lookupNoCache(Session session, String id)
+ {
Query query = session.createQuery("from InstanceImpl where instanceId=:instanceId");
query.setParameter("instanceId", id);
query.setCacheable(true);
Modified: branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java
===================================================================
--- branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java 2006-11-15 00:50:54 UTC (rev 5655)
+++ branches/JBoss_Portal_Branch_2_4/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java 2006-11-15 01:06:05 UTC (rev 5656)
@@ -52,6 +52,8 @@
import java.util.Iterator;
import java.util.Set;
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision$
@@ -87,6 +89,12 @@
/** . */
protected ObjectContextualizer contextualizer;
+ /** . */
+ protected ConcurrentReaderHashMap cache;
+
+ /** . */
+ protected boolean cacheNaturalId;
+
public PersistentPortalObjectContainer()
{
ctx = new ContainerContext()
@@ -126,8 +134,29 @@
//
contextualizer = new ObjectContextualizer(ctx);
+ cache = new ConcurrentReaderHashMap();
}
+ public void flushNaturalIdCache()
+ {
+ cache.clear();
+ }
+
+ public int getNaturalIdCacheSize()
+ {
+ return cache.size();
+ }
+
+ public boolean getCacheNaturalId()
+ {
+ return cacheNaturalId;
+ }
+
+ public void setCacheNaturalId(boolean cacheNaturalId)
+ {
+ this.cacheNaturalId = cacheNaturalId;
+ }
+
public JBossAuthorizationDomainRegistry getAuthorizationDomainRegistry()
{
return authorizationDomainRegistry;
@@ -410,7 +439,7 @@
session.flush();
}
- private ObjectNode lookup(Session session, String path)
+ private ObjectNode lookupNoCache(Session session, String path)
{
String s = LOOKUP_QUERY;
if (path.length() == 0)
@@ -426,6 +455,50 @@
return (ObjectNode)objectNode;
}
+ private ObjectNode lookup(Session session, String path)
+ {
+ // Get cached pk from natural id
+ Long pk = cacheNaturalId ? (Long)cache.get(path) : null;
+
+ //
+ ObjectNode objectNode;
+
+ //
+ if (pk == null)
+ {
+ // No pk
+ objectNode = lookupNoCache(session, path);
+ }
+ else
+ {
+ // Try lookup using the cached pk
+ objectNode = (ObjectNode)session.get(ObjectNode.class, pk);
+
+ // The pk may be invalid if the object has been recreted under the same path with a different pk
+ if (objectNode == null)
+ {
+ // In that case we try a no cache
+ objectNode = lookupNoCache(session, path);
+ }
+ }
+
+ //
+ if (cacheNaturalId)
+ {
+ if (objectNode != null)
+ {
+ cache.put(path, objectNode.getKey());
+ }
+ else
+ {
+ cache.remove(path);
+ }
+ }
+
+ //
+ return objectNode;
+ }
+
private Set getConstraints(String uri, Session session)
{
Set constraints = null;
Modified: branches/JBoss_Portal_Branch_2_4/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_4/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2006-11-15 00:50:54 UTC (rev 5655)
+++ branches/JBoss_Portal_Branch_2_4/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2006-11-15 01:06:05 UTC (rev 5656)
@@ -525,6 +525,7 @@
optional-attribute-name="AuthorizationDomainRegistry"
proxy-type="attribute">portal:service=AuthorizationDomainRegistry</depends>
<attribute name="SessionFactoryJNDIName">java:/portal/InstanceSessionFactory</attribute>
+ <attribute name="CacheNaturalId">true</attribute>
</mbean>
<mbean
code="org.jboss.portal.core.impl.model.portal.PersistentPortalObjectContainer"
@@ -543,6 +544,7 @@
optional-attribute-name="PortalEventListenerRegistry"
proxy-type="attribute">portal:service=ListenerRegistry</depends>
<attribute name="SessionFactoryJNDIName">java:/portal/PortalObjectSessionFactory</attribute>
+ <attribute name="CacheNaturalId">true</attribute>
</mbean>
<!-- Command factories -->
More information about the jboss-svn-commits
mailing list