[infinispan-commits] Infinispan SVN: r841 - in trunk: query and 18 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Sep 22 07:23:04 EDT 2009


Author: navssurtani
Date: 2009-09-22 07:23:04 -0400 (Tue, 22 Sep 2009)
New Revision: 841

Added:
   trunk/query/
   trunk/query/infinispan-query.iml
   trunk/query/pom.xml
   trunk/query/src/
   trunk/query/src/main/
   trunk/query/src/main/java/
   trunk/query/src/main/java/org/
   trunk/query/src/main/java/org/infinispan/
   trunk/query/src/main/java/org/infinispan/query/
   trunk/query/src/main/java/org/infinispan/query/CacheQuery.java
   trunk/query/src/main/java/org/infinispan/query/QueryFactory.java
   trunk/query/src/main/java/org/infinispan/query/QueryIterator.java
   trunk/query/src/main/java/org/infinispan/query/Version.java
   trunk/query/src/main/java/org/infinispan/query/backend/
   trunk/query/src/main/java/org/infinispan/query/backend/IndexSearcherCloser.java
   trunk/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java
   trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
   trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java
   trunk/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java
   trunk/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.java
   trunk/query/src/main/java/org/infinispan/query/impl/
   trunk/query/src/main/java/org/infinispan/query/impl/AbstractIterator.java
   trunk/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java
   trunk/query/src/main/java/org/infinispan/query/impl/EagerIterator.java
   trunk/query/src/main/java/org/infinispan/query/impl/LazyIterator.java
   trunk/query/src/test/
   trunk/query/src/test/java/
   trunk/query/src/test/java/org/
   trunk/query/src/test/java/org/infinispan/
   trunk/query/src/test/java/org/infinispan/query/
   trunk/query/src/test/java/org/infinispan/query/backend/
   trunk/query/src/test/java/org/infinispan/query/backend/TransactionalEventTransactionContextTest.java
   trunk/query/src/test/java/org/infinispan/query/blackbox/
   trunk/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java
   trunk/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java
   trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java
   trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
   trunk/query/src/test/java/org/infinispan/query/helper/
   trunk/query/src/test/java/org/infinispan/query/helper/IndexCleanUp.java
   trunk/query/src/test/java/org/infinispan/query/impl/
   trunk/query/src/test/java/org/infinispan/query/impl/EagerIteratorTest.java
   trunk/query/src/test/java/org/infinispan/query/impl/LazyIteratorTest.java
   trunk/query/src/test/java/org/infinispan/query/test/
   trunk/query/src/test/java/org/infinispan/query/test/BrokenDocumentId.java
   trunk/query/src/test/java/org/infinispan/query/test/BrokenProvided.java
   trunk/query/src/test/java/org/infinispan/query/test/Person.java
Log:
Adding query module to trunk

Added: trunk/query/infinispan-query.iml
===================================================================
--- trunk/query/infinispan-query.iml	                        (rev 0)
+++ trunk/query/infinispan-query.iml	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,293 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="false" type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/target/classes" />
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/target" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.13/log4j-1.2.13.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.13/log4j-1.2.13-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module" module-name="infinispan-core" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/jgroups/jgroups/2.8.0.Beta1/jgroups-2.8.0.Beta1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/jgroups/jgroups/2.8.0.Beta1/jgroups-2.8.0.Beta1-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/javax/transaction/jta/1.1/jta-1.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/javax/transaction/jta/1.1/jta-1.1-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/jboss-common-core/2.2.14.GA/jboss-common-core-2.2.14.GA.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/jboss-common-core/2.2.14.GA/jboss-common-core-2.2.14.GA-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging-spi/2.1.0.GA/jboss-logging-spi-2.1.0.GA.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging-spi/2.1.0.GA/jboss-logging-spi-2.1.0.GA-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/marshalling-api/1.2.0.CR2/marshalling-api-1.2.0.CR2.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/marshalling-api/1.2.0.CR2/marshalling-api-1.2.0.CR2-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/river/1.2.0.CR2/river-1.2.0.CR2.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/river/1.2.0.CR2/river-1.2.0.CR2-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymockclassextension/2.4/easymockclassextension-2.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymockclassextension/2.4/easymockclassextension-2.4-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymock/2.4/easymock-2.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymock/2.4/easymock-2.4-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module" module-name="infinispan-tree" />
+    <orderEntry type="module" module-name="infinispan-core" />
+    <orderEntry type="module" module-name="infinispan-tree" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/jboss/jbossts/jbossjta/4.4.0.GA/jbossjta-4.4.0.GA.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/hibernate-search/3.1.0.GA/hibernate-search-3.1.0.GA.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/hibernate-search/3.1.0.GA/hibernate-search-3.1.0.GA-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/hibernate-core/3.3.1.GA/hibernate-core-3.3.1.GA.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/hibernate-core/3.3.1.GA/hibernate-core-3.3.1.GA-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/antlr/antlr/2.7.6/antlr-2.7.6.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/antlr/antlr/2.7.6/antlr-2.7.6-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/3.1/commons-collections-3.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/3.1/commons-collections-3.1-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/dom4j/dom4j/1.6.1/dom4j-1.6.1-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/hibernate-commons-annotations/3.1.0.GA/hibernate-commons-annotations-3.1.0.GA.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/hibernate-commons-annotations/3.1.0.GA/hibernate-commons-annotations-3.1.0.GA-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/ejb3-persistence/1.0.2.GA/ejb3-persistence-1.0.2.GA.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/ejb3-persistence/1.0.2.GA/ejb3-persistence-1.0.2.GA-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/lucene/lucene-core/2.4.0/lucene-core-2.4.0.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/lucene/lucene-core/2.4.0/lucene-core-2.4.0-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/testng/testng/5.8/testng-5.8-jdk15.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/testng/testng/5.8/testng-5.8-jdk15-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/junit/junit/3.8.1/junit-3.8.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/junit/junit/3.8.1/junit-3.8.1-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+  </component>
+</module>
+

