Author: skabashnyuk
Date: 2009-12-25 08:43:32 -0500 (Fri, 25 Dec 2009)
New Revision: 1183
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
Log:
EXOJCR-331 : changes now made in transaction
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java 2009-12-25
11:46:14 UTC (rev 1182)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java 2009-12-25
13:43:32 UTC (rev 1183)
@@ -19,11 +19,18 @@
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import java.io.Serializable;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+
/**
* @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey
Kabashnyuk</a>
* @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
@@ -31,6 +38,10 @@
*/
public class JbossCacheIndexUpdateMonitor implements IndexUpdateMonitor
{
+ /**
+ * Logger instance for this class
+ */
+ private final Log log = ExoLogger.getLogger(JbossCacheIndexUpdateMonitor.class);
private final Cache<Serializable, Object> cache;
@@ -62,7 +73,41 @@
*/
public void setUpdateInProgress(boolean updateInProgress)
{
- cache.put(PARAMETER_ROOT, PARAMETER_NAME, new Boolean(updateInProgress));
+
+ TransactionManager tm = ((CacheSPI<Serializable,
Object>)cache).getTransactionManager();
+ try
+ {
+ // if any active transaction, use it
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(PARAMETER_ROOT, PARAMETER_NAME, new Boolean(updateInProgress));
+ }
+ else if (tm.getStatus() == Status.STATUS_NO_TRANSACTION)
+ {
+ // no active transaction, creating new one
+ tm.begin();
+ cache.put(PARAMETER_ROOT, PARAMETER_NAME, new Boolean(updateInProgress));
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ log.error(e.getMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ log.error(e.getMessage(), e.getCause());
+ }
+ }
+
}
}
Show replies by date