Author: sohil.shah(a)jboss.com
Date: 2009-01-13 04:14:42 -0500 (Tue, 13 Jan 2009)
New Revision: 12479
Added:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/MaterializedBlobType.java
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java
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/impl/jcr/JCRCMS.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/jackrabbit/JackrabbitJCRService.java
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/TestJackrabbit.java
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/AbstractCommandTestCase.java
modules/cms/trunk/cms-jackrabbit/src/test/resources/domain.hbm.xml
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml
Log:
code backup (a bit more stable, passes the testsuite locally)...more code cleanup to
follow
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java 2009-01-13
06:57:04 UTC (rev 12478)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java 2009-01-13
09:14:42 UTC (rev 12479)
@@ -37,7 +37,6 @@
import org.jboss.portal.common.io.IOTools;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -869,13 +868,9 @@
List rs = query.list();
//
Iterator iter = rs.iterator();
- java.sql.Blob blob = (java.sql.Blob)iter.next();
- /*
- InputStream is = blob.getBinaryStream();
- Tools.safeClose(is);
- */
- BlobInputStream blobIs = new BlobInputStream(blob);
- return blobIs;
+ byte[] blob = (byte[])iter.next();
+
+ return new ByteArrayInputStream(blob);
}
catch (Exception e)
{
@@ -991,7 +986,6 @@
session.save(repoEntry);
}
- //session.flush();
}
catch (Exception e)
{
@@ -1027,7 +1021,6 @@
RepositoryEntry repoEntry = new RepositoryEntry(parentDir,
name, IOTools.getBytes(in), System.currentTimeMillis(), length);
session.save(repoEntry);
}
- //session.flush();
}
catch (Exception e)
{
@@ -1196,7 +1189,6 @@
session.save(repoEntry);
}
- //session.flush();
}
catch (Exception e)
{
@@ -1232,7 +1224,6 @@
RepositoryEntry repoEntry = new RepositoryEntry(parentDir,
name, IOTools.getBytes(in), System.currentTimeMillis(), length);
session.save(repoEntry);
}
- //session.flush();
}
catch (Exception e)
{
@@ -1491,7 +1482,6 @@
RepositoryEntry repoEntry = new RepositoryEntry(parentDir, name, null,
System.currentTimeMillis(), 0);
session.save(repoEntry);
}
- //session.flush();
}
catch (Exception e)
{
@@ -1550,7 +1540,7 @@
}
finally
{
-// resetStatement(stmt);
+ resetStatement(stmt);
}
}
*/
@@ -1604,95 +1594,11 @@
}
finally
{
-// resetStatement(stmt);
+ resetStatement(stmt);
}
}
*/
}
-
-// Hibernate additions
-/*
- private class Blah
- {
- Session session;
- Transaction tx;
- public Blah()
- {
- }
- public void open()
- {
- session = hibernateSessionFactory.openSession();
- tx = session.beginTransaction();
- }
- public void close()
- {
- try
- {
- tx.commit();
- }
- finally
- {
- session.close();
- }
- }
- }
-*/
- /*
- public static class BlobInputStream extends ByteArrayInputStream
- {
-
- public BlobInputStream(Blob blob) throws Exception
- {
- super(getBytes(blob));
- }
-
- private static byte[] getBytes(Blob blob) throws Exception
- {
- InputStream in = null;
- try
- {
- in = blob.getBinaryStream();
- ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
- Tools.copy(in, out);
- return out.toByteArray();
- }
- finally
- {
- Tools.safeClose(in);
- }
- }
-
- }
-*/
-
-
- public static class BlobInputStream extends ByteArrayInputStream
- {
-
- public BlobInputStream(Blob blob) throws Exception
- {
- super(getBytes(blob));
- }
-
- private static byte[] getBytes(Blob blob) throws Exception
- {
- InputStream in = null;
- try
- {
- in = blob.getBinaryStream();
- ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
- IOTools.copy(in, out);
- return out.toByteArray();
- }
- finally
- {
- IOTools.safeClose(in);
- }
- }
-
-
- }
-
}
/*
* Copyright 2004-2005 The Apache Software Foundation or its licensors,
Added:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/MaterializedBlobType.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/MaterializedBlobType.java
(rev 0)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/MaterializedBlobType.java 2009-01-13
09:14:42 UTC (rev 12479)
@@ -0,0 +1,33 @@
+package org.jboss.portal.cms.hibernate;
+
+import java.sql.Types;
+
+import org.hibernate.type.AbstractBynaryType;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class MaterializedBlobType extends AbstractBynaryType {
+
+ public int sqlType() {
+ return Types.BLOB;
+ }
+
+ public String getName() {
+ return "materialized-blob";
+ }
+
+ public Class getReturnedClass() {
+ return byte[].class;
+ }
+
+ protected Object toExternalFormat(byte[] bytes) {
+ return bytes;
+ }
+
+ protected byte[] toInternalFormat(Object bytes) {
+ return ( byte[] ) bytes;
+ }
+}
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 2009-01-13
06:57:04 UTC (rev 12478)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2009-01-13
09:14:42 UTC (rev 12479)
@@ -1548,11 +1548,7 @@
String msg = "failed to write node state: " + blobId;
log.error(msg, e);
throw new ItemStateException(msg, e);
- }
- finally
- {
- //session.flush();
- }
+ }
}
else
// insert
@@ -1583,11 +1579,7 @@
String msg = "failed to write node state: " + blobId;
log.error(msg, e);
throw new ItemStateException(msg, e);
- }
- finally
- {
- //session.flush();
- }
+ }
}
}
@@ -1619,11 +1611,7 @@
String msg = "failed to delete binval: " + blobId;
log.error(msg, e);
throw new ItemStateException(msg, e);
- }
- finally
- {
- //session.flush();
- }
+ }
}
}
}
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2009-01-13
06:57:04 UTC (rev 12478)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2009-01-13
09:14:42 UTC (rev 12479)
@@ -39,6 +39,7 @@
import org.jboss.portal.cms.model.File;
import org.jboss.portal.cms.model.Folder;
import org.jboss.portal.cms.util.RepositoryUtil;
+import org.jboss.portal.cms.util.HibernateUtil;
import org.jboss.portal.cms.workflow.ApprovePublish;
import org.jboss.portal.cms.security.AuthorizationManager;
import org.jboss.portal.common.invocation.InterceptorStackFactory;
@@ -57,6 +58,8 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.hibernate.Transaction;
+
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.transaction.xa.XAResource;
@@ -69,6 +72,7 @@
import java.util.LinkedList;
import java.util.Locale;
import java.util.Set;
+
import javax.transaction.TransactionManager;
import javax.transaction.Status;
import javax.naming.InitialContext;
@@ -106,6 +110,8 @@
private String jndiName;
private JNDI.Binding jndiBinding;
+
+ private String cmsSessionFactory;
private InvocationHandler handler = new InvocationHandler()
{
@@ -134,10 +140,7 @@
{
turnOffWorkflow.set(null);
}
-
- /**
- *
- */
+
protected static ThreadLocal applyUISecurityFilter = new ThreadLocal();
public static void enableUISecurityFilter()
{
@@ -286,45 +289,295 @@
{
this.jndiName = jndiName;
}
+
+ public CommandFactory getCommandFactory()
+ {
+ return commandFactory;
+ }
- /** CMS Start */
+ public Repository getRepository()
+ {
+ return jcr.getRepository();
+ }
+
+ /** @return */
+ public boolean isWorkflowActivated()
+ {
+ return (this.approvePublishWorkflow != null);
+ }
+
+ public void setStackFactory(InterceptorStackFactory stackFactory)
+ {
+ this.stackFactory = stackFactory;
+ }
+
+ public InterceptorStackFactory getStackFactory()
+ {
+ return stackFactory;
+ }
+
+ public String getCmsSessionFactory()
+ {
+ return this.cmsSessionFactory;
+ }
+
+ public void setCmsSessionFactory(String cmsSessionFactory)
+ {
+ this.cmsSessionFactory = cmsSessionFactory;
+ }
+
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void startService() throws Exception
{
- if (this.jndiName != null)
+ org.hibernate.Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
+ Transaction tx = session.beginTransaction();
+ try
+ {
+
+ if (this.jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ //check the version of jbosscache being run
+ String cacheVersion = Version.getVersionString(Version.getVersionShort());
+ log.info("JBossCache Version=" + cacheVersion);
+
+ // See how long it takes us to start up
+ StopWatch watch = new StopWatch(true);
+ log.info("Starting JCR CMS");
+ //addInterceptors();
+ startJCR();
+ watch.stop();
+ log.info("Started JCR CMS in: " + watch);
+
+ tx.commit();
+ }
+ catch(Exception e)
+ {
+ log.error(this, e);
+ if(tx != null)
+ {
+ tx.rollback();
+ }
+ }
+ finally
+ {
+ if(session !=null && session.isOpen())
+ {
+ session.close();
+ }
+ }
+ }
+
+ public void stopService()
+ {
+ org.hibernate.Session session =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
+ Transaction tx = session.beginTransaction();
+ try
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+ log.info("Stopping JCR CMS");
+ stopJCR();
+
+ tx.commit();
+ }
+ catch(Exception e)
+ {
+ if(tx != null)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch(Exception tme)
+ {
+ log.error(this, tme);
+ }
+ }
+ }
+ finally
+ {
+ if(session !=null && session.isOpen())
+ {
+ session.close();
+ }
+ }
+ }
+
+ public Object execute(Command cmd) throws CMSException
+ {
+ org.apache.jackrabbit.core.XASession session = null;
+ try
{
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
+ session = (org.apache.jackrabbit.core.XASession)jcr.login("anonid",
"");
}
+ catch (Exception e)
+ {
+ throw new RuntimeException(e); // Fixme
+ }
+ // get XAResource
+ XAResource xares = session.getXAResource();
- //check the version of jbosscache being run
- String cacheVersion = Version.getVersionString(Version.getVersionShort());
- log.info("JBossCache Version=" + cacheVersion);
+ // create dummy Xid
+ Xid xid = new Xid()
+ {
+ public byte[] getBranchQualifier()
+ {
+ return new byte[0];
+ }
- // See how long it takes us to start up
- StopWatch watch = new StopWatch(true);
- log.info("Starting JCR CMS");
- //addInterceptors();
- startJCR();
- watch.stop();
- log.info("Started JCR CMS in: " + watch);
- }
+ public int getFormatId()
+ {
+ return 0;
+ }
+ public byte[] getGlobalTransactionId()
+ {
+ return new byte[0];
+ }
+ };
- /** Shuts down the repo and unregisters it */
- public void stopService()
- {
- if (jndiBinding != null)
+ Object obj = null;
+ boolean isClusterDelegatedRequest = false; //used to indicate this request is from
another cluster node instead of the master node
+ boolean clusterWorkflowStatus = false;
+ org.hibernate.Session hibernateSession =
HibernateUtil.getSessionFactory(this.cmsSessionFactory).openSession();
+ Transaction tx = hibernateSession.beginTransaction();
+ try
+ {
+ xares.start(xid, XAResource.TMNOFLAGS);
+
+ //Check and make sure in the case of a clustered call, the Identity propagated
+ //as part of the invocation is handled correctly
+ JCRCommandContext propagatedContext =
(JCRCommandContext)((JCRCommand)cmd).getContext();
+ if (propagatedContext != null)
+ {
+ CMSUser propagatedUser =
(CMSUser)propagatedContext.getClusterContextInfo("user");
+ if (propagatedUser != null)
+ {
+ JCRCMS.getUserInfo().set(propagatedUser);
+ isClusterDelegatedRequest = true;
+ }
+ Boolean workflowStatus =
(Boolean)propagatedContext.getClusterContextInfo("workflowStatus");
+ if (workflowStatus != null)
+ {
+ JCRCMS.turnOffWorkflow();
+ clusterWorkflowStatus = true;
+ }
+ Boolean enableUISecurityFilter =
(Boolean)propagatedContext.getClusterContextInfo("enableUISecurityFilter");
+ if(enableUISecurityFilter != null)
+ {
+ JCRCMS.enableUISecurityFilter();
+ }
+ Set<String> roles =
(Set<String>)propagatedContext.getClusterContextInfo("roles");
+ if(roles != null)
+ {
+ JCRCMS.setRoles(roles);
+ }
+ }
+
+ // .... add new nodes & properties and save them
+ JCRCommand jcrCmd = (JCRCommand)cmd;
+ JCRCommandContext ctx = new JCRCommandContext(session, commandFactory,
defaultLocale);
+ jcrCmd.setContext(ctx);
+
+ ctx.setAttribute(JCRCommandContext.scope, "user",
JCRCMS.getUserInfo().get());
+ Object isWorkflowOff = JCRCMS.turnOffWorkflow.get();
+ if (this.approvePublishWorkflow != null //this checks and makes sure workflow
is activated for the CMS
+ &&
+ isWorkflowOff == null //this checks and makes sure workflow is not turned off
only for this particular request
+ )
+ {
+ ctx.setAttribute(JCRCommandContext.scope, "approvePublishWorkflow",
this.approvePublishWorkflow);
+ }
+
+
+ if ((stackFactory != null) &&
(stackFactory.getInterceptorStack().getLength() != 0))
+ {
+ jcrCmd.setHandler(handler);
+ obj = jcrCmd.invoke(stackFactory.getInterceptorStack());
+ jcrCmd.setHandler(null);
+ }
+ else
+ {
+ obj = jcrCmd.execute();
+ }
+
+ //committ the transaction
+ xares.end(xid, XAResource.TMSUCCESS);
+ xares.prepare(xid);
+ session.save();
+ xares.commit(xid, false);
+
+ tx.commit();
+ }
+ catch (Exception e)
{
- jndiBinding.unbind();
- jndiBinding = null;
+ log.error(this, e);
+ try
+ {
+ xares.rollback(xid);
+ }
+ catch (Exception ex)
+ {
+ //we tried to roll it back...not sure what more we can do here
+ throw new CMSException(ex);
+ }
+
+ if(tx != null)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch(Exception rbe)
+ {
+ log.error(this, rbe);
+ }
+ }
+
+ if (e instanceof CMSException)
+ {
+ throw (CMSException)e;
+ }
+ else if (e instanceof RuntimeException)
+ {
+ throw (RuntimeException)e;
+ }
+ else
+ {
+ throw new CMSException(e);
+ }
}
- log.info("Stopping JCR CMS");
- stopJCR();
-// removeInterceptors();
+ finally
+ {
+ if (session != null)
+ {
+ //must do this otherwise, the whole cms will hang
+ session.logout();
+ }
+ if (isClusterDelegatedRequest)
+ {
+ JCRCMS.getUserInfo().set(null);
+ }
+ if (clusterWorkflowStatus)
+ {
+ JCRCMS.turnOnWorkflow();
+ }
+ if(hibernateSession !=null && hibernateSession.isOpen())
+ {
+ hibernateSession.close();
+ }
+ }
+ return obj;
}
-
- public void startJCR() throws Exception
+
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ private void startJCR() throws Exception
{
// Serialize the embedded configuration
DOMImplementation impl = config.getOwnerDocument().getImplementation();
@@ -357,7 +610,7 @@
}
}
- public void stopJCR()
+ private void stopJCR()
{
jcr.stop();
jcr = null;
@@ -383,9 +636,12 @@
}
}
- // /**
- /** Loads content from sar and adds it to the repo. */
- public void createContent() throws Exception
+ /**
+ * Initilizes the repository with initial/boot content
+ *
+ * @throws Exception
+ */
+ private void createContent() throws Exception
{
log.info("Creating default CMS content.");
@@ -523,199 +779,5 @@
//
URLNavigator.visit(root, visitor);
log.info("Default content created.");
- }
-
-
- public CommandFactory getCommandFactory()
- {
- return commandFactory;
- }
-
-
- public Repository getRepository()
- {
- return jcr.getRepository();
- }
-
- public Object execute(Command cmd) throws CMSException
- {
- org.apache.jackrabbit.core.XASession session = null;
- try
- {
- session = (org.apache.jackrabbit.core.XASession)jcr.login("anonid",
"");
- }
- catch (Exception e)
- {
- throw new RuntimeException(e); // Fixme
- }
- // get XAResource
- XAResource xares = session.getXAResource();
-
- // create dummy Xid
- Xid xid = new Xid()
- {
- public byte[] getBranchQualifier()
- {
- return new byte[0];
- }
-
- public int getFormatId()
- {
- return 0;
- }
-
- public byte[] getGlobalTransactionId()
- {
- return new byte[0];
- }
- };
-
- Object obj = null;
- boolean isClusterDelegatedRequest = false; //used to indicate this request is from
another cluster node instead of the master node
- boolean clusterWorkflowStatus = false;
- TransactionManager tm = null;
- boolean isStartedHere = false;
- try
- {
- tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
- if(tm.getStatus() == Status.STATUS_NO_TRANSACTION)
- {
- tm.begin();
- isStartedHere = true;
- }
-
- xares.start(xid, XAResource.TMNOFLAGS);
-
- //Check and make sure in the case of a clustered call, the Identity propagated
- //as part of the invocation is handled correctly
- JCRCommandContext propagatedContext =
(JCRCommandContext)((JCRCommand)cmd).getContext();
- if (propagatedContext != null)
- {
- CMSUser propagatedUser =
(CMSUser)propagatedContext.getClusterContextInfo("user");
- if (propagatedUser != null)
- {
- JCRCMS.getUserInfo().set(propagatedUser);
- isClusterDelegatedRequest = true;
- }
- Boolean workflowStatus =
(Boolean)propagatedContext.getClusterContextInfo("workflowStatus");
- if (workflowStatus != null)
- {
- JCRCMS.turnOffWorkflow();
- clusterWorkflowStatus = true;
- }
- Boolean enableUISecurityFilter =
(Boolean)propagatedContext.getClusterContextInfo("enableUISecurityFilter");
- if(enableUISecurityFilter != null)
- {
- JCRCMS.enableUISecurityFilter();
- }
- Set<String> roles =
(Set<String>)propagatedContext.getClusterContextInfo("roles");
- if(roles != null)
- {
- JCRCMS.setRoles(roles);
- }
- }
-
- // .... add new nodes & properties and save them
- JCRCommand jcrCmd = (JCRCommand)cmd;
- JCRCommandContext ctx = new JCRCommandContext(session, commandFactory,
defaultLocale);
- jcrCmd.setContext(ctx);
-
- ctx.setAttribute(JCRCommandContext.scope, "user",
JCRCMS.getUserInfo().get());
- Object isWorkflowOff = JCRCMS.turnOffWorkflow.get();
- if (this.approvePublishWorkflow != null //this checks and makes sure workflow
is activated for the CMS
- &&
- isWorkflowOff == null //this checks and makes sure workflow is not turned off
only for this particular request
- )
- {
- ctx.setAttribute(JCRCommandContext.scope, "approvePublishWorkflow",
this.approvePublishWorkflow);
- }
-
-
- if ((stackFactory != null) &&
(stackFactory.getInterceptorStack().getLength() != 0))
- {
- jcrCmd.setHandler(handler);
- obj = jcrCmd.invoke(stackFactory.getInterceptorStack());
- jcrCmd.setHandler(null);
- }
- else
- {
- obj = jcrCmd.execute();
- }
-
- //committ the transaction
- xares.end(xid, XAResource.TMSUCCESS);
- xares.prepare(xid);
- session.save();
- xares.commit(xid, false);
-
- if(isStartedHere)
- {
- tm.getTransaction().commit();
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- try
- {
- xares.rollback(xid);
- }
- catch (Exception ex)
- {
- //we tried to roll it back...not sure what more we can do here
- throw new CMSException(ex);
- }
-
- if(tm != null)
- {
- try{tm.getTransaction().rollback();}catch(Exception tme){}
- }
-
- if (e instanceof CMSException)
- {
- throw (CMSException)e;
- }
- else if (e instanceof RuntimeException)
- {
- throw (RuntimeException)e;
- }
- else
- {
- throw new CMSException(e);
- }
- }
- finally
- {
- if (session != null)
- {
- //must do this otherwise, the whole cms will hang
- session.logout();
- }
- if (isClusterDelegatedRequest)
- {
- JCRCMS.getUserInfo().set(null);
- }
- if (clusterWorkflowStatus)
- {
- JCRCMS.turnOnWorkflow();
- }
- }
- return obj;
- }
-
- /** @return */
- public boolean isWorkflowActivated()
- {
- return (this.approvePublishWorkflow != null);
- }
-
- public void setStackFactory(InterceptorStackFactory stackFactory)
- {
- this.stackFactory = stackFactory;
- }
-
- public InterceptorStackFactory getStackFactory()
- {
- return stackFactory;
- }
+ }
}
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/jackrabbit/JackrabbitJCRService.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/jackrabbit/JackrabbitJCRService.java 2009-01-13
06:57:04 UTC (rev 12478)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/jackrabbit/JackrabbitJCRService.java 2009-01-13
09:14:42 UTC (rev 12479)
@@ -50,11 +50,7 @@
import javax.jcr.version.OnParentVersionAction;
import java.io.StringReader;
-import javax.transaction.TransactionManager;
-import javax.transaction.Status;
-import javax.naming.InitialContext;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 6469 $
@@ -104,82 +100,38 @@
public void start() throws Exception
{
- TransactionManager tm = null;
- boolean isStartedHere = false;
- try
- {
- tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
- if(tm.getStatus() == Status.STATUS_NO_TRANSACTION)
- {
- tm.begin();
- isStartedHere = true;
- }
-
- log.debug("JackRabbit configuration: " + config);
- // Create repository
- StringReader reader = new StringReader(config);
- InputSource src = new InputSource(reader);
- RepositoryConfig cfg = RepositoryConfig.create(src, homeDir);
- repository = RepositoryImpl.create(cfg);
- log.info("Repository '" + repositoryName + "'
created");
-
- // Check portalcms-namespace nodetypes exist
- if (!nodeTypesExist())
- {
- log.info("The repository does not know about CMS node types");
- registerCustomNodeTypes(repository);
- }
- else
- {
- log.info("The repository has already the CMS node types
registered");
- }
-
- if(isStartedHere)
- {
- tm.getTransaction().commit();
- }
- }
- catch(Exception e)
- {
- if(tm != null)
- {
- tm.getTransaction().rollback();
- }
- throw e;
- }
+ log.debug("JackRabbit configuration: " + config);
+ // Create repository
+ StringReader reader = new StringReader(config);
+ InputSource src = new InputSource(reader);
+ RepositoryConfig cfg = RepositoryConfig.create(src, homeDir);
+ repository = RepositoryImpl.create(cfg);
+ log.info("Repository '" + repositoryName + "'
created");
+
+ // Check portalcms-namespace nodetypes exist
+ if (!nodeTypesExist())
+ {
+ log.info("The repository does not know about CMS node types");
+ registerCustomNodeTypes(repository);
+ }
+ else
+ {
+ log.info("The repository has already the CMS node types registered");
+ }
}
public void stop()
- {
- TransactionManager tm = null;
- boolean isStartedHere = false;
- try
- {
- tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
- if(tm.getStatus() == Status.STATUS_NO_TRANSACTION)
- {
- tm.begin();
- isStartedHere = true;
- }
-
+ {
+ try
+ {
log.info("Shutting down repository");
repository.shutdown();
- log.info("Repository shut down successfully");
-
- if(isStartedHere)
- {
- tm.getTransaction().commit();
- }
+ log.info("Repository shut down successfully");
}
catch (Exception e)
- {
- if(tm != null)
- {
- try{tm.getTransaction().rollback();}catch(Exception ex){}
- }
- e.printStackTrace();
+ {
log.error("Failed to unregister repository. Some locks may persist!",
e);
- }
+ }
}
/** Check for existence of namespace nodetypes. */
Modified:
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/TestJackrabbit.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/TestJackrabbit.java 2009-01-13
06:57:04 UTC (rev 12478)
+++
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/TestJackrabbit.java 2009-01-13
09:14:42 UTC (rev 12479)
@@ -67,21 +67,24 @@
LoaderResource res = new
CLResourceLoader().getResource("jcr/repository.xml");
String config = res.asString();
+ TransactionManager tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
+ tm.begin();
jcr = new JackrabbitJCRService();
jcr.setRepositoryName("repo");
jcr.setConfig(config);
jcr.setHomeDir("repotest-" + getDataSourceName());
jcr.start();
+ tm.commit();
}
@Destroy
public void tearDown() throws Exception
- {
+ {
TransactionManager tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
- tm.commit();
-
+ tm.begin();
jcr.stop();
jcr = null;
+ tm.commit();
}
@Test
@@ -92,11 +95,10 @@
//
Session session = null;
- TransactionManager tm = null;
+ TransactionManager tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
try
{
- tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
- tm.begin();
+ tm.begin();
session = jcr.login("anonid", "");
Workspace wosp = session.getWorkspace();
@@ -123,8 +125,7 @@
//
try
- {
- tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
+ {
tm.begin();
session = jcr.login("anonid", "");
@@ -150,8 +151,7 @@
//
try
- {
- tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
+ {
tm.begin();
session = jcr.login("anonid", "");
Modified:
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/AbstractCommandTestCase.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/AbstractCommandTestCase.java 2009-01-13
06:57:04 UTC (rev 12478)
+++
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/AbstractCommandTestCase.java 2009-01-13
09:14:42 UTC (rev 12479)
@@ -71,6 +71,7 @@
service.setRepositoryName("repo");
service.setHomeDir("repotest-" + getDataSourceName());
service.setJNDIName("java:portal/CMS");
+ service.setCmsSessionFactory("java:/SessionFactory");
service.startService();
}
Modified: modules/cms/trunk/cms-jackrabbit/src/test/resources/domain.hbm.xml
===================================================================
--- modules/cms/trunk/cms-jackrabbit/src/test/resources/domain.hbm.xml 2009-01-13 06:57:04
UTC (rev 12478)
+++ modules/cms/trunk/cms-jackrabbit/src/test/resources/domain.hbm.xml 2009-01-13 09:14:42
UTC (rev 12479)
@@ -41,7 +41,7 @@
<property
name="data"
column="BINVAL_DATA"
- type="binary"
+ type="org.jboss.portal.cms.hibernate.MaterializedBlobType"
length="100000000"
not-null="true"/>
</class>
@@ -117,7 +117,7 @@
<property
name="data"
column="BINVAL_DATA"
- type="binary"
+ type="org.jboss.portal.cms.hibernate.MaterializedBlobType"
length="100000000"
not-null="true"/>
</class>
@@ -198,7 +198,7 @@
length="245"/>
<property name="data"
column="FSENTRY_DATA"
- type="binary"
+ type="org.jboss.portal.cms.hibernate.MaterializedBlobType"
length="100000000"
not-null="false"/>
<property name="lastmod"
@@ -230,7 +230,7 @@
length="245"/>
<property name="data"
column="FSENTRY_DATA"
- type="binary"
+ type="org.jboss.portal.cms.hibernate.MaterializedBlobType"
length="100000000"
not-null="false"/>
<property name="lastmod"
@@ -262,7 +262,7 @@
length="245"/>
<property name="data"
column="FSENTRY_DATA"
- type="binary"
+ type="org.jboss.portal.cms.hibernate.MaterializedBlobType"
length="100000000"
not-null="false"/>
<property name="lastmod"
Modified: modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml
===================================================================
--- modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml 2009-01-13 06:57:04
UTC (rev 12478)
+++ modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml 2009-01-13 09:14:42
UTC (rev 12479)
@@ -6,13 +6,14 @@
<pojo>
<parameter name="datasources" value="datasources.xml"/>
<parameter name="dataSourceName">
- <value>hsqldb</value>
+ <value>hsqldb</value>
+ <!--
<value>oracle10g</value>
<value>mysql5</value>
- <value>postgresql8</value>
+ <value>postgresql8</value>
+ -->
</parameter>
<parameter name="hibernateConfig"
value="hibernates.xml"/>
- <!--
<test >
<class
name="org.jboss.portal.cms.test.commands.TestFileArchiveUpload"/>
</test>
@@ -61,11 +62,9 @@
<test >
<class name="org.jboss.portal.cms.test.commands.TestSearch"/>
</test>
- -->
<test >
<class name="org.jboss.portal.cms.test.TestJackrabbit"/>
</test>
- <!--
<test >
<class name="org.jboss.portal.cms.test.TestRegEx"/>
</test>
@@ -75,21 +74,21 @@
<test >
<class
name="org.jboss.portal.cms.test.commands.TestRepositoryBootStrap"/>
</test>
- -->
</pojo>
<pojo>
<parameter name="datasources" value="datasources.xml"/>
<parameter name="dataSourceName">
- <value>hsqldb</value>
+ <value>hsqldb</value>
+ <!--
<value>oracle10g</value>
<value>mysql5</value>
- <value>postgresql8</value>
+ <value>postgresql8</value>
+ -->
</parameter>
<parameter name="hibernateConfig"
value="hibernates.xml"/>
<parameter name="standardIdentityConfig"
value="standardidentity-config.xml"/>
<parameter name="identityConfig" value="db-config.xml"/>
- <!--
<test >
<class
name="org.jboss.portal.cms.test.security.TestManageAccess"/>
</test>
@@ -102,21 +101,21 @@
<test >
<class
name="org.jboss.portal.cms.test.security.TestNewReadCommand"/>
</test>
- -->
</pojo>
<pojo>
<parameter name="datasources" value="datasources.xml"/>
<parameter name="dataSourceName">
<value>hsqldb</value>
+ <!--
<value>oracle10g</value>
<value>mysql5</value>
- <value>postgresql8</value>
+ <value>postgresql8</value>
+ -->
</parameter>
<parameter name="hibernateConfig"
value="hibernates.xml"/>
<parameter name="standardIdentityConfig"
value="standardidentity-config.xml"/>
<parameter name="identityConfig" value="db-config.xml"/>
- <!--
<test >
<class
name="org.jboss.portal.cms.test.workflow.TestApprovedPublish"/>
</test>
@@ -126,21 +125,5 @@
<test >
<class
name="org.jboss.portal.cms.test.workflow.TestWorkflowEnvironment"/>
</test>
- -->
- </pojo>
-
- <!--
- <pojo>
- <parameter name="datasources" value="datasources.xml"/>
- <parameter name="dataSourceName">
- <value>hsqldb</value>
- <value>oracle10g</value>
- <value>mysql5</value>
- </parameter>
- <parameter name="hibernateConfig"
value="hibernates.xml"/>
- <test >
- <class
name="org.jboss.portal.cms.test.commands.TestFileArchiveUpload"/>
- </test>
- </pojo>
- -->
+ </pojo>
</jboss-unit>