[hibernate-commits] Hibernate SVN: r14742 - in search/trunk/src/java/org/hibernate/search: impl and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jun 5 17:40:13 EDT 2008


Author: epbernard
Date: 2008-06-05 17:40:13 -0400 (Thu, 05 Jun 2008)
New Revision: 14742

Modified:
   search/trunk/src/java/org/hibernate/search/FullTextSession.java
   search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
   search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java
Log:
HSEARCH-208 raise IAE on non indexed entity during s.index s.purge(All)

Modified: search/trunk/src/java/org/hibernate/search/FullTextSession.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/FullTextSession.java	2008-06-05 11:25:56 UTC (rev 14741)
+++ search/trunk/src/java/org/hibernate/search/FullTextSession.java	2008-06-05 21:40:13 UTC (rev 14742)
@@ -24,6 +24,7 @@
 	 * Non indexable entities are ignored
 	 *
 	 * @param entity The entity to index - must not be <code>null</code>.
+	 * @throws IllegalArgumentException if entity is null or not an @Indexed entity
 	 */
 	void index(Object entity);
 
@@ -37,6 +38,8 @@
 	 *
 	 * @param entityType
 	 * @param id
+	 *
+	 * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
 	 */
 	public void purge(Class entityType, Serializable id);
 
@@ -44,6 +47,7 @@
 	 * Remove all entities from a particular class of an index.
 	 *
 	 * @param entityType
+	 * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
 	 */
 	public void purgeAll(Class entityType);
 }

Modified: search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java	2008-06-05 11:25:56 UTC (rev 14741)
+++ search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java	2008-06-05 21:40:13 UTC (rev 14742)
@@ -43,6 +43,7 @@
 import org.hibernate.search.FullTextQuery;
 import org.hibernate.search.FullTextSession;
 import org.hibernate.search.SearchFactory;
+import org.hibernate.search.SearchException;
 import org.hibernate.search.backend.Work;
 import org.hibernate.search.backend.WorkType;
 import org.hibernate.search.engine.DocumentBuilder;
@@ -85,6 +86,7 @@
 	 * Remove all entities from a particular class of an index.
 	 *
 	 * @param entityType
+	 * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
 	 */
 	public void purgeAll(Class entityType) {
 		purge( entityType, null );
@@ -95,6 +97,8 @@
 	 *
 	 * @param entityType
 	 * @param id
+	 *
+	 * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
 	 */
 	public void purge(Class entityType, Serializable id) {
 		if ( entityType == null ) return;
@@ -107,17 +111,15 @@
 		if ( builder == null ) {
 			throw new IllegalArgumentException( entityType.getName() + " is not a mapped entity (don't forget to add @Indexed)" );
 		}
+		WorkType type;
+		if ( id == null ) {
+			type = WorkType.PURGE_ALL;
+		}
 		else {
-			WorkType type;
-			if ( id == null ) {
-				type = WorkType.PURGE_ALL;
-			}
-			else {
-				type = WorkType.PURGE;
-			}
-			Work work = new Work(entityType, id, type);
-			searchFactoryImplementor.getWorker().performWork( work, eventSource );
+			type = WorkType.PURGE;
 		}
+		Work work = new Work(entityType, id, type);
+		searchFactoryImplementor.getWorker().performWork( work, eventSource );
 	}
 
 	/**
@@ -126,19 +128,22 @@
 	 * The entity must be associated with the session
 	 *
 	 * @param entity The entity to index - must not be <code>null</code>.
+	 * @throws IllegalArgumentException if entity is null or not an @Indexed entity
 	 */
 	public void index(Object entity) {
-		if (entity == null) return;
+		if (entity == null) throw new IllegalArgumentException("Entity to index should not be null");;
 		Class clazz = Hibernate.getClass( entity );
 		//TODO cache that at the FTSession level
 		SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
 		//not strictly necessary but a small optimization
 		DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( clazz );
-		if ( builder != null ) {
-			Serializable id = session.getIdentifier( entity );
-			Work work = new Work(entity, id, WorkType.INDEX);
-			searchFactoryImplementor.getWorker().performWork( work, eventSource );
+		if ( builder == null ) {
+			throw new IllegalArgumentException( "Entity to index not an @Indexed entity: " + entity.getClass().getName() );
 		}
+		Serializable id = session.getIdentifier( entity );
+		Work work = new Work(entity, id, WorkType.INDEX);
+		searchFactoryImplementor.getWorker().performWork( work, eventSource );
+
 		//TODO
 		//need to add elements in a queue kept at the Session level
 		//the queue will be processed by a Lucene(Auto)FlushEventListener

Modified: search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java	2008-06-05 11:25:56 UTC (rev 14741)
+++ search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java	2008-06-05 21:40:13 UTC (rev 14742)
@@ -22,6 +22,8 @@
 	/**
 	 * Force the (re)indexing of a given <b>managed</b> object.
 	 * Indexation is batched per transaction
+	 *
+	 * @throws IllegalArgumentException if entity is null or not an @Indexed entity
 	 */
 	void index(Object entity);
 
@@ -34,6 +36,8 @@
 	 *
 	 * @param entityType
 	 * @param id
+	 *
+	 * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
 	 */
 	public void purge(Class entityType, Serializable id);
 
@@ -41,6 +45,8 @@
 	 * Remove all entities from a particular class of an index.
 	 *
 	 * @param entityType
+	 *
+	 * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
 	 */
 	public void purgeAll(Class entityType);
 




More information about the hibernate-commits mailing list