Added: trunk/query/pom.xml
===================================================================
--- trunk/query/pom.xml	                        (rev 0)
+++ trunk/query/pom.xml	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+   <parent>
+      <groupId>org.infinispan</groupId>
+      <artifactId>infinispan-parent</artifactId>
+      <version>4.0.0-SNAPSHOT</version>
+      <relativePath>../parent/pom.xml</relativePath>
+   </parent>
+
+   <groupId>org.infinispan</groupId>
+   <artifactId>infinispan-query</artifactId>
+   <name>Infinispan Query API</name>
+   <description>Infinispan Query API module</description>
+   <dependencies>
+      <dependency>
+         <groupId>${project-package}</groupId>
+         <artifactId>infinispan-core</artifactId>
+         <version>${project-version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.hibernate</groupId>
+         <artifactId>hibernate-search</artifactId>
+         <version>3.1.0.GA</version>
+      </dependency>
+
+      <dependency>
+         <groupId>${project-package}</groupId>
+         <artifactId>infinispan-tree</artifactId>
+         <version>${project-version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>${project-package}</groupId>
+         <artifactId>infinispan-core</artifactId>
+         <version>${project-version}</version>
+         <type>test-jar</type>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>${project-package}</groupId>
+         <artifactId>infinispan-tree</artifactId>
+         <version>${project-version}</version>
+         <type>test-jar</type>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>org.slf4j</groupId>
+         <artifactId>slf4j-api</artifactId>
+         <version>1.4.2</version>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>org.slf4j</groupId>
+         <artifactId>slf4j-log4j12</artifactId>
+         <version>1.4.2</version>
+         <scope>test</scope>
+      </dependency>
+
+   </dependencies>
+</project>

Added: trunk/query/src/main/java/org/infinispan/query/CacheQuery.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/CacheQuery.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/CacheQuery.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query;
+
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.Sort;
+import org.hibernate.search.FullTextFilter;
+
+import java.util.List;
+
+/**
+ * A cache-query is what will be returned when the createQuery() method is run. This object can have methods such
+ * as list, setFirstResult,setMaxResults, setFetchSize, getResultSize and setSort.
+ *
+ * <p/>
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ * @see org.infinispan.query.SearchableCache#createQuery(org.apache.lucene.search.Query, Class[])
+ */
+public interface CacheQuery extends Iterable
+{
+   /**
+    * Returns the results of a search as a list.
+    *
+    * @return list of objects that were found from the search.
+    */
+
+   List<Object> list();
+
+   /**
+    * Returns the results of a search as a {@link QueryIterator} with a given
+    * integer parameter - the fetchSize.
+    *
+    * @param fetchSize integer to be given to the implementation constructor.
+    * @return a QueryResultIterator which can be used to iterate through the results that were found.
+    */
+
+   QueryIterator iterator(int fetchSize);
+
+   /**
+    * Returns the results of a search as a {@link QueryIterator}. This calls {@link CacheQuery#iterator(int fetchSize)}
+    * but uses a default fetchSize of 1. 
+    *
+    * @return a QueryResultIterator which can be used to iterate through the results that were found.
+    */
+
+   QueryIterator iterator();
+
+   /**
+    * Lazily loads the results from the Query as a {@link QueryIterator} with a given
+    * integer parameter - the fetchSize.
+    *
+    * @param fetchSize integer to be passed into the lazy implementation of {@link QueryIterator}
+    * @return a QueryResultIterator which can be used to <B>lazily</B> iterate through results.
+    */
+
+   QueryIterator lazyIterator(int fetchSize);
+
+   /**
+    * Calls the {@link CacheQuery#lazyIterator(int fetchSize)} method but passes in a default 1 as a parameter.
+    *
+    * @return a QueryResultIterator which can be used to <B>lazily</B> iterate through results.
+    */
+
+
+   QueryIterator lazyIterator();
+
+   /**
+    * Sets a result with a given index to the first result.
+    *
+    * @param index of result to be set to the first.
+    * @throws IllegalArgumentException if the index given is less than zero.
+    */
+
+   void setFirstResult(int index);
+
+   /**
+    * Sets the maximum number of results to the number passed in as a parameter.
+    *
+    * @param numResults that are to be set to the maxResults.
+    */
+
+   void setMaxResults(int numResults);
+
+   /**
+    * Gets the integer number of results.
+    *
+    * @return integer number of results.
+    */
+
+   int getResultSize();
+
+   /**
+    * Allows lucene to sort the results. Integers are sorted in descending order.
+    *
+    * @param s - lucene sort object
+    */
+
+   void setSort(Sort s);
+
+   /**
+    * Enable a given filter by its name.
+    *
+    * @param name of filter.
+    * @return a FullTextFilter object.
+    */
+   public FullTextFilter enableFullTextFilter(String name);
+
+
+   /**
+    * Disable a given filter by its name.
+    *
+    * @param name of filter.
+    */
+   public void disableFullTextFilter(String name);
+
+   /**
+    * Allows lucene to filter the results.
+    *
+    * @param f - lucene filter
+    */
+
+   public void setFilter(Filter f);
+
+
+
+
+}

Added: trunk/query/src/main/java/org/infinispan/query/QueryFactory.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/QueryFactory.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/QueryFactory.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,63 @@
+package org.infinispan.query;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.Cache;
+import org.infinispan.query.impl.CacheQueryImpl;
+
+/**
+ * // TODO: navssurtani --> Document this
+ *
+ * @author Navin Surtani
+ * @since 4.0
+ */
+
+
+public class QueryFactory {
+
+   private Cache cache;
+   private SearchFactoryImplementor searchFactory;
+
+   public QueryFactory(Cache cache, SearchFactoryImplementor searchFactory){
+      this.cache = cache;
+      this.searchFactory = searchFactory;
+   }
+
+   /**
+    * This is a simple method that will just return a {@link CacheQuery}
+    *
+    * @param luceneQuery - {@link org.apache.lucene.search.Query}
+    * @return the query result
+    */
+
+   public CacheQuery getQuery(Query luceneQuery){
+      return new CacheQueryImpl(luceneQuery, searchFactory, cache);
+   }
+
+   /**
+    * This method is a basic query. The user provides 2 strings and internally the {@link org.apache.lucene.search.Query} is built.
+    *
+    * The first string is the field that they are searching and the second one is the search that they want to run.
+    *
+    * For example: -
+    *
+    * {@link org.infinispan.query.CacheQuery} cq = new QueryFactory
+    *
+    * The query is built by use of a {@link org.apache.lucene.queryParser.QueryParser} and a {@link org.apache.lucene.analysis.standard.StandardAnalyzer}
+    * </p>
+    *
+    * @param field - the field on the class that you are searching
+    * @param search - the String that you want to be using to search
+    * @return {@link org.infinispan.query.CacheQuery} result
+    */
+
+   public CacheQuery getBasicQuery(String field, String search) throws org.apache.lucene.queryParser.ParseException{
+
+      QueryParser parser = new QueryParser(field, new StandardAnalyzer());
+      org.apache.lucene.search.Query luceneQuery = parser.parse(search);
+      return new CacheQueryImpl(luceneQuery, searchFactory, cache);
+
+   }
+}

Added: trunk/query/src/main/java/org/infinispan/query/QueryIterator.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/QueryIterator.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/QueryIterator.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+
+package org.infinispan.query;
+
+import java.util.ListIterator;
+
+/**
+ * Iterates over query results
+ * <p/>
+ * @author Manik Surtani
+ * @author Navin Surtani 
+ */
+public interface QueryIterator extends ListIterator
+{
+   /**
+    * Jumps to a specific index in the iterator.
+    *
+    * @param index index to jump to.
+    * @throws IndexOutOfBoundsException if the index is out of bounds
+    */
+   void jumpToResult(int index) throws IndexOutOfBoundsException;
+
+   /**
+    * Jumps to the first result
+    */
+   void first();
+
+   /**
+    * Jumps to the last result
+    */
+   void last();
+
+   /**
+    * Jumps to the one-after-the-first result
+    */
+   void afterFirst();
+
+   /**
+    * Jumps to the one-before-the-last result
+    */
+   void beforeLast();
+
+   /**
+    * @return true if the current result is the first
+    */
+   boolean isFirst();
+
+   /**
+    * @return true if the current result is the last
+    */
+   boolean isLast();
+
+   /**
+    * @return true if the current result is one after the first
+    */
+   boolean isAfterFirst();
+
+   /**
+    * @return true if the current result is one before the last
+    */
+   boolean isBeforeLast();
+
+   /**
+    * This method must be called on your iterator once you have finished so that Lucene resources can be freed up. 
+    */
+
+   void close();
+}

Added: trunk/query/src/main/java/org/infinispan/query/Version.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/Version.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/Version.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,16 @@
+package org.infinispan.query;
+
+/**
+ * Spits out the version number.
+ *
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+public class Version
+{
+   //version string - should correspond with the version in the pom
+   private static final String version = "1.0.0-SNAPSHOT";
+   public static void main(String[] args)
+   {
+      System.out.println("\nJBoss Cache Searchable Edition\nVersion:\t" + version + "\n\n");
+   }
+}

Added: trunk/query/src/main/java/org/infinispan/query/backend/IndexSearcherCloser.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/IndexSearcherCloser.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/backend/IndexSearcherCloser.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query.backend;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Searcher;
+import org.hibernate.search.reader.ReaderProvider;
+import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
+
+import java.util.Set;
+
+/**
+ * Class with static method that is called by {@link org.infinispan.query.impl.CacheQueryImpl} and {@link org.infinispan.query.impl.EagerIterator}
+ * <p />
+ * @author Navin Surtani
+ */
+ public class IndexSearcherCloser
+{
+   public static void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
+   {
+      Set<IndexReader> indexReaders = getIndexReaders(searcher);
+
+      for (IndexReader indexReader : indexReaders)
+      {
+         readerProvider.closeReader(indexReader);
+      }
+   }
+}

Added: trunk/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,132 @@
+package org.infinispan.query.backend;
+
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.factories.annotations.Inject;
+import org.infinispan.context.InvocationContext;
+import org.infinispan.commands.write.PutKeyValueCommand;
+import org.infinispan.commands.write.RemoveCommand;
+import org.infinispan.commands.write.ReplaceCommand;
+import org.infinispan.commands.write.PutMapCommand;
+
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
+/**
+ * // TODO: Document this
+ * <p/>
+ * This class is an interceptor that will index data only if it has come from a local source.
+ * <p/>
+ * Currently, this is a property that is determined by setting "indexLocal" as a System property to "true".
+ *
+ * @author Navin Surtani
+ * @since 4.0
+ */
+
+
+public class LocalQueryInterceptor extends QueryInterceptor {
+
+
+   // TODO:  navssurtani --> check to make sure that these fields will be assigned properly on superclass method so that they can be used correctly when needed.
+
+   
+
+   @Inject
+   public void init(SearchFactoryImplementor searchFactory, TransactionManager transactionManager) {
+
+      log.debug("Entered LocalQueryInterceptor.init()");
+
+      // Fields on superclass.
+
+      this.searchFactory = searchFactory;
+      this.transactionManager = transactionManager;
+   }
+
+
+   @Override
+   public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
+
+      // This method will get the put() calls on the cache and then send them into Lucene once it's successful.
+
+      log.debug("Entered the LocalQueryInterceptor visitPutKeyValueCommand()");
+
+      // do the actual put first.
+      Object toReturn = invokeNextInterceptor(ctx, command);
+
+      // Since this is going to index if local only, then we must first check to see if the
+      // context is local.
+
+      if (ctx.isOriginLocal()) {
+         log.debug("Origin is local");
+         addToIndexes(command.getValue(), command.getKey().toString());
+      }
+
+      return toReturn;
+   }
+
+   @Override
+   public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable {
+
+      log.debug("Entered the LocalQueryInterceptor visitRemoveCommand()");
+
+      // remove the object out of the cache first.
+      Object valueRemoved = invokeNextInterceptor(ctx, command);
+
+      // Check to make sure that the context is local as well as successful.
+
+      if (command.isSuccessful() && ctx.isOriginLocal()) {
+         log.debug("Origin is local");
+         removeFromIndexes(valueRemoved, command.getKey().toString());
+      }
+
+      return valueRemoved;
+
+   }
+
+
+   @Override
+   public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable {
+      log.debug("Entered the LocalQueryInterceptor visitReplaceCommand()");
+
+      Object valueReplaced = invokeNextInterceptor(ctx, command);
+
+      // Checking for local as well as making sure that the valueReplaced is not null.
+
+      if (valueReplaced != null && ctx.isOriginLocal()) {
+
+         log.debug("Origin is local");
+         Object[] parameters = command.getParameters();
+         String keyString = command.getKey().toString();
+
+         removeFromIndexes(parameters[1], keyString);
+         addToIndexes(parameters[2], keyString);
+      }
+
+      return valueReplaced;
+   }
+
+   @Override
+   public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable {
+
+      log.debug("Entered LocalQueryInterceptor visitPutMapCommand()");
+
+      Object mapPut = invokeNextInterceptor(ctx, command);
+
+      // Check to make sure the origin is local.
+
+      if (ctx.isOriginLocal()) {
+
+         log.debug("Origin is local");
+         Map<Object, Object> dataMap = command.getMap();
+
+         // Loop through all the keys and put those key, value pairings into lucene.
+
+         for (Map.Entry entry : dataMap.entrySet()) {
+            addToIndexes(entry.getValue(), entry.getKey().toString());
+         }
+      }
+
+      return mapPut;
+   }
+
+
+}

Added: trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,201 @@
+package org.infinispan.query.backend;
+
+import org.hibernate.search.cfg.SearchConfiguration;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.infinispan.Cache;
+import org.infinispan.factories.ComponentRegistry;
+import org.infinispan.factories.InterceptorChainFactory;
+import org.infinispan.interceptors.base.CommandInterceptor;
+import org.infinispan.interceptors.LockingInterceptor;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+import java.lang.reflect.Field;
+import java.util.Properties;
+
+/**
+ * // TODO: Document this
+ * <p/>
+ * This is a TEMPORARY helper class that will be used to add the QueryInterceptor to the chain.
+ *
+ * @author Navin Surtani
+ * @since 4.0
+ */
+
+
+public class QueryHelper {
+
+   private Cache cache;
+   private Properties properties;
+   private Class[] classes;
+   private SearchFactoryImplementor searchFactory;
+
+   Log log = LogFactory.getLog(getClass());
+
+
+   /**
+    * Constructor that will take in 3 params and build the searchFactory for Hibernate Search.
+    * <p/>
+    * <p/>
+    * Once this constructor is called, the user MUST call applyProperties() to set up the interceptors.
+    * <p/>
+    *
+    * @param cache      - the cache instance.
+    * @param properties - {@link java.util.Properties}
+    * @param classes    - the Class[] for Hibernate Search.
+    */
+
+   public QueryHelper(Cache cache, Properties properties, Class... classes) {
+
+
+      // assume cache is already created and running.
+      // otherwise, start the cache!!
+      if (cache.getStatus().needToInitializeBeforeStart()) {
+         log.debug("Cache not started.  Starting cache first.");
+         cache.start();
+      }
+
+      if (classes.length == 0) {
+         throw new IllegalArgumentException("You haven't passed in any classes to index.");
+      }
+
+      // Make the validation check here.
+      validateClasses(classes);
+
+      if (properties == null) log.debug("Properties is null.");
+
+      this.cache = cache;
+      this.properties = properties;
+      this.classes = classes;
+
+      // Set up the search factory for hibernate search first.
+
+      SearchConfiguration cfg = new SearchableCacheConfiguration(classes, properties);
+      searchFactory = new SearchFactoryImpl(cfg);
+
+
+   }
+
+   /**
+    * This method MUST be called if running the query module and you want to index objects in the cache.
+    * <p/>
+    * <p/>
+    * <p/>
+    * e.g.:- QueryHelper.applyQueryProperties(); has to be used BEFORE any objects are put in the cache so that they can
+    * be indexed.
+    * <p/>
+    * <p/>
+    * <p/>
+    * <p/>
+    * Anything put before calling this method will NOT not be picked up by the {@link QueryInterceptor} and hence not be
+    * indexed.
+    *
+    * @throws Exception
+    */
+
+   public void applyProperties()
+         throws Exception {
+
+
+      log.debug("Entered QueryHelper.applyProperties()");
+
+      // If the query property is set to true, i.e. we want to query objects in the cache, then we need to add the QueryInterceptor.
+
+      if (System.getProperty("query").equals("true")) {
+
+         String indexLocal = System.getProperty("indexLocal");
+
+         // Validation check first to make sure there isn't some gibberish passed in.
+         if (!indexLocal.equals("true") && !indexLocal.equals("false")) {
+            throw new IllegalArgumentException("Incorrect system property passed into QueryHelper. indexLocal must be set" +
+                  " to either true or false. Cannot be " + indexLocal);
+         }
+
+
+         if (indexLocal.equals("true")) {
+            // Add a LocalQueryInterceptor to the chain
+            addInterceptor(LocalQueryInterceptor.class);
+
+         }
+         // We're indexing data even if it comes from other sources
+
+         else {
+            // Add in a QueryInterceptor to the chain
+            addInterceptor(QueryInterceptor.class);
+         }
+      }
+   }
+
+   /**
+    * Simple getter.
+    *
+    * @return the {@link org.hibernate.search.engine.SearchFactoryImplementor} instance being used.
+    */
+
+   public SearchFactoryImplementor getSearchFactory() {
+      return searchFactory;
+   }
+
+   /**
+    * Simple getter.
+    *
+    * @return the class[].
+    */
+
+
+   public Class[] getClasses() {
+      return classes;
+   }
+
+   /**
+    * Simple getter.
+    *
+    * @return {@link java.util.Properties}
+    */
+
+   public Properties getProperties() {
+      return properties;
+   }
+
+
+   // Private method that adds the interceptor from the classname parameter.
+
+
+   private void addInterceptor(Class<? extends QueryInterceptor> interceptorClass)
+         throws IllegalAccessException, InstantiationException {
+
+      // get the component registry and then register the searchFactory.
+      ComponentRegistry cr = cache.getAdvancedCache().getComponentRegistry();
+      cr.registerComponent(searchFactory, SearchFactoryImplementor.class);
+      
+      // Get the interceptor chain factory so I can create my interceptor.
+      InterceptorChainFactory icf = cr.getComponent(InterceptorChainFactory.class);
+
+      CommandInterceptor inter = icf.createInterceptor(interceptorClass);
+      cr.registerComponent(inter, QueryInterceptor.class);
+
+      cache.getAdvancedCache().addInterceptorAfter(inter, LockingInterceptor.class);
+
+   }
+
+   //This is to check that both the @ProvidedId is present and the the @DocumentId is not present. This is because
+   // don't want both of these 2 annotations used at the same time.
+
+   private void validateClasses(Class... classes) {
+      for (Class c : classes) {
+         if (!c.isAnnotationPresent(org.hibernate.search.annotations.ProvidedId.class)) {
+            throw new IllegalArgumentException("There is no provided id on " + c.getName() + " class");
+         }
+
+         for (Field field : c.getFields()) {
+            if (field.getAnnotation(org.hibernate.search.annotations.DocumentId.class) != null) {
+               throw new IllegalArgumentException("Please remove the documentId annotation in " + c.getName());
+            }
+         }
+      }
+
+   }
+
+
+}

Added: trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,133 @@
+package org.infinispan.query.backend;
+
+import org.hibernate.search.backend.TransactionContext;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.commands.write.PutKeyValueCommand;
+import org.infinispan.commands.write.PutMapCommand;
+import org.infinispan.commands.write.RemoveCommand;
+import org.infinispan.commands.write.ReplaceCommand;
+import org.infinispan.context.InvocationContext;
+import org.infinispan.factories.annotations.Inject;
+import org.infinispan.interceptors.base.CommandInterceptor;
+
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
+/**
+ * // TODO: navssurtani --> Document this
+ *
+ * @author Navin Surtani
+ * @since 4.0
+ */
+
+public class QueryInterceptor extends CommandInterceptor {
+
+   protected SearchFactoryImplementor searchFactory;
+   protected TransactionManager transactionManager;
+
+   @Inject
+   public void init(SearchFactoryImplementor searchFactory, TransactionManager transactionManager) {
+
+      log.debug("Entered QueryInterceptor.init()");
+
+      this.searchFactory = searchFactory;
+      this.transactionManager = transactionManager;
+   }
+
+
+   @Override
+   public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
+
+      // This method will get the put() calls on the cache and then send them into Lucene once it's successful.
+
+      log.debug("Entered the searchable core interceptor visitPutKeyValueCommand()");
+
+      // do the actual put first.
+      Object toReturn = invokeNextInterceptor(ctx, command);
+
+      addToIndexes(command.getValue(), command.getKey().toString());
+
+      return toReturn;
+   }
+
+   @Override
+   public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable {
+
+      log.debug("Entered the searchable core interceptor visitRemoveCommand()");
+
+      // remove the object out of the cache first.
+      Object valueRemoved = invokeNextInterceptor(ctx, command);
+
+      System.out.println("Transaction Manager is " + transactionManager);
+
+      if (command.isSuccessful()) {
+         removeFromIndexes(valueRemoved, command.getKey().toString());
+      }
+
+      return valueRemoved;
+
+   }
+
+
+   @Override
+   public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable {
+      log.debug("Entered the searchable core interceptor visitReplaceCommand()");
+
+      Object valueReplaced = invokeNextInterceptor(ctx, command);
+      if (valueReplaced != null) {
+
+         Object[] parameters = command.getParameters();
+         String keyString = command.getKey().toString();
+
+         removeFromIndexes(parameters[1], keyString);
+         addToIndexes(parameters[2], keyString);
+      }
+
+      return valueReplaced;
+   }
+
+   @Override
+   public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable {
+
+      log.debug("Entered searchable core interceptor visitPutMapCommand()");
+
+      Object mapPut = invokeNextInterceptor(ctx, command);
+
+
+      Map<Object, Object> dataMap = command.getMap();
+
+      // Loop through all the keys and put those key, value pairings into lucene.
+
+      for (Map.Entry entry : dataMap.entrySet()) {
+         addToIndexes(entry.getValue(), entry.getKey().toString());
+      }
+      return mapPut;
+   }
+
+
+   // Method that will be called when data needs to be added into Lucene.
+   protected void addToIndexes(Object value, String key) {
+
+      // The key here is the String representation of the key that is stored in the cache.
+      // The key is going to be the documentID for Lucene.
+      // The object parameter is the actual value that needs to be put into lucene.
+
+      TransactionContext transactionContext = new TransactionalEventTransactionContext(transactionManager);
+      searchFactory.getWorker().performWork(new Work(value, key, WorkType.ADD), transactionContext);
+   }
+
+
+   // Method that will be called when data needs to be removed from Lucene.
+   protected void removeFromIndexes(Object value, String key) {
+
+      // The key here is the String representation of the key that is stored in the cache.
+      // The key is going to be the documentID for Lucene.
+      // The object parameter is the actual value that needs to be removed from lucene.
+
+      TransactionContext transactionContext = new TransactionalEventTransactionContext(transactionManager);
+      searchFactory.getWorker().performWork(new Work(value, key, WorkType.DELETE), transactionContext);
+   }
+
+}

