[infinispan-commits] Infinispan SVN: r834 - in branches/ISPN-32/query/src: main/java/org/infinispan/query/backend and 4 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Sep 18 06:01:33 EDT 2009


Author: navssurtani
Date: 2009-09-18 06:01:33 -0400 (Fri, 18 Sep 2009)
New Revision: 834

Added:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryFactory.java
Removed:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/SearchableCacheImpl.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/impl/SearchableCacheImplTest.java
Modified:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
Log:
[ISPN - 32] Changed old API. SearchFactory is null

Added: branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryFactory.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryFactory.java	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/QueryFactory.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -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);
+
+   }
+}

Deleted: branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -1,49 +0,0 @@
-/*
- * 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.Query;
-import org.infinispan.Cache;
-
-/**
- * This will be the most used interface in JBossCache searchable. It extends Cache and therefore will have
- * the standard get(), put() and remove() methods. The additional method is the createQuery method which people
- * will use to build their Hibernate Search queries from a luceneQuery - Hibernate Search users will be very familiar
- * with this.
- *
- * @author Navin Surtani
- *         <p/>
- */
-public interface SearchableCache<K, V> extends Cache<K, V>
-{
-
-
-   /**
-    * Creates a CacheQuery from a lucene query and a class array.
-    *
-    * @param classes     - array of classes to be searched from.
-    * @param luceneQuery - from {@link org.apache.lucene.search.Query}
-    * @return a CacheQuery instance from which the user can get a list/iterator object.
-    */
-   CacheQuery createQuery(Query luceneQuery, Class... classes);
-}

Deleted: branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -1,132 +0,0 @@
-/*
- * 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.hibernate.search.cfg.SearchConfiguration;
-import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.search.impl.SearchFactoryImpl;
-import org.infinispan.Cache;
-import org.infinispan.query.impl.SearchableCacheImpl;
-import org.infinispan.query.backend.QueryInterceptor;
-import org.infinispan.query.backend.SearchableCacheConfiguration;
-import org.infinispan.factories.ComponentRegistry;
-import org.infinispan.factories.InterceptorChainFactory;
-import org.infinispan.interceptors.LockingInterceptor;
-import org.infinispan.interceptors.base.CommandInterceptor;
-
-import java.lang.reflect.Field;
-import java.util.Properties;
-
-/**
- * Factory class used to create the searchable-cache like so: -
- * <p/>
- * <p/>
- * SearchableCache searchableCache = SearchableCacheFactory.createSearchableCache(coreCache, class[]);
- * <p/>
- * <p/>
- *
- * @author Navin Surtani
- */
-public class SearchableCacheFactory {
-   org.infinispan.util.logging.Log log;
-
-   /**
-    * Creates a searchable cache from a cache object and a class array, without the properties object.
-    *
-    * @param c       - the Cache
-    * @param classes - Class array to be added
-    * @return a SearchableCache
-    */
-   public SearchableCache createSearchableCache(Cache<?, ?> c, Class... classes) throws IllegalAccessException, InstantiationException {
-      return createSearchableCache(c, null, classes);
-   }
-
-   /**
-    * This method creates a searchable cache as well but requires the properties object.
-    *
-    * @param c          - the Cache
-    * @param properties - java.util.properties
-    * @param classes    - a class array
-    * @return a SearchableCache
-    */
-   public SearchableCache createSearchableCache(Cache<?, ?> c, Properties properties, Class... classes) throws IllegalAccessException, InstantiationException {
-
-      //validate the classes first. make sure the correct annotations are put in.
-
-      validateClasses(classes);
-
-      // assume cache is already created and running.
-      // otherwise, start the cache!!
-      if (c.getStatus().needToInitializeBeforeStart()) {
-         log.debug("Cache not started.  Starting cache first.");
-         c.start();
-      }
-
-      if (classes.length == 0) {
-         throw new IllegalArgumentException("You haven't passed in any classes to index.");
-      }
-
-      // step 1: create hibernate search searchFactory
-      SearchConfiguration cfg = new SearchableCacheConfiguration(classes, properties);
-      SearchFactoryImplementor searchFactory = new SearchFactoryImpl(cfg);
-
-
-      // get the component registry and then register the searchFactory.
-      ComponentRegistry cr = c.getAdvancedCache().getComponentRegistry();
-      cr.registerComponent(searchFactory, SearchFactoryImplementor.class);
-
-      // do the same for the transaction manager
-
-
-      // Get the interceptor chain factory so I can create my interceptor.
-      InterceptorChainFactory icf = cr.getComponent(InterceptorChainFactory.class);
-
-      // Create my interceptor.
-      CommandInterceptor inter =  icf.createInterceptor(QueryInterceptor.class);
-      cr.registerComponent(inter, QueryInterceptor.class);
-
-      c.getAdvancedCache().addInterceptorAfter(inter, LockingInterceptor.class);
-
-      //Create the searchableCache and pass it on.
-      SearchableCache sc = new SearchableCacheImpl(c, searchFactory);
-      return sc;
-   }
-
-   //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());
-            }
-         }
-      }
-
-   }
-
-}

Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -1,8 +1,22 @@
 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
