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

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Sep 3 11:06:19 EDT 2009


Author: navssurtani
Date: 2009-09-03 11:06:19 -0400 (Thu, 03 Sep 2009)
New Revision: 773

Added:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java
Removed:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCoreInterceptor.java
Modified:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.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/LocalCacheTest.java
Log:
[ISPN-32] Changing old SearchableCache API to QueryFactory API. Building QueryHelper and LocalQueryInterceptor

Modified: 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-03 13:05:58 UTC (rev 772)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -27,7 +27,7 @@
 import org.hibernate.search.impl.SearchFactoryImpl;
 import org.infinispan.Cache;
 import org.infinispan.query.impl.SearchableCacheImpl;
-import org.infinispan.query.backend.SearchableCoreInterceptor;
+import org.infinispan.query.backend.QueryInterceptor;
 import org.infinispan.query.backend.SearchableCacheConfiguration;
 import org.infinispan.factories.ComponentRegistry;
 import org.infinispan.factories.InterceptorChainFactory;
@@ -102,8 +102,8 @@
       InterceptorChainFactory icf = cr.getComponent(InterceptorChainFactory.class);
 
       // Create my interceptor.
-      CommandInterceptor inter =  icf.createInterceptor(SearchableCoreInterceptor.class);
-      cr.registerComponent(inter, SearchableCoreInterceptor.class);
+      CommandInterceptor inter =  icf.createInterceptor(QueryInterceptor.class);
+      cr.registerComponent(inter, QueryInterceptor.class);
 
       c.getAdvancedCache().addInterceptorAfter(inter, LockingInterceptor.class);
 

Added: branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -0,0 +1,17 @@
+package org.infinispan.query.backend;
+
+/**
+ * // TODO: Document this
+ *
+ * This class is an interceptor that will index data only if it has come from a local source.
+ *
+ * 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 {
+}

Added: 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	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -0,0 +1,52 @@
+package org.infinispan.query.backend;
+
+/**
+ * // TODO: Document this
+ *
+ * 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 {
+
+   /**
+    * This method MUST be called if running the query module and you want to index objects in the
+    * cache.
+    * </p>
+    *
+    * e.g.: - QueryHelper.applyQueryProperties(); has to be used BEFORE any objects are put in the
+    * cache so that they can be indexed.
+    *
+    * </p>
+    *
+    * Anything put before calling this method will NOT not be picked up by the {@link QueryInterceptor}
+    * and hence not be indexed.
+    *
+    */
+
+   public static void applyQueryProperties(){
+      System.out.println("Entered QueryHelper");
+
+      // 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")){
+
+         // Make the indexLocal check.
+
+         if(System.getProperty("indexLocal").equals("true")){
+            // Add a LocalQueryInterceptor to the chain
+         }
+
+         // We're indexing data even if it comes from other sources
+         else{
+            // Add in a QueryInterceptor to the chain
+         }
+
+      }
+      
+   }
+
+}

Copied: branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java (from rev 731, branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCoreInterceptor.java)
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	                        (rev 0)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -0,0 +1,134 @@
+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 {
+
+   private SearchFactoryImplementor searchFactory;
+   private 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);
+   }
+
+}

Deleted: branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCoreInterceptor.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCoreInterceptor.java	2009-09-03 13:05:58 UTC (rev 772)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/SearchableCoreInterceptor.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -1,131 +0,0 @@
-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 SearchableCoreInterceptor extends CommandInterceptor {
-
-   private SearchFactoryImplementor searchFactory;
-   private TransactionManager transactionManager;
-
-   @Inject
-   public void init(SearchFactoryImplementor searchFactory, TransactionManager transactionManager) {
-
-      log.debug("Entered SearchableCoreInterceptor.init()");
-
-      this.searchFactory = searchFactory;
-      this.transactionManager = transactionManager;
-   }
-
-   // This method will get the put() calls on the cache and then send them into Lucene once it's successful.
-
-   @Override
-   public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
-
-      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.
-   private 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.
-   private 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);
-   }
-
-}

Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.java	2009-09-03 13:05:58 UTC (rev 772)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/TransactionalEventTransactionContext.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -35,14 +35,14 @@
  * 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 SearchableCoreInterceptor} to pass transaction information to a
