Author: sohil.shah(a)jboss.com
Date: 2008-10-25 14:30:46 -0400 (Sat, 25 Oct 2008)
New Revision: 12169
Removed:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/Tools.java
Modified:
modules/cms/trunk/cms-jackrabbit/pom.xml
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/PortalCMSCacheLoader.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/interceptors/ACLInterceptor.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/security/AuthorizationProviderImpl.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/util/HibernateUtil.java
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security-test.xml
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security.xml
modules/cms/trunk/cms-jackrabbit/src/test/resources/pm-cache.xml
Log:
trying to fix the postresql issue with the test suite
Modified: modules/cms/trunk/cms-jackrabbit/pom.xml
===================================================================
--- modules/cms/trunk/cms-jackrabbit/pom.xml 2008-10-24 22:35:12 UTC (rev 12168)
+++ modules/cms/trunk/cms-jackrabbit/pom.xml 2008-10-25 18:30:46 UTC (rev 12169)
@@ -220,13 +220,13 @@
<artifactId>postgresql</artifactId>
<version>8.1-407.jdbc3</version>
<scope>test</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.0.2.0</version>
<scope>test</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
@@ -299,6 +299,9 @@
<tasks>
<delete dir="repotest" />
<delete dir="repotest-hsqldb" />
+ <delete dir="repotest-postgresql8" />
+ <delete dir="repotest-mysql5" />
+ <delete dir="repotest-oracle10g" />
<delete file="test.properties" />
<delete file="test.script" />
</tasks>
@@ -314,6 +317,9 @@
<tasks>
<delete dir="repotest" />
<delete dir="repotest-hsqldb" />
+ <delete dir="repotest-postgresql8" />
+ <delete dir="repotest-mysql5" />
+ <delete dir="repotest-oracle10g" />
<delete file="test.properties" />
<delete file="test.script" />
</tasks>
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2008-10-25
18:30:46 UTC (rev 12169)
@@ -56,6 +56,7 @@
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.portal.cms.hibernate.HibernateStoreConstants;
import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.cms.util.HibernateUtil;
import javax.jcr.PropertyType;
import javax.management.MBeanServer;
@@ -208,8 +209,7 @@
initialized = true;
try
- {
- Tools.init(this.jndiName);
+ {
if (pmCache == null)
{
@@ -269,7 +269,7 @@
// pre-load the cache with property nodes
if (!JBossCachePersistenceManager.preloaded)
{
- JBossCachePersistenceManager.loadProperties();
+ JBossCachePersistenceManager.loadProperties(this.jndiName);
log.info("-------------------------------------------------");
log.info("JBossCachePersistenceManager is fully loaded.....");
log.info("-------------------------------------------------");
@@ -285,7 +285,7 @@
*
*
*/
- private static synchronized void loadProperties() throws Exception
+ private static synchronized void loadProperties(String hibernateJndiName) throws
Exception
{
if (JBossCachePersistenceManager.preloaded)
{
@@ -296,22 +296,22 @@
.info("Pre-loading the PersistenceManager Cache in the background
(started).......");
CacheLoader wspProp = new CacheLoader(CacheLoader.wspProp,
- PortalCMSCacheLoader.WSP_PROP_NODE);
+ PortalCMSCacheLoader.WSP_PROP_NODE, hibernateJndiName);
Thread wspPropLoader = new Thread(wspProp);
CacheLoader versionProp = new CacheLoader(CacheLoader.versionProp,
- PortalCMSCacheLoader.VERSION_PROP_NODE);
+ PortalCMSCacheLoader.VERSION_PROP_NODE, hibernateJndiName);
Thread versionPropLoader = new Thread(versionProp);
CacheLoader wspNode = new CacheLoader(CacheLoader.wspNode,
- PortalCMSCacheLoader.WSP_NODE_NODE);
+ PortalCMSCacheLoader.WSP_NODE_NODE, hibernateJndiName);
Thread wspNodeLoader = new Thread(wspNode);
CacheLoader versionNode = new CacheLoader(CacheLoader.versionNode,
- PortalCMSCacheLoader.VERSION_NODE_NODE);
+ PortalCMSCacheLoader.VERSION_NODE_NODE, hibernateJndiName);
Thread versionNodeLoader = new Thread(versionNode);
CacheLoader wspRef = new CacheLoader(CacheLoader.wspRef,
- PortalCMSCacheLoader.WSP_REF_NODE);
+ PortalCMSCacheLoader.WSP_REF_NODE, hibernateJndiName);
Thread wspRefLoader = new Thread(wspRef);
CacheLoader versionRef = new CacheLoader(CacheLoader.versionRef,
- PortalCMSCacheLoader.VERSION_REF_NODE);
+ PortalCMSCacheLoader.VERSION_REF_NODE, hibernateJndiName);
Thread versionRefLoader = new Thread(versionRef);
wspPropLoader.start();
@@ -359,11 +359,14 @@
private String nodePrefix = null;
private boolean done = false;
+
+ private String hibernateJndiName = null;
- private CacheLoader(String nodeQuery, String nodePrefix)
+ private CacheLoader(String nodeQuery, String nodePrefix, String hibernateJndiName)
{
this.nodeQuery = nodeQuery;
this.nodePrefix = nodePrefix;
+ this.hibernateJndiName = hibernateJndiName;
}
public void run()
@@ -371,7 +374,7 @@
Session session = null;
try
{
- session = Tools.getOpenSession();
+ session =
HibernateUtil.getSessionFactory(this.hibernateJndiName).openSession();
List rs = session.createQuery(this.nodeQuery).list();
if (rs != null)
{
@@ -441,7 +444,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
this.done = true;
}
}
@@ -522,7 +525,7 @@
boolean success = false;
try
{
- session = Tools.getOpenSession();
+ session = HibernateUtil.getSessionFactory(this.jndiName).openSession();
tx = session.beginTransaction();
InputStream in = new ByteArrayInputStream(nodeData);
@@ -552,7 +555,7 @@
{
tx.rollback();
}
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
@@ -798,7 +801,7 @@
boolean success = false;
try
{
- session = Tools.getOpenSession();
+ session = HibernateUtil.getSessionFactory(this.jndiName).openSession();
tx = session.beginTransaction();
InputStream in = new ByteArrayInputStream(propertyData);
@@ -828,7 +831,7 @@
{
tx.rollback();
}
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
@@ -1112,7 +1115,7 @@
boolean success = false;
try
{
- session = Tools.getOpenSession();
+ session = HibernateUtil.getSessionFactory(this.jndiName).openSession();
tx = session.beginTransaction();
InputStream in = new ByteArrayInputStream(nodeData);
@@ -1142,7 +1145,7 @@
{
tx.rollback();
}
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
@@ -1255,9 +1258,6 @@
*/
public void close() throws Exception
{
- // cleanup session factory.
- Tools.destroy();
-
// cleanup the jboss cache service
if (pmCache != null)
{
@@ -1309,7 +1309,7 @@
Transaction tx = null;
try
{
- session = Tools.getOpenSession();
+ session = HibernateUtil.getSessionFactory(this.jndiName).openSession();
tx = session.beginTransaction();
storeHB(changeLog);
tx.commit();
@@ -1321,7 +1321,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
@@ -1409,7 +1409,7 @@
throw new IllegalStateException("not initialized");
}
- Session session = Tools.getOpenSession();
+ Session session = HibernateUtil.getSessionFactory(this.jndiName).openSession();
try
{
List rs = session.createQuery(query).setString(0, id).list();
@@ -1424,7 +1424,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
@@ -1464,14 +1464,35 @@
*/
public InputStream get(String blobId) throws Exception
{
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(jndiName).getCurrentSession();
try
{
List rs = session.createQuery(blobSelectData).setString(0, blobId)
.list();
Iterator iter = rs.iterator();
java.sql.Blob blob = (java.sql.Blob)iter.next();
- InputStream is = blob.getBinaryStream();
+
+ /**
+ * This needs to be done this way due to issues with a combination of
Postgresql driver handling blobs and Jackrabbit 1.4
+ *
+ * Its fine for: hsqldb, mysql5, and oracle10g
+ */
+ InputStream is = null;
+
+ InputStream blobStream = blob.getBinaryStream();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024]; //using a 1K buffer
+ int bytesRead = -1;
+ while((bytesRead=blobStream.read(buffer)) != -1)
+ {
+ bos.write(buffer, 0, bytesRead);
+ bos.flush();
+ }
+
+ try{blobStream.close();}catch(Exception e){}
+
+ is = new ByteArrayInputStream(bos.toByteArray());
+
return is;
}
catch (Exception e)
@@ -1494,7 +1515,7 @@
{
boolean update = exists(blobId);
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(jndiName).getCurrentSession();
if (update)
{
try
@@ -1578,7 +1599,7 @@
// public synchronized boolean remove(String blobId) throws Exception
public boolean remove(String blobId) throws Exception
{
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(jndiName).getCurrentSession();
try
{
Query query = session.createQuery(nodeBinValSelect).setString(0,
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/PortalCMSCacheLoader.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/PortalCMSCacheLoader.java 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/PortalCMSCacheLoader.java 2008-10-25
18:30:46 UTC (rev 12169)
@@ -30,6 +30,8 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.logging.Logger;
+import org.jboss.portal.cms.util.HibernateUtil;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -98,6 +100,7 @@
*
*/
private TreeCache cache = null;
+ private String cmsSessionFactory = null;
/**
@@ -105,6 +108,7 @@
*/
public void setConfig(Properties properties)
{
+ this.cmsSessionFactory = (String)properties.get("cmsSessionFactory");
}
/**
@@ -696,7 +700,7 @@
Session session = null;
try
{
- session = Tools.getOpenSession();
+ session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
List rs = session.createQuery(query).list();
for (Iterator itr = rs.iterator(); itr.hasNext();)
@@ -711,7 +715,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
return children;
}
@@ -726,7 +730,7 @@
Session session = null;
try
{
- session = Tools.getOpenSession();
+ session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
//node = session.createQuery(query).setString(0,id).uniqueResult();
List rs = session.createQuery(query).setString(0, id).list();
@@ -737,7 +741,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
return node;
}
@@ -750,7 +754,7 @@
{
Object node = null;
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).getCurrentSession();
//node = session.createQuery(query).setString(0,id).uniqueResult();
List rs = session.createQuery(query).setString(0, id).list();
if (rs != null && !rs.isEmpty())
@@ -766,7 +770,7 @@
*/
private void save(Object object) throws Exception
{
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).getCurrentSession();
if (((Base)object).getKey() != null)
{
session.merge(object);
@@ -787,7 +791,7 @@
removedValue = this.loadManagedNode(loadQuery, id);
if (removedValue != null)
{
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).getCurrentSession();
session.delete(removedValue);
}
return removedValue;
Deleted:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/Tools.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/Tools.java 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/Tools.java 2008-10-25
18:30:46 UTC (rev 12169)
@@ -1,193 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * 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.jboss.portal.cms.hibernate.state;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
-import org.jboss.logging.Logger;
-
-import javax.naming.InitialContext;
-
-/**
- * Static state is evil.
- * <p/>
- * Created on Aug 29, 2006
- * <p/>
- * A Tool for performing some Hibernate related utilities. This is designed to work in
both managed as well as
- * non-managed environments
- *
- * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
- */
-public class Tools
-{
- private static final Logger log = Logger.getLogger(Tools.class);
-
- //hibernate configuration relation information
- private static SessionFactory sessionFactory = null;
- private static Configuration cfg = null;
- private static boolean autoClose = false;
-
- public static void destroy()
- {
- sessionFactory = null;
- }
-
- /**
- *
- *
- */
- public static void init(String jndiName)
- {
- if (Tools.sessionFactory == null)
- {
- try
- {
- log.debug("Loading the PersistenceManager Hibernate System
(Started)...........................");
-
- boolean loadSuccess = true;
- try
- {
- //just to initialize the session factory
- Tools.sessionFactory = (SessionFactory)new
InitialContext().lookup(jndiName);
- }
- catch (Exception e)
- {
- //some reason this is not found in JNDI environment....try and load from
hibernate.cfg.xml from
- //classpath
- loadSuccess = false;
- }
-
- if (!loadSuccess)
- {
- //configure session factory from configuration
- Tools.cfg = new Configuration();
- Tools.cfg.configure();
- Tools.sessionFactory = Tools.cfg.buildSessionFactory();
- Tools.generateSiteSchema(Tools.cfg);
- }
-
-
- log.debug("Loading the PersistenceManager Hibernate System
(Done)...........................");
- }
- catch (Exception e)
- {
- log.error("org.jboss.portal.cms.hibernate.state.Tools", e);
- }
- }
- }
-
-
//---------------------------------------------------------------------------------------------------------------------------------------------------
- /**
- *
- */
- public static SessionFactory getSessionFactory()
- {
- return Tools.sessionFactory;
- }
-
- /** @return */
- public static Session getCurrentSession()
- {
- Session session = Tools.sessionFactory.getCurrentSession();
- return session;
- }
-
- /** @return */
- public static Session getOpenSession()
- {
- Session session = Tools.sessionFactory.openSession();
- return session;
- }
-
- /** @param session */
- public static void closeSession(Session session)
- {
- if (session != null && session.isOpen() && !Tools.autoClose)
- {
- session.close();
- }
- }
-
- //-----------------------schema generation
capabilities-------------------------------------------------------------------------------------------
- /** @param cfg */
- private static void generateSiteSchema(Configuration cfg)
- {
- if (!doesSiteSchemaExist())
- {
- SchemaExport export = new SchemaExport(cfg);
- export.create(true, //print to the console
- true //run inside the database
- );
- }
- else
- {
- log.info("Site Schema successfully found....No need to recreate
it.");
- }
- }
-
- /** @return */
- private static boolean doesSiteSchemaExist()
- {
- Session session = null;
- Transaction tx = null;
- try
- {
- session = Tools.sessionFactory.openSession();
- tx = session.beginTransaction();
- ClassMetadata cmd =
(ClassMetadata)Tools.sessionFactory.getAllClassMetadata().values().iterator().next();
- if (cmd != null)
- {
- Query query = session.createQuery("from " + cmd.getEntityName());
- query.setFirstResult(0);
- query.setMaxResults(0);
- try
- {
- query.list();
- }
- catch (HibernateException e)
- {
- // We consider that exception means that the schema deos not exist
- return false;
- }
- }
- //if I get here the schemaExists, dont recreate it
- return true;
- }
- finally
- {
- if (tx != null)
- {
- tx.rollback(); //does not matter since this is only a read operation
- //this is only so that this operation executes within the context
- //of a transaction that performs any necessary cleanup automatically
- }
- Tools.closeSession(session);
- }
- }
-}
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/interceptors/ACLInterceptor.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/interceptors/ACLInterceptor.java 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/interceptors/ACLInterceptor.java 2008-10-25
18:30:46 UTC (rev 12169)
@@ -29,7 +29,6 @@
import org.hibernate.Transaction;
import org.jboss.portal.cms.CMSException;
import org.jboss.portal.cms.CMSInterceptor;
-import org.jboss.portal.cms.hibernate.state.Tools;
import org.jboss.portal.cms.impl.jcr.JCRCMS;
import org.jboss.portal.cms.impl.jcr.JCRCommand;
import org.jboss.portal.cms.impl.jcr.command.SearchCommand;
@@ -41,6 +40,7 @@
import org.jboss.portal.cms.security.PermRoleAssoc;
import org.jboss.portal.cms.security.Permission;
import org.jboss.portal.cms.security.PortalCMSSecurityContext;
+import org.jboss.portal.cms.util.HibernateUtil;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.RoleModule;
@@ -315,7 +315,6 @@
this.jndiBinding.bind();
}
- Tools.init(this.cmsSessionFactory);
try
{
@@ -360,7 +359,7 @@
Collection parsedPermissions =
this.parseDefaultPermissions(permissions);
try
{
- session = Tools.getOpenSession();
+ session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
tx = session.beginTransaction();
for (Iterator itr = parsedPermissions.iterator(); itr.hasNext();)
{
@@ -378,7 +377,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
}
@@ -401,7 +400,6 @@
this.jndiBinding.unbind();
this.jndiBinding = null;
}
- Tools.destroy();
}
/**
@@ -488,7 +486,7 @@
boolean bootRequired = false;
String hsqlQuery = "select count(permission) from
org.jboss.portal.cms.security.Permission as permission";
- Session session = Tools.getOpenSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
Transaction tx = session.beginTransaction();
try
{
@@ -506,7 +504,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
return bootRequired;
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/security/AuthorizationProviderImpl.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/security/AuthorizationProviderImpl.java 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/security/AuthorizationProviderImpl.java 2008-10-25
18:30:46 UTC (rev 12169)
@@ -25,7 +25,7 @@
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.jboss.portal.cms.hibernate.state.Tools;
+import org.jboss.portal.cms.util.HibernateUtil;
import org.jboss.portal.cms.impl.jcr.JCRCMS;
import org.jboss.portal.identity.AnonymousRole;
import org.jboss.portal.identity.IdentityContext;
@@ -70,6 +70,8 @@
private String cmsRootUserName = null;
private User adminUser = null;
+
+ private String cmsSessionFactory = null;
/**
*
@@ -135,7 +137,16 @@
{
this.cmsRootUserName = cmsRootUserName;
}
+
+ public String getCmsSessionFactory()
+ {
+ return cmsSessionFactory;
+ }
+ public void setCmsSessionFactory(String cmsSessionFactory)
+ {
+ this.cmsSessionFactory = cmsSessionFactory;
+ }
// ------DomainConfigurator
// impl------------------------------------------------------------------
/**
@@ -223,7 +234,7 @@
if (adminUser == null)
{
- Session session = Tools.getOpenSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
Transaction tx = session.beginTransaction();
try
{
@@ -237,7 +248,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
@@ -385,7 +396,7 @@
private void store(Permission permission)
{
// persist this into the database
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).getCurrentSession();
session.saveOrUpdate(permission);
}
@@ -396,7 +407,7 @@
*/
private void remove(Collection permissions)
{
- Session session = Tools.getCurrentSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).getCurrentSession();
if (permissions != null)
{
for (Iterator itr = permissions.iterator(); itr.hasNext();)
@@ -415,7 +426,7 @@
*/
private Collection findPermissionsByUser(String userId)
{
- Session session = Tools.getOpenSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
Transaction tx = session.beginTransaction();
try
{
@@ -483,7 +494,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
}
@@ -499,7 +510,7 @@
String lookupByRole = "SELECT permission from Permission permission JOIN
permission.roleAssoc role WHERE role.roleId=?";
- Session session = Tools.getOpenSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
Transaction tx = session.beginTransaction();
try
{
@@ -518,7 +529,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
return permissions;
@@ -536,7 +547,7 @@
String lookupByCriteria = "SELECT permission from Permission permission JOIN
permission.criteria criteria WHERE criteria.name=? AND criteria.value=?";
- Session session = Tools.getOpenSession();
+ Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
Transaction tx = session.beginTransaction();
try
{
@@ -556,7 +567,7 @@
}
finally
{
- Tools.closeSession(session);
+ HibernateUtil.closeSession(session);
}
return permissions;
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/util/HibernateUtil.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/util/HibernateUtil.java 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/util/HibernateUtil.java 2008-10-25
18:30:46 UTC (rev 12169)
@@ -23,6 +23,7 @@
package org.jboss.portal.cms.util;
+import org.hibernate.Session;
import org.hibernate.SessionFactory;
import javax.naming.InitialContext;
@@ -46,4 +47,27 @@
throw new IllegalStateException("No HibernateSessionFactory can be found in
the JNDI tree at: " + jndiName);
}
}
+
+ /** @return */
+ public static Session getCurrentSession(SessionFactory sessionFactory)
+ {
+ Session session = sessionFactory.getCurrentSession();
+ return session;
+ }
+
+ /** @return */
+ public static Session getOpenSession(SessionFactory sessionFactory)
+ {
+ Session session = sessionFactory.openSession();
+ return session;
+ }
+
+ /** @param session */
+ public static void closeSession(Session session)
+ {
+ if (session != null && session.isOpen())
+ {
+ session.close();
+ }
+ }
}
Modified:
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security-test.xml
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security-test.xml 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security-test.xml 2008-10-25
18:30:46 UTC (rev 12169)
@@ -124,6 +124,7 @@
<bean name="AuthorizationProvider"
class="org.jboss.portal.cms.security.AuthorizationProviderImpl">
<property name="identityServiceController"><inject
bean="IdentityServiceController"/></property>
<property name="cmsRootUserName">admin</property>
+ <property
name="cmsSessionFactory">java:/SessionFactory</property>
</bean>
<bean name="AuthorizationManager"
class="org.jboss.portal.cms.test.security.TestAuthorizationManagerImpl">
Modified: modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security.xml
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security.xml 2008-10-24
22:35:12 UTC (rev 12168)
+++
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-beans-security.xml 2008-10-25
18:30:46 UTC (rev 12169)
@@ -124,6 +124,7 @@
<bean name="AuthorizationProvider"
class="org.jboss.portal.cms.security.AuthorizationProviderImpl">
<property name="identityServiceController"><inject
bean="IdentityServiceController"/></property>
<property name="cmsRootUserName">admin</property>
+ <property
name="cmsSessionFactory">java:/SessionFactory</property>
</bean>
<bean name="AuthorizationManager"
class="org.jboss.portal.cms.security.AuthorizationManagerImpl">
Modified: modules/cms/trunk/cms-jackrabbit/src/test/resources/pm-cache.xml
===================================================================
--- modules/cms/trunk/cms-jackrabbit/src/test/resources/pm-cache.xml 2008-10-24 22:35:12
UTC (rev 12168)
+++ modules/cms/trunk/cms-jackrabbit/src/test/resources/pm-cache.xml 2008-10-25 18:30:46
UTC (rev 12169)
@@ -174,7 +174,9 @@
<shared>false</shared>
<cacheloader>
<class>org.jboss.portal.cms.hibernate.state.PortalCMSCacheLoader</class>
- <properties></properties>
+ <properties>
+ cmsSessionFactory=java:/SessionFactory
+ </properties>
<async>false</async>
<fetchPersistentState>true</fetchPersistentState>
<ignoreModifications>false</ignoreModifications>