[hibernate-commits] Hibernate SVN: r20817 - 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
Tue Oct 12 14:02:55 EDT 2010


Author: sannegrinovero
Date: 2010-10-12 14:02:55 -0400 (Tue, 12 Oct 2010)
New Revision: 20817

Added:
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SecretBook.java
Modified:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java
   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
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java
Log:
HSEARCH-528 MassIndexer attempts to index non-indexed subclasses of indexed types

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java	2010-10-12 17:47:26 UTC (rev 20816)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java	2010-10-12 18:02:55 UTC (rev 20817)
@@ -132,6 +132,12 @@
 		Serializable id = session.getIdentifier( entity );
 		Class<?> clazz = HibernateHelper.getClass( entity );
 		DocumentBuilderIndexedEntity docBuilder = documentBuilders.get( clazz );
+		if ( docBuilder == null ) {
+			// it might be possible to receive not-indexes subclasses of the currently indexed type;
+			// being not-indexed, we skip them.
+			// FIXME for improved performance: avoid loading them in an early phase.
+			return;
+		}
 		TwoWayFieldBridge idBridge = docBuilder.getIdBridge();
 		ContextualException2WayBridge contextualBridge = new ContextualException2WayBridge()
 				.setClass(clazz)


Property changes on: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java
___________________________________________________________________
Name: svn:keywords
   + Id


Property changes on: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java	2010-10-12 17:47:26 UTC (rev 20816)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java	2010-10-12 18:02:55 UTC (rev 20817)
@@ -1,4 +1,4 @@
-/*
+/* $Id$
  * Hibernate, Relational Persistence for Idiomatic Java
  *
  *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
@@ -29,7 +29,9 @@
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 
+import org.hibernate.Session;
 import org.hibernate.Transaction;
+import org.hibernate.criterion.Projections;
 import org.hibernate.search.FullTextQuery;
 import org.hibernate.search.FullTextSession;
 import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
@@ -46,6 +48,7 @@
 
 	private final int BOOK_NUM = 140;
 	private final int ANCIENTBOOK_NUM = 120;
+	private final int SECRETBOOK_NUM = 20;
 	private final int DVD_NUM = 200;
 
 	private SentenceInventor sentenceInventor = new SentenceInventor( 7L, 4000 );
@@ -61,12 +64,14 @@
 				.addAnnotatedClass( Dvd.class )
 				.addAnnotatedClass( AncientBook.class )
 				.addAnnotatedClass( Nation.class )
+				.addAnnotatedClass( SecretBook.class )
 				.setProperty( "hibernate.show_sql", "false" ) // too verbose for this test
 				.setProperty( LuceneBatchBackend.CONCURRENT_WRITERS, "4" )
 				.build();
 		createMany( Book.class, BOOK_NUM );
 		createMany( Dvd.class, DVD_NUM );
 		createMany( AncientBook.class, ANCIENTBOOK_NUM );
+		createMany( SecretBook.class, SECRETBOOK_NUM );
 		storeAllBooksInNation();
 	}
 
@@ -170,6 +175,14 @@
 				countByFT( Book.class )
 		);
 		assertEquals(
+				ANCIENTBOOK_NUM + BOOK_NUM + SECRETBOOK_NUM,
+				countByDatabaseCriteria( Book.class )
+		);
+		assertEquals(
+				SECRETBOOK_NUM,
+				countByDatabaseCriteria( SecretBook.class )
+		);
+		assertEquals(
 				ANCIENTBOOK_NUM,
 				countByFT( AncientBook.class )
 		);
@@ -209,5 +222,19 @@
 		assertEquals( bySize, byResultSize );
 		return bySize;
 	}
+	
+	private long countByDatabaseCriteria(Class<? extends TitleAble> type) {
+		Session session = builder.openFullTextSession();
+		try {
+			Number countAsNumber = (Number) session
+					.createCriteria( type )
+					.setProjection( Projections.rowCount() )
+					.uniqueResult();
+			return countAsNumber.longValue();
+		}
+		finally {
+			session.close();
+		}
+	}
 
 }


Property changes on: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SecretBook.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SecretBook.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SecretBook.java	2010-10-12 18:02:55 UTC (rev 20817)
@@ -0,0 +1,51 @@
+/* $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 javax.persistence.Entity;
+
+/**
+ * To cover the unusual case in which a non-indexed entity
+ * extends an indexed entity.
+ * It shouldn't be possible to find SecretBooks by using a
+ * fulltext query.
+ * 
+ * @author Sanne Grinovero
+ */
+ at Entity
+public class SecretBook extends Book {
+	
+	boolean allCopiesBurnt = true;
+	
+	public boolean isAllCopiesBurnt() {
+		return allCopiesBurnt;
+	}
+	
+	public void setAllCopiesBurnt(boolean allCopiesBurnt) {
+		this.allCopiesBurnt = allCopiesBurnt;
+	}
+
+}
+


Property changes on: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SecretBook.java
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the hibernate-commits mailing list