[infinispan-commits] Infinispan SVN: r2091 - in trunk: query/src/main/java/org/infinispan/query/backend and 1 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jul 21 13:12:25 EDT 2010


Author: navssurtani
Date: 2010-07-21 13:12:25 -0400 (Wed, 21 Jul 2010)
New Revision: 2091

Modified:
   trunk/core/src/main/java/org/infinispan/context/InvocationContext.java
   trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java
   trunk/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java
Log:
ISPN-548. Problem with MarshalledValueQueryTest. 2 test failures here. Checking in so mmarkus can see the updates

Modified: trunk/core/src/main/java/org/infinispan/context/InvocationContext.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/context/InvocationContext.java	2010-07-21 11:06:23 UTC (rev 2090)
+++ trunk/core/src/main/java/org/infinispan/context/InvocationContext.java	2010-07-21 17:12:25 UTC (rev 2091)
@@ -61,7 +61,7 @@
    InvocationContext clone();
 
    /**
-    * Retrieves a set of keys added to the context within the scope of the current ivocation up to the current point
+    * Retrieves a set of keys added to the context within the scope of the current invocation up to the current point
     * in time.  This is usually all of the keys added to the context, unless transactions are used in which case it is
     * a subset of all the keys added to the context.
     * @return a Set of keys, which may be an empty set.

Modified: trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	2010-07-21 11:06:23 UTC (rev 2090)
+++ trunk/query/src/main/java/org/infinispan/query/backend/QueryInterceptor.java	2010-07-21 17:12:25 UTC (rev 2091)
@@ -30,6 +30,7 @@
 import org.infinispan.commands.write.PutMapCommand;
 import org.infinispan.commands.write.RemoveCommand;
 import org.infinispan.commands.write.ReplaceCommand;
+import org.infinispan.container.entries.CacheEntry;
 import org.infinispan.context.InvocationContext;
 import org.infinispan.factories.annotations.Inject;
 import org.infinispan.interceptors.base.CommandInterceptor;
@@ -75,9 +76,26 @@
       // do the actual put first.
       Object toReturn = invokeNextInterceptor(ctx, command);
 
-      if (shouldModifyIndexes(ctx))
-         addToIndexes(extractValue(command.getValue()), extractValue(command.getKey()));
+      if (shouldModifyIndexes(ctx)) {
+         // First making a check to see if the key is already in the cache or not. If it isn't we can add the key no problem,
+         // otherwise we need to be updating the indexes as opposed to simply adding to the indexes.
+         Object key = command.getKey();
+         Object value = command.getValue();
+         System.out.println("Key, value pairing is: - " + key + " + " + value);
+         CacheEntry entry = ctx.lookupEntry(key);
 
+         // New entry so we will add it to the indexes.
+         if(entry.isCreated()) {
+            System.out.println("Entry is created");
+            addToIndexes(extractValue(value), extractValue(key));
+         }
+         // Updated entry so we are going to update the indexes and not add them.
+         if(entry.isChanged()){
+            System.out.println("Entry is changed");            
+            updateIndexes((value), extractValue(key));
+         }
+
+      }
       return toReturn;
    }
 
@@ -144,6 +162,7 @@
 
 
    // Method that will be called when data needs to be added into Lucene.
+
    protected void addToIndexes(Object value, Object key) {
       if (trace) log.trace("Adding to indexes for key [{0}] and value [{0}]", key, value);
 
@@ -157,6 +176,7 @@
 
 
    // Method that will be called when data needs to be removed from Lucene.
+
    protected void removeFromIndexes(Object value, Object key) {
 
       // The key here is the String representation of the key that is stored in the cache.
@@ -167,6 +187,16 @@
       searchFactory.getWorker().performWork(new Work<Object>(value, keyToString(key), WorkType.DELETE), transactionContext);
    }
 
+   protected void updateIndexes(Object value, Object 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.
+      if (value == null) throw new NullPointerException("Cannot handle a null value!");
+      TransactionContext transactionContext = new TransactionalEventTransactionContext(transactionManager);
+      searchFactory.getWorker().performWork(new Work<Object>(value, keyToString(key), WorkType.UPDATE), transactionContext);
+
+   }
+
    private Object extractValue(Object wrappedValue) {
       if (wrappedValue instanceof MarshalledValue)
          return ((MarshalledValue) wrappedValue).get();

Modified: trunk/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java	2010-07-21 11:06:23 UTC (rev 2090)
+++ trunk/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java	2010-07-21 17:12:25 UTC (rev 2091)
@@ -120,6 +120,7 @@
 
       found = cacheQuery.list();
 
+      System.out.println("Found size is: - " + found.size());
       assert found.size() == 1;
       assert found.get(0).equals(person1);
    }
@@ -169,14 +170,34 @@
       cacheQuery = new QueryFactory(cache, qh).getQuery(luceneQuery);
       found = cacheQuery.list();
 
-      System.out.println("found is: - " + found);
       assert found.size() == 1;
       assert found.contains(person2);
       assert !found.contains(person3) : "The search should not return person3";
+   }
 
+   public void testUpdated() throws ParseException{
+      queryParser = new QueryParser("name", new StandardAnalyzer());
 
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh).getQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2) : "The search should have person2";
+
+      cache.put(key2, person1);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = new QueryFactory(cache, qh).getQuery(luceneQuery);
+      found = cacheQuery.list();
+      
+      assert found.size() == 1 : "Size of list should be 1";
+      assert !found.contains(person2) : "Person 2 should not be found now";
+      assert !found.contains(person1) : "Person 1 should not be found because it does not meet the search criteria";
+
    }
 
+
    public void testSetSort() throws ParseException {
       person2.setAge(35);
       person3.setAge(12);



More information about the infinispan-commits mailing list