Author: nzamosenchuk
Date: 2009-12-24 10:16:11 -0500 (Thu, 24 Dec 2009)
New Revision: 1169
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
Log:
EXOJCR-327: JbossCacheChangesFilter 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/JbossCacheIndexChangesFilter.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-24
15:12:17 UTC (rev 1168)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-24
15:16:11 UTC (rev 1169)
@@ -26,6 +26,7 @@
import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import
org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.JBossCacheWorkspaceStorageCache;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -43,6 +44,9 @@
import java.util.Set;
import javax.jcr.RepositoryException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
/**
* @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey
Kabashnyuk</a>
@@ -120,16 +124,14 @@
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
//parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
- //parentHandler.setIndexInfos(new IndexInfos());
- parentHandler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
+ //parentHandler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
parentHandler.init();
}
if (!handler.isInitialized())
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
//handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
- //handler.setIndexInfos(new IndexInfos());
- handler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
+ //handler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
handler.init();
}
@@ -143,8 +145,43 @@
Set<String> parentAddedNodes)
{
String id = IdGenerator.generate();
- cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes, removedNodes,
parentAddedNodes,
- parentRemovedNodes));
+ // get TransactionManager
+ TransactionManager tm = ((CacheSPI<Serializable,
Object>)cache).getTransactionManager();
+ try
+ {
+ // if any active transaction, use it
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes,
removedNodes, parentAddedNodes,
+ parentRemovedNodes));
+ }
+ else
+ {
+ // no active transaction, creating new one
+ tm.begin();
+ cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes,
removedNodes, parentAddedNodes,
+ parentRemovedNodes));
+ 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