[hibernate-commits] Hibernate SVN: r15495 - search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/engine.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Nov 4 10:58:44 EST 2008


Author: anthonyHib
Date: 2008-11-04 10:58:44 -0500 (Tue, 04 Nov 2008)
New Revision: 15495

Modified:
   search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/engine/DocumentBuilder.java
Log:
JBPAPP-1361 port of HSEARCH-257 Ignore delete operation when Core does update then delete on the same entity

Modified: search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/engine/DocumentBuilder.java	2008-11-04 03:12:55 UTC (rev 15494)
+++ search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/engine/DocumentBuilder.java	2008-11-04 15:58:44 UTC (rev 15495)
@@ -3,13 +3,7 @@
 
 import java.io.Serializable;
 import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -399,18 +393,39 @@
 	//TODO could we use T instead of EntityClass?
 	public void addWorkToQueue(Class entityClass, T entity, Serializable id, WorkType workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor) {
 		//TODO with the caller loop we are in a n^2: optimize it using a HashMap for work recognition
+		List<LuceneWork> toDelete = new ArrayList<LuceneWork>();
+		boolean duplicateDelete = false;
 		for (LuceneWork luceneWork : queue) {
-			//any work on the same entity should be ignored
-			if ( luceneWork.getEntityClass() == entityClass
-					 ) {
+	   		//avoid unecessary duplicated work
+			if ( luceneWork.getEntityClass() == entityClass ) {
 				Serializable currentId = luceneWork.getId();
-				if ( currentId != null  && currentId.equals( id ) ) { //find a way to use Type.equals(x,y)
-					return;
+				//currentId != null => either ADD or Delete work
+				if ( currentId != null && currentId.equals( id ) ) { //find a way to use Type.equals(x,y)
+					if (workType == WorkType.DELETE) { //TODO add PURGE?
+						//DELETE should have precedence over any update before (HSEARCH-257)
+						//if an Add work is here, remove it
+						//if an other delete is here remember but still search for Add
+						if (luceneWork instanceof AddLuceneWork) {
+							toDelete.add( luceneWork );
+						}
+						else if (luceneWork instanceof DeleteLuceneWork) {
+							duplicateDelete = true;
+						}
+					}
+					else {
+						//we can safely say we are out, the other work is an ADD
+						return;
+					}
 				}
 				//TODO do something to avoid multiple PURGE ALL and OPTIMIZE
 			}
+		}
 
+   		for (LuceneWork luceneWork : toDelete) {
+			queue.remove( luceneWork );
 		}
+		if (duplicateDelete) return;
+
 		boolean searchForContainers = false;
 		String idInString = idBridge.objectToString( id );
 		if ( workType == WorkType.ADD ) {




More information about the hibernate-commits mailing list