+ * 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 SearchableCoreInterceptor
+ * @see QueryInterceptor
  */
 public class TransactionalEventTransactionContext implements TransactionContext {
 

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-03 13:05:58 UTC (rev 772)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/ClusteredCacheTest.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -93,7 +93,7 @@
 
       found = cacheQuery.list();
 
-      assert found.size() == 2;
+      assert found.size() == 1;
 
       if(found.get(0) == null)
       {
@@ -124,7 +124,7 @@
 
       found = cacheQuery.list();
 
-      assert found.size() == 2;
+      assert found.size() == 1;
       assert found.get(0).equals(person1);
 
       person1.setBlurb("Likes pizza");
@@ -137,7 +137,7 @@
 
       found = cacheQuery.list();
 
-      assert found.size() == 2;
+      assert found.size() == 1;
       assert found.get(0).equals(person1);
    }
 
@@ -151,7 +151,7 @@
 
       System.out.println("found.size() is " + found.size());
 
-      assert found.size() == 4 : "Size of list should be 4";
+      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";
@@ -166,7 +166,7 @@
       cacheQuery = searchableCache2.createQuery(luceneQuery);
       found = cacheQuery.list();
 
-      assert found.size() == 6 : "Size of list should be 6";
+      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";
@@ -179,7 +179,7 @@
       cacheQuery = searchableCache2.createQuery(luceneQuery);
       found = cacheQuery.list();
 
-      assert found.size() == 4;
+      assert found.size() == 2;
       assert found.contains(person2);
       assert found.contains(person3) : "This should still contain object person3";
 

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-03 13:05:58 UTC (rev 772)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java	2009-09-03 15:06:19 UTC (rev 773)
@@ -9,17 +9,18 @@
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Sort;
 import org.infinispan.Cache;
-import org.infinispan.transaction.lookup.DummyTransactionManagerLookup;
 import org.infinispan.config.Configuration;
 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.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;
@@ -31,8 +32,7 @@
  */
 
 @Test(groups = "functional")
-public class LocalCacheTest extends SingleCacheManagerTest
-{
+public class LocalCacheTest extends SingleCacheManagerTest {
    SearchableCache searchableCache;
    Person person1;
    Person person2;
@@ -54,12 +54,16 @@
 
       return TestCacheManagerFactory.createCacheManager(c);
    }
-   
 
 
    @BeforeMethod
-   public void setUp() throws Exception
-   {
+   public void setUp() throws Exception {
+      System.setProperty("query", "true");
+      System.setProperty("indexLocal", "true");
+
+      QueryHelper.applyQueryProperties();
+
+
       Cache coreCache = createCacheManager().getCache();
 
       searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
@@ -88,14 +92,12 @@
    }
 
    @AfterMethod
-   public void tearDown()
-   {
+   public void tearDown() {
       if (searchableCache != null) searchableCache.stop();
       IndexCleanUp.cleanUpIndexes();
    }
 
-   public void testSimple() throws ParseException
-   {
+   public void testSimple() throws ParseException {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
       cacheQuery = searchableCache.createQuery(luceneQuery);
@@ -106,8 +108,7 @@
       assert found.get(0).equals(person1);
    }
 
-   public void testEagerIterator() throws ParseException
-   {
+   public void testEagerIterator() throws ParseException {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
       cacheQuery = searchableCache.createQuery(luceneQuery);
@@ -118,8 +119,7 @@
       assert found.isLast();
    }
 
-   public void testMultipleResults() throws ParseException
-   {
+   public void testMultipleResults() throws ParseException {
 
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
@@ -133,8 +133,7 @@
 
    }
 
-   public void testModified() throws ParseException
-   {
+   public void testModified() throws ParseException {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
       cacheQuery = searchableCache.createQuery(luceneQuery);
@@ -157,8 +156,7 @@
       assert found.get(0).equals(person1);
    }
 
-   public void testAdded() throws ParseException
-   {
+   public void testAdded() throws ParseException {
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
@@ -186,8 +184,7 @@
       assert found.contains(person4) : "This should now contain object person4";
    }
 
-   public void testRemoved() throws ParseException
-   {
+   public void testRemoved() throws ParseException {
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("Goat");
@@ -211,8 +208,7 @@
 
    }
 
-   public void testSetSort() throws ParseException
-   {
+   public void testSetSort() throws ParseException {
       person2.setAge(35);
       person3.setAge(12);
 
@@ -235,8 +231,7 @@
       assert found.get(1).equals(person3);
    }
 
-   public void testSetFilter() throws ParseException
-   {
+   public void testSetFilter() throws ParseException {
       queryParser = new QueryParser("name", new StandardAnalyzer());
 
       luceneQuery = queryParser.parse("goat");
@@ -255,8 +250,7 @@
 
    }
 
-   public void testLazyIterator() throws ParseException
-   {
+   public void testLazyIterator() throws ParseException {
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");
       cacheQuery = searchableCache.createQuery(luceneQuery);
@@ -268,7 +262,7 @@
 
    }
 
-   public void testGetResultSize() throws ParseException{
+   public void testGetResultSize() throws ParseException {
 
       queryParser = new QueryParser("blurb", new StandardAnalyzer());
       luceneQuery = queryParser.parse("playing");



More information about the infinispan-commits mailing list