[hibernate-commits] Hibernate SVN: r19205 - in search/trunk/hibernate-search/src: test/java/org/hibernate/search/test/batchindexing and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Apr 9 15:23:02 EDT 2010


Author: sannegrinovero
Date: 2010-04-09 15:23:01 -0400 (Fri, 09 Apr 2010)
New Revision: 19205

Added:
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java
Modified:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AncientBook.java
Log:
HSEARCH-490 MassIndexer needs to use distinct on primary key selection

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java	2010-04-09 19:15:27 UTC (rev 19204)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java	2010-04-09 19:23:01 UTC (rev 19205)
@@ -34,6 +34,7 @@
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
+import org.hibernate.criterion.CriteriaSpecification;
 import org.hibernate.criterion.Restrictions;
 import org.hibernate.search.util.LoggerFactory;
 import org.slf4j.Logger;
@@ -126,6 +127,7 @@
 			.setLockMode( LockMode.NONE )
 			.setCacheable( false )
 			.setFlushMode( FlushMode.MANUAL )
+			.setResultTransformer( CriteriaSpecification.DISTINCT_ROOT_ENTITY )
 			.add( Restrictions.in( "id", listIds ) );
 		List<?> list = criteria.list();
 		monitor.entitiesLoaded( list.size() );

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AncientBook.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AncientBook.java	2010-04-09 19:15:27 UTC (rev 19204)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AncientBook.java	2010-04-09 19:23:01 UTC (rev 19205)
@@ -24,7 +24,12 @@
  */
 package org.hibernate.search.test.batchindexing;
 
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.ElementCollection;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 
 import org.hibernate.search.annotations.Indexed;
 
@@ -33,6 +38,7 @@
 public class AncientBook extends Book {
 	
 	public String catalogueGroupName = "";
+	public Set<String> alternativeTitles = new HashSet<String>();
 
 	public String getCatalogueGroupName() {
 		return catalogueGroupName;
@@ -41,5 +47,14 @@
 	public void setCatalogueGroupName(String catalogueGroupName) {
 		this.catalogueGroupName = catalogueGroupName;
 	}
+
+	@ElementCollection( fetch=FetchType.EAGER )
+	public Set<String> getAlternativeTitles() {
+		return alternativeTitles;
+	}
 	
+	public void setAlternativeTitles(Set<String> alternativeTitles) {
+		this.alternativeTitles = alternativeTitles;
+	}
+	
 }

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java	2010-04-09 19:23:01 UTC (rev 19205)
@@ -0,0 +1,92 @@
+/* $Id$
+ * 
+ * Hibernate, Relational Persistence for Idiomatic Java
+ * 
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ * 
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.search.test.batchindexing;
+
+import junit.framework.Assert;
+
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.MassIndexer;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.SearchTestCase;
+
+public class AvoidDuplicatesTest extends SearchTestCase {
+	
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+		Session session = openSession();
+		Transaction transaction = session.beginTransaction();
+		
+		AncientBook aeneid = new AncientBook();
+		aeneid.setTitle( "Aeneid" );
+		aeneid.getAlternativeTitles().add( "Aeneis" );
+		aeneid.getAlternativeTitles().add( "Eneide" );
+		session.persist( aeneid );
+		
+		AncientBook commedia = new AncientBook();
+		commedia.setTitle( "Commedia" );
+		commedia.getAlternativeTitles().add( "La Commedia" );
+		commedia.getAlternativeTitles().add( "La Divina Commedia" );
+		session.persist( commedia );
+		
+		transaction.commit();
+		session.close();
+	}
+	
+	public void testReindexedOnce() throws InterruptedException {
+		Assert.assertEquals( 2, countBooksInIndex() );
+		Session session = openSession();
+		FullTextSession fullTextSession = Search.getFullTextSession( session );
+		MassIndexer massIndexer = fullTextSession.createIndexer();
+		massIndexer.startAndWait();
+		session.close();
+		Assert.assertEquals( 2, countBooksInIndex() );
+	}
+
+	private int countBooksInIndex() {
+		Session session = openSession();
+		FullTextSession fullTextSession = Search.getFullTextSession( session );
+		fullTextSession.beginTransaction();
+		FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() );
+		int size = fullTextQuery.list().size();
+		fullTextSession.getTransaction().commit();
+		fullTextSession.close();
+		return size;
+	}
+
+	@Override
+	protected Class<?>[] getMappings() {
+		return new Class[] {
+				AncientBook.class,
+				Book.class
+		};
+	}
+
+}
+

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java	2010-04-09 19:23:01 UTC (rev 19205)
@@ -0,0 +1,66 @@
+/* $Id$
+ * 
+ * Hibernate, Relational Persistence for Idiomatic Java
+ * 
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ * 
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.search.test.batchindexing;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.MassIndexer;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
+import org.hibernate.search.test.util.FullTextSessionBuilder;
+
+/**
+ * Verifies the batch backend is considering the configuration properties
+ * @author Sanne Grinovero
+ */
+public class BatchBackendConfigurationTest extends TestCase {
+	
+	/**
+	 * Verifies the batch configuration is read by the backend
+	 */
+	public void testConfigurationIsRead() throws InterruptedException {
+		FullTextSessionBuilder fsBuilder = new FullTextSessionBuilder()
+			.addAnnotatedClass( Book.class )
+			// illegal option:
+			.setProperty( LuceneBatchBackend.CONCURRENT_WRITERS, "0" )
+			.build();
+		
+		FullTextSession fullTextSession = fsBuilder.openFullTextSession();
+		MassIndexer massIndexer = fullTextSession.createIndexer();
+		try {
+			massIndexer.startAndWait();
+			Assert.fail( "should have thrown an exception as configuration is illegal" );
+		}
+		catch (SearchException e) {
+			// it's ok
+		}
+		fullTextSession.close();
+		fsBuilder.close();
+	}
+
+}
+



More information about the hibernate-commits mailing list