Added: trunk/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query.backend;
+
+import org.hibernate.search.cfg.SearchConfiguration;
+import org.hibernate.annotations.common.reflection.ReflectionManager;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Class that implements {@link org.hibernate.search.cfg.SearchConfiguration} so that within Infinispan-Query, there is
+ * no need for a Hibernate Core configuration object.
+ *
+ * @author Navin Surtani
+ */
+public class SearchableCacheConfiguration implements SearchConfiguration {
+   protected Map<String, Class> classes;
+   private Properties properties;
+
+   public SearchableCacheConfiguration(Class[] classArray, Properties properties) {
+      // null chks
+      if (classArray == null) throw new NullPointerException("Classes provided are null");
+      this.properties = properties;
+      if (this.properties == null) this.properties = new Properties();
+
+      classes = new HashMap<String, Class>();
+
+      // loop thru your classArray
+      // populate your Map
+
+      for (Class c : classArray) {
+         String classname = c.getName();
+         classes.put(classname, c);
+      }
+   }
+
+   public Iterator getClassMappings() {
+      return classes.values().iterator();
+   }
+
+   public Class getClassMapping(String name) {
+      return classes.get(name);
+   }
+
+   public String getProperty(String propertyName) {
+      return properties.getProperty(propertyName);
+   }
+
+   public Properties getProperties() {
+      return properties;
+   }
+
+   public ReflectionManager getReflectionManager() {
+      return null;
+   }
+
+//   public SearchMapping getProgrammaticMapping() {
+//
+//      // Documentation on interface says "returns the programmatic configuration or null".
+//      // Since I don't have this parameter set on my implementation, I will just return this
+//      // as a null.
+//
+//      return null;
+//   }
+
+
+}

Added: trunk/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query.backend;
+
+import org.hibernate.search.backend.TransactionContext;
+import org.infinispan.util.logging.Log;
+
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * This class implements the {@link org.hibernate.search.backend.TransactionContext} interface.  It retrieves
+ * transaction context information from the {@link javax.transaction.TransactionManager} that gets passed in as a
+ * parameter upon instantiation.
+ * <p/>
+ * It is used by the {@link QueryInterceptor} to pass transaction information to a
+ * Hibernate Search {@link org.hibernate.search.backend.Work} object.
+ * <p/>
+ * <p/>
+ * // TODO: navssurtani--> Document up this class. Clean up old JBCS stuff etc etc.
+ *
+ * @author Navin Surtani
+ * @see QueryInterceptor
+ */
+public class TransactionalEventTransactionContext implements TransactionContext {
+
+   TransactionManager transactionManager;
+   Log log;
+
+   /**
+    * Creates a new instance of NodeModifiedTransactionContext.
+    * <p/>
+    *
+    * @param transactionManager a NodeModifiedEvent to wrap.  Should not be null.
+    * @throws NullPointerException if event is null.
+    */
+   public TransactionalEventTransactionContext(TransactionManager transactionManager) {
+//      if (transactionManager == null) throw new NullPointerException("transaction manager cannot be null");
+      this.transactionManager = transactionManager;
+   }
+
+   /**
+    * Returns a boolean value whether or not a transaction is in progress (JTA transaction and in this case *not* an
+    * org.hibernate transaction).
+    *
+    * @return true if a transaction is in progress, false otherwise.
+    */
+   public boolean isTransactionInProgress() {
+      if (transactionManager == null) return false;
+
+      Transaction transaction = null;
+      try {
+         transaction = transactionManager.getTransaction();
+      }
+      catch (SystemException e) {
+         log.debug("Caught SystemException in TransactionalEventTransactionContext", e);
+      }
+      return (transaction != null);
+   }
+
+   /**
+    * Returns a JTA transaction.
+    *
+    * @return a JTA transaction if one is available, or a null otherwise.
+    * @see javax.transaction.TransactionManager
+    */
+
+   public Object getTransactionIdentifier() {
+      if (transactionManager == null) return null;
+
+      Transaction transaction = null;
+      try {
+         transaction = transactionManager.getTransaction();
+      }
+      catch (SystemException e) {
+         log.debug("Caught SystemException in TransactionalEventTransactionContext", e);
+      }
+
+      return transaction;
+   }
+
+   /**
+    * Registers the synchronization passed in as a parameter with the ongoing transaction.
+    * <p/>
+    * If there is no ongoing transaction, then this method will do nothing and simply return.
+    * <p/>
+    *
+    * @param synchronization synchronization to register.  Must not be null.
+    * @throws NullPointerException if the synchronization is null.
+    */
+   public void registerSynchronization(Synchronization synchronization) {
+      if (transactionManager != null) {
+         if (synchronization == null) throw new NullPointerException("Synchronization passed in is null!");
+
+         try {
+            Transaction transaction = transactionManager.getTransaction();
+            transaction.registerSynchronization(synchronization);
+         }
+         catch (Exception e) {
+            throw new RuntimeException(e);
+         }
+      }
+   }
+}

Added: trunk/query/src/main/java/org/infinispan/query/impl/AbstractIterator.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/impl/AbstractIterator.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/impl/AbstractIterator.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,68 @@
+package org.infinispan.query.impl;
+
+import org.infinispan.Cache;
+import org.infinispan.query.QueryIterator;
+
+/**
+ * // TODO: Document this
+ * <p/>
+ * This is the abstract superclass of the 2 iterators. Since some of the methods have the same implementations they have
+ * been put onto a separate class.
+ *
+ * @author Navin Surtani
+ * @since 4.0
+ */
+
+
+public abstract class AbstractIterator implements QueryIterator {
+
+   protected Object[] buffer;
+   protected Cache cache;
+
+   protected int index = 0;
+   protected int bufferIndex = -1;
+   protected int max;
+   protected int first;
+   protected int fetchSize;
+
+   public void first() {
+      index = first;
+   }
+
+   public void last() {
+      index = max;
+   }
+
+   public void afterFirst() {
+      index = first + 1;
+   }
+
+   public void beforeLast() {
+      index = max - 1;
+   }
+
+   public boolean isFirst() {
+      return index == first;
+   }
+
+   public boolean isLast() {
+      return index == max;
+   }
+
+   public boolean isAfterFirst() {
+      return index == first + 1;
+   }
+
+   public boolean isBeforeLast() {
+      return index == max - 1;
+   }
+
+   public boolean hasPrevious() {
+      return index >= first;
+   }
+
+   public boolean hasNext() {
+      return index <= max;
+   }
+   
+}

