[jboss-svn-commits] JBoss Portal SVN: r5654 - in trunk/core: . src/main/org/jboss/portal/core/impl/model/instance src/main/org/jboss/portal/core/impl/model/portal src/resources/portal-core-sar/META-INF

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Nov 14 19:36:13 EST 2006


Author: julien at jboss.com
Date: 2006-11-14 19:36:07 -0500 (Tue, 14 Nov 2006)
New Revision: 5654

Modified:
   trunk/core/build.xml
   trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java
   trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
Log:
make the natural id caches disablable and flushable

Modified: trunk/core/build.xml
===================================================================
--- trunk/core/build.xml	2006-11-15 00:23:20 UTC (rev 5653)
+++ trunk/core/build.xml	2006-11-15 00:36:07 UTC (rev 5654)
@@ -572,26 +572,31 @@
          <x-test>
             <zest todir="${test.reports}" name="org.jboss.portal.test.core.model.portal.PortalObjectContainerTestCase"
                   outfile="TEST-PortalObjectContainerTestCase">
+               <parameter name="CacheNaturalId" value="true"/>
             </zest>
             <zest todir="${test.reports}" name="org.jboss.portal.test.core.model.instance.InstanceContainerTestCase"
                   outfile="TEST-PersistedLocally-ClonedOnCreate-InstanceContainerTestCase">
                <parameter name="PersistLocally" value="true"/>
                <parameter name="CloneOnCreate" value="true"/>
+               <parameter name="CacheNaturalId" value="true"/>
             </zest>
             <zest todir="${test.reports}" name="org.jboss.portal.test.core.model.instance.InstanceContainerTestCase"
                   outfile="TEST-NotPersistedLocally-ClonedOnCreate-InstanceContainerTestCase">
                <parameter name="PersistLocally" value="false"/>
                <parameter name="CloneOnCreate" value="true"/>
+               <parameter name="CacheNaturalId" value="true"/>
             </zest>
             <zest todir="${test.reports}" name="org.jboss.portal.test.core.model.instance.InstanceContainerTestCase"
                   outfile="TEST-PersistedLocally-NotClonedOnCreate-InstanceContainerTestCase">
                <parameter name="PersistLocally" value="true"/>
                <parameter name="CloneOnCreate" value="false"/>
+               <parameter name="CacheNaturalId" value="true"/>
             </zest>
             <zest todir="${test.reports}" name="org.jboss.portal.test.core.model.instance.InstanceContainerTestCase"
                   outfile="TEST-NotPersistedLocally-NotClonedOnCreate-InstanceContainerTestCase">
                <parameter name="PersistLocally" value="false"/>
                <parameter name="CloneOnCreate" value="false"/>
+               <parameter name="CacheNaturalId" value="true"/>
             </zest>
             <test todir="${test.reports}"
                   name="org.jboss.portal.test.core.deployment.JBossApplicationMetaDataFactoryTestCase"/>

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java	2006-11-15 00:23:20 UTC (rev 5653)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java	2006-11-15 00:36:07 UTC (rev 5654)
@@ -22,7 +22,6 @@
  ******************************************************************************/
 package org.jboss.portal.core.impl.model.instance;
 
-import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.Criteria;
@@ -131,6 +130,9 @@
    /** . */
    protected ConcurrentReaderHashMap cache;
 
+   /** . */
+   protected boolean cacheNaturalId;
+
    public PersistentInstanceContainer()
    {
       ctx = new ContainerContext(this);
@@ -139,9 +141,29 @@
       contextualizer = new ObjectContextualizer(ctx);
       cache = new ConcurrentReaderHashMap();
    }
+   
+   public void flushNaturalIdCache()
+   {
+      cache.clear();
+   }
 
-   public boolean isCloneOnCreate()
+   public int getNaturalIdCacheSize()
    {
+      return cache.size();
+   }
+
+   public boolean getCacheNaturalId()
+   {
+      return cacheNaturalId;
+   }
+
+   public void setCacheNaturalId(boolean cacheNaturalId)
+   {
+      this.cacheNaturalId = cacheNaturalId;
+   }
+
+   public boolean getCloneOnCreate()
+   {
       return cloneOnCreate;
    }
 
