Author: nzamosenchuk
Date: 2009-12-24 10:38:31 -0500 (Thu, 24 Dec 2009)
New Revision: 1170
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
Log:
EXOJCR-327: JbossCacheIndexInfos extended to handle Transactions and transaction manager.
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2009-12-24
15:16:11 UTC (rev 1169)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2009-12-24
15:38:31 UTC (rev 1170)
@@ -23,6 +23,7 @@
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 org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeModified;
@@ -32,6 +33,10 @@
import java.io.Serializable;
import java.util.Set;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+
/**
* List of indexes is stored in FS and all operations with it are wrapped by IndexInfos
class. In
* standalone mode index and so the list of indexes are managed by indexer and can't
be changed
@@ -56,7 +61,7 @@
private static final String SYSINDEX_NAMES = "$sysNames".intern();
- private static final String LIST_KEY = "$list".intern();
+ private static final String LIST_KEY = "$listOfIndexes".intern();
private final Cache<Serializable, Object> cache;
@@ -109,7 +114,7 @@
{
if (this.ioMode != ioMode)
{
- log.info("New IoMode:"+ioMode);
+ log.info("New IoMode:" + ioMode);
super.setIoMode(ioMode);
if (ioMode == IndexerIoMode.READ_WRITE)
{
@@ -139,7 +144,41 @@
// write to FS
super.write();
// write to cache
- cache.put(namesFqn, LIST_KEY, getNames());
+ // cache.put(namesFqn, LIST_KEY, getNames());
+ // get transaction manager
+ TransactionManager tm = ((CacheSPI<Serializable,
Object>)cache).getTransactionManager();
+ try
+ {
+ // if any active transaction, use it
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(namesFqn, LIST_KEY, getNames());
+ }
+ else
+ {
+ // no active transaction, creating new one
+ tm.begin();
+ cache.put(namesFqn, LIST_KEY, getNames());
+ 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