Author: navssurtani
Date: 2008-06-18 10:46:01 -0400 (Wed, 18 Jun 2008)
New Revision: 14776
Added:
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/EventSourceTransactionContext.java
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/TransactionContext.java
search/branches/jboss_cache_integration/x.y
Modified:
search/branches/jboss_cache_integration/common-build.xml
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/Worker.java
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
search/branches/jboss_cache_integration/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
search/branches/jboss_cache_integration/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
Log:
Created transaction package with TransactionContext. Changed other classes that call the
doWork() method.
Modified: search/branches/jboss_cache_integration/common-build.xml
===================================================================
--- search/branches/jboss_cache_integration/common-build.xml 2008-06-18 06:04:17 UTC (rev
14775)
+++ search/branches/jboss_cache_integration/common-build.xml 2008-06-18 14:46:01 UTC (rev
14776)
@@ -458,7 +458,7 @@
<!-- maven deploy: to be used by the subbuild and delcare deps on jar -->
<target name="install" depends="jar">
- <fail unless="offline.repository.jboss.org"
message="offline.repository.jboss.org must be defined"/>
+ <!-- <fail unless="offline.repository.jboss.org"
message="offline.repository.jboss.org must be defined"/> -->
<jar jarfile="${src.jar}" basedir="${src.dir}">
<include name="**/*.java" />
<exclude name="**/test/*.java" />
Modified:
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/Worker.java
===================================================================
---
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/Worker.java 2008-06-18
06:04:17 UTC (rev 14775)
+++
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/Worker.java 2008-06-18
14:46:01 UTC (rev 14776)
@@ -1,11 +1,11 @@
//$Id$
package org.hibernate.search.backend;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.transaction.TransactionContext;
+
import java.util.Properties;
-import org.hibernate.event.EventSource;
-import org.hibernate.search.engine.SearchFactoryImplementor;
-
/**
* Perform work for a given session. This implementation has to be multi threaded
* @author Emmanuel Bernard
@@ -13,7 +13,7 @@
public interface Worker {
//Use of EventSource since it's the common subinterface for Session and
SessionImplementor
//the alternative would have been to do a subcasting or to retrieve 2 parameters :(
- void performWork(Work work, EventSource session);
+ void performWork(Work work, TransactionContext session);
void initialize(Properties props, SearchFactoryImplementor searchFactoryImplementor);
Modified:
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
---
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2008-06-18
06:04:17 UTC (rev 14775)
+++
search/branches/jboss_cache_integration/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2008-06-18
14:46:01 UTC (rev 14776)
@@ -1,17 +1,16 @@
//$Id$
package org.hibernate.search.backend.impl;
-import java.util.Properties;
-
-import org.hibernate.Transaction;
-import org.hibernate.event.EventSource;
import org.hibernate.search.backend.QueueingProcessor;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.backend.Worker;
import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.transaction.TransactionContext;
import org.hibernate.search.util.WeakIdentityHashMap;
+import java.util.Properties;
+
/**
* Queue works per transaction.
* If out of transaction, the work is executed right away
@@ -26,14 +25,14 @@
protected final WeakIdentityHashMap synchronizationPerTransaction = new
WeakIdentityHashMap();
private QueueingProcessor queueingProcessor;
- public void performWork(Work work, EventSource session) {
- if ( session.isTransactionInProgress() ) {
- Transaction transaction = session.getTransaction();
+ public void performWork(Work work, TransactionContext transactionContext) {
+ if ( transactionContext.isTxInProgress() ) {
+ Object transaction = transactionContext.getTransactionIdentifier();
PostTransactionWorkQueueSynchronization txSync =
(PostTransactionWorkQueueSynchronization)
synchronizationPerTransaction.get( transaction );
if ( txSync == null || txSync.isConsumed() ) {
txSync = new PostTransactionWorkQueueSynchronization( queueingProcessor,
synchronizationPerTransaction );
- transaction.registerSynchronization( txSync );
+ transactionContext.registerSynchronization( txSync );
synchronizationPerTransaction.put(transaction, txSync);
}
txSync.add( work );
Modified:
search/branches/jboss_cache_integration/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
---
search/branches/jboss_cache_integration/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2008-06-18
06:04:17 UTC (rev 14775)
+++
search/branches/jboss_cache_integration/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2008-06-18
14:46:01 UTC (rev 14776)
@@ -1,10 +1,9 @@
//$Id$
package org.hibernate.search.event;
-import java.io.Serializable;
-
import org.hibernate.cfg.Configuration;
import org.hibernate.event.AbstractEvent;
+import org.hibernate.event.Destructible;
import org.hibernate.event.Initializable;
import org.hibernate.event.PostDeleteEvent;
import org.hibernate.event.PostDeleteEventListener;
@@ -12,13 +11,15 @@
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PostUpdateEvent;
import org.hibernate.event.PostUpdateEventListener;
-import org.hibernate.event.Destructible;
+import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkType;
-import org.hibernate.search.backend.Work;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.transaction.EventSourceTransactionContext;
+import java.io.Serializable;
+
/**
* This listener supports setting a parent directory for all generated index files.
* It also supports setting the analyzer class to be used.
@@ -30,64 +31,78 @@
//TODO work on sharing the same indexWriters and readers across a single post
operation...
//TODO implement and use a LockableDirectoryProvider that wraps a DP to handle the lock
inside the LDP
public class FullTextIndexEventListener implements PostDeleteEventListener,
PostInsertEventListener,
- PostUpdateEventListener, Initializable, Destructible {
+ PostUpdateEventListener, Initializable, Destructible
+{
+ @SuppressWarnings({"WeakerAccess"})
+ protected boolean used;
+ protected SearchFactoryImplementor searchFactoryImplementor;
- @SuppressWarnings( { "WeakerAccess" } )
- protected boolean used;
- protected SearchFactoryImplementor searchFactoryImplementor;
+ public void initialize(Configuration cfg)
+ {
+ searchFactoryImplementor = SearchFactoryImpl.getSearchFactory(cfg);
+ String indexingStrategy = searchFactoryImplementor.getIndexingStrategy();
+ if ("event".equals(indexingStrategy))
+ {
+ used = searchFactoryImplementor.getDocumentBuilders().size() != 0;
+ }
+ else if ("manual".equals(indexingStrategy))
+ {
+ used = false;
+ }
+ }
- public void initialize(Configuration cfg) {
- searchFactoryImplementor = SearchFactoryImpl.getSearchFactory( cfg );
- String indexingStrategy = searchFactoryImplementor.getIndexingStrategy();
- if ( "event".equals( indexingStrategy ) ) {
- used = searchFactoryImplementor.getDocumentBuilders().size() != 0;
- }
- else if ( "manual".equals( indexingStrategy ) ) {
- used = false;
- }
- }
+ public SearchFactoryImplementor getSearchFactoryImplementor()
+ {
+ return searchFactoryImplementor;
+ }
- public SearchFactoryImplementor getSearchFactoryImplementor() {
- return searchFactoryImplementor;
- }
+ public void onPostDelete(PostDeleteEvent event)
+ {
+ if (used &&
searchFactoryImplementor.getDocumentBuilders().containsKey(event.getEntity().getClass()))
+ {
+ processWork(event.getEntity(), event.getId(), WorkType.DELETE, event);
+ }
+ }
- public void onPostDelete(PostDeleteEvent event) {
- if ( used && searchFactoryImplementor.getDocumentBuilders().containsKey(
event.getEntity().getClass() ) ) {
- processWork( event.getEntity(), event.getId(), WorkType.DELETE, event );
- }
- }
+ public void onPostInsert(PostInsertEvent event)
+ {
+ if (used)
+ {
+ final Object entity = event.getEntity();
+ DocumentBuilder<Object> builder =
searchFactoryImplementor.getDocumentBuilders().get(entity.getClass());
+ //not strictly necessary but a small optimization
+ if (builder != null)
+ {
+ Serializable id = event.getId();
+ processWork(entity, id, WorkType.ADD, event);
+ }
+ }
+ }
- public void onPostInsert(PostInsertEvent event) {
- if (used) {
- final Object entity = event.getEntity();
- DocumentBuilder<Object> builder =
searchFactoryImplementor.getDocumentBuilders().get( entity.getClass() );
- //not strictly necessary but a small optimization
- if ( builder != null ) {
- Serializable id = event.getId();
- processWork( entity, id, WorkType.ADD, event );
- }
- }
- }
+ public void onPostUpdate(PostUpdateEvent event)
+ {
+ if (used)
+ {
+ final Object entity = event.getEntity();
+ //not strictly necessary but a small optimization
+ DocumentBuilder<Object> builder =
searchFactoryImplementor.getDocumentBuilders().get(entity.getClass());
+ if (builder != null)
+ {
+ Serializable id = event.getId();
+ processWork(entity, id, WorkType.UPDATE, event);
+ }
+ }
+ }
- public void onPostUpdate(PostUpdateEvent event) {
- if (used) {
- final Object entity = event.getEntity();
- //not strictly necessary but a small optimization
- DocumentBuilder<Object> builder =
searchFactoryImplementor.getDocumentBuilders().get( entity.getClass() );
- if ( builder != null ) {
- Serializable id = event.getId();
- processWork( entity, id, WorkType.UPDATE, event );
- }
- }
- }
+ @SuppressWarnings({"WeakerAccess"})
+ protected void processWork(Object entity, Serializable id, WorkType workType,
AbstractEvent event)
+ {
+ Work work = new Work(entity, id, workType);
+ searchFactoryImplementor.getWorker().performWork(work, new
EventSourceTransactionContext(event.getSession()));
+ }
- @SuppressWarnings( { "WeakerAccess" } )
- protected void processWork(Object entity, Serializable id, WorkType workType,
AbstractEvent event) {
- Work work = new Work(entity, id, workType);
- searchFactoryImplementor.getWorker().performWork( work, event.getSession() );
- }
-
- public void cleanup() {
- searchFactoryImplementor.close();
- }
+ public void cleanup()
+ {
+ searchFactoryImplementor.close();
+ }
}
Modified:
search/branches/jboss_cache_integration/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
---
search/branches/jboss_cache_integration/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-06-18
06:04:17 UTC (rev 14775)
+++
search/branches/jboss_cache_integration/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-06-18
14:46:01 UTC (rev 14776)
@@ -1,29 +1,7 @@
//$Id$
package org.hibernate.search.impl;
-import java.io.Serializable;
-import java.sql.Connection;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.hibernate.CacheMode;
-import org.hibernate.Criteria;
-import org.hibernate.EntityMode;
-import org.hibernate.Filter;
-import org.hibernate.FlushMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.Interceptor;
-import org.hibernate.LockMode;
-import org.hibernate.Query;
-import org.hibernate.ReplicationMode;
-import org.hibernate.SQLQuery;
-import org.hibernate.ScrollMode;
-import org.hibernate.ScrollableResults;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
+import org.hibernate.*;
import org.hibernate.classic.Session;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.EntityKey;
@@ -48,10 +26,19 @@
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.query.FullTextQueryImpl;
+import org.hibernate.search.transaction.EventSourceTransactionContext;
+import org.hibernate.search.transaction.TransactionContext;
import org.hibernate.search.util.ContextHelper;
import org.hibernate.stat.SessionStatistics;
import org.hibernate.type.Type;
+import java.io.Serializable;
+import java.sql.Connection;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/**
* Lucene full text search aware session.
*
@@ -61,13 +48,13 @@
*/
public class FullTextSessionImpl implements FullTextSession, SessionImplementor {
private final Session session;
- private final EventSource eventSource;
+ private final TransactionContext transactionContext;
private final SessionImplementor sessionImplementor;
private transient SearchFactoryImplementor searchFactory;
public FullTextSessionImpl(org.hibernate.Session session) {
this.session = (Session) session;
- this.eventSource = (EventSource) session;
+ this.transactionContext = new EventSourceTransactionContext((EventSource) session);
this.sessionImplementor = (SessionImplementor) session;
}
@@ -116,7 +103,7 @@
type = WorkType.PURGE;
}
Work work = new Work(entityType, id, type);
- searchFactoryImplementor.getWorker().performWork( work, eventSource );
+ searchFactoryImplementor.getWorker().performWork( work, transactionContext );
}
}
@@ -137,7 +124,7 @@
if ( builder != null ) {
Serializable id = session.getIdentifier( entity );
Work work = new Work(entity, id, WorkType.INDEX);
- searchFactoryImplementor.getWorker().performWork( work, eventSource );
+ searchFactoryImplementor.getWorker().performWork( work, transactionContext );
}
//TODO
//need to add elements in a queue kept at the Session level
Added:
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/EventSourceTransactionContext.java
===================================================================
---
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/EventSourceTransactionContext.java
(rev 0)
+++
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/EventSourceTransactionContext.java 2008-06-18
14:46:01 UTC (rev 14776)
@@ -0,0 +1,36 @@
+package org.hibernate.search.transaction;
+
+import org.hibernate.Transaction;
+import org.hibernate.event.EventSource;
+
+import javax.transaction.Synchronization;
+
+/**
+@author Navin Surtani - navin(a)surtani.org
+ */
+public class EventSourceTransactionContext implements TransactionContext
+{
+ EventSource eventSource;
+
+ public EventSourceTransactionContext(EventSource eventSource)
+ {
+ this.eventSource = eventSource;
+ }
+
+ public Object getTransactionIdentifier()
+ {
+ return eventSource.getTransaction();
+ }
+
+ public void registerSynchronization(Synchronization synchronization)
+ {
+ Transaction transaction = eventSource.getTransaction();
+ transaction.registerSynchronization(synchronization);
+ }
+
+ public boolean isTxInProgress()
+ {
+ return eventSource.isTransactionInProgress();
+ }
+
+}
Added:
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/TransactionContext.java
===================================================================
---
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/TransactionContext.java
(rev 0)
+++
search/branches/jboss_cache_integration/src/java/org/hibernate/search/transaction/TransactionContext.java 2008-06-18
14:46:01 UTC (rev 14776)
@@ -0,0 +1,22 @@
+package org.hibernate.search.transaction;
+
+import javax.transaction.Synchronization;
+
+/**
+@author Navin Surtani - navin(a)surtani.org
+ */
+public interface TransactionContext
+{
+ /**
+ *@return A boolean whether a transaction is in progress or not.
+ */
+ public boolean isTxInProgress();
+
+ /**
+ *
+ * @return a transaction object.
+ */
+ public Object getTransactionIdentifier();
+
+ public void registerSynchronization(Synchronization synchronization);
+}
Added: search/branches/jboss_cache_integration/x.y
===================================================================