[exo-jcr-commits] exo-jcr SVN: r1165 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 24 09:42:15 EST 2009
Author: skabashnyuk
Date: 2009-12-24 09:42:15 -0500 (Thu, 24 Dec 2009)
New Revision: 1165
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
Log:
EXOJCR-334 : added support of transactions
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml 2009-12-24 14:42:15 UTC (rev 1165)
@@ -146,6 +146,17 @@
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjts</artifactId>
+ <version>4.6.1.GA</version>
+</dependency>
+<dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossts-common</artifactId>
+ <version>4.6.1.GA</version>
+</dependency>
+
+ <dependency>
<groupId>org.apache.ws.commons</groupId>
<artifactId>ws-commons-util</artifactId>
<exclusions>
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 14:42:15 UTC (rev 1165)
@@ -18,11 +18,13 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent;
+import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.JBossCacheWorkspaceStorageCache;
import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
@@ -32,6 +34,9 @@
import java.util.concurrent.CountDownLatch;
import javax.jcr.RepositoryException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
/**
* Created by The eXo Platform SAS.
@@ -301,6 +306,54 @@
}
/**
+ * @see org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#save(org.exoplatform.services.jcr.dataflow.ItemStateChangesLog)
+ */
+ @Override
+ public void save(ItemStateChangesLog changesLog) throws RepositoryException
+ {
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ tm.begin();
+ super.save(changesLog);
+ tm.commit();
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (RepositoryException e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ throw e;
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+
+ }
+
+ /**
* {@inheritDoc}
*/
public List<NodeData> getChildNodesData(NodeData nodeData) throws RepositoryException
@@ -364,7 +417,39 @@
if (parentData != null)
{
- cache.addChildNodes(parentData, childNodes);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildNodes(parentData, childNodes);
+ }
+ else
+ {
+ tm.begin();
+ cache.addChildNodes(parentData, childNodes);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
return childNodes;
@@ -431,7 +516,38 @@
if (parentData != null)
{
- cache.addChildProperties(parentData, childProperties);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildProperties(parentData, childProperties);
+ }
+ else
+ {
+ tm.begin();
+ cache.addChildProperties(parentData, childProperties);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
return childProperties;
@@ -480,7 +596,39 @@
if (parentData != null)
{
- cache.addChildPropertiesList(parentData, propertiesList);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildPropertiesList(parentData, propertiesList);
+ }
+ else
+ {
+ tm.begin();
+ cache.addChildPropertiesList(parentData, propertiesList);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
return propertiesList;
@@ -539,7 +687,38 @@
data = super.getItemData(parentData, name);
if (data != null && cache.isEnabled())
{
- cache.put(data);
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ tm.begin();
+ cache.put(data);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
return data;
}
@@ -571,7 +750,40 @@
ItemData data = super.getItemData(identifier);
if (data != null && cache.isEnabled())
{
- cache.put(data);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ tm.begin();
+ cache.put(data);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+
}
return data;
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-24 14:42:15 UTC (rev 1165)
@@ -37,6 +37,7 @@
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -52,6 +53,8 @@
import java.util.Set;
import javax.jcr.RepositoryException;
+import javax.transaction.RollbackException;
+import javax.transaction.TransactionManager;
/**
* Created by The eXo Platform SAS.<p/>
@@ -292,9 +295,12 @@
// TODO transaction
// prepare cache structures
- txStart();
+
+ TransactionManager tm = getTransactionManager();
+
try
{
+ tm.begin();
this.itemsRoot = Fqn.fromElements(ITEMS);
cacheRoot.addChild(this.itemsRoot).setResident(true);
@@ -315,14 +321,27 @@
// TODO apply locks
//this.locks = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.LOCKS));
-
- txCommit();
+ tm.commit();
}
- catch (Throwable e)
+ catch (RollbackException e)
{
- txRollback();
- throw new RepositoryException("Cannot preare cache", e);
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ throw new RepositoryException("Cannot preare cache", e);
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+
}
/**
@@ -658,51 +677,130 @@
protected void txStart()
{
- if (!txStarted)
- {
- txStarted = true;
- this.cache.startBatch();
- }
+ // if (!txStarted)
+ // {
+ // txStarted = true;
+ // //this.cache.startBatch();
+ // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ // try
+ // {
+ // tm.begin();
+ // }
+ // catch (NotSupportedException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SystemException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // }
}
protected void txCommit()
{
- if (LOG.isDebugEnabled())
- {
- LOG.debug("commit " + txStarted);
- }
+ // if (LOG.isDebugEnabled())
+ // {
+ // LOG.debug("commit " + txStarted);
+ // }
+ //
+ // // end batch
+ // if (txStarted)
+ // {
+ // //this.cache.endBatch(true);
+ // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ // try
+ // {
+ // tm.commit();
+ // }
+ // catch (SecurityException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (IllegalStateException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (RollbackException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (HeuristicMixedException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (HeuristicRollbackException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SystemException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // txStarted = false;
+ // }
+ // else
+ // {
+ // // TODO
+ // LOG.warn("Commit call without changes made.");
+ // }
+ }
- // end batch
- if (txStarted)
- {
- this.cache.endBatch(true);
- txStarted = false;
- }
- else
- {
- // TODO
- LOG.warn("Commit call without changes made.");
- }
+ /**
+ * Return TransactionManager.
+ * @return TransactionManager.
+ */
+ public TransactionManager getTransactionManager()
+ {
+ return ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
}
protected void txRollback()
{
- if (LOG.isDebugEnabled())
- {
- LOG.debug("rollback " + txStarted);
- }
-
- // rollback batch
- if (txStarted)
- {
- this.cache.endBatch(false);
- txStarted = false;
- }
- else
- {
- // TODO
- LOG.warn("Rollback call without changes made.");
- }
+ // if (LOG.isDebugEnabled())
+ // {
+ // LOG.debug("rollback " + txStarted);
+ // }
+ //
+ // // rollback batch
+ // if (txStarted)
+ // {
+ // //this.cache.endBatch(false);
+ // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ // try
+ // {
+ // tm.rollback();
+ // }
+ // catch (IllegalStateException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SecurityException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SystemException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // txStarted = false;
+ // }
+ // else
+ // {
+ // // TODO
+ // LOG.warn("Rollback call without changes made.");
+ // }
}
/**
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2009-12-24 14:42:15 UTC (rev 1165)
@@ -3,7 +3,7 @@
xmlns="urn:jboss:jbosscache-core:config:3.1">
<!-- Configure the TransactionManager -->
- <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" />
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.JBossStandaloneJTAManagerLookup" />
<!-- Enable batching -->
<invocationBatching enabled="true"/>
More information about the exo-jcr-commits
mailing list