@@ -12,41 +26,176 @@
 
 public class QueryHelper {
 
+   private Cache cache;
+   private Properties properties;
+   private Class[] classes;
+   private SearchFactoryImplementor searchFactory;
+
+   Log log = LogFactory.getLog(getClass());
+
+
    /**
-    * This method MUST be called if running the query module and you want to index objects in the
-    * cache.
-    * </p>
+    * 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/>
     *
-    * e.g.: - QueryHelper.applyQueryProperties(); has to be used BEFORE any objects are put in the
-    * cache so that they can be indexed.
+    * @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.
     *
-    * </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 static void applyQueryProperties(){
-      System.out.println("Entered QueryHelper");
+   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")){
+      if (System.getProperty("query").equals("true")) {
 
-         // Make the indexLocal check.
+         String indexLocal = System.getProperty("indexLocal");
 
-         if(System.getProperty("indexLocal").equals("true")){
+         // 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
 
-         // We're indexing data even if it comes from other sources
-         else{
+         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());
+            }
+         }
+      }
+
+   }
+
+
 }

Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCacheConfiguration.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -31,57 +31,49 @@
 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.
+ * 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
-{
+public class SearchableCacheConfiguration implements SearchConfiguration {
    protected Map<String, Class> classes;
    private Properties properties;
 
-   public SearchableCacheConfiguration(Class[] classArray, 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)
-      {
+      for (Class c : classArray) {
          String classname = c.getName();
          classes.put(classname, c);
       }
    }
 
-   public Iterator getClassMappings()
-   {
+   public Iterator getClassMappings() {
       return classes.values().iterator();
    }
 
-   public Class getClassMapping(String name)
-   {
+   public Class getClassMapping(String name) {
       return classes.get(name);
    }
 
-   public String getProperty(String propertyName)
-   {
+   public String getProperty(String propertyName) {
       return properties.getProperty(propertyName);
    }
 
-   public Properties getProperties()
-   {
+   public Properties getProperties() {
       return properties;
    }
 
-   public ReflectionManager getReflectionManager()
-   {
+   public ReflectionManager getReflectionManager() {
       return null;
    }
 

Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -85,7 +85,6 @@
    private SearchFactoryImplementor searchFactory;
    private Set<Class<?>> targetedEntities;
    private Cache cache;
-   private Class[] classes;
 
    public org.infinispan.util.logging.Log log;
 
@@ -98,7 +97,6 @@
       this.cache = cache;
       this.searchFactory = searchFactory;
       this.targetedEntities = this.searchFactory.getIndexedTypesPolymorphic(classes);
-      this.classes = classes;
                  
    }
 

Deleted: branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/SearchableCacheImpl.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/SearchableCacheImpl.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/impl/SearchableCacheImpl.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -1,370 +0,0 @@
-/*
- * 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.search.Query;
-import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.infinispan.AdvancedCache;
-import org.infinispan.Cache;
-import org.infinispan.CacheException;
-import org.infinispan.query.SearchableCache;
-import org.infinispan.query.CacheQuery;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.CacheManager;
-import org.infinispan.util.concurrent.NotifyingFuture;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Implementation class for the SearchableCache interface.
- * <p/>
- *
- * //TODO: navssurtani --> Document this class properly.
- *
- * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
- */
-public class SearchableCacheImpl<K, V> implements SearchableCache<K, V> {
-   // this is the ACTUAL cache. that does all the work.
-
-
-   private Cache<K, V> cache;
-   private SearchFactoryImplementor searchFactory;
-
-
-   public SearchableCacheImpl(Cache<K, V> cache, SearchFactoryImplementor searchFactory) {
-      if (cache == null) throw new NullPointerException("Cache is null");
-      if (searchFactory == null) throw new NullPointerException("searchFactory is null");
-      this.cache = cache;
-      this.searchFactory = searchFactory;
-   }
-
-
-   /**
-    * Creates a CacheQuery object from a Lucene Query and a class array.
-    *
-    * @param luceneQuery - for lucene
-    * @param classes     array
-    * @return CacheQuery object.
-    */
-
-
-   public CacheQuery createQuery(Query luceneQuery, Class[] classes) {
-      return new CacheQueryImpl(luceneQuery, searchFactory, cache, classes);
-
-   }
-
-   /**
-    * Returns an org.jboss.cache.config.Configuration instance.
-    *
-    * @return org.jboss.cache.config.Configuration
-    */
-
-   public org.infinispan.config.Configuration getConfiguration() {
-      return cache.getConfiguration();
-   }
-
-   /**
-    * Adds a listener to the cache.
-    *
-    * @param listener to be removed
-    */
-   public void addListenter(Object listener) {
-      cache.addListener(listener);
-   }
-
-   public void addListener(Object listener) {
-      cache.addListener(listener);
-   }
-
-   /**
-    * Removes a listener from the cache.
-    *
-    * @param listener to be removed
-    */
-   public void removeListener(Object listener) {
-      cache.removeListener(listener);
-   }
-
-   /**
-    * Returns a set of listeners that the cache has.
-    *
-    * @return A set of listeners.
-    */
-
-   public Set<Object> getListeners() {
-      return cache.getListeners();
-   }
-
-   public int size() {
-      return cache.size();
-   }
-
-   public boolean isEmpty() {
-      return cache.isEmpty();
-   }
-
-   public boolean containsKey(Object key) {
-      return cache.containsKey(key);
-   }
-
-   public boolean containsValue(Object value) {
-      return cache.containsValue(value);
-   }
-
-   public V get(Object key) {
-      return cache.get(key);
-   }
-
-   /**
-    * Puts something into the cache with a given Fqn, key and value.
-    *
-    * @param key
-    * @param value
-    * @return
-    */
-
-   public V put(K key, V value) {
-      return cache.put(key, value);
-   }
-
-   public V remove(Object key) {
-      return cache.remove(key);
-   }
-
-   public void putAll(Map<? extends K, ? extends V> t) {
-      cache.putAll(t);
-   }
-
-   public void clear() {
-      cache.clear();
-   }
-
-   public void putForExternalRead(K key, V value) {
-      cache.putForExternalRead(key, value);
-   }
-
-   public void evict(K key) {
-      cache.evict(key);
-   }
-
-   /**
-    * Lifecycle method that starts the cache loader, starts cache replication, starts the region manager, etc., and (if
-    * configured) warms the cache using a state transfer or cache loader preload.
-    *
-    * @throws CacheException
-    */
-
-   public void start() throws CacheException {
-      cache.start();
-   }
-
-   /**
-    * Lifecycle method that stops the cache, including replication, clustering, cache loading, notifications, etc., and
-    * clears all cache in-memory state.
-    */
-
-   public void stop() {
-      cache.stop();
-   }
-
-   /**
-    * Returns the version of the cache as a string.
-    *
-    * @return Returns the version of the cache as a string.
-    */
-   public String getVersion() {
-      return cache.getVersion();
-   }
-
-   public CacheManager getCacheManager() {
-      return cache.getCacheManager();
-   }
-
-   public V put(K key, V value, long lifespan, TimeUnit unit) {
-      return cache.put(key, value, lifespan, unit);
-   }
-
-   public V putIfAbsent(K key, V value, long lifespan, TimeUnit unit) {
-      return cache.putIfAbsent(key, value, lifespan, unit);
-   }
-
-   public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit unit) {
-      cache.putAll(map, lifespan, unit);
-   }
-
-   public V replace(K key, V value, long lifespan, TimeUnit unit) {
-      return cache.replace(key, value, lifespan, unit);
-   }
-
-   public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit) {
-      return cache.replace(key, oldValue, value, lifespan, unit);
-   }
-
-   public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
-      return cache.put(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-   }
-
-   public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
-      return cache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-   }
-
-   public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
-      cache.putAll(map, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-   }
-
-   public V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
-      return cache.replace(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-   }
-
-   public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
-      return cache.replace(key, oldValue, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-   }
-
-   public NotifyingFuture<V> putAsync(K key, V value) {
-      return cache.putAsync(key, value);
-   }
-
-   public NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit) {
-      return cache.putAsync(key, value, lifespan, unit);
-   }
-
-   public NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
-      return cache.putAsync(key, value, lifespan, lifespanUnit, maxIdle,  maxIdleUnit);
-   }
-
-   public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data) {
-      return cache.putAllAsync(data);
-   }
-
-   public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit unit) {
-      return cache.putAllAsync(data, lifespan, unit);
-   }
-
-   public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
-      return cache.putAllAsync(data, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-   }
-
-   public NotifyingFuture<Void> clearAsync() {
-      return cache.clearAsync();
-   }
-
-   public NotifyingFuture<V> putIfAbsentAsync(K key, V value) {
-      return cache.putIfAbsentAsync(key, value);
-   }
-
-   public NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit) {
-      return cache.putIfAbsentAsync(key, value, lifespan, unit);
-   }
-
-   public NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
-      return cache.putIfAbsentAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-   }
-
-   public NotifyingFuture<V> removeAsync(Object key) {
-      return cache.removeAsync(key);
-   }
-
-   public NotifyingFuture<Boolean> removeAsync(Object key, Object value) {
-      return cache.removeAsync(key, value);
-   }
-
-   public NotifyingFuture<V> replaceAsync(K key, V value) {
-      return cache.replaceAsync(key, value);
-   }
-
-   public NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit) {
-      return cache.replaceAsync(key, value, lifespan, unit);
-   }
-
-   public NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
-      return cache.replaceAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-   }
-
-   public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
-      return cache.replaceAsync(key, oldValue, newValue);
-   }
-
-   public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit) {
-      return cache.replaceAsync(key, oldValue, newValue, lifespan, unit);
-   }
-
-   public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
-      return cache.replaceAsync(key, oldValue, newValue, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-   }
-
-   public AdvancedCache<K, V> getAdvancedCache() {
-      return cache.getAdvancedCache();
-   }
-
-   public void compact() {
-      cache.compact();
-   }
-
-   public ComponentStatus getStatus() {
-      return cache.getStatus();
-   }
-
-   public Set<K> keySet() {
-      return cache.keySet();
-   }
-
-   public Collection<V> values() {
-      return cache.values();
-   }
-
-   public Set<Entry<K, V>> entrySet() {
-      return cache.entrySet();
-   }
-
-   public boolean startBatch() {
-      return cache.startBatch();
-   }
-
-   public void endBatch(boolean successful) {
-      cache.endBatch(successful);
-   }
-
-   public String getName() {
-      return cache.getName();
-   }
-
-   public V putIfAbsent(K key, V value) {
-      return cache.putIfAbsent(key, value);
-   }
-
-   public boolean remove(Object key, Object value) {
-      return cache.remove(key, value);
-   }
-
-   public boolean replace(K key, V oldValue, V newValue) {
-      return cache.replace(key, oldValue, newValue);
-   }
-
-   public V replace(K key, V value) {
-      return cache.replace(key, value);
-   }
-
-}