@@ -467,18 +489,21 @@
    private InstanceDefinitionImpl lookup(Session session, String id)
    {
       // Get cached pk from natural id
-      Long pk = (Long)cache.get(id);
+      Long pk = cacheNaturalId ? (Long)cache.get(id) : null;
 
       //
+      InstanceDefinitionImpl instance ;
+
+      //
       if (pk == null)
       {
          // No pk
-         return lookupNocache(session, id);
+         instance = lookupNocache(session, id);
       }
       else
       {
          // Try lookup using the cached pk
-         InstanceDefinitionImpl instance = (InstanceDefinitionImpl)session.get(InstanceDefinitionImpl.class, pk);
+         instance = (InstanceDefinitionImpl)session.get(InstanceDefinitionImpl.class, pk);
 
          // The pk may be invalid if the instance has been recreted under the same path with a different pk
          if (instance == null)
@@ -486,10 +511,23 @@
             // In that case we try a no cache
             instance = lookupNocache(session, id);
          }
+      }
 
-         //
-         return instance;
+      //
+      if (cacheNaturalId)
+      {
+         if (instance != null)
+         {
+            cache.put(id, instance.getKey());
+         }
+         else
+         {
+            cache.remove(id);
+         }
       }
+
+      //
+      return instance;
    }
 
    private InstanceDefinitionImpl lookupNocache(Session session, String id)
@@ -497,16 +535,7 @@
       Criteria criteria = session.createCriteria(InstanceDefinitionImpl.class);
       criteria.add(Restrictions.naturalId().set("instanceId", id));
       criteria.setCacheable(true);
-      InstanceDefinitionImpl instanceDefinition = (InstanceDefinitionImpl)criteria.uniqueResult();
-      if (instanceDefinition != null)
-      {
-         cache.put(id, instanceDefinition.getKey());
-      }
-      else
-      {
-         cache.remove(id);
-      }
-      return instanceDefinition;
+      return (InstanceDefinitionImpl)criteria.uniqueResult();
    }
 
    //**********************************************************************

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java	2006-11-15 00:23:20 UTC (rev 5653)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java	2006-11-15 00:36:07 UTC (rev 5654)
@@ -75,6 +75,9 @@
    /** . */
    protected ConcurrentReaderHashMap cache;
 
+   /** . */
+   protected boolean cacheNaturalId;
+
    public PersistentPortalObjectContainer()
    {
       ctx = new ContainerContext()
@@ -113,6 +116,26 @@
       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;
@@ -240,42 +263,35 @@
          Query query = session.createQuery(LOOKUP_QUERY_FOR_NULL_PATH);
          query.setParameter("path", path);
          query.setCacheable(true);
-         ObjectNode objectNode = (ObjectNode)query.uniqueResult();
-         if (objectNode != null)
-         {
-            cache.put(path, objectNode.getKey());
-         }
-         return objectNode;
+         return (ObjectNode)query.uniqueResult();
       }
       else
       {
          Criteria criteria = session.createCriteria(ObjectNode.class);
          criteria.add(Restrictions.naturalId().set("path", path));
          criteria.setCacheable(true);
-         ObjectNode objectNode = (ObjectNode)criteria.uniqueResult();
-         if (objectNode != null)
-         {
-            cache.put(path, objectNode.getKey());
-         }
-         return objectNode;
+         return (ObjectNode)criteria.uniqueResult();
       }
    }
 
    private ObjectNode getObjectNode(Session session, String path)
    {
       // Get cached pk from natural id
-      Long pk = (Long)cache.get(path);
+      Long pk = cacheNaturalId ? (Long)cache.get(path) : null;
 
       //
+      ObjectNode objectNode;
+
+      //
       if (pk == null)
       {
          // No pk
-         return getObjectNodeNoCache(session, path);
+         objectNode = getObjectNodeNoCache(session, path);
       }
       else
       {
          // Try lookup using the cached pk
-         ObjectNode objectNode = (ObjectNode)session.get(ObjectNode.class, 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)
@@ -283,13 +299,22 @@
             // In that case we try a no cache
             objectNode = getObjectNodeNoCache(session, path);
          }
+      }
+
+      //
+      if (cacheNaturalId)
+      {
+         if (objectNode != null)
+         {
+            cache.put(path, objectNode.getKey());
+         }
          else
          {
             cache.remove(path);
          }
+      }
 
-         //
-         return objectNode;
-      }
+      //
+      return objectNode;
    }
 }

Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml	2006-11-15 00:23:20 UTC (rev 5653)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml	2006-11-15 00:36:07 UTC (rev 5654)
@@ -580,6 +580,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"
@@ -595,6 +596,7 @@
          optional-attribute-name="AuthorizationDomainRegistry"
          proxy-type="attribute">portal:service=AuthorizationDomainRegistry</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