Author: navssurtani
Date: 2008-06-13 11:36:15 -0400 (Fri, 13 Jun 2008)
New Revision: 5987
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
Log:
Work objects now added to queue.
Wrote up NodeModifiedTransactionContext which implements TransactionContext from
HibernateSearch.
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-13
15:36:15 UTC (rev 5987)
@@ -0,0 +1,49 @@
+package org.jboss.cache.search;
+
+import org.hibernate.search.transaction.TransactionContext;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: navin
+ * Date: Jun 13, 2008
+ * Time: 4:23:26 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class NodeModifiedTransactionContext implements TransactionContext
+{
+ NodeModifiedEvent event;
+
+ public boolean isTxInProgress()
+ {
+ return (event.getTransaction() != null);
+ }
+
+ public Object getTransactionIdentifier()
+ {
+ return event.getTransaction();
+ }
+
+ public void registerSynchronization(Synchronization synchronization)
+ {
+ Transaction transaction = event.getTransaction();
+ try
+ {
+ transaction.registerSynchronization(synchronization);
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ }
+ catch (RollbackException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-13
02:36:30 UTC (rev 5986)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-13
15:36:15 UTC (rev 5987)
@@ -3,6 +3,7 @@
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.transaction.TransactionContext;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeModified;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
@@ -22,18 +23,27 @@
{
private SearchFactoryImpl searchFactory;
+ private TransactionContext transactionContext;
@NodeModified
public void updateLuceneIndexes(NodeModifiedEvent event)
{
if (!event.isPre())
{
+ if (event.getModificationType() ==
NodeModifiedEvent.ModificationType.valueOf("PUT_DATA"))
+ {
+ handlePutData(event);
+ }
- // TODO: Update Lucene Indexes. See Hibernate Search's
FullTextEventListener class for details on what to do.
+ if (event.getModificationType() ==
NodeModifiedEvent.ModificationType.valueOf("DELETE_DATA"))
+ {
+ handleDeleteData(event);
+ }
+
}
else
{
- // ignore the event.
+ //TODO: Ask Manik or EB about good ways to ignore the data. Just have souts?
Perhaps log stuff.
}
}
@@ -46,11 +56,9 @@
String keyString = (String) key;
String docId = Transformer.generateId(event.getFqn(), keyString);
- new Work(dataMap.get(key), docId, WorkType.ADD);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId,
WorkType.DELETE), transactionContext);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId,
WorkType.DELETE);
- );
-
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId,
WorkType.ADD), transactionContext);
}
}
@@ -64,10 +72,8 @@
String keyString = (String) key;
String docId = Transformer.generateId(event.getFqn(), keyString);
- new Work(dataMap.get(key), docId, WorkType.DELETE);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId,
WorkType.DELETE), transactionContext);
- //TODO: Add to queue.
-
}
}
Show replies by date