Added: trunk/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,809 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query.impl;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.*;
+import org.hibernate.HibernateException;
+import org.hibernate.search.FullTextFilter;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.FilterDef;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.filter.ChainedFilter;
+import org.hibernate.search.filter.FilterKey;
+import org.hibernate.search.filter.StandardFilterKey;
+import org.hibernate.search.query.FullTextFilterImpl;
+import org.hibernate.search.query.QueryHits;
+import org.hibernate.search.reader.ReaderProvider;
+import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
+import org.hibernate.search.store.DirectoryProvider;
+import static org.hibernate.search.util.FilterCacheModeTypeHelper.cacheInstance;
+import static org.hibernate.search.util.FilterCacheModeTypeHelper.cacheResults;
+import org.hibernate.transform.ResultTransformer;
+import org.infinispan.Cache;
+import org.infinispan.query.CacheQuery;
+import org.infinispan.query.QueryIterator;
+import org.infinispan.query.backend.IndexSearcherCloser;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Implementation class of the CacheQuery interface.
+ * <p/>
+ *
+ * //TODO: navssurtani --> Document this up.
+ *
+ * @author Navin Surtani
+ */
+public class CacheQueryImpl implements CacheQuery
+{
+   private Sort sort;
+   private Filter filter;
+   private Map<String, FullTextFilterImpl> filterDefinitions;
+   private Integer firstResult;
+   private Integer resultSize;
+   private Integer maxResults;
+   private boolean needClassFilterClause;
+   private String[] indexProjection;
+   private ResultTransformer resultTransformer;
+   private Set<Class<?>> classesAndSubclasses;
+   private Set<String> idFieldNames;
+   private boolean allowFieldSelectionInProjection = true;
+   private Query luceneQuery;
+   private SearchFactoryImplementor searchFactory;
+   private Set<Class<?>> targetedEntities;
+   private Cache cache;
+
+   public org.infinispan.util.logging.Log log;
+
+
+
+
+   public CacheQueryImpl(Query luceneQuery, SearchFactoryImplementor searchFactory, Cache cache, Class... classes)
+   {
+      this.luceneQuery = luceneQuery;
+      this.cache = cache;
+      this.searchFactory = searchFactory;
+      this.targetedEntities = this.searchFactory.getIndexedTypesPolymorphic(classes);
+                 
+   }
+
+
+   /**
+    * Takes in a lucene filter and sets it to the filter field in the class.
+    *
+    * @param f - lucene filter
+    */
+
+   public void setFilter(Filter f)
+   {
+      filter = f;
+   }
+
+
+   /**
+    * @return The result size of the query.
+    */
+   public int getResultSize()
+   {
+      if (resultSize == null)
+      {
+         //get result size without object initialization
+         IndexSearcher searcher = buildSearcher(searchFactory);
+         if (searcher == null)
+         {
+            resultSize = 0;
+         }
+         else
+         {
+            TopDocs hits;
+            try
+            {
+               hits = getQueryHits(searcher, 1).topDocs; // Lucene enforces that at least one top doc will be retrieved.
+               resultSize = hits.totalHits;
+            }
+            catch (IOException e)
+            {
+               throw new HibernateException("Unable to query Lucene index", e);
+            }
+            finally
+            {
+               //searcher cannot be null
+               try
+               {
+                  closeSearcher(searcher, searchFactory.getReaderProvider());
+                  //searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
+               }
+               catch (SearchException e)
+               {
+                  log.warn("Unable to properly close searcher during lucene query: " + e);
+               }
+            }
+         }
+      }
+      return this.resultSize;
+   }
+
+   private void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
+   {
+      Set<IndexReader> indexReaders = getIndexReaders(searcher);
+
+      for (IndexReader indexReader : indexReaders)
+      {
+         readerProvider.closeReader(indexReader);
+      }
+   }
+
+
+   public void setSort(Sort s)
+   {
+      sort = s;
+   }
+
+
+   /**
+    * Enable a given filter by its name.
+    *
+    * @param name of filter.
+    * @return a FullTextFilter object.
+    */
+   public FullTextFilter enableFullTextFilter(String name)
+   {
+      if (filterDefinitions == null)
+      {
+         filterDefinitions = new HashMap<String, FullTextFilterImpl>();
+      }
+      FullTextFilterImpl filterDefinition = filterDefinitions.get(name);
+      if (filterDefinition != null) return filterDefinition;
+
+      filterDefinition = new FullTextFilterImpl();
+      filterDefinition.setName(name);
+      FilterDef filterDef = searchFactory.getFilterDefinition(name);
+      if (filterDef == null)
+      {
+         throw new SearchException("Unkown @FullTextFilter: " + name);
+      }
+      filterDefinitions.put(name, filterDefinition);
+      return filterDefinition;
+   }
+
+   /**
+    * Disable a given filter by its name.
+    *
+    * @param name of filter.
+    */
+   public void disableFullTextFilter(String name)
+   {
+      filterDefinitions.remove(name);
+   }
+
+   /**
+    * Sets the the result of the given integer value to the first result.
+    *
+    * @param firstResult index to be set.
+    * @throws IllegalArgumentException if the index given is less than zero.
+    */
+   public void setFirstResult(int firstResult)
+   {
+      if (firstResult < 0)
+      {
+         throw new IllegalArgumentException("'first' pagination parameter less than 0");
+      }
+      this.firstResult = firstResult;
+
+   }
+
+   public QueryIterator iterator() throws HibernateException
+   {
+      return iterator(1);
+   }
+
+   public QueryIterator iterator(int fetchSize) throws HibernateException
+   {
+      List<Object> keyList = null;
+      IndexSearcher searcher = buildSearcher(searchFactory);
+      if (searcher == null)
+      {
+         throw new NullPointerException("IndexSearcher instance is null.");
+      }
+
+      try
+      {
+         QueryHits queryHits = getQueryHits(searcher, calculateTopDocsRetrievalSize());
+         int first = first();
+         int max = max(first, queryHits.totalHits);
+         int size = max - first + 1 < 0 ? 0 : max - first + 1;
+         keyList = new ArrayList<Object>(size);
+
+         DocumentExtractor extractor = new DocumentExtractor(queryHits, searchFactory, indexProjection, idFieldNames, allowFieldSelectionInProjection);
+         for (int index = first; index <= max; index++)
+         {
+            // Since the documentId is same thing as the key in each key, value pairing. We can just get the documentId
+            // from Lucene and then get it from the cache.
+
+            // The extractor.extract.id gives me the documentId that we need.
+
+
+            Object key = extractor.extract(index).id;
+            keyList.add(key);
+         }
+
+      }
+      catch (IOException e)
+      {
+         throw new HibernateException("Unable to query Lucene index", e);
+
+      }
+
+      finally
+      {
+
+         IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
+
+      }
+
+      return new EagerIterator(keyList, cache, fetchSize);
+   }
+
+   public QueryIterator lazyIterator()
+   {
+      return lazyIterator(1);
+   }
+
+   public QueryIterator lazyIterator(int fetchSize)
+   {
+      IndexSearcher searcher = buildSearcher(searchFactory);
+
+      try
+      {
+         QueryHits queryHits = getQueryHits(searcher, calculateTopDocsRetrievalSize());
+         int first = first();
+         int max = max(first, queryHits.totalHits);
+
+         DocumentExtractor extractor = new DocumentExtractor(queryHits, searchFactory, indexProjection, idFieldNames, allowFieldSelectionInProjection);
+
+         return new LazyIterator(extractor, cache, searcher, searchFactory, first, max, fetchSize);
+      }
+      catch (IOException e)
+      {
+         try
+         {
+            IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
+         }
+         catch (SearchException ee)
+         {
+            //we have the initial issue already
+         }
+         throw new HibernateException("Unable to query Lucene index", e);
+
+      }
+
+   }
+
+   public List<Object> list() throws HibernateException
+   {
+      IndexSearcher searcher = buildSearcher(searchFactory);
+
+      if (searcher == null) return Collections.EMPTY_LIST;
+
+
+      try
+      {
+
+         QueryHits queryHits = getQueryHits(searcher, calculateTopDocsRetrievalSize());
+
+         int first = first();
+         int max = max(first, queryHits.totalHits);
+
+         int size = max - first + 1 < 0 ? 0 : max - first + 1;
+
+         DocumentExtractor extractor = new DocumentExtractor(queryHits, searchFactory, indexProjection, idFieldNames, allowFieldSelectionInProjection);
+
+         List<Object> keysForCache = new ArrayList<Object>(size);
+         for (int index = first; index <= max; index++)
+         {
+            // Since the documentId is same thing as the key in each key, value pairing. We can just get the documentId
+            // from Lucene and then get it from the cache.
+
+            // The extractor.extract.id gives me the documentId that we need.
+
+            Object cacheKey = extractor.extract(index).id;
+            keysForCache.add(cacheKey);
+         }
+
+         // Loop through my list of keys and get it from the cache. Put each object that I get into a separate list.
+         List<Object> listToReturn = new ArrayList<Object>(size);
+         for (Object key : keysForCache){
+            listToReturn.add(cache.get(key));
+         }
+
+
+         // TODO: navssurtani --> Speak with EB or HF about what a resultTransformer is and what it does etc etc.
+
+         if (resultTransformer == null)
+         {
+            return listToReturn;
+         }
+         else
+         {
+            return resultTransformer.transformList(listToReturn);
+
+         }
+
+      }
+      catch (IOException e)
+      {
+         throw new HibernateException("Unable to query Lucene index", e);
+
+      }
+      finally
+      {
+         IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
+
+      }
+
+   }
+
+   private int max(int first, int totalHits)
+   {
+      if (maxResults == null)
+      {
+         return totalHits - 1;
+      }
+      else
+      {
+         return maxResults + first < totalHits ?
+                 first + maxResults - 1 :
+                 totalHits - 1;
+      }
+   }
+
+   private int first()
+   {
+      return firstResult != null ?
+              firstResult :
+              0;
+   }
+
+   private QueryHits getQueryHits(Searcher searcher, Integer n) throws IOException
+   {
+      org.apache.lucene.search.Query query = filterQueryByClasses(luceneQuery);
+      buildFilters();
+      QueryHits queryHits;
+      if (n == null)
+      { // try to make sure that we get the right amount of top docs
+         queryHits = new QueryHits(searcher, query, filter, sort);
+      }
+      else
+      {
+         queryHits = new QueryHits(searcher, query, filter, sort, n);
+      }
+      resultSize = queryHits.totalHits;
+      return queryHits;
+   }
+
+   private Integer calculateTopDocsRetrievalSize()
+   {
+      if (maxResults == null)
+      {
+         return null;
+      }
+      else
+      {
+         return first() + maxResults;
+      }
+   }
+
+
+   public void setMaxResults(int maxResults)
+   {
+      if (maxResults < 0)
+      {
+         throw new IllegalArgumentException("'max' pagination parameter less than 0");
+      }
+      this.maxResults = maxResults;
+   }
+
+   private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor)
+   {
+      Map<Class<?>, DocumentBuilderIndexedEntity<?>> builders = searchFactoryImplementor.getDocumentBuildersIndexedEntities();
+      List<DirectoryProvider> directories = new ArrayList<DirectoryProvider>();
+      Set<String> idFieldNames = new HashSet<String>();
+      Similarity searcherSimilarity = null;
+      if (targetedEntities.size() == 0)
+      {
+         // empty targetedEntities array means search over all indexed enities,
+         // but we have to make sure there is at least one
+         if (builders.isEmpty())
+         {
+            throw new HibernateException(
+                    "There are no mapped entities. Don't forget to add @Indexed to at least one class."
+            );
+         }
+
+         for (DocumentBuilderIndexedEntity builder : builders.values())
+         {
+            searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
+            if (builder.getIdKeywordName() != null)
+            {
+               idFieldNames.add(builder.getIdKeywordName());
+               allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
+            }
+            final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy()
+                    .getDirectoryProvidersForAllShards();
+            populateDirectories(directories, directoryProviders);
+         }
+         classesAndSubclasses = null;
+      }
+      else
+      {
+         Set<Class<?>> involvedClasses = new HashSet<Class<?>>(targetedEntities.size());
+         involvedClasses.addAll(targetedEntities);
+         for (Class<?> clazz : targetedEntities)
+         {
+            DocumentBuilderIndexedEntity<?> builder = builders.get(clazz);
+            if (builder != null)
+            {
+               involvedClasses.addAll(builder.getMappedSubclasses());
+            }
+         }
+
+         for (Class clazz : involvedClasses)
+         {
+            DocumentBuilderIndexedEntity builder = builders.get(clazz);
+            if (builder == null)
+            {
+               throw new HibernateException("Not a mapped entity (don't forget to add @Indexed): " + clazz);
+            }
+            if (builder.getIdKeywordName() != null)
+            {
+               idFieldNames.add(builder.getIdKeywordName());
+               allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
+            }
+            final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy()
+                    .getDirectoryProvidersForAllShards();
+            searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
+            populateDirectories(directories, directoryProviders);
+         }
+         this.classesAndSubclasses = involvedClasses;
+      }
+      this.idFieldNames = idFieldNames;
+
+      //compute optimization needClassFilterClause
+      //if at least one DP contains one class that is not part of the targeted classesAndSubclasses we can't optimize
+      if (classesAndSubclasses != null)
+      {
+         for (DirectoryProvider dp : directories)
+         {
+            final Set<Class<?>> classesInDirectoryProvider = searchFactoryImplementor.getClassesInDirectoryProvider(
+                    dp
+            );
+            // if a DP contains only one class, we know for sure it's part of classesAndSubclasses
+            if (classesInDirectoryProvider.size() > 1)
+            {
+               //risk of needClassFilterClause
+               for (Class clazz : classesInDirectoryProvider)
+               {
+                  if (!classesAndSubclasses.contains(clazz))
+                  {
+                     this.needClassFilterClause = true;
+                     break;
+                  }
+               }
+            }
+            if (this.needClassFilterClause)
+            {
+               break;
+            }
+         }
+      }
+
+      //set up the searcher
+      final DirectoryProvider[] directoryProviders = directories.toArray(new DirectoryProvider[directories.size()]);
+      IndexSearcher is = new IndexSearcher(
+              searchFactoryImplementor.getReaderProvider().openReader(
+                      directoryProviders
+              )
+      );
+      is.setSimilarity(searcherSimilarity);
+      return is;
+   }
+
+
+   private Similarity checkSimilarity(Similarity similarity, DocumentBuilderIndexedEntity builder)
+   {
+      if (similarity == null)
+      {
+         similarity = builder.getSimilarity();
+      }
+      else if (!similarity.getClass().equals(builder.getSimilarity().getClass()))
+      {
+         throw new HibernateException("Cannot perform search on two entities with differing Similarity implementations (" + similarity.getClass().getName() + " & " + builder.getSimilarity().getClass().getName() + ")");
+      }
+
+      return similarity;
+   }
+
+   private void populateDirectories(List<DirectoryProvider> directories, DirectoryProvider[] directoryProviders)
+
+   {
+      for (DirectoryProvider provider : directoryProviders)
+      {
+         if (!directories.contains(provider))
+         {
+            directories.add(provider);
+         }
+      }
+   }
+
+
+   private org.apache.lucene.search.Query filterQueryByClasses(org.apache.lucene.search.Query luceneQuery)
+   {
+      if (!needClassFilterClause)
+      {
+         return luceneQuery;
+      }
+      else
+      {
+         //A query filter is more practical than a manual class filtering post query (esp on scrollable resultsets)
+         //it also probably minimise the memory footprint
+         BooleanQuery classFilter = new BooleanQuery();
+         //annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
+         classFilter.setBoost(0);
+         for (Class clazz : classesAndSubclasses)
+         {
+            Term t = new Term(DocumentBuilder.CLASS_FIELDNAME, clazz.getName());
+            TermQuery termQuery = new TermQuery(t);
+            classFilter.add(termQuery, BooleanClause.Occur.SHOULD);
+         }
+         BooleanQuery filteredQuery = new BooleanQuery();
+         filteredQuery.add(luceneQuery, BooleanClause.Occur.MUST);
+         filteredQuery.add(classFilter, BooleanClause.Occur.MUST);
+         return filteredQuery;
+      }
+   }
+
+
+   // Method changed by Navin Surtani on Dec 16th 2008. Copied out from FullTextQueryImpl from Hibernate Search code like
+   // previously done. Also copied in methods like buildLuceneFilter(), createFilter() and those methods that follow down
+   // until the end of the class.
+   private void buildFilters()
+   {
+      if (filterDefinitions == null || filterDefinitions.size() == 0)
+      {
+         return; // there is nothing to do if we don't have any filter definitions
+      }
+
+      ChainedFilter chainedFilter = new ChainedFilter();
+      for (FullTextFilterImpl fullTextFilter : filterDefinitions.values())
+      {
+         Filter filter = buildLuceneFilter(fullTextFilter);
+         chainedFilter.addFilter(filter);
+      }
+
+      if (filter != null)
+      {
+         chainedFilter.addFilter(filter);
+      }
+      filter = chainedFilter;
+   }
+
+   private Filter buildLuceneFilter(FullTextFilterImpl fullTextFilter)
+   {
+
+      /*
+      * FilterKey implementations and Filter(Factory) do not have to be threadsafe wrt their parameter injection
+      * as FilterCachingStrategy ensure a memory barrier between concurrent thread calls
+      */
+      FilterDef def = searchFactory.getFilterDefinition(fullTextFilter.getName());
+      Object instance = createFilterInstance(fullTextFilter, def);
+      FilterKey key = createFilterKey(def, instance);
+
+      // try to get the filter out of the cache
+      Filter filter = cacheInstance(def.getCacheMode()) ?
+              searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
+              null;
+
+      if (filter == null)
+      {
+         filter = createFilter(def, instance);
+
+         // add filter to cache if we have to
+         if (cacheInstance(def.getCacheMode()))
+         {
+            searchFactory.getFilterCachingStrategy().addCachedFilter(key, filter);
+         }
+      }
+      return filter;
+   }
+
+   private Filter createFilter(FilterDef def, Object instance)
+   {
+      Filter filter;
+      if (def.getFactoryMethod() != null)
+      {
+         try
+         {
+            filter = (Filter) def.getFactoryMethod().invoke(instance);
+         }
+         catch (IllegalAccessException e)
+         {
+            throw new SearchException(
+                    "Unable to access @Factory method: "
+                            + def.getImpl().getName() + "." + def.getFactoryMethod().getName()
+            );
+         }
+         catch (InvocationTargetException e)
+         {
+            throw new SearchException(
+                    "Unable to access @Factory method: "
+                            + def.getImpl().getName() + "." + def.getFactoryMethod().getName()
+            );
+         }
+         catch (ClassCastException e)
+         {
+            throw new SearchException(
+                    "@Key method does not return a org.apache.lucene.search.Filter class: "
+                            + def.getImpl().getName() + "." + def.getFactoryMethod().getName()
+            );
+         }
+      }
+      else
+      {
+         try
+         {
+            filter = (Filter) instance;
+         }
+         catch (ClassCastException e)
+         {
+            throw new SearchException(
+                    "Filter implementation does not implement the Filter interface: "
+                            + def.getImpl().getName() + ". "
+                            + (def.getFactoryMethod() != null ? def.getFactoryMethod().getName() : ""), e
+            );
+         }
+      }
+
+      filter = addCachingWrapperFilter(filter, def);
+      return filter;
+   }
+
+   private Object createFilterInstance(FullTextFilterImpl fullTextFilter,
+                                       FilterDef def)
+   {
+      Object instance;
+      try
+      {
+         instance = def.getImpl().newInstance();
+      }
+      catch (InstantiationException e)
+      {
+         throw new SearchException("Unable to create @FullTextFilterDef: " + def.getImpl(), e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new SearchException("Unable to create @FullTextFilterDef: " + def.getImpl(), e);
+      }
+      for (Map.Entry<String, Object> entry : fullTextFilter.getParameters().entrySet())
+      {
+         def.invoke(entry.getKey(), instance, entry.getValue());
+      }
+      if (cacheInstance(def.getCacheMode()) && def.getKeyMethod() == null && fullTextFilter.getParameters()
+              .size() > 0)
+      {
+         throw new SearchException("Filter with parameters and no @Key method: " + fullTextFilter.getName());
+      }
+      return instance;
+   }
+
+
+   private FilterKey createFilterKey(FilterDef def, Object instance)
+   {
+      FilterKey key = null;
+      if (!cacheInstance(def.getCacheMode()))
+      {
+         return key; // if the filter is not cached there is no key!
+      }
+
+      if (def.getKeyMethod() == null)
+      {
+         key = new FilterKey()
+         {
+            public int hashCode()
+            {
+               return getImpl().hashCode();
+            }
+
+            public boolean equals(Object obj)
+            {
+               if (!(obj instanceof FilterKey))
+               {
+                  return false;
+               }
+               FilterKey that = (FilterKey) obj;
+               return this.getImpl().equals(that.getImpl());
+            }
+         };
+      }
+      else
+      {
+         try
+         {
+            key = (FilterKey) def.getKeyMethod().invoke(instance);
+         }
+         catch (IllegalAccessException e)
+         {
+            throw new SearchException(
+                    "Unable to access @Key method: "
+                            + def.getImpl().getName() + "." + def.getKeyMethod().getName()
+            );
+         }
+         catch (InvocationTargetException e)
+         {
+            throw new SearchException(
+                    "Unable to access @Key method: "
+                            + def.getImpl().getName() + "." + def.getKeyMethod().getName()
+            );
+         }
+         catch (ClassCastException e)
+         {
+            throw new SearchException(
+                    "@Key method does not return FilterKey: "
+                            + def.getImpl().getName() + "." + def.getKeyMethod().getName()
+            );
+         }
+      }
+      key.setImpl(def.getImpl());
+
+      //Make sure Filters are isolated by filter def name
+      StandardFilterKey wrapperKey = new StandardFilterKey();
+      wrapperKey.addParameter(def.getName());
+      wrapperKey.addParameter(key);
+      return wrapperKey;
+   }
+
+   private Filter addCachingWrapperFilter(Filter filter, FilterDef def)
+   {
+      if (cacheResults(def.getCacheMode()))
+      {
+         int cachingWrapperFilterSize = searchFactory.getFilterCacheBitResultsSize();
+         filter = new org.hibernate.search.filter.CachingWrapperFilter(filter, cachingWrapperFilterSize);
+      }
+
+      return filter;
+   }
+  
+}
+