Deleted: branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -1,31 +0,0 @@
-package org.infinispan.query;
-
-import org.infinispan.Cache;
-import org.infinispan.manager.CacheManager;
-import org.infinispan.test.SingleCacheManagerTest;
-import org.infinispan.test.fwk.TestCacheManagerFactory;
-import org.testng.annotations.Test;
-
-/**
- * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
- *
- * Test class for the SearchableCacheFactory.
- */
-
- at Test (groups = "functional")
-public class SearchableCacheFactoryTest extends SingleCacheManagerTest
-{
-   protected CacheManager createCacheManager() throws Exception {
-      return TestCacheManagerFactory.createLocalCacheManager();
-   }
-
-   @Test (expectedExceptions = IllegalArgumentException.class)
-   public void testCreateSearchableCacheWithZeroArray() throws Exception {
-      Class[] fakeClasses = new Class[0];
-      Cache coreCache = createCacheManager().getCache();
-      SearchableCache searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, null, fakeClasses);
-      
-   }
-
-
-}

Modified: branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/BrokenAnnotationTest.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -3,9 +3,8 @@
 import org.infinispan.Cache;
 import org.infinispan.manager.CacheManager;
 import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.query.SearchableCache;
-import org.infinispan.query.SearchableCacheFactory;
 import org.infinispan.query.test.BrokenProvided;
