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

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Aug 28 11:39:14 EDT 2007


Author: epbernard
Date: 2007-08-28 11:39:14 -0400 (Tue, 28 Aug 2007)
New Revision: 13954

Added:
   search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java
   search/trunk/src/test/org/hibernate/search/test/PurgeTest.java
Log:
HSEARCH-69 purge and purge all

Added: search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java	                        (rev 0)
+++ search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java	2007-08-28 15:39:14 UTC (rev 13954)
@@ -0,0 +1,14 @@
+package org.hibernate.search.backend;
+
+import java.io.Serializable;
+
+/**
+ * A unit of work used to purge an entire index.
+ *
+ * @author John Griffin
+ */
+public class PurgeAllLuceneWork extends LuceneWork {
+	public PurgeAllLuceneWork(Class entity) {
+		super( null, null, entity, null );
+	}
+}

Added: search/trunk/src/test/org/hibernate/search/test/PurgeTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/PurgeTest.java	                        (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/PurgeTest.java	2007-08-28 15:39:14 UTC (rev 13954)
@@ -0,0 +1,110 @@
+package org.hibernate.search.test;
+
+import java.util.List;
+
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.query.AlternateBook;
+import org.hibernate.search.test.query.Author;
+import org.hibernate.search.test.query.Book;
+import org.hibernate.search.test.query.Clock;
+import org.hibernate.search.test.query.Employee;
+
+/**
+ * Test the PURGE and PURGE_ALL functionality.
+ *
+ * @author John Griffin
+ */
+public class PurgeTest extends SearchTestCase {
+
+	public void testPurge() throws Exception {
+		FullTextSession s = Search.createFullTextSession( openSession() );
+		Transaction tx = s.beginTransaction();
+		org.hibernate.search.test.query.Clock clock = new Clock( 1, "Seiko" );
+		s.save( clock );
+		clock = new Clock( 2, "Festina" );
+		s.save( clock );
+		Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
+		s.save( book );
+		book = new Book( 2, "La gloire de mon père", "Les deboires de mon père en vélo" );
+		s.save( book );
+		tx.commit();
+		s.clear();
+
+		tx = s.beginTransaction();
+		QueryParser parser = new QueryParser( "brand", new StopAnalyzer() );
+
+		Query query = parser.parse( "brand:Seiko" );
+		org.hibernate.Query hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
+		List results = hibQuery.list();
+		assertEquals("incorrect test record", 1, results.size());
+		assertEquals("incorrect test record", 1, ((Clock)results.get( 0 )).getId().intValue());
+
+		s.purge( Clock.class, ((Clock)results.get( 0 )).getId());
+
+		tx.commit();
+
+		tx = s.beginTransaction();
+
+		query = parser.parse( "brand:Festina or brand:Seiko" );
+		hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
+		results = hibQuery.list();
+		assertEquals("incorrect test record count", 1, results.size());
+		assertEquals("incorrect test record", 2, ((Clock)results.get( 0 )).getId().intValue());
+
+		for (Object element : s.createQuery( "from java.lang.Object" ).list()) s.delete( element );
+		tx.commit();
+		s.close();
+	}
+
+	public void testPurgeAll() throws Exception {
+		FullTextSession s = Search.createFullTextSession( openSession() );
+		Transaction tx = s.beginTransaction();
+		org.hibernate.search.test.query.Clock clock = new Clock( 1, "Seiko" );
+		s.save( clock );
+		clock = new Clock( 2, "Festina" );
+		s.save( clock );
+		clock = new Clock( 3, "Longine" );
+		s.save( clock );
+		clock = new Clock( 4, "Rolex" );
+		s.save( clock );
+		Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
+		s.save( book );
+		book = new Book( 2, "La gloire de mon père", "Les deboires de mon père en vélo" );
+		s.save( book );
+		tx.commit();
+		s.clear();
+
+		tx = s.beginTransaction();
+		QueryParser parser = new QueryParser( "brand", new StopAnalyzer() );
+		                     tx = s.beginTransaction();
+		s.purge( Clock.class);
+
+		tx.commit();
+
+		tx = s.beginTransaction();
+
+		Query query = parser.parse( "brand:Festina or brand:Seiko" );
+		org.hibernate.Query hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
+		List results = hibQuery.list();
+		assertEquals("incorrect test record count", 0, results.size());
+
+		for (Object element : s.createQuery( "from java.lang.Object" ).list()) s.delete( element );
+		tx.commit();
+		s.close();
+	}
+
+	protected Class[] getMappings() {
+		return new Class[] {
+				Book.class,
+				AlternateBook.class,
+				Clock.class,
+				Author.class,
+				Employee.class
+		};
+	}
+}




More information about the hibernate-commits mailing list