[hibernate-commits] Hibernate SVN: r11627 - in trunk/HibernateExt/search/src: test/org/hibernate/search/test/query and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon Jun 4 20:00:53 EDT 2007
Author: epbernard
Date: 2007-06-04 20:00:53 -0400 (Mon, 04 Jun 2007)
New Revision: 11627
Added:
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Music.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/QueryLoaderTest.java
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java
Log:
HSEARCH-66 no longer use setMaxResult
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java 2007-06-04 17:42:10 UTC (rev 11626)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java 2007-06-05 00:00:53 UTC (rev 11627)
@@ -19,7 +19,6 @@
* @author Emmanuel Bernard
*/
public class QueryLoader implements Loader {
- private static final Log log = LogFactory.getLog( QueryLoader.class );
private static final int MAX_IN_CLAUSE = 500;
private static final List EMPTY_LIST = new ArrayList(0);
@@ -66,7 +65,6 @@
disjunction.add( Restrictions.in( idName, ids ) );
}
criteria.add( disjunction );
- criteria.setMaxResults( maxResults ); //is it faster
criteria.list(); //load all objects
//mandatory to keep the same ordering
Added: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Music.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Music.java (rev 0)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Music.java 2007-06-05 00:00:53 UTC (rev 11627)
@@ -0,0 +1,80 @@
+//$Id: $
+package org.hibernate.search.test.query;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+import org.hibernate.search.annotations.Store;
+
+ at Entity
+ at Indexed()
+public class Music {
+ protected Long id;
+ protected String title;
+ protected Set<Author> authors = new HashSet<Author>();
+
+ @Id
+ @GeneratedValue
+ @DocumentId
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the singers
+ */
+ @ManyToMany( cascade = CascadeType.ALL,
+ fetch = FetchType.EAGER,
+ targetEntity = Author.class )
+ @IndexedEmbedded( depth = 1 )
+ public Set<Author> getAuthors() {
+ return authors;
+ }
+
+ /**
+ * @param authors the authors to set
+ */
+ public void setAuthors(Set<Author> authors) {
+ this.authors = authors;
+ }
+
+ public void addAuthor(Author author) {
+ this.getAuthors().add( author );
+ }
+
+ /**
+ * @return the title
+ */
+ @Column( name = "title",
+ length = 255,
+ nullable = false )
+ @Field( name = "title",
+ index = Index.TOKENIZED,
+ store = Store.YES )
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * @param title the title to set
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+}
Added: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/QueryLoaderTest.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/QueryLoaderTest.java (rev 0)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/QueryLoaderTest.java 2007-06-05 00:00:53 UTC (rev 11627)
@@ -0,0 +1,98 @@
+//$Id: $
+package org.hibernate.search.test.query;
+
+import java.util.List;
+
+import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.Search;
+import org.hibernate.Transaction;
+import org.hibernate.Session;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.analysis.KeywordAnalyzer;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class
+ QueryLoaderTest extends SearchTestCase {
+
+ public void testWithEagerCollectionLoad() throws Exception
+ {
+ Session sess = openSession();
+ Transaction tx = sess.beginTransaction();
+ Music music = new Music();
+ music.setTitle("Moo Goes The Cow");
+ Author author = new Author();
+ author.setName("Moo Cow");
+ music.addAuthor(author);
+ sess.persist(author);
+ author = new Author();
+ author.setName("Another Moo Cow");
+ music.addAuthor(author);
+ sess.persist(author);
+ author = new Author();
+ author.setName("A Third Moo Cow");
+ music.addAuthor(author);
+ sess.persist(author);
+ author = new Author();
+ author.setName("Random Moo Cow");
+ music.addAuthor(author);
+ sess.persist(author);
+ sess.save(music);
+
+ Music music2 = new Music();
+ music2.setTitle("The Cow Goes Moo");
+ author = new Author();
+ author.setName("Moo Cow The First");
+ music2.addAuthor(author);
+ sess.persist(author);
+ author = new Author();
+ author.setName("Moo Cow The Second");
+ music2.addAuthor(author);
+ sess.persist(author);
+ author = new Author();
+ author.setName("Moo Cow The Third");
+ music2.addAuthor(author);
+ sess.persist(author);
+ author = new Author();
+ author.setName("Moo Cow The Fourth");
+ music2.addAuthor(author);
+ sess.persist(author);
+ sess.save(music2);
+ tx.commit();
+ sess.clear();
+
+ FullTextSession s = Search.createFullTextSession(sess);
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser("title", new KeywordAnalyzer());
+ Query query = parser.parse("title:moo");
+ FullTextQuery hibQuery = s.createFullTextQuery(query, Music.class);
+ List result = hibQuery.list();
+ assertEquals("Should have returned 2 Books", 2, result.size());
+ music = (Music) result.get( 0 );
+ assertEquals("Book 1 should have four authors", 4, music.getAuthors().size());
+ music2 = (Music) result.get( 1 );
+ assertEquals("Book 2 should have four authors", 4, music2.getAuthors().size());
+
+ //cleanup
+ music.getAuthors().clear();
+ music2.getAuthors().clear();
+
+ for (Object o : s.createCriteria( Object.class ).list() ) {
+ s.delete( o );
+ }
+
+ tx.commit();
+ s.close();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Author.class,
+ Music.class
+ };
+ }
+}
More information about the hibernate-commits
mailing list