Added: trunk/query/src/main/java/org/infinispan/query/impl/EagerIterator.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/impl/EagerIterator.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/impl/EagerIterator.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,275 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query.impl;
+
+
+import net.jcip.annotations.NotThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.infinispan.Cache;
+import org.infinispan.query.impl.AbstractIterator;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * This is the implementation class for the interface QueryResultIterator which extends ListIterator. It is what is
+ * returned when the {@link org.infinispan.query.CacheQuery#iterator()}.
+ * <p/>
+ * <p/>
+ *
+ * //TODO: navssurtani --> Document this.
+ *
+ * @author Navin Surtani
+ */
+
+ at NotThreadSafe
+public class EagerIterator extends AbstractIterator {
+   //private final int size;
+   private List<Object> idList;
+
+   private int lowerLimit = 0;
+   private int upperLimit = 0;
+   private static final Log log = LogFactory.getLog(EagerIterator.class);
+
+
+   public EagerIterator(List<Object> idList, Cache cache, int fetchSize)
+   {
+      if (fetchSize < 1)
+      {
+         throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
+      }
+
+      this.idList = idList;
+      this.cache = cache;
+      this.fetchSize = fetchSize;
+
+      // Set the values of first and max so that they can be used by the methods on the superclass.
+      // Since this is the eager version, we know that we can set the 'first' field to 0.
+
+      first = 0;
+
+      // Similarly max can be set to the size of the list that gets passed in - 1. Using -1 because max is on base 0 while
+      // the size of the list is base 1.
+
+      max = idList.size() - 1;
+
+      buffer = new Object[this.fetchSize];
+   }
+
+   /**
+    * Jumps to a given index in the list of results.
+    *
+    * @param index to jump to
+    * @throws IndexOutOfBoundsException
+    */
+
+   public void jumpToResult(int index) throws IndexOutOfBoundsException
+   {
+      if (index > idList.size() || index < 0)
+      {
+         throw new IndexOutOfBoundsException("The index you entered is either greater than the size of the list or negative");
+      }
+      this.index = index;
+   }
+
+   public void close()
+   {
+      // This method does not need to do anything for this type of iterator as when an instace of it is
+      // created, the iterator() method in CacheQueryImpl closes everything that needs to be closed.
+
+      // TODO: Should I be throwing an exception here?
+   }
+
+   /**
+    * Returns the next element in the list
+    *
+    * @return The next element in the list.
+    */
+   public Object next()
+   {
+      if (!hasNext()) throw new IndexOutOfBoundsException("Out of boundaries. There is no next");
+
+      Object toReturn;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+      if (bufferIndex >= 0                                       // buffer init check
+              && index >= bufferIndex                           // lower boundary
+              && index < (bufferIndex + bufferSize))          // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = index - bufferIndex;
+         toReturn = buffer[indexToReturn];
+      }
+
+      else
+      {
+         // We need to populate the buffer.
+
+         toReturn = cache.get(idList.get(index));
+
+         //Wiping bufferObjects and the bufferIndex so that there is no stale data.
+
+         Arrays.fill(buffer, null);
+         buffer[0] = toReturn;
+
+         // we now need to buffer item at index "index", as well as the next "fetchsize - 1" elements.  I.e., a total of fetchsize elements will be buffered.
+         //now loop through bufferSize times to add the rest of the objects into the list.
+
+         for (int i = 1; i < bufferSize; i++)
+         {
+            if (index + i > max)
+            {
+               if (log.isDebugEnabled())
+               {
+                  log.debug("Your current index + bufferSize exceeds the size of your number of hits");
+               }
+               break;
+            }
+
+            Object toBuffer = cache.get(idList.get(index + i));
+            buffer[i] = toBuffer;
+         }
+         bufferIndex = index;
+
+      }
+
+      index++;
+      return toReturn;
+   }
+
+
+   /**
+    * Returns the previous element in the list.
+    *
+    * @return The previous element in the list.
+    */
+
+   public Object previous()
+   {
+      if (!hasPrevious()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no previous");
+
+      Object toReturn;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+
+      if (bufferIndex >= 0 // buffer init check
+              && index <= bufferIndex // lower boundary
+              && index >= (bufferIndex + bufferSize)) // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = bufferIndex - index;        // Unlike next() we have to make sure that we are subtracting index from bufferIndex
+         toReturn = buffer[indexToReturn];
+      }
+      else
+      {
+         toReturn = cache.get(idList.get(index));
+         // Wiping bufferObjects and the bufferIndex so that there is no stale data.
+
+         Arrays.fill(buffer, null);
+         buffer[0] = toReturn;
+
+         // we now need to buffer objects at index "index", as well as the next "fetchsize - 1" elements.
+         // I.e., a total of fetchsize elements will be buffered.
+         // now loop through bufferSize times to add the rest of the objects into the list.
+
+         for (int i = 1; i < bufferSize; i++)
+         {
+            if (index - i < first)
+            {
+               if (log.isDebugEnabled())
+               {
+                  log.debug("Your current index - bufferSize exceeds the size of your number of hits");
+               }
+               break;
+            }
+            Object toBuffer = cache.get(idList.get(index - i));
+            buffer[i] = toBuffer;
+         }
+         bufferIndex = index;
+      }
+      index--;
+      return toReturn;
+   }
+
+   /**
+    * Returns the index of the element that would be returned by a subsequent call to next.
+    *
+    * @return Index of next element.
+    */
+
+   public int nextIndex()
+   {
+      if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
+      return index + 1;
+
+   }
+
+   /**
+    * Returns the index of the element that would be returned by a subsequent call to previous.
+    *
+    * @return Index of previous element.
+    */
+
+   public int previousIndex()
+   {
+      if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries");
+      return index - 1;
+   }
+
+   /**
+    * This method is not supported and should not be used. Use cache.remove() instead.
+    */
+   public void remove()
+   {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache.  Please use searchableCache.put()");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+   public void set(Object o) throws UnsupportedOperationException
+   {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache.  Please use searchableCache.put()");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+
+   public void add(Object o)
+   {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache. Please use searchableCache.put()");
+   }
+
+
+}

Added: trunk/query/src/main/java/org/infinispan/query/impl/LazyIterator.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/impl/LazyIterator.java	                        (rev 0)
+++ trunk/query/src/main/java/org/infinispan/query/impl/LazyIterator.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,211 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.query.impl;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.apache.lucene.search.IndexSearcher;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.query.impl.AbstractIterator;
+import org.infinispan.query.backend.IndexSearcherCloser;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+
+/**
+ * Implementation for {@link org.infinispan.query.QueryIterator}. This is what is returned when the {@link org.infinispan.query.CacheQuery#lazyIterator()} method
+ * is called. This loads the results only when required and hence differs from {@link EagerIterator} which is the
+ * other implementation of QueryResultIterator.
+ *
+ * @author Navin Surtani
+ */
+
+ at NotThreadSafe
+public class LazyIterator extends AbstractIterator {
+
+   private DocumentExtractor extractor;
+   private IndexSearcher searcher;
+   private SearchFactoryImplementor searchFactory;
+
+
+
+   public LazyIterator(DocumentExtractor extractor, Cache cache,
+                            IndexSearcher searcher, SearchFactoryImplementor searchFactory, int first, int max, int fetchSize) {
+      if (fetchSize < 1) {
+         throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
+      }
+
+      this.extractor = extractor;
+      this.cache = cache;
+      index = first;
+      this.first = first;
+      this.max = max;
+      this.fetchSize = fetchSize;
+      this.searcher = searcher;
+      this.searchFactory = searchFactory;
+
+      //Create an buffer with size fetchSize (which is the size of the required buffer).
+      buffer = new Object[this.fetchSize];
+   }
+
+   public void jumpToResult(int index) throws IndexOutOfBoundsException {
+      if (index < first || index > max) {
+         throw new IndexOutOfBoundsException("The given index is incorrect. Please check and try again.");
+      }
+
+      this.index = first + index;
+   }
+
+   public void close() {
+      IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
+   }
+
+   public Object next() {
+      if (!hasNext()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no next");
+
+      Object toReturn = null;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+      if (bufferIndex >= 0                                       // buffer init check
+            && index >= bufferIndex                           // lower boundary
+            && index < (bufferIndex + bufferSize))          // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = index - bufferIndex;
+         toReturn = buffer[indexToReturn];
+      } else {
+         // else we need to populate the buffer and get what we need.
+
+         try {
+            String documentId = (String) extractor.extract(index).id;
+            toReturn = cache.get(documentId);
+
+            //Wiping bufferObjects and the bufferIndex so that there is no stale data.
+            Arrays.fill(buffer, null);
+            buffer[0] = toReturn;
+
+            // we now need to buffer item at index "index", as well as the next "fetchsize - 1" elements.  I.e., a total of fetchsize elements will be buffered.
+            // ignore loop below, in needs fixing
+            //now loop through bufferSize times to add the rest of the objects into the list.
+
+            for (int i = 1; i < bufferSize; i++) {
+               String bufferDocumentId = (String) extractor.extract(index + i).id;
+               Object toBuffer = cache.get(bufferDocumentId);
+               buffer[i] = toBuffer;
+            }
+            bufferIndex = index;
+         }
+         catch (IOException e) {
+            throw new CacheException();
+         }
+      }
+
+      index++;
+      return toReturn;
+   }
+
+   public Object previous() {
+      if (!hasPrevious()) throw new IndexOutOfBoundsException("Index is out of bounds. There is no previous");
+
+      Object toReturn = null;
+      int bufferSize = buffer.length;
+
+      // make sure the index we are after is in the buffer.  If it is, then index >= bufferIndex and index <= (bufferIndex + bufferSize).
+
+      if (bufferIndex >= 0 // buffer init check
+            && index <= bufferIndex // lower boundary
+            && index >= (bufferIndex + bufferSize)) // upper boundary
+      {
+         // now we can get this from the buffer.  Sweet!
+         int indexToReturn = bufferIndex - index;        // Unlike next() we have to make sure that we are subtracting index from bufferIndex
+         toReturn = buffer[indexToReturn];
+      }
+
+      try {
+         //Wiping the buffer
+         Arrays.fill(buffer, null);
+
+         String documentId = (String) extractor.extract(index).id;
+         toReturn = cache.get(documentId);
+
+         buffer[0] = toReturn;
+
+         //now loop through bufferSize times to add the rest of the objects into the list.
+         for (int i = 1; i < bufferSize; i++) {
+            String bufferDocumentId = (String) extractor.extract(index - i).id;    //In this case it has to be index - i because previous() is called.
+            Object toBuffer = cache.get(bufferDocumentId);
+            buffer[i] = toBuffer;
+         }
+
+         bufferIndex = index;
+      }
+      catch (IOException e) {
+         e.printStackTrace();
+      }
+      index--;
+      return toReturn;
+   }
+
+   public int nextIndex() {
+      if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
+      return index + 1;
+   }
+
+   public int previousIndex() {
+      if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries.");
+      return index - 1;
+   }
+
+   /**
+    * This method is not supported and should not be used. Use cache.remove() instead.
+    */
+   public void remove() {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+   public void set(Object o) throws UnsupportedOperationException {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+   }
+
+   /**
+    * This method is not supported in and should not be called. Use cache.put() instead.
+    *
+    * @param o
+    * @throws UnsupportedOperationException
+    */
+
+   public void add(Object o) {
+      throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+   }
+
+}

Added: trunk/query/src/test/java/org/infinispan/query/backend/TransactionalEventTransactionContextTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/backend/TransactionalEventTransactionContextTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/backend/TransactionalEventTransactionContextTest.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,21 @@
+package org.infinispan.query.backend;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Navin Surtani
+ */
+
+ at Test
+public class TransactionalEventTransactionContextTest
+{
+
+   @Test (expectedExceptions = NullPointerException.class)
+   public void testNullConstuctor()
+   {
+      TransactionalEventTransactionContext tetc = new TransactionalEventTransactionContext(null);
+   }
+
+
+
+}

Added: trunk/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,49 @@
+package org.infinispan.query.blackbox;
+
+import org.infinispan.Cache;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.query.test.BrokenProvided;
+import org.infinispan.query.backend.QueryHelper;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.testng.annotations.Test;
+
+/**
+ * This test is to try and create a searchable cache without the proper annotations used.
+ *
+ * @author Navin Surtani
+ */
+ at Test (groups = "functional")
+public class BrokenAnnotationTest extends SingleCacheManagerTest
+{
+   @Test (expectedExceptions = IllegalArgumentException.class)
+   public void testProvided() throws Exception
+   {
+      org.infinispan.query.test.BrokenProvided provided = new org.infinispan.query.test.BrokenProvided();
+      provided.setBoth("Cat", 5);
+      
+      Cache cache = createCacheManager().getCache();
+
+      QueryHelper qh = new QueryHelper(cache, null, BrokenProvided.class);
+
+
+   }
+
+   @Test (expectedExceptions = IllegalArgumentException.class)
+   public void testDocumentId() throws Exception
+   {
+      org.infinispan.query.test.BrokenDocumentId provided = new org.infinispan.query.test.BrokenDocumentId();
+      provided.setBoth("Cat", 5);
+
+      Cache cache = createCacheManager().getCache();
+
+      QueryHelper qh = new QueryHelper(cache, null, BrokenProvided.class);
+
+
+
+   }
+
+   protected CacheManager createCacheManager() throws Exception {
+      return new DefaultCacheManager();  // TODO: Is there a better way to do this?
+   }
+}

Added: trunk/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,214 @@
+package org.infinispan.query.blackbox;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.query.CacheQuery;
+import org.infinispan.query.QueryFactory;
+import org.infinispan.query.backend.QueryHelper;
+import org.infinispan.query.helper.IndexCleanUp;
+import org.infinispan.query.test.Person;
+import org.infinispan.test.MultipleCacheManagersTest;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.tree.Fqn;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * @author Navin Surtani
+ */
+ at Test(groups = "functional")
+public class ClusteredCacheTest extends MultipleCacheManagersTest
+{
+   Cache<String, Person> cache1, cache2;
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   QueryHelper qh;
+   List found;
+   String key1 = "Navin";
+   String key2 = "BigGoat";
+   String key3 = "MiniGoat";
+   private static final Log log = LogFactory.getLog(Person.class);
+
+   public ClusteredCacheTest() {
+      cleanup = CleanupPhase.AFTER_METHOD;
+   }
+
+   @BeforeMethod
+   protected void createCacheManagers() throws Throwable {
+      Configuration cacheCfg = new Configuration();
+      cacheCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+      cacheCfg.setFetchInMemoryState(false);
+
+      List<Cache<String, Person>> caches = createClusteredCaches(2, "infinispan-query", cacheCfg);
+
+      cache1 = caches.get(0);
+      cache2 = caches.get(1);
+
+      // We will put objects into cache1 and then try and run the queries on cache2. This would mean that indexLocal
+      // must be set to false.
+
+      System.setProperty("query", "true");
+      System.setProperty("indexLocal", "false");
+
+      qh = new QueryHelper(cache2, null, Person.class);
+      qh.applyProperties();
+
+      TestingUtil.blockUntilViewsReceived(60000, cache1, cache2);
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("BigGoat");
+      person2.setBlurb("Eats grass");
+
+      person3 = new Person();
+      person3.setName("MiniGoat");
+      person3.setBlurb("Eats cheese");
+
+      //Put the 3 created objects in the cache1.
+
+      cache1.put(key1, person1);
+      cache1.put(key2, person2);
+      cache1.put(key3, person3);
+   }
+
+   @AfterMethod
+   public void tearDown() {
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   public void testSimple() throws ParseException
+   {
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory())
+            .getBasicQuery("blurb", "playing");
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+
+      if(found.get(0) == null)
+      {
+         log.warn("found.get(0) is null");
+         Person p1 = (Person) cache2.get(key1);
+         if(p1 == null)
+         {
+            log.warn("Person p1 is null in sc2 and cannot actually see the data of person1 in sc1");
+         }
+
+         else
+         {
+            log.trace("p1 name is  " + p1.getName());
+
+         }
+      }
+
+      assert found.get(0).equals(person1);
+
+   }
+
+   public void testModified() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+      cache1.put("Navin", person1);
+
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   public void testAdded() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      System.out.println("found.size() is " + found.size());
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert !found.contains(person4) : "This should not contain object person4";
+
+      person4 = new Person();
+      person4.setName("Mighty Goat");
+      person4.setBlurb("Also eats grass");
+
+      cache1.put("mighty", person4);
+
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 3 : "Size of list should be 3";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert found.contains(person4) : "This should now contain object person4";
+   }
+
+   public void testRemoved() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person2);
+      assert found.contains(person3) : "This should still contain object person3";
+
+      cache1.remove(Fqn.fromString("/a/b/c/"), key3);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      System.out.println("list is: - " + found);
+
+   }
+
+   public void testGetResultSize() throws ParseException{
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      System.out.println("Result size is: - " + cacheQuery.getResultSize());
+   }
+
+
+}
+
+

