[infinispan-commits] Infinispan SVN: r776 - branches/ISPN-32/query/src/main/java/org/infinispan/query/backend.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Sep 4 06:05:04 EDT 2009


Author: navssurtani
Date: 2009-09-04 06:05:04 -0400 (Fri, 04 Sep 2009)
New Revision: 776

Modified:
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java
   branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.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/backend/LocalQueryInterceptor.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java	2009-09-03 16:49:40 UTC (rev 775)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/LocalQueryInterceptor.java	2009-09-04 10:05:04 UTC (rev 776)
@@ -1,17 +1,128 @@
 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".
  *
- * 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.
+
+   
+   private SearchFactoryImplementor searchFactory;
+   private TransactionManager transactionManager;
+
+   @Inject
+   public void init(SearchFactoryImplementor searchFactory, TransactionManager transactionManager) {
+
+      log.debug("Entered LocalQueryInterceptor.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 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()) {
+         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()) {
+         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()) {
+
+         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()) {
+
+         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;
+   }
+
+
 }

Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	2009-09-03 16:49:40 UTC (rev 775)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	2009-09-04 10:05:04 UTC (rev 776)
@@ -47,8 +47,7 @@
       // do the actual put first.
       Object toReturn = invokeNextInterceptor(ctx, command);
 
-         addToIndexes(command.getValue(), command.getKey().toString());
-      
+      addToIndexes(command.getValue(), command.getKey().toString());
 
       return toReturn;
    }
@@ -97,13 +96,13 @@
       Object mapPut = invokeNextInterceptor(ctx, command);
 
 
-         Map<Object, Object> dataMap = command.getMap();
+      Map<Object, Object> dataMap = command.getMap();
 
-         // Loop through all the keys and put those key, value pairings into lucene.
+      // 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());
-         }
+      for (Map.Entry entry : dataMap.entrySet()) {
+         addToIndexes(entry.getValue(), entry.getKey().toString());
+      }
       return mapPut;
    }
 



More information about the infinispan-commits mailing list