+import org.infinispan.query.backend.QueryHelper;
 import org.infinispan.test.SingleCacheManagerTest;
 import org.testng.annotations.Test;
 
@@ -25,7 +24,7 @@
       
       Cache cache = createCacheManager().getCache();
 
-      SearchableCache searchable = new SearchableCacheFactory().createSearchableCache(cache, BrokenProvided.class);
+      QueryHelper qh = new QueryHelper(cache, null, BrokenProvided.class);
 
 
    }
@@ -38,7 +37,7 @@
 
       Cache cache = createCacheManager().getCache();
 
-      SearchableCache searchable = new SearchableCacheFactory().createSearchableCache(cache, BrokenProvided.class);
+      QueryHelper qh = new QueryHelper(cache, null, BrokenProvided.class);
 
 
 

Modified: branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -9,26 +9,26 @@
 import org.infinispan.Cache;
 import org.infinispan.config.Configuration;
 import org.infinispan.query.CacheQuery;
-import org.infinispan.query.SearchableCache;
-import org.infinispan.query.SearchableCacheFactory;
+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 (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ * @author Navin Surtani
  */
 @Test(groups = "functional")
 public class ClusteredCacheTest extends MultipleCacheManagersTest
 {
-   Cache cache1, cache2;
-   SearchableCache searchableCache1, searchableCache2;
+   Cache<String, Person> cache1, cache2;
    Person person1;
    Person person2;
    Person person3;
@@ -36,6 +36,7 @@
    QueryParser queryParser;
    Query luceneQuery;
    CacheQuery cacheQuery;
+   QueryHelper qh;
    List found;
    String key1 = "Navin";
    String key2 = "BigGoat";
@@ -46,19 +47,26 @@
       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, "searchable", cacheCfg);
+      List<Cache<String, Person>> caches = createClusteredCaches(2, "infinispan-query", cacheCfg);
 
       cache1 = caches.get(0);
-      searchableCache1 = new SearchableCacheFactory().createSearchableCache(cache1, Person.class);
-
       cache2 = caches.get(1);
-      searchableCache2 = new SearchableCacheFactory().createSearchableCache(cache2, Person.class);
 
+      // 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();
@@ -73,11 +81,11 @@
       person3.setName("MiniGoat");
       person3.setBlurb("Eats cheese");
 
-      //Put the 3 created objects in the searchableCache1.
+      //Put the 3 created objects in the cache1.
 
-      searchableCache1.put(key1, person1);
-      searchableCache1.put(key2, person2);
-      searchableCache1.put(key3, person3);
+      cache1.put(key1, person1);
+      cache1.put(key2, person2);
+      cache1.put(key3, person3);
    }
 
    @AfterMethod
