Author: julien(a)jboss.com
Date: 2007-07-16 12:27:26 -0400 (Mon, 16 Jul 2007)
New Revision: 7787
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ObjectNode.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
Log:
port to trunk the removal of hibernate natural id cache + the minor improvement of the
oracle fix
Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ObjectNode.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ObjectNode.java 2007-07-16
16:09:37 UTC (rev 7786)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ObjectNode.java 2007-07-16
16:27:26 UTC (rev 7787)
@@ -243,7 +243,7 @@
public String toString()
{
- return path.toString() + PortalObjectId.NAMESPACE_SEPARATOR + name;
+ return "PortalObject[id=" + path + "]";
}
protected PortalObjectId toChildPath(String name)
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 2007-07-16
16:09:37 UTC (rev 7786)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java 2007-07-16
16:27:26 UTC (rev 7787)
@@ -23,13 +23,9 @@
package org.jboss.portal.core.impl.model.portal;
import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
-import org.hibernate.ObjectNotFoundException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
-import org.hibernate.criterion.Restrictions;
import org.jboss.logging.Logger;
import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
import org.jboss.portal.core.model.portal.PortalObjectId;
@@ -48,9 +44,11 @@
{
/** The query for lookup when the path is null. */
- private static final String LOOKUP_QUERY_FOR_EMPTY_PATH = "from ObjectNode where
path=:path";
private static final String LOOKUP_QUERY_FOR_ROOT = "from ObjectNode where
path=:path or path is null";
+ /** The query for lookup when the path is null. */
+ private static final String LOOKUP_QUERY = "from ObjectNode where
path=:path";
+
/** . */
private static Logger log = Logger.getLogger(PersistentPortalObjectContainer.class);
@@ -247,35 +245,24 @@
private ObjectNode getObjectNodeNoCache(Session session, PortalObjectId id)
{
Object result;
- if (id.getPath().getLength() == 0)
- {
- // Oracle returns the root object when using LOOKUP_QUERY_FOR_NULL_PATH thus
preventing the creation of the
- // dashboard node as null is never returned for it and is therefore cached...
- String queryString = LOOKUP_QUERY_FOR_EMPTY_PATH;
- if (id.toString().lastIndexOf(PortalObjectPath.CanonicalFormat.PATH_SEPARATOR)
== 0)
- {
- queryString = LOOKUP_QUERY_FOR_ROOT;
- }
- Query query = session.createQuery(queryString);
- query.setParameter("path", id);
- query.setCacheable(true);
- try
- {
- result = query.uniqueResult();
- }
- catch (ObjectNotFoundException e)
- {
- throw new HibernateException("Could not find ObjectNode with path
'" + id + "'", e);
- }
- }
- else
+ //
+ String queryString = LOOKUP_QUERY;
+
+ // We need to lookup the root of the empty namespace with a special query in order
to fix
+ // oracle weird behavior with zero length strings considered as null value
+ if (id.getPath().getLength() == 0 && id.getNamespace().length() == 0)
{
- Criteria criteria = session.createCriteria(ObjectNode.class);
- criteria.add(Restrictions.naturalId().set("path", id));
- criteria.setCacheable(true);
- result = criteria.uniqueResult();
+ queryString = LOOKUP_QUERY_FOR_ROOT;
}
+
+ //
+ Query query = session.createQuery(queryString);
+ query.setParameter("path", id);
+
+ // Unique result will return null if no object is found
+ result = query.uniqueResult();
+
return (ObjectNode)result;
}
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 2007-07-16
16:09:37 UTC (rev 7786)
+++
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2007-07-16
16:27:26 UTC (rev 7787)
@@ -80,6 +80,14 @@
TransactionAssert.commitTransaction();
}
+ public void testRetrieveNonExistingObject()
+ {
+ TransactionAssert.beginTransaction();
+ PortalObject foo = container.getObject(PortalObjectId.parse("/foo",
PortalObjectPath.CANONICAL_FORMAT));
+ assertNull(foo);
+ TransactionAssert.commitTransaction();
+ }
+
public void testPropertyUpdateCascadeToDescendantsWhenTheyDoNotDeclareIt() throws
Exception
{
TransactionAssert.beginTransaction();
Show replies by date