Hibernate SVN: r11020 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 07:00:02 -0500 (Mon, 08 Jan 2007)
New Revision: 11020
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competitor.java
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
Log:
Testcase for HHH-2292
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2007-01-08 11:59:41 UTC (rev 11019)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2007-01-08 12:00:02 UTC (rev 11020)
@@ -20,7 +20,7 @@
}
public String[] getMappings() {
- return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml" };
+ return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml", "ops/Competition.hbm.xml" };
}
public String getCacheConcurrencyStrategy() {
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml 2007-01-08 11:59:41 UTC (rev 11019)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml 2007-01-08 12:00:02 UTC (rev 11020)
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+-->
+
+<hibernate-mapping package="org.hibernate.test.ops">
+
+ <class name="Competition">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <list name="competitors"
+ cascade="persist,merge"
+ table="COMPET_ION_OR">
+ <key column="TION_ID"/>
+ <list-index column="INDEX_COL"/>
+ <many-to-many class="Competitor" column="TOR_ID" />
+ </list>
+ </class>
+
+ <class name="Competitor">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <property name="name"/>
+ </class>
+
+</hibernate-mapping>
+
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.java 2007-01-08 11:59:41 UTC (rev 11019)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competition.java 2007-01-08 12:00:02 UTC (rev 11020)
@@ -0,0 +1,31 @@
+//$Id: $
+package org.hibernate.test.ops;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Competition {
+ private Integer id;
+
+ private List competitors = new ArrayList();
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public List getCompetitors() {
+ return competitors;
+ }
+
+ public void setCompetitors(List competitors) {
+ this.competitors = competitors;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competitor.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competitor.java 2007-01-08 11:59:41 UTC (rev 11019)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Competitor.java 2007-01-08 12:00:02 UTC (rev 11020)
@@ -0,0 +1,34 @@
+//$Id: $
+package org.hibernate.test.ops;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Competitor {
+ public Integer id;
+ private String name;
+
+
+ public Competitor() {
+ }
+
+ public Competitor(String name) {
+ this.name = name;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2007-01-08 11:59:41 UTC (rev 11019)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2007-01-08 12:00:02 UTC (rev 11020)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import junit.framework.Test;
@@ -569,6 +570,33 @@
cleanup();
}
+ public void testMergeManyToManyWithColelctionDeference() throws Exception {
+ Competition competition = new Competition();
+ competition.getCompetitors().add( new Competitor("Name") );
+ competition.getCompetitors().add( new Competitor() );
+ competition.getCompetitors().add( new Competitor() );
+ Session s = openSession( );
+ Transaction tx = s.beginTransaction();
+ s.persist( competition );
+ s.flush();
+ s.clear();
+ List newComp = new ArrayList();
+ newComp.add( competition.getCompetitors().get(0) );
+ newComp.add( new Competitor() );
+ ( (Competitor) newComp.get(0) ).setName( "Name2" );
+ competition.setCompetitors( newComp );
+ competition = (Competition) s.merge( competition );
+ s.flush();
+ s.clear();
+ competition = (Competition) s.get( Competition.class, competition.getId() );
+ assertEquals( 2, competition.getCompetitors().size() );
+ assertEquals( "Name2", ( (Competitor) competition.getCompetitors().get(0) ).getName() );
+ tx.rollback();
+ s.close();
+
+ cleanup();
+ }
+
private void cleanup() {
Session s = openSession();
s.beginTransaction();
18 years
Hibernate SVN: r11019 - trunk/Hibernate3/test/org/hibernate/test/ops
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 06:59:41 -0500 (Mon, 08 Jan 2007)
New Revision: 11019
Added:
trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java
trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
Log:
Testcase for HHH-2292
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2007-01-07 01:05:14 UTC (rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2007-01-08 11:59:41 UTC (rev 11019)
@@ -20,7 +20,7 @@
}
public String[] getMappings() {
- return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml" };
+ return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml", "ops/Competition.hbm.xml" };
}
public String getCacheConcurrencyStrategy() {
Added: trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml 2007-01-07 01:05:14 UTC (rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml 2007-01-08 11:59:41 UTC (rev 11019)
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+-->
+
+<hibernate-mapping package="org.hibernate.test.ops">
+
+ <class name="Competition">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <list name="competitors"
+ cascade="persist,merge"
+ table="COMPET_ION_OR">
+ <key column="TION_ID"/>
+ <list-index column="INDEX_COL"/>
+ <many-to-many class="Competitor" column="TOR_ID" />
+ </list>
+ </class>
+
+ <class name="Competitor">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <property name="name"/>
+ </class>
+
+</hibernate-mapping>
+
Added: trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java 2007-01-07 01:05:14 UTC (rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java 2007-01-08 11:59:41 UTC (rev 11019)
@@ -0,0 +1,31 @@
+//$Id: $
+package org.hibernate.test.ops;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Competition {
+ private Integer id;
+
+ private List competitors = new ArrayList();
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public List getCompetitors() {
+ return competitors;
+ }
+
+ public void setCompetitors(List competitors) {
+ this.competitors = competitors;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java 2007-01-07 01:05:14 UTC (rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java 2007-01-08 11:59:41 UTC (rev 11019)
@@ -0,0 +1,34 @@
+//$Id: $
+package org.hibernate.test.ops;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Competitor {
+ public Integer id;
+ private String name;
+
+
+ public Competitor() {
+ }
+
+ public Competitor(String name) {
+ this.name = name;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2007-01-07 01:05:14 UTC (rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2007-01-08 11:59:41 UTC (rev 11019)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import junit.framework.Test;
@@ -569,6 +570,33 @@
cleanup();
}
+ public void testMergeManyToManyWithColelctionDeference() throws Exception {
+ Competition competition = new Competition();
+ competition.getCompetitors().add( new Competitor("Name") );
+ competition.getCompetitors().add( new Competitor() );
+ competition.getCompetitors().add( new Competitor() );
+ Session s = openSession( );
+ Transaction tx = s.beginTransaction();
+ s.persist( competition );
+ s.flush();
+ s.clear();
+ List newComp = new ArrayList();
+ newComp.add( competition.getCompetitors().get(0) );
+ newComp.add( new Competitor() );
+ ( (Competitor) newComp.get(0) ).setName( "Name2" );
+ competition.setCompetitors( newComp );
+ competition = (Competition) s.merge( competition );
+ s.flush();
+ s.clear();
+ competition = (Competition) s.get( Competition.class, competition.getId() );
+ assertEquals( 2, competition.getCompetitors().size() );
+ assertEquals( "Name2", ( (Competitor) competition.getCompetitors().get(0) ).getName() );
+ tx.rollback();
+ s.close();
+
+ cleanup();
+ }
+
private void cleanup() {
Session s = openSession();
s.beginTransaction();
18 years
Hibernate SVN: r11018 - in branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search: backend backend/impl event impl store
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-06 20:05:14 -0500 (Sat, 06 Jan 2007)
New Revision: 11018
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java
Removed:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/DirectoryProvider.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/FSDirectoryProvider.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/RAMDirectoryProvider.java
Log:
ANN-522 avoid deadlocks with multiple directoryproviders
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -13,6 +13,7 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.hibernate.HibernateException;
+import org.hibernate.AssertionFailure;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.store.DirectoryProvider;
@@ -50,6 +51,9 @@
public IndexReader getIndexReader(Class entity) {
//TODO NPEs
DirectoryProvider provider = documentBuilders.get( entity ).getDirectoryProvider();
+ //one cannot access a reader for update after a writer has been accessed
+ if ( writers.containsKey( provider ) )
+ throw new AssertionFailure("Tries to read for update a index while a writer is accessed" + entity);
IndexReader reader = readers.get( provider );
if ( reader != null ) return reader;
lockProvider( provider );
@@ -65,6 +69,17 @@
public IndexWriter getIndexWriter(Class entity) {
DirectoryProvider provider = documentBuilders.get( entity ).getDirectoryProvider();
+ //one has to close a reader for update before a writer is accessed
+ IndexReader reader = readers.get( provider );
+ if ( reader != null ) {
+ try {
+ reader.close();
+ }
+ catch (IOException e) {
+ throw new HibernateException( "Exception while closing IndexReader", e );
+ }
+ readers.remove( provider );
+ }
IndexWriter writer = writers.get( provider );
if ( writer != null ) return writer;
lockProvider( provider );
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -1,95 +0,0 @@
-//$Id: $
-package org.hibernate.search.backend.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.store.DirectoryProvider;
-import org.hibernate.search.backend.impl.LuceneWorker;
-import org.hibernate.search.backend.WorkQueue;
-import org.hibernate.search.backend.Workspace;
-import org.hibernate.search.backend.Work;
-import org.hibernate.search.backend.UpdateWork;
-import org.hibernate.search.backend.DeleteWork;
-import org.hibernate.search.backend.AddWork;
-
-/**
- * Batch work until #performWork is called.
- * The work is then executed synchronously or asynchronously
- *
- * @author Emmanuel Bernard
- */
-public class BatchLuceneWorkQueue implements WorkQueue {
- private Workspace workspace;
- private LuceneWorker worker;
- private List<Work> queue = new ArrayList<Work>();
- private boolean sync;
-
- public BatchLuceneWorkQueue(Map<Class, DocumentBuilder<Object>> documentBuilders,
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders, boolean sync) {
- workspace = new Workspace( documentBuilders, lockableDirectoryProviders );
- worker = new LuceneWorker( workspace );
- this.sync = sync;
- }
-
- public void add(Work work) {
- //TODO optimize by getting rid of dupe works
- if ( work instanceof UpdateWork ) {
- //split in 2 to optimize the process (reader first, writer next
- queue.add( new DeleteWork( work.getId(), work.getEntity() ) );
- queue.add( new AddWork( work.getId(), work.getEntity(), work.getDocument() ) );
- }
- else {
- queue.add( work );
- }
- }
-
- //TODO implements parallel batchWorkers (one per Directory)
- public void performWork() {
- BatchWorker batchWorker = new BatchWorker( queue, workspace, worker );
- if (sync) {
- batchWorker.run();
- }
- else {
- //TODO pool threads?
- Thread thread = new Thread(batchWorker);
- thread.start();
- }
- }
-
- public void cancelWork() {
- queue.clear();
- }
-
- private class BatchWorker implements Runnable {
- private List<Work> queue;
- private Workspace workspace;
- private LuceneWorker worker;
-
- public BatchWorker(List<Work> queue, Workspace workspace, LuceneWorker worker) {
- this.queue = queue;
- this.workspace = workspace;
- this.worker = worker;
- }
-
- public void run() {
- try {
- //use of index reader
- for ( Work work : queue ) {
- if ( work instanceof DeleteWork ) worker.performWork( work );
- }
- workspace.clean(); //close readers
- for ( Work work : queue ) {
- if ( work instanceof AddWork ) worker.performWork( work );
- }
- }
- finally {
- workspace.clean();
- queue.clear();
- }
- }
- }
-}
Copied: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java (from rev 11017, branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java)
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -0,0 +1,124 @@
+//$Id: $
+package org.hibernate.search.backend.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.backend.impl.LuceneWorker;
+import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.backend.Workspace;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.UpdateWork;
+import org.hibernate.search.backend.DeleteWork;
+import org.hibernate.search.backend.AddWork;
+
+/**
+ * Batch work until #performWork is called.
+ * The work is then executed synchronously or asynchronously
+ *
+ * @author Emmanuel Bernard
+ */
+public class BatchedWorkQueue implements WorkQueue {
+ private List<Work> queue = new ArrayList<Work>();
+ private boolean sync;
+ Map<Class, DocumentBuilder<Object>> documentBuilders;
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+
+ public BatchedWorkQueue(Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders, boolean sync) {
+ this.documentBuilders = documentBuilders;
+ this.lockableDirectoryProviders = lockableDirectoryProviders;
+ this.sync = sync;
+ }
+
+ public void add(Work work) {
+ //TODO optimize by getting rid of dupe works
+ if ( work instanceof UpdateWork ) {
+ //split in 2 to optimize the process (reader first, writer next
+ queue.add( new DeleteWork( work.getId(), work.getEntity() ) );
+ queue.add( new AddWork( work.getId(), work.getEntity(), work.getDocument() ) );
+ }
+ else {
+ queue.add( work );
+ }
+ }
+
+ //TODO implements parallel batchWorkers (one per Directory)
+ public void performWork() {
+ BatchWorker batchWorker = new BatchWorker( queue, documentBuilders, lockableDirectoryProviders );
+ if (sync) {
+ batchWorker.run();
+ }
+ else {
+ //TODO pool threads?
+ Thread thread = new Thread(batchWorker);
+ thread.start();
+ }
+ }
+
+ public void cancelWork() {
+ queue.clear();
+ }
+
+ private class BatchWorker implements Runnable {
+ private List<Work> queue;
+ private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+ private Map<Class, DocumentBuilder<Object>> documentBuilders;
+
+
+ public BatchWorker(List<Work> queue, Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ this.queue = queue;
+ this.documentBuilders = documentBuilders;
+ this.lockableDirectoryProviders = lockableDirectoryProviders;
+ }
+
+ public void run() {
+ Workspace workspace;
+ LuceneWorker worker;
+ workspace = new Workspace( documentBuilders, lockableDirectoryProviders );
+ worker = new LuceneWorker( workspace );
+ try {
+ deadlockFreeQueue(queue, workspace);
+ for ( Work work : queue ) {
+ worker.performWork( work );
+ }
+ }
+ finally {
+ workspace.clean();
+ queue.clear();
+ }
+ }
+
+ /**
+ * one must lock the directory providers in the exact same order to avoid
+ * dead lock between concurrent threads or processes
+ * To achieve that, the work will be done per directory provider
+ */
+ private void deadlockFreeQueue(List<Work> queue, final Workspace workspace) {
+ Collections.sort( queue, new Comparator<Work>() {
+ public int compare(Work o1, Work o2) {
+ long h1 = getWorkHashCode( o1, workspace );
+ long h2 = getWorkHashCode( o2, workspace );
+ return h1 < h2 ?
+ -1 :
+ h1 == h2 ?
+ 0 :
+ 1;
+ }
+ } );
+ }
+
+ private long getWorkHashCode(Work work, Workspace workspace) {
+ long h = workspace.getDocumentBuilder( work.getEntity() ).hashCode() * 2;
+ if (work instanceof AddWork) h+=1; //addwork after deleteWork
+ return h;
+ }
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -38,7 +38,7 @@
PostTransactionWorkQueueSynchronization txSync = (PostTransactionWorkQueueSynchronization)
queuePerTransaction.get( transaction );
if ( txSync == null || txSync.isConsumed() ) {
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
+ WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
txSync = new PostTransactionWorkQueueSynchronization( workQueue, queuePerTransaction );
transaction.registerSynchronization( txSync );
queuePerTransaction.put(transaction, txSync);
@@ -46,7 +46,7 @@
txSync.add( work );
}
else {
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
+ WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
PostTransactionWorkQueueSynchronization sync = new PostTransactionWorkQueueSynchronization( workQueue );
sync.add( work );
sync.afterCompletion( Status.STATUS_COMMITTED );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -7,7 +7,6 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
-import javax.transaction.Status;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -15,7 +14,6 @@
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.hibernate.HibernateException;
-import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.event.AbstractEvent;
@@ -27,17 +25,13 @@
import org.hibernate.event.PostUpdateEvent;
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.search.Environment;
-import org.hibernate.search.util.WeakIdentityHashMap;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.backend.AddWork;
import org.hibernate.search.backend.DeleteWork;
import org.hibernate.search.backend.UpdateWork;
import org.hibernate.search.backend.Work;
-import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.backend.Worker;
import org.hibernate.search.backend.WorkerFactory;
-import org.hibernate.search.backend.impl.BatchLuceneWorkQueue;
-import org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.DirectoryProviderFactory;
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -33,7 +33,7 @@
import org.hibernate.search.backend.UpdateWork;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkQueue;
-import org.hibernate.search.backend.impl.BatchLuceneWorkQueue;
+import org.hibernate.search.backend.impl.BatchedWorkQueue;
import org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.FullTextSession;
@@ -113,7 +113,7 @@
Map<Class, DocumentBuilder<Object>> documentBuilders,
Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
//FIXME should be harmonized with the WorkerFactory?
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders, true );
+ WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, true );
return new PostTransactionWorkQueueSynchronization( workQueue );
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/DirectoryProvider.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/DirectoryProvider.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/DirectoryProvider.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -9,9 +9,10 @@
/**
* Set up and provide a Lucene <code>Directory</code>
* <code>equals()</code> and <code>hashCode()</code> must guaranty equality
- * between two providers pointing to the same underlying Lucene Store
- * This class must be thread safe regarding <code>getDirectory()</code>
- * calls
+ * between two providers pointing to the same underlying Lucene Store.
+ * Besides that, hashCode ordering is used to avoid deadlock when locking a directory provider.
+ *
+ * This class must be thread safe regarding <code>getDirectory()</code> calls
*
* @author Emmanuel Bernard
* @author Sylvain Vieujot
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/FSDirectoryProvider.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/FSDirectoryProvider.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/FSDirectoryProvider.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -75,6 +75,7 @@
// this code is actually broken since the value change after initialize call
// but from a practical POV this is fine since we only call this method
// after initialize call
- return indexName.hashCode();
+ int hash = 11;
+ return 37 * hash + indexName.hashCode();
}
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/RAMDirectoryProvider.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/RAMDirectoryProvider.java 2007-01-06 17:12:57 UTC (rev 11017)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/store/RAMDirectoryProvider.java 2007-01-07 01:05:14 UTC (rev 11018)
@@ -51,7 +51,8 @@
// this code is actually broken since the value change after initialize call
// but from a practical POV this is fine since we only call this method
// after initialize call
- return indexName.hashCode();
+ int hash = 7;
+ return 29 * hash + indexName.hashCode();
}
}
18 years
Hibernate SVN: r11017 - in branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search: . backend backend/impl event impl
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-06 12:12:57 -0500 (Sat, 06 Jan 2007)
New Revision: 11017
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkerFactory.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/Environment.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
Log:
ANN-519 ANN-520
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/Environment.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/Environment.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/Environment.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -14,4 +14,7 @@
* Lucene analyser
*/
public static final String ANALYZER_CLASS = "hibernate.search.analyzer";
+
+ public static final String WORKER_PREFIX = "hibernate.search.worker.";
+ public static final String WORKER_IMPL = WORKER_PREFIX + "impl";
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.search.backend;
+
+import java.util.Properties;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.hibernate.event.AbstractEvent;
+import org.hibernate.event.EventSource;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.store.DirectoryProvider;
+
+/**
+ * Perform work for a given session. This implementation has to be multi threaded
+ * @author Emmanuel Bernard
+ */
+//TODO merge worker and workQueue to do a list of workers through work delegation
+public interface Worker {
+ void performWork(Work work, EventSource session);
+
+ void initialize(Properties props, Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders);
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkerFactory.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkerFactory.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkerFactory.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -0,0 +1,73 @@
+//$Id: $
+package org.hibernate.search.backend;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.backend.impl.TransactionalWorker;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.Environment;
+import org.hibernate.util.StringHelper;
+import org.hibernate.util.ReflectHelper;
+import org.hibernate.AnnotationException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class WorkerFactory {
+ private Map<Class, DocumentBuilder<Object>> documentBuilders;
+ private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+ private Configuration cfg;
+
+ public void configure(Configuration cfg,
+ Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ this.documentBuilders = documentBuilders;
+ this.lockableDirectoryProviders = lockableDirectoryProviders;
+ this.cfg = cfg;
+ }
+
+ private static Properties getProperties(Configuration cfg) {
+ Properties props = cfg.getProperties();
+ Properties workerProperties = new Properties();
+ for ( Map.Entry entry : props.entrySet() ) {
+ String key = (String) entry.getKey();
+ if ( key.startsWith( Environment.WORKER_PREFIX ) ) {
+ workerProperties.setProperty( key.substring( Environment.WORKER_PREFIX.length() ), (String) entry.getValue() );
+ }
+ }
+ return workerProperties;
+ }
+
+ public Worker createWorker() {
+ Properties props = getProperties( cfg );
+ String impl = props.getProperty( Environment.WORKER_IMPL );
+ Worker worker;
+ if ( StringHelper.isEmpty( impl ) ) {
+ worker = new TransactionalWorker();
+ }
+ else if ( "transaction".equalsIgnoreCase( impl ) ) {
+ worker = new TransactionalWorker();
+ }
+ else {
+ try {
+ Class workerClass = ReflectHelper.classForName( impl, WorkerFactory.class );
+ worker = (Worker) workerClass.newInstance();
+ }
+ catch (ClassNotFoundException e) {
+ throw new AnnotationException("Unable to find worker class: " + impl, e );
+ }
+ catch (IllegalAccessException e) {
+ throw new AnnotationException("Unable to instanciate worker class: " + impl, e );
+ }
+ catch (InstantiationException e) {
+ throw new AnnotationException("Unable to instanciate worker class: " + impl, e );
+ }
+ }
+ worker.initialize( props, documentBuilders, lockableDirectoryProviders );
+ return worker;
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Workspace.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -91,7 +91,7 @@
}
private void cleanUp(HibernateException originalException) {
- //release all readers and writers, then reelase locks
+ //release all readers and writers, then release locks
HibernateException raisedException = originalException;
for ( IndexReader reader : readers.values() ) {
try {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchLuceneWorkQueue.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -17,17 +17,22 @@
import org.hibernate.search.backend.AddWork;
/**
+ * Batch work until #performWork is called.
+ * The work is then executed synchronously or asynchronously
+ *
* @author Emmanuel Bernard
*/
public class BatchLuceneWorkQueue implements WorkQueue {
private Workspace workspace;
private LuceneWorker worker;
private List<Work> queue = new ArrayList<Work>();
+ private boolean sync;
public BatchLuceneWorkQueue(Map<Class, DocumentBuilder<Object>> documentBuilders,
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders, boolean sync) {
workspace = new Workspace( documentBuilders, lockableDirectoryProviders );
worker = new LuceneWorker( workspace );
+ this.sync = sync;
}
public void add(Work work) {
@@ -42,24 +47,49 @@
}
}
+ //TODO implements parallel batchWorkers (one per Directory)
public void performWork() {
- try {
- //use of index reader
- for ( Work work : queue ) {
- if ( work instanceof DeleteWork ) worker.performWork( work );
- }
- workspace.clean(); //close readers
- for ( Work work : queue ) {
- if ( work instanceof AddWork ) worker.performWork( work );
- }
+ BatchWorker batchWorker = new BatchWorker( queue, workspace, worker );
+ if (sync) {
+ batchWorker.run();
}
- finally {
- workspace.clean();
- queue.clear();
+ else {
+ //TODO pool threads?
+ Thread thread = new Thread(batchWorker);
+ thread.start();
}
}
public void cancelWork() {
queue.clear();
}
+
+ private class BatchWorker implements Runnable {
+ private List<Work> queue;
+ private Workspace workspace;
+ private LuceneWorker worker;
+
+ public BatchWorker(List<Work> queue, Workspace workspace, LuceneWorker worker) {
+ this.queue = queue;
+ this.workspace = workspace;
+ this.worker = worker;
+ }
+
+ public void run() {
+ try {
+ //use of index reader
+ for ( Work work : queue ) {
+ if ( work instanceof DeleteWork ) worker.performWork( work );
+ }
+ workspace.clean(); //close readers
+ for ( Work work : queue ) {
+ if ( work instanceof AddWork ) worker.performWork( work );
+ }
+ }
+ finally {
+ workspace.clean();
+ queue.clear();
+ }
+ }
+ }
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -18,10 +18,16 @@
private boolean consumed;
private WeakIdentityHashMap queuePerTransaction;
+ /**
+ * out of transaction work
+ */
public PostTransactionWorkQueueSynchronization(WorkQueue workQueue) {
this.workQueue = workQueue;
}
+ /**
+ * in transaction work
+ */
public PostTransactionWorkQueueSynchronization(WorkQueue workQueue, WeakIdentityHashMap queuePerTransaction) {
this(workQueue);
this.queuePerTransaction = queuePerTransaction;
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -0,0 +1,63 @@
+//$Id: $
+package org.hibernate.search.backend.impl;
+
+import java.util.Properties;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantLock;
+import javax.transaction.Status;
+
+import org.hibernate.search.backend.Worker;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.util.WeakIdentityHashMap;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.Environment;
+import org.hibernate.event.EventSource;
+import org.hibernate.Transaction;
+
+/**
+ * Queue works per transaction.
+ * If out of transaction, the work is executed right away
+ *
+ * When <code>hibernate.search.worker.type</code> is set to <code>async</code>
+ * the work is done in a
+ *
+ * @author Emmanuel Bernard
+ */
+public class TransactionalWorker implements Worker {
+ //not a synchronized map since for a given transaction, we have not concurrent access
+ protected WeakIdentityHashMap queuePerTransaction = new WeakIdentityHashMap();
+ private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+ private Map<Class, DocumentBuilder<Object>> documentBuilders;
+ private boolean sync;
+
+ public void performWork(Work work, EventSource session) {
+ if ( session.isTransactionInProgress() ) {
+ Transaction transaction = session.getTransaction();
+ PostTransactionWorkQueueSynchronization txSync = (PostTransactionWorkQueueSynchronization)
+ queuePerTransaction.get( transaction );
+ if ( txSync == null || txSync.isConsumed() ) {
+ WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
+ txSync = new PostTransactionWorkQueueSynchronization( workQueue, queuePerTransaction );
+ transaction.registerSynchronization( txSync );
+ queuePerTransaction.put(transaction, txSync);
+ }
+ txSync.add( work );
+ }
+ else {
+ WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
+ PostTransactionWorkQueueSynchronization sync = new PostTransactionWorkQueueSynchronization( workQueue );
+ sync.add( work );
+ sync.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+
+ public void initialize(Properties props, Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ this.documentBuilders = documentBuilders;
+ this.lockableDirectoryProviders = lockableDirectoryProviders;
+ //default to sync if none defined
+ this.sync = ! "async".equalsIgnoreCase( props.getProperty( Environment.WORKER_PREFIX + "type") );
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -6,7 +6,6 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.util.WeakHashMap;
import java.util.concurrent.locks.ReentrantLock;
import javax.transaction.Status;
@@ -35,6 +34,8 @@
import org.hibernate.search.backend.UpdateWork;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.backend.Worker;
+import org.hibernate.search.backend.WorkerFactory;
import org.hibernate.search.backend.impl.BatchLuceneWorkQueue;
import org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization;
import org.hibernate.search.engine.DocumentBuilder;
@@ -58,9 +59,9 @@
public class FullTextIndexEventListener implements PostDeleteEventListener, PostInsertEventListener,
PostUpdateEventListener, Initializable {
protected ReflectionManager reflectionManager;
- //not a synchronized map since for a given transaction, we have not concurrent access
- protected WeakIdentityHashMap queuePerTransaction;
+ protected Worker worker;
+
//FIXME keeping this here is a bad decision since you might want to search indexes wo maintain it
@Deprecated
public Map<Class, DocumentBuilder<Object>> getDocumentBuilders() {
@@ -80,7 +81,6 @@
if ( initialized ) return;
//yuk
reflectionManager = ( (AnnotationConfiguration) cfg ).createExtendedMappings().getReflectionManager();
- queuePerTransaction = new WeakIdentityHashMap();
Class analyzerClass;
String analyzerClassName = cfg.getProperty( Environment.ANALYZER_CLASS );
@@ -136,6 +136,9 @@
for ( DocumentBuilder builder : documentBuilders.values() ) {
builder.postInitialize( indexedClasses );
}
+ WorkerFactory workerFactory = new WorkerFactory();
+ workerFactory.configure( cfg, documentBuilders, lockableDirectoryProviders );
+ worker = workerFactory.createWorker();
initialized = true;
}
@@ -169,24 +172,7 @@
}
private void processWork(Work work, AbstractEvent event) {
- if ( event.getSession().isTransactionInProgress() ) {
- Transaction transaction = event.getSession().getTransaction();
- PostTransactionWorkQueueSynchronization sync = (PostTransactionWorkQueueSynchronization)
- queuePerTransaction.get( transaction );
- if ( sync == null || sync.isConsumed() ) {
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders );
- sync = new PostTransactionWorkQueueSynchronization( workQueue, queuePerTransaction );
- transaction.registerSynchronization( sync );
- queuePerTransaction.put(transaction, sync);
- }
- sync.add( work );
- }
- else {
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders );
- PostTransactionWorkQueueSynchronization sync = new PostTransactionWorkQueueSynchronization( workQueue );
- sync.add( work );
- sync.afterCompletion( Status.STATUS_COMMITTED );
- }
+ worker.performWork( work, event.getSession() );
}
public Map<DirectoryProvider, ReentrantLock> getLockableDirectoryProviders() {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-01-04 10:42:06 UTC (rev 11016)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-01-06 17:12:57 UTC (rev 11017)
@@ -112,7 +112,8 @@
private PostTransactionWorkQueueSynchronization createWorkQueueSync(
Map<Class, DocumentBuilder<Object>> documentBuilders,
Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders );
+ //FIXME should be harmonized with the WorkerFactory?
+ WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders, true );
return new PostTransactionWorkQueueSynchronization( workQueue );
}
18 years
Hibernate SVN: r11016 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-04 05:42:06 -0500 (Thu, 04 Jan 2007)
New Revision: 11016
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java
Log:
bump
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java 2007-01-04 10:39:51 UTC (rev 11015)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java 2007-01-04 10:42:06 UTC (rev 11016)
@@ -5,7 +5,7 @@
final public class Version {
- public static final String VERSION = "3.2.0.snapshotb9";
+ public static final String VERSION = "3.2.0.b9";
private static final Version instance = new Version();
18 years
Hibernate SVN: r11015 - tags/TOOLS_3_2_0_BETA9
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-04 05:39:51 -0500 (Thu, 04 Jan 2007)
New Revision: 11015
Added:
tags/TOOLS_3_2_0_BETA9/HibernateExt/
Log:
tools b9
Copied: tags/TOOLS_3_2_0_BETA9/HibernateExt (from rev 11014, branches/Branch_3_2/HibernateExt)
18 years
Hibernate SVN: r11014 - tags
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-04 05:38:11 -0500 (Thu, 04 Jan 2007)
New Revision: 11014
Added:
tags/TOOLS_3_2_0_BETA9/
Log:
Created folder remotely
18 years
Hibernate SVN: r11013 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-04 03:31:19 -0500 (Thu, 04 Jan 2007)
New Revision: 11013
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
Log:
imports
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2007-01-04 08:30:46 UTC (rev 11012)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2007-01-04 08:31:19 UTC (rev 11013)
@@ -9,7 +9,6 @@
import java.util.StringTokenizer;
import org.hibernate.cfg.Configuration;
-import org.hibernate.engine.CascadeStyle;
import org.hibernate.mapping.Component;
import org.hibernate.tool.hbm2x.pojo.ComponentPOJOClass;
import org.hibernate.tool.hbm2x.pojo.POJOClass;
@@ -17,7 +16,7 @@
public class GenericExporter extends AbstractExporter {
-
+
static abstract class ModelIterator {
abstract void process(GenericExporter ge);
}
18 years
Hibernate SVN: r11012 - branches/Branch_3_2/HibernateExt/tools/doc/reference/en/images
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-04 03:30:46 -0500 (Thu, 04 Jan 2007)
New Revision: 11012
Modified:
branches/Branch_3_2/HibernateExt/tools/doc/reference/en/images/consolecfgwizard.jpg
Log:
updated screenshot
Modified: branches/Branch_3_2/HibernateExt/tools/doc/reference/en/images/consolecfgwizard.jpg
===================================================================
(Binary files differ)
18 years