@@ -87,10 +95,8 @@
 
    public void testSimple() throws ParseException
    {
-      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-      luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache2.createQuery(luceneQuery);
-
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory())
+            .getBasicQuery("blurb", "playing");
       found = cacheQuery.list();
 
       assert found.size() == 1;
@@ -98,7 +104,7 @@
       if(found.get(0) == null)
       {
          log.warn("found.get(0) is null");
-         Person p1 = (Person) searchableCache2.get(key1);
+         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");
@@ -111,7 +117,6 @@
          }
       }
 
-
       assert found.get(0).equals(person1);
 
    }
@@ -120,7 +125,7 @@
    {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
 
       found = cacheQuery.list();
 
@@ -128,12 +133,12 @@
       assert found.get(0).equals(person1);
 
       person1.setBlurb("Likes pizza");
-      searchableCache1.put("Navin", person1);
+      cache1.put("Navin", person1);
 
 
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("pizza");
-      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
 
       found = cacheQuery.list();
 
@@ -146,7 +151,7 @@
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("eats");
-      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       System.out.println("found.size() is " + found.size());
@@ -160,10 +165,10 @@
       person4.setName("Mighty Goat");
       person4.setBlurb("Also eats grass");
 
-      searchableCache1.put("mighty", person4);
+      cache1.put("mighty", person4);
 
       luceneQuery = queryParser.parse("eats");
-      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 3 : "Size of list should be 3";
@@ -176,18 +181,18 @@
    {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("eats");
-      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      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";
 
-      searchableCache1.remove(Fqn.fromString("/a/b/c/"), key3);
+      cache1.remove(Fqn.fromString("/a/b/c/"), key3);
 
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("eats");
-      cacheQuery = searchableCache1.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       System.out.println("list is: - " + found);
@@ -198,7 +203,7 @@
 
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache2, qh.getSearchFactory()).getQuery(luceneQuery);
 
       System.out.println("Result size is: - " + cacheQuery.getResultSize());
    }