Added: trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,285 @@
+package org.infinispan.query.blackbox;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.PrefixFilter;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Sort;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.query.CacheQuery;
+import org.infinispan.query.QueryIterator;
+import org.infinispan.query.QueryFactory;
+import org.infinispan.query.backend.QueryHelper;
+import org.infinispan.query.helper.IndexCleanUp;
+import org.infinispan.query.test.Person;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.transaction.lookup.DummyTransactionManagerLookup;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test(groups = "functional", enabled = false)
+public class LocalCacheProfilerTest extends SingleCacheManagerTest {
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   Person person5;
+   Person person6;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   List found;
+   String key1 = "Navin";
+   String key2 = "BigGoat";
+   String key3 = "MiniGoat";
+
+   Cache<String, Person> cache;
+   QueryHelper qh;
+
+   protected CacheManager createCacheManager() throws Exception {
+      Configuration c = new Configuration();
+      c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+      return TestCacheManagerFactory.createCacheManager(c);
+   }
+
+
+   @BeforeMethod
+   public void setUp() throws Exception {
+      System.setProperty("query", "true");
+      System.setProperty("indexLocal", "true");
+
+
+      cache = createCacheManager().getCache();
+
+      qh = new QueryHelper(cache, null, Person.class);
+      qh.applyProperties();
+
+
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("Big Goat");
+      person2.setBlurb("Eats grass");
+
+      person3 = new Person();
+      person3.setName("Mini Goat");
+      person3.setBlurb("Eats cheese");
+
+      person5 = new Person();
+      person5.setName("Smelly Cat");
+      person5.setBlurb("Eats fish");
+
+      //Put the 3 created objects in the cache.
+      cache.put(key1, person1);
+      cache.put(key2, person2);
+      cache.put(key3, person3);
+
+   }
+
+   @AfterMethod
+   public void tearDown() {
+      if (cache != null) cache.stop();
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testSimple() throws ParseException {
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getBasicQuery("blurb", "playing");
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testEagerIterator() throws ParseException {
+
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).
+            getBasicQuery("blurb", "playing");
+
+      QueryIterator found = cacheQuery.iterator();
+
+      assert found.isFirst();
+      assert found.isLast();
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testMultipleResults() throws ParseException {
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0) == person2;
+      assert found.get(1) == person3;
+
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testModified() throws ParseException {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+      cache.put(key1, person1);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testAdded() throws ParseException {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert !found.contains(person4) : "This should not contain object person4";
+
+      person4 = new Person();
+      person4.setName("Mighty Goat");
+      person4.setBlurb("Also eats grass");
+
+      cache.put("mighty", person4);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 3 : "Size of list should be 3";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert found.contains(person4) : "This should now contain object person4";
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testRemoved() throws ParseException {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person2);
+      assert found.contains(person3) : "This should still contain object person3";
+
+      cache.remove(key3);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.contains(person2);
+      assert !found.contains(person3) : "The search should not return person3";
+
+
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testSetSort() throws ParseException {
+      person2.setAge(35);
+      person3.setAge(12);
+
+      Sort sort = new Sort("age");
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      cacheQuery.setSort(sort);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0).equals(person2);
+      assert found.get(1).equals(person3);
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testSetFilter() throws ParseException {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      Filter filter = new PrefixFilter(new Term("blurb", "cheese"));
+
+      cacheQuery.setFilter(filter);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testLazyIterator() throws ParseException {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      QueryIterator found = cacheQuery.lazyIterator();
+
+      assert found.isFirst();
+      assert found.isLast();
+
+   }
+
+   @Test (invocationCount = 2000, enabled = false)
+   public void testGetResultSize() throws ParseException {
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      assert cacheQuery.getResultSize() == 1;
+   }
+
+}

Added: trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,274 @@
+package org.infinispan.query.blackbox;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.PrefixFilter;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Sort;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.query.CacheQuery;
+import org.infinispan.query.QueryIterator;
+import org.infinispan.query.QueryFactory;
+import org.infinispan.query.backend.QueryHelper;
+import org.infinispan.query.helper.IndexCleanUp;
+import org.infinispan.query.test.Person;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.transaction.lookup.DummyTransactionManagerLookup;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test(groups = "functional")
+public class LocalCacheTest extends SingleCacheManagerTest {
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   Person person5;
+   Person person6;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   List found;
+   String key1 = "Navin";
+   String key2 = "BigGoat";
+   String key3 = "MiniGoat";
+
+   Cache<String, Person> cache;
+   QueryHelper qh;
+   
+   protected CacheManager createCacheManager() throws Exception {
+      Configuration c = new Configuration();
+      c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+      return TestCacheManagerFactory.createCacheManager(c);
+   }
+
+
+   @BeforeMethod
+   public void setUp() throws Exception {
+      System.setProperty("query", "true");
+      System.setProperty("indexLocal", "true");
+
+
+      cache = createCacheManager().getCache();
+
+      qh = new QueryHelper(cache, null, Person.class);
+      qh.applyProperties();
+      
+      
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("Big Goat");
+      person2.setBlurb("Eats grass");
+
+      person3 = new Person();
+      person3.setName("Mini Goat");
+      person3.setBlurb("Eats cheese");
+
+      person5 = new Person();
+      person5.setName("Smelly Cat");
+      person5.setBlurb("Eats fish");
+
+      //Put the 3 created objects in the cache.
+      cache.put(key1, person1);
+      cache.put(key2, person2);
+      cache.put(key3, person3);
+
+   }
+
+   @AfterMethod
+   public void tearDown() {
+      if (cache != null) cache.stop();
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   public void testSimple() throws ParseException {
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getBasicQuery("blurb", "playing");
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   public void testEagerIterator() throws ParseException {
+
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).
+            getBasicQuery("blurb", "playing");
+
+      QueryIterator found = cacheQuery.iterator();
+
+      assert found.isFirst();
+      assert found.isLast();
+   }
+
+   public void testMultipleResults() throws ParseException {
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0) == person2;
+      assert found.get(1) == person3;
+
+   }
+
+   public void testModified() throws ParseException {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+      cache.put(key1, person1);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   public void testAdded() throws ParseException {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert !found.contains(person4) : "This should not contain object person4";
+
+      person4 = new Person();
+      person4.setName("Mighty Goat");
+      person4.setBlurb("Also eats grass");
+
+      cache.put("mighty", person4);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 3 : "Size of list should be 3";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert found.contains(person4) : "This should now contain object person4";
+   }
+
+   public void testRemoved() throws ParseException {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person2);
+      assert found.contains(person3) : "This should still contain object person3";
+
+      cache.remove(key3);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.contains(person2);
+      assert !found.contains(person3) : "The search should not return person3";
+
+
+   }
+
+   public void testSetSort() throws ParseException {
+      person2.setAge(35);
+      person3.setAge(12);
+
+      Sort sort = new Sort("age");
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      cacheQuery.setSort(sort);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0).equals(person2);
+      assert found.get(1).equals(person3);
+   }
+
+   public void testSetFilter() throws ParseException {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      Filter filter = new PrefixFilter(new Term("blurb", "cheese"));
+
+      cacheQuery.setFilter(filter);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+
+   }
+
+   public void testLazyIterator() throws ParseException {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      QueryIterator found = cacheQuery.lazyIterator();
+
+      assert found.isFirst();
+      assert found.isLast();
+
+   }
+
+   public void testGetResultSize() throws ParseException {
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
+
+      assert cacheQuery.getResultSize() == 1;
+   }
+
+}

Added: trunk/query/src/test/java/org/infinispan/query/helper/IndexCleanUp.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/helper/IndexCleanUp.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/helper/IndexCleanUp.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,41 @@
+package org.infinispan.query.helper;
+
+import org.infinispan.query.test.Person;
+
+import java.io.File;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+public class IndexCleanUp
+{
+
+   public static void cleanUpIndexes()
+   {
+      Class[] knownClasses = {Person.class};
+      for (Class c : knownClasses)
+      {
+         String dirName = c.getName();
+         File file = new File(dirName);
+         if (file.exists())
+         {
+            recursiveDelete(file);
+         }
+      }
+   }
+
+   private static void recursiveDelete(File f)
+   {
+      if (f.isDirectory())
+      {
+         File[] files = f.listFiles();
+         for (File file : files) recursiveDelete(file);
+      }
+      else
+      {
+         f.delete();
+      }
+   }
+
+}
+

Added: trunk/query/src/test/java/org/infinispan/query/impl/EagerIteratorTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/impl/EagerIteratorTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/impl/EagerIteratorTest.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,221 @@
+package org.infinispan.query.impl;
+
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.*;
+import org.easymock.IAnswer;
+import org.infinispan.Cache;
+import org.infinispan.query.QueryIterator;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Navin Surtani
+ *         <p/>
+ *         Test class for the {@link EagerIterator}
+ */
+
+ at Test(groups = "functional")
+public class EagerIteratorTest {
+   List<Object> keys;
+   Map<String, String> dummyResults;
+   QueryIterator iterator;
+   int fetchSize = 1;
+   Cache<String, String> cache;
+
+   @BeforeMethod
+   public void setUp() throws Exception {
+
+      // create a set of dummy keys
+      keys = new ArrayList<Object>();
+      // create some dummy data
+      dummyResults = new HashMap<String, String>();
+
+      for (int i=1; i<=10; i++) {
+         String key = "key" + i;
+         keys.add(key);
+         dummyResults.put(key, "Result number " + i);
+      }
+
+      // create the instance of the iterator.
+      cache = createMock(Cache.class);
+
+      expect(cache.get(anyObject())).andAnswer(new IAnswer<String>(){
+         public String answer() throws Throwable {
+            String k = getCurrentArguments()[0].toString();
+            return dummyResults.get(k);
+         }
+      }).anyTimes();
+
+      iterator = new EagerIterator(keys, cache, fetchSize);
+      EasyMock.replay(cache);
+   }
+
+   @AfterMethod
+   public void tearDown() {
+      keys = null;
+      dummyResults = null;
+      iterator = null;
+   }
+
+   public void testJumpToResult() throws IndexOutOfBoundsException {
+      iterator.jumpToResult(0);
+      assert iterator.isFirst();
+
+      iterator.jumpToResult(1);
+      assert iterator.isAfterFirst();
+
+      iterator.jumpToResult((keys.size() - 1));
+      assert iterator.isLast();
+
+      iterator.jumpToResult(keys.size() - 2);
+      assert iterator.isBeforeLast();
+   }
+
+   public void testFirst() {
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      Object next = iterator.next();
+      System.out.println(next);
+
+      assert next == dummyResults.get(keys.get(0));
+
+      assert !iterator.isFirst();
+
+      iterator.first();
+
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      next = iterator.next();
+      assert next == dummyResults.get(keys.get(0));
+      assert !iterator.isFirst();
+
+   }
+
+   public void testLast() {
+      //Jumps to the last element
+      iterator.last();
+
+      //Makes sure that the iterator is pointing at the last element.
+      assert iterator.isLast();
+
+      Object next = iterator.next();
+
+      //Returns the size of the list of keys.
+      int size = keys.size();
+
+      //Makes sure that previous is the last element.
+      assert next == dummyResults.get(keys.get(size - 1));
+
+      //Check that the iterator is NOT pointing at the last element.
+      assert !iterator.isLast();
+   }
+
+   public void testAfterFirst() {
+      //Jump to the second element.
+      iterator.afterFirst();
+
+      //Check this
+      assert iterator.isAfterFirst();
+
+      //Previous element in the list
+      Object previous = iterator.previous();
+
+      //Check that previous is the first element.
+      assert previous == dummyResults.get(keys.get(1));
+
+      //Make sure that the iterator isn't pointing at the second element.
+      assert !iterator.isAfterFirst();
+
+   }
+
+   public void testBeforeLast() {
+      //Jump to the penultimate element.
+      iterator.beforeLast();
+
+      //Check this
+      assert iterator.isBeforeLast();
+
+      //Next element - which should be the last.
+      Object next = iterator.next();
+
+      //Check that next is the penultimate element.
+      int size = keys.size();
+      assert next == dummyResults.get(keys.get(size - 2));
+
+      //Make sure that the iterator is not pointing at the penultimate element.
+      assert !iterator.isBeforeLast();
+   }
+
+   public void testIsFirst() {
+      iterator.first();
+      assert iterator.isFirst();
+
+      iterator.next();
+      assert !iterator.isFirst();
+   }
+
+   public void testIsLast() {
+      iterator.last();
+      assert iterator.isLast();
+
+      iterator.previous();
+      assert !iterator.isLast();
+   }
+
+   public void testIsAfterFirst() {
+      iterator.afterFirst();
+      assert iterator.isAfterFirst();
+
+      iterator.previous();
+      assert !iterator.isAfterFirst();
+   }
+
+   public void testIsBeforeLast() {
+      iterator.beforeLast();
+      assert iterator.isBeforeLast();
+   }
+
+   public void testNextAndHasNext() {
+      iterator.first();
+      for (int i = 0; i < keys.size(); i++) {
+         System.out.println("Loop number count: - " + (i + 1));
+         Object expectedValue = dummyResults.get(keys.get(i));
+         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
+         assert expectedValue == iterator.next(); // tests next()
+      }
+      assert !iterator.hasNext(); // this should now NOT be true.
+   }
+
+   public void testPreviousAndHasPrevious() {
+      iterator.last();
+      for (int i = keys.size() - 1; i >= 0; i--) {
+         Object expectedValue = dummyResults.get(keys.get(i));
+         assert iterator.hasPrevious(); // should have previous as long as we are more than the number of elements.
+         assert expectedValue == iterator.previous(); // tests previous()
+      }
+      assert !iterator.hasPrevious(); // this should now NOT be true.
+
+   }
+
+   public void testNextIndex() {
+      iterator.first();
+      assert iterator.nextIndex() == 1;
+
+      iterator.last();
+      assert iterator.nextIndex() == keys.size();
+
+   }
+
+   public void testPreviousIndex() {
+      iterator.first();
+      assert iterator.previousIndex() == -1;
+
+      iterator.last();
+      assert iterator.previousIndex() == (keys.size() - 2);
+   }
+
+}

Added: trunk/query/src/test/java/org/infinispan/query/impl/LazyIteratorTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/impl/LazyIteratorTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/impl/LazyIteratorTest.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,345 @@
+package org.infinispan.query.impl;
+
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.IndexSearcher;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.*;
+import org.easymock.IAnswer;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.EntityInfo;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.Cache;
+import org.infinispan.query.helper.IndexCleanUp;
+import org.infinispan.query.test.Person;
+import org.infinispan.query.impl.LazyIterator;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import org.testng.annotations.ExpectedExceptions;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * @author Navin Surtani
+ */
+ at Test(groups = "functional")
+public class LazyIteratorTest {
+   Cache<String, Person> cache;
+   LazyIterator iterator = null;
+   int fetchSize = 1;
+   Person person1, person2, person3, person4, person5, person6, person7, person8, person9, person10;
+   StringBuilder builder;
+   Map<String, Person> dummyDataMap;
+   List<String> keyList;
+
+   @BeforeTest
+   public void setUpBeforeTest() throws Exception {
+      dummyDataMap = new HashMap<String, Person>();
+
+      // Create a bunch of Person instances.
+      person1 = new Person();
+      person2 = new Person();
+      person3 = new Person();
+      person4 = new Person();
+      person5 = new Person();
+      person6 = new Person();
+      person7 = new Person();
+      person8 = new Person();
+      person9 = new Person();
+      person10 = new Person();
+
+
+      // Set the fields to something so that everything will be found.
+      person1.setBlurb("cat");
+      person2.setBlurb("cat");
+      person3.setBlurb("cat");
+      person4.setBlurb("cat");
+      person5.setBlurb("cat");
+      person6.setBlurb("cat");
+      person7.setBlurb("cat");
+      person8.setBlurb("cat");
+      person9.setBlurb("cat");
+      person10.setBlurb("cat");
+
+      // Stick them all into a dummy map.
+      dummyDataMap.put("key1", person1);
+      dummyDataMap.put("key2", person2);
+      dummyDataMap.put("key3", person3);
+      dummyDataMap.put("key4", person4);
+      dummyDataMap.put("key5", person5);
+      dummyDataMap.put("key6", person6);
+      dummyDataMap.put("key7", person7);
+      dummyDataMap.put("key8", person8);
+      dummyDataMap.put("key9", person9);
+      dummyDataMap.put("key10", person10);
+
+      keyList = new ArrayList<String>();
+
+      keyList.add("key1");
+      keyList.add("key2");
+      keyList.add("key3");
+      keyList.add("key4");
+      keyList.add("key5");
+      keyList.add("key6");
+      keyList.add("key7");
+      keyList.add("key8");
+      keyList.add("key9");
+      keyList.add("key10");
+
+
+   }
+
+   @AfterTest
+   public void tearDownAfterTest() {
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   @BeforeMethod
+   public void setUp() throws ParseException {
+
+      // Setting up the cache mock instance
+      cache = createMock(Cache.class);
+
+      expect(cache.get(anyObject())).andAnswer(new IAnswer<Person>() {
+
+         public Person answer() throws Throwable {
+            String key = getCurrentArguments()[0].toString();
+            return dummyDataMap.get(key);
+         }
+      }).anyTimes();
+
+
+      // Create mock instances of other things required to create a lazy iterator.
+
+      SearchFactoryImplementor searchFactory = createMock(SearchFactoryImplementor.class);
+
+      DocumentExtractor extractor = org.easymock.classextension.EasyMock.createMock(DocumentExtractor.class);
+
+
+      try {
+         org.easymock.classextension.EasyMock.expect(extractor.extract(anyInt())).andAnswer(new IAnswer<EntityInfo>() {
+
+            public EntityInfo answer() throws Throwable {
+               int index = (Integer) getCurrentArguments()[0];
+               String keyString = keyList.get(index);
+
+               System.out.println("The key for index parameter " + index + " is " + keyString);
+
+               return new EntityInfo(Person.class, keyString, null);
+            }
+         }).anyTimes();
+
+
+      } catch (IOException e) {
+         e.printStackTrace();
+      }
+      IndexSearcher searcher = org.easymock.classextension.EasyMock.createMock(IndexSearcher.class);
+
+      EasyMock.replay(cache, searchFactory);
+      org.easymock.classextension.EasyMock.replay(searcher, extractor);
+
+      iterator = new LazyIterator(extractor, cache, searcher, searchFactory, 0, 9, fetchSize);
+
+   }
+
+
+   @AfterMethod
+   public void tearDown() {
+      iterator = null;
+   }
+
+   public void testJumpToResult() throws IndexOutOfBoundsException {
+      iterator.jumpToResult(0);
+      assert iterator.isFirst();
+
+      iterator.jumpToResult(1);
+      assert iterator.isAfterFirst();
+
+      iterator.jumpToResult(9);
+      assert iterator.isLast();
+
+      iterator.jumpToResult(8);
+      assert iterator.isBeforeLast();
+   }
+
+
+   //TODO: This is deprecated. What should I be using instead?
+   @ExpectedExceptions(IndexOutOfBoundsException.class)
+   public void testOutOfBoundsBelow(){     
+      iterator.jumpToResult(-1);
+   }
+
+   @ExpectedExceptions(IndexOutOfBoundsException.class)
+   public void testOutOfBoundsAbove(){
+      iterator.jumpToResult(keyList.size() + 1);
+   }
+
+
+
+   public void testFirst() {
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      Object next = iterator.next();
+
+      System.out.println(next);
+      assert next == person1;
+      assert !iterator.isFirst();
+
+      iterator.first();
+
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      next = iterator.next();
+      assert next == person1;
+      assert !iterator.isFirst();
+
+   }
+
+   public void testLast() {
+      //Jumps to the last element
+      iterator.last();
+
+      //Makes sure that the iterator is pointing at the last element.
+      assert iterator.isLast();
+
+      iterator.first();
+
+      //Check that the iterator is NOT pointing at the last element.
+      assert !iterator.isLast();
+   }
+
+   public void testAfterFirst() {
+      //Jump to the second element.
+      iterator.afterFirst();
+
+      //Check this
+      assert iterator.isAfterFirst();
+
+      //Previous element in the list
+      Object previous = iterator.previous();
+
+      //Check that previous is the first element.
+      assert previous == person2;
+
+      //Make sure that the iterator isn't pointing at the second element.
+      assert !iterator.isAfterFirst();
+
+   }
+
+   public void testBeforeLast() {
+      //Jump to the penultimate element.
+      iterator.beforeLast();
+
+      //Check this
+      assert iterator.isBeforeLast();
+
+      //Next element - which should be the last.
+      Object next = iterator.next();
+
+      //Check that next is the penultimate element.
+      assert next == person9;
+
+      //Make sure that the iterator is not pointing at the penultimate element.
+      assert !iterator.isBeforeLast();
+   }
+
+   public void testIsFirst() {
+      iterator.first();
+      assert iterator.isFirst();
+
+      iterator.next();
+      assert !iterator.isFirst();
+   }
+
+   public void testIsLast() {
+      iterator.last();
+      assert iterator.isLast();
+
+      iterator.previous();
+      assert !iterator.isLast();
+   }
+
+   public void testIsAfterFirst() {
+      iterator.afterFirst();
+      assert iterator.isAfterFirst();
+
+      iterator.previous();
+      assert !iterator.isAfterFirst();
+   }
+
+   public void testIsBeforeLast() {
+      iterator.beforeLast();
+      assert iterator.isBeforeLast();
+   }
+
+   public void testNextAndHasNext() {
+      iterator.first();
+
+      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
+      builder = new StringBuilder();
+
+      for (int i = 1; i <= 10; i++) {
+         builder.delete(0, 4);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
+         builder.append("key");
+         builder.append(i);
+         String keyString = builder.toString();
+         Object expectedValue = cache.get(keyString);
+         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
+
+         Object next = iterator.next();
+
+         assert expectedValue == next; // tests next()
+      }
+      assert !iterator.hasNext(); // this should now NOT be true.
+   }
+
+   public void testPreviousAndHasPrevious() {
+      iterator.last();
+
+      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
+      builder = new StringBuilder();
+
+      for (int i = 10; i >= 1; i--) {
+         builder.delete(0, 5);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
+         builder.append("key");
+         builder.append(i);
+         String keyString = builder.toString();
+
+
+         Object expectedValue = cache.get(keyString);
+
+         assert iterator.hasPrevious(); // should have previous as long as we are less than the number of elements.
+
+         Object previous = iterator.previous();
+
+         assert expectedValue == previous; // tests previous()
+      }
+      assert !iterator.hasPrevious(); // this should now NOT be true.
+
+   }
+
+   public void testNextIndex() {
+      iterator.first();
+      assert iterator.nextIndex() == 1;
+
+      iterator.last();
+      assert iterator.nextIndex() == 10; //Index will be the index of the last element + 1.
+
+   }
+
+   public void testPreviousIndex() {
+      iterator.first();
+      assert iterator.previousIndex() == -1;
+
+      iterator.last();
+      assert iterator.previousIndex() == 8; //Index will be that of the last element - 1.
+   }
+
+}
+
+

Added: trunk/query/src/test/java/org/infinispan/query/test/BrokenDocumentId.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/test/BrokenDocumentId.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/test/BrokenDocumentId.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,27 @@
+package org.infinispan.query.test;
+
+import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+
+/**
+ * @author Navin Surtani
+ */
+ at ProvidedId
+ at Indexed
+public class BrokenDocumentId
+{
+   @DocumentId
+   @Field
+   String name;
+
+   @Field
+   int age;
+
+   public void setBoth(String name, int age)
+   {
+      this.name = name;
+      this.age = age;
+   }
+}

Added: trunk/query/src/test/java/org/infinispan/query/test/BrokenProvided.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/test/BrokenProvided.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/test/BrokenProvided.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,26 @@
+package org.infinispan.query.test;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+ at Indexed
+public class BrokenProvided
+{
+   @Field   
+   public String name;
+
+   @Field
+   public int age;
+
+   public void setBoth(String name, int age)
+   {
+      this.name = name;
+      this.age = age;
+
+   }
+
+}

Added: trunk/query/src/test/java/org/infinispan/query/test/Person.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/test/Person.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/test/Person.java	2009-09-22 11:23:04 UTC (rev 841)
@@ -0,0 +1,92 @@
+package org.infinispan.query.test;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.FieldBridge;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Store;
+import org.hibernate.search.bridge.builtin.StringBridge;
+
+import java.io.Serializable;
+
+/**
+ * @author Navin Surtani
+ */
+ at ProvidedId (bridge = @FieldBridge(impl = StringBridge.class))
+ at Indexed
+public class Person implements Serializable
+{
+   private static final Log log = LogFactory.getLog(Person.class);
+
+
+   @Field (store = Store.YES)
+   private String name;
+   @Field (store = Store.YES)
+   private String blurb;
+   @Field (store = Store.YES, index = Index.UN_TOKENIZED )
+   private int age;
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   public String getBlurb()
+   {
+      return blurb;
+   }
+
+   public void setBlurb(String blurb)
+   {
+      this.blurb = blurb;
+   }
+
+   public int getAge()
+   {
+      return age;
+   }
+
+   public void setAge(int age)
+   {
+      this.age = age;
+   }
+
+   public boolean equals(Object o)
+   {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      Person person = (Person) o;
+
+      if (blurb != null ? !blurb.equals(person.blurb) : person.blurb != null) return false;
+      if (name != null ? !name.equals(person.name) : person.name != null) return false;
+
+      return true;
+   }
+
+   public int hashCode()
+   {
+      int result;
+      result = (name != null ? name.hashCode() : 0);
+      result = 31 * result + (blurb != null ? blurb.hashCode() : 0);
+      return result;
+   }
+
+
+   public String toString()
+   {
+      return "Person{" +
+              "name='" + name + '\'' +
+              ", blurb='" + blurb + '\'' +
+              '}';
+   }
+}



More information about the infinispan-commits mailing list