[jboss-svn-commits] JBoss Portal SVN: r5652 - in trunk/core: . src/main/org/jboss/portal/core/impl/model/instance src/main/org/jboss/portal/core/impl/model/portal src/main/org/jboss/portal/test/core/model/instance src/main/org/jboss/portal/test/core/model/portal
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 14 19:00:43 EST 2006
Author: julien at jboss.com
Date: 2006-11-14 19:00:33 -0500 (Tue, 14 Nov 2006)
New Revision: 5652
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/main/org/jboss/portal/test/core/model/instance/InstanceContainerTestCase.java
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
Log:
handle and test when an entity (portal object or instance) has its pk that changes for its natural id (on recreation using the same id) that we retrieve the good object
Modified: trunk/core/build.xml
===================================================================
--- trunk/core/build.xml 2006-11-14 20:19:33 UTC (rev 5651)
+++ trunk/core/build.xml 2006-11-15 00:00:33 UTC (rev 5652)
@@ -570,6 +570,9 @@
</x-sysproperty>
<x-test>
+ <zest todir="${test.reports}" name="org.jboss.portal.test.core.model.portal.PortalObjectContainerTestCase"
+ outfile="TEST-PortalObjectContainerTestCase">
+ </zest>
<zest todir="${test.reports}" name="org.jboss.portal.test.core.model.instance.InstanceContainerTestCase"
outfile="TEST-PersistedLocally-ClonedOnCreate-InstanceContainerTestCase">
<parameter name="PersistLocally" value="true"/>
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-14 20:19:33 UTC (rev 5651)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java 2006-11-15 00:00:33 UTC (rev 5652)
@@ -409,8 +409,6 @@
}
}
-
-
public Collection getInstances()
{
Session session = ctx.getCurrentSession();
@@ -468,23 +466,47 @@
private InstanceDefinitionImpl lookup(Session session, String id)
{
+ // Get cached pk from natural id
Long pk = (Long)cache.get(id);
+
+ //
if (pk == null)
{
- Criteria criteria = session.createCriteria(InstanceDefinitionImpl.class);
- criteria.add(Restrictions.naturalId().set("instanceId", id));
- criteria.setCacheable(true);
- InstanceDefinitionImpl instanceDefinition = (InstanceDefinitionImpl)criteria.uniqueResult();
- if (instanceDefinition != null)
+ // No pk
+ return lookupNocache(session, id);
+ }
+ else
+ {
+ // Try lookup using the cached pk
+ InstanceDefinitionImpl 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)
{
- cache.put(id, instanceDefinition.getKey());
+ // In that case we try a no cache
+ instance = lookupNocache(session, id);
}
- return instanceDefinition;
+
+ //
+ return instance;
}
+ }
+
+ private InstanceDefinitionImpl lookupNocache(Session session, String id)
+ {
+ 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
{
- return (InstanceDefinitionImpl)session.get(InstanceDefinitionImpl.class, pk);
+ cache.remove(id);
}
+ return instanceDefinition;
}
//**********************************************************************
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-14 20:19:33 UTC (rev 5651)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java 2006-11-15 00:00:33 UTC (rev 5652)
@@ -188,7 +188,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error("", e);
}
}
@@ -231,41 +231,65 @@
return getObjectNode(sessionFactory.getCurrentSession(), uri);
}
+ private ObjectNode getObjectNodeNoCache(Session session, String path)
+ {
+ if (path.length() == 0)
+ {
+ // For oracle where an empty path is treated as null so we need to add that here
+ // See also org.jboss.portal.core.hibernate.OracleString
+ 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;
+ }
+ 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;
+ }
+ }
+
private ObjectNode getObjectNode(Session session, String path)
{
+ // Get cached pk from natural id
Long pk = (Long)cache.get(path);
+
+ //
if (pk == null)
{
- if (path.length() == 0)
+ // No pk
+ return getObjectNodeNoCache(session, path);
+ }
+ else
+ {
+ // Try lookup using the cached pk
+ ObjectNode 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)
{
- // For oracle where an empty path is treated as null so we need to add that here
- // See also org.jboss.portal.core.hibernate.OracleString
- 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;
+ // In that case we try a no cache
+ objectNode = getObjectNodeNoCache(session, path);
}
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;
+ cache.remove(path);
}
+
+ //
+ return objectNode;
}
- else
- {
- return (ObjectNode)session.get(ObjectNode.class, pk);
- }
}
}
Modified: trunk/core/src/main/org/jboss/portal/test/core/model/instance/InstanceContainerTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/model/instance/InstanceContainerTestCase.java 2006-11-14 20:19:33 UTC (rev 5651)
+++ trunk/core/src/main/org/jboss/portal/test/core/model/instance/InstanceContainerTestCase.java 2006-11-15 00:00:33 UTC (rev 5652)
@@ -758,6 +758,34 @@
TransactionAssert.commitTransaction();
}
}
+
+ public void testRecreate() throws Exception
+ {
+ portletContainer.addPortlet("MyPortlet", new TestPortletSupport());
+
+ TransactionAssert.beginTransaction();
+ instanceContainer.createInstance("MyInstance", "MyPortlet");
+ TransactionAssert.commitTransaction();
+
+ //
+ TransactionAssert.beginTransaction();
+ Instance instance = instanceContainer.getInstance("MyInstance");
+ assertNotNull(instance);
+ TransactionAssert.commitTransaction();
+
+ //
+ TransactionAssert.beginTransaction();
+ instanceContainer.destroyInstance("MyInstance");
+ instanceContainer.createInstance("MyInstance", "MyPortlet");
+ TransactionAssert.commitTransaction();
+
+ //
+ TransactionAssert.beginTransaction();
+ instance = instanceContainer.getInstance("MyInstance");
+ assertNotNull(instance);
+ TransactionAssert.commitTransaction();
+ }
+
//
//// /**Tests the authorization of portal objects */
//// public void testInstanceAuthorization() throws Exception
Modified: trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2006-11-14 20:19:33 UTC (rev 5651)
+++ trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2006-11-15 00:00:33 UTC (rev 5652)
@@ -22,7 +22,6 @@
******************************************************************************/
package org.jboss.portal.test.core.model.portal;
-
import junit.framework.TestSuite;
import org.jboss.portal.core.impl.model.portal.PersistentPortalObjectContainer;
import org.jboss.portal.core.model.portal.Context;
@@ -125,26 +124,18 @@
}
/** todo same with a transaction wrapping the start method */
- public void testRootNodeCreatedDuringStartup() throws Exception
+ public void testRootNodeCreation() throws Exception
{
-// container.setCreateRootOnStartup(false);
container.start();
+ //
hibernate.openSession();
- PortalObject root = container.getObject("");
- assertNull(root);
+ container.createContext();
assertTrue(hibernate.commitTransaction());
//
- container.stop();
-
- //
-// container.setCreateRootOnStartup(true);
- container.start();
-
- //
hibernate.openSession();
- root = container.getObject("");
+ PortalObject root = container.getObject("");
assertNotNull(root);
assertTrue(hibernate.commitTransaction());
@@ -154,11 +145,15 @@
public void testCRUD() throws Exception
{
-// container.setCreateRootOnStartup(true);
container.start();
//
hibernate.openSession();
+ container.createContext();
+ assertTrue(hibernate.commitTransaction());
+
+ //
+ hibernate.openSession();
Context ctx = container.getContext();
Portal portal = ctx.createPortal("default");
String portalId = portal.getId();
@@ -185,7 +180,7 @@
assertNull(page.getDeclaredProperty("foo1"));
assertEquals("bar1", page.getProperty("foo1"));
assertEquals("bar2_", page.getDeclaredProperty("foo2"));
- assertEquals("bar2_", page.getProperty("foo2"));
+ assertEquals("bar2", page.getProperty("foo2"));
assertEquals("bar3", page.getDeclaredProperty("foo3"));
assertEquals("bar3", page.getProperty("foo3"));
@@ -249,6 +244,39 @@
container.stop();
}
+ public void testRecreate() throws Exception
+ {
+ container.start();
+
+ //
+ hibernate.openSession();
+ container.createContext();
+ assertTrue(hibernate.commitTransaction());
+
+ //
+ hibernate.openSession();
+ Context ctx = container.getContext();
+ Portal portal = ctx.createPortal("default");
+ assertNotNull(portal);
+
+ //
+ PortalObject object = container.getObject("default");
+ assertNotNull(object);
+
+ //
+ ctx.destroyChild("default");
+ ctx.createPortal("default");
+
+ //
+ object = container.getObject("default");
+ assertNotNull(object);
+
+ assertTrue(hibernate.commitTransaction());
+
+ //
+ container.stop();
+ }
+
// private void constructPortalObjects() throws Exception
// {
// Context root = container.getContext();
More information about the jboss-svn-commits
mailing list