Modified: branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheProfilerTest.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -9,16 +9,19 @@
 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.manager.DefaultCacheManager;
 import org.infinispan.query.CacheQuery;
 import org.infinispan.query.QueryIterator;
-import org.infinispan.query.SearchableCache;
-import org.infinispan.query.SearchableCacheFactory;
+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.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
+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;
@@ -28,9 +31,7 @@
  */
 
 @Test(groups = "functional", enabled = false)
-public class LocalCacheProfilerTest
-{
-   SearchableCache searchableCache;
+public class LocalCacheProfilerTest extends SingleCacheManagerTest {
    Person person1;
    Person person2;
    Person person3;
@@ -45,13 +46,30 @@
    String key2 = "BigGoat";
    String key3 = "MiniGoat";
 
-   @BeforeTest
-   public void setUp() throws IllegalAccessException, InstantiationException {
-      CacheManager manager = new DefaultCacheManager();
-      Cache coreCache = manager.getCache();
+   Cache<String, Person> cache;
+   QueryHelper qh;
 
-      searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
+   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");
@@ -68,54 +86,49 @@
       person5.setName("Smelly Cat");
       person5.setBlurb("Eats fish");
 
-      //Put the 3 created objects in the searchableCache.
-      searchableCache.put(key1, person1);
-      searchableCache.put(key2, person2);
-      searchableCache.put(key3, person3);
+      //Put the 3 created objects in the cache.
+      cache.put(key1, person1);
+      cache.put(key2, person2);
+      cache.put(key3, person3);
 
    }
 
-   @AfterTest
-   public void tearDown()
-   {
-      if (searchableCache != null) searchableCache.stop();
+   @AfterMethod
+   public void tearDown() {
+      if (cache != null) cache.stop();
       IndexCleanUp.cleanUpIndexes();
    }
 
-   @Test (invocationCount = 200000, enabled = false)
-   public void testSimple() throws ParseException
-   {
-      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-      luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
 
+   @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 = 200000, enabled = false)
-   public void testSimpleIterator() throws ParseException
-   {
-      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-      luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+   @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 = 200000, enabled = false)
-   public void testMultipleResults() throws ParseException
-   {
+   @Test (invocationCount = 2000, enabled = false)
+   public void testMultipleResults() throws ParseException {
 
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2;
@@ -124,12 +137,11 @@
 
    }
 
-   @Test (invocationCount = 200000, enabled = false)
-   public void testModified() throws ParseException
-   {
+   @Test (invocationCount = 2000, enabled = false)
+   public void testModified() throws ParseException {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
 
       found = cacheQuery.list();
 
@@ -137,11 +149,11 @@
       assert found.get(0).equals(person1);
 
       person1.setBlurb("Likes pizza");
-      searchableCache.put(key1, person1);
+      cache.put(key1, person1);
 
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("pizza");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
 
       found = cacheQuery.list();
 
@@ -149,13 +161,12 @@
       assert found.get(0).equals(person1);
    }
 
-   @Test (invocationCount = 200000, enabled = false)
-   public void testAdded() throws ParseException
-   {
+   @Test (invocationCount = 2000, enabled = false)
+   public void testAdded() throws ParseException {
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2 : "Size of list should be 2";
@@ -167,10 +178,10 @@
       person4.setName("Mighty Goat");
       person4.setBlurb("Also eats grass");
 
-      searchableCache.put("mighty", person4);
+      cache.put("mighty", person4);
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 3 : "Size of list should be 3";
@@ -179,34 +190,33 @@
       assert found.contains(person4) : "This should now contain object person4";
    }
 
-   @Test (invocationCount = 200000, enabled = false)
-   public void testRemoved() throws ParseException
-   {
+   @Test (invocationCount = 2000, enabled = false)
+   public void testRemoved() throws ParseException {
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      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";
 
-      searchableCache.remove(key3);
+      cache.remove(key3);
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      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 = 200000, enabled = false)
-   public void testSetSort() throws ParseException
-   {
+   @Test (invocationCount = 2000, enabled = false)
+   public void testSetSort() throws ParseException {
       person2.setAge(35);
       person3.setAge(12);
 
@@ -215,7 +225,7 @@
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2;
@@ -229,13 +239,12 @@
       assert found.get(1).equals(person3);
    }
 
-   @Test (invocationCount = 200000, enabled = false)   
-   public void testSetFilter() throws ParseException
-   {
+   @Test (invocationCount = 2000, enabled = false)
+   public void testSetFilter() throws ParseException {
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2;
@@ -250,4 +259,27 @@
 
    }
 
+   @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;
+   }
+
 }

Modified: branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -13,8 +13,7 @@
 import org.infinispan.manager.CacheManager;
 import org.infinispan.query.CacheQuery;
 import org.infinispan.query.QueryIterator;
-import org.infinispan.query.SearchableCache;
-import org.infinispan.query.SearchableCacheFactory;
+import org.infinispan.query.QueryFactory;
 import org.infinispan.query.backend.QueryHelper;
 import org.infinispan.query.helper.IndexCleanUp;
 import org.infinispan.query.test.Person;
@@ -33,7 +32,6 @@
 
 @Test(groups = "functional")
 public class LocalCacheTest extends SingleCacheManagerTest {
-   SearchableCache searchableCache;
    Person person1;
    Person person2;
    Person person3;
@@ -48,6 +46,9 @@
    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());
@@ -61,13 +62,14 @@
       System.setProperty("query", "true");
       System.setProperty("indexLocal", "true");
 
-      QueryHelper.applyQueryProperties();
 
+      cache = createCacheManager().getCache();
 
-      Cache coreCache = createCacheManager().getCache();
+      qh = new QueryHelper(cache, null, Person.class);
+      qh.applyProperties();
+      
+      
 
-      searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
-
       person1 = new Person();
       person1.setName("Navin Surtani");
       person1.setBlurb("Likes playing WoW");
@@ -84,23 +86,21 @@
       person5.setName("Smelly Cat");
       person5.setBlurb("Eats fish");
 
-      //Put the 3 created objects in the searchableCache.
-      searchableCache.put(key1, person1);
-      searchableCache.put(key2, person2);
-      searchableCache.put(key3, person3);
+      //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 (searchableCache != null) searchableCache.stop();
+      if (cache != null) cache.stop();
       IndexCleanUp.cleanUpIndexes();
    }
 
    public void testSimple() throws ParseException {
-      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-      luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getBasicQuery("blurb", "playing");
 
       found = cacheQuery.list();
 
@@ -109,10 +109,10 @@
    }
 
    public void testEagerIterator() throws ParseException {
-      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-      luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
 
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).
+            getBasicQuery("blurb", "playing");
+
       QueryIterator found = cacheQuery.iterator();
 
       assert found.isFirst();
@@ -124,7 +124,7 @@
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2;
@@ -136,7 +136,7 @@
    public void testModified() throws ParseException {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
 
       found = cacheQuery.list();
 
@@ -144,11 +144,11 @@
       assert found.get(0).equals(person1);
 
       person1.setBlurb("Likes pizza");
-      searchableCache.put(key1, person1);
+      cache.put(key1, person1);
 
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("pizza");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
 
       found = cacheQuery.list();
 
@@ -160,7 +160,7 @@
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2 : "Size of list should be 2";
@@ -172,10 +172,10 @@
       person4.setName("Mighty Goat");
       person4.setBlurb("Also eats grass");
 
-      searchableCache.put("mighty", person4);
+      cache.put("mighty", person4);
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 3 : "Size of list should be 3";
@@ -188,17 +188,17 @@
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      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";
 
-      searchableCache.remove(key3);
+      cache.remove(key3);
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 1;
@@ -217,7 +217,7 @@
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2;
@@ -235,7 +235,7 @@
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("goat");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 2;
@@ -253,7 +253,7 @@
    public void testLazyIterator() throws ParseException {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
 
       QueryIterator found = cacheQuery.lazyIterator();
 
@@ -266,7 +266,7 @@
 
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
-      cacheQuery = searchableCache.createQuery(luceneQuery);
+      cacheQuery = new QueryFactory(cache, qh.getSearchFactory()).getQuery(luceneQuery);
 
       assert cacheQuery.getResultSize() == 1;
    }

Deleted: branches/ISPN-32/query/src/test/java/org/infinispan/query/impl/SearchableCacheImplTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/impl/SearchableCacheImplTest.java	2009-09-18 09:39:11 UTC (rev 833)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/impl/SearchableCacheImplTest.java	2009-09-18 10:01:33 UTC (rev 834)
@@ -1,35 +0,0 @@
-package org.infinispan.query.impl;
-
-import org.infinispan.Cache;
-import org.infinispan.manager.CacheManager;
-import org.infinispan.test.SingleCacheManagerTest;
-import org.infinispan.test.fwk.TestCacheManagerFactory;
-import org.testng.annotations.Test;
-
-/**
- * @author Navin Surtani
- */
-
- at Test (groups = "functional")
-public class SearchableCacheImplTest extends SingleCacheManagerTest
-{
-
-   protected CacheManager createCacheManager() throws Exception {
-      return TestCacheManagerFactory.createLocalCacheManager();
-   }
-
-
-   @Test (expectedExceptions = NullPointerException.class)
-   public void testConstructorWithNullCache() throws Exception
-   {
-      SearchableCacheImpl nullCache = new SearchableCacheImpl(null, null);
-      
-   }
-
-   @Test (expectedExceptions = NullPointerException.class)
-   public void testConstructorWithNullSearchFactory() throws Exception
-   {
-      Cache cache = createCacheManager().getCache();
-      SearchableCacheImpl nullSearchFactory = new SearchableCacheImpl(cache, null);
-   }
-}



More information about the infinispan-commits mailing list