[jbosscache-commits] JBoss Cache SVN: r7742 - in searchable/trunk/src: test/java/org/jboss/cache/search and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Feb 20 10:15:26 EST 2009


Author: navssurtani
Date: 2009-02-20 10:15:26 -0500 (Fri, 20 Feb 2009)
New Revision: 7742

Modified:
   searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
   searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java
   searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java
   searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java
   searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
   searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
   searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
   searchable/trunk/src/test/resources/log4j.xml
Log:
More stuff coming in

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java	2009-02-20 15:15:26 UTC (rev 7742)
@@ -332,7 +332,10 @@
             EntityId id = createCacheEntityId(documentId);
             ids.add(id);
          }
-
+         if (entityLoader instanceof PojoEntityLoader)
+         {
+            System.out.println("entityLoader is a PEL");
+         }
          List<Object> list = entityLoader.load(ids);
          if (resultTransformer == null)
          {

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java	2009-02-20 15:15:26 UTC (rev 7742)
@@ -21,7 +21,7 @@
 
       // Create a pojo entity loader instead of a cache entity loader since we are dealing with a pojo cache
       entityLoader = new PojoEntityLoader(pojo);
-
+      System.out.println("Created a new CacheQueryPojoImpl");
    }
 
    protected EntityId createCacheEntityId(String docId)

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java	2009-02-20 15:15:26 UTC (rev 7742)
@@ -3,7 +3,7 @@
 import org.jboss.cache.Fqn;
 
 /**
- *   This class is used to get fqns, keys and documentId's by calling methods on {@link org.jboss.cache.search.Transformer}
+ * This class is used to get fqns, keys and documentId's by calling methods on {@link org.jboss.cache.search.Transformer}
  * <p/>
  *
  * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
@@ -14,7 +14,7 @@
    protected String documentId;
    protected Fqn fqn;
 
-   public PojoEntityId (Fqn fqn)
+   public PojoEntityId(Fqn fqn)
    {
       if (fqn == null) throw new NullPointerException("Fqn is null.");
       this.fqn = fqn;
@@ -22,7 +22,7 @@
 
    }
 
-   public PojoEntityId (String documentId)
+   public PojoEntityId(String documentId)
    {
       if (documentId == null) throw new NullPointerException("doc ID is null.");
       this.documentId = documentId;
@@ -54,7 +54,7 @@
 
    public String getDocumentId() throws InvalidKeyException
    {
-      if  (fqn == null)
+      if (fqn == null)
       {
          throw new IllegalArgumentException("Either your key or fqn is null. Please check again.");
       }

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java	2009-02-20 15:15:26 UTC (rev 7742)
@@ -14,9 +14,11 @@
    {
       super(pojoCache.getCache());
       this.pojoCache = pojoCache;
+      System.out.println("Created new PojoEntityLoader");
    }
 
-   protected Object loadFromCache(CacheEntityId id)
+   @Override
+   protected Object loadFromCache(EntityId id)
    {
       return pojoCache.find(id.getFqn());
    }

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java	2009-02-20 15:15:26 UTC (rev 7742)
@@ -29,13 +29,14 @@
 import org.hibernate.search.engine.SearchFactoryImplementor;
 import org.jboss.cache.notifications.event.NodeModifiedEvent;
 import org.jboss.cache.notifications.event.NodeCreatedEvent;
+import org.jboss.cache.notifications.event.NodeRemovedEvent;
+import org.jboss.cache.notifications.event.NodeEvent;
 import org.jboss.cache.notifications.annotation.NodeModified;
 import org.jboss.cache.notifications.annotation.CacheListener;
 import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.notifications.annotation.NodeRemoved;
 import org.jboss.cache.pojo.notification.annotation.*;
-import org.jboss.cache.pojo.notification.event.AttachedEvent;
-import org.jboss.cache.pojo.notification.event.DetachedEvent;
-import org.jboss.cache.pojo.notification.event.Event;
+import org.jboss.cache.pojo.notification.event.*;
 import org.jboss.cache.pojo.notification.NotificationContext;
 import org.jboss.cache.pojo.PojoCache;
 import org.jboss.cache.pojo.impl.InternalHelper;
@@ -44,6 +45,9 @@
 import org.apache.commons.logging.LogFactory;
 
 import javax.transaction.Transaction;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
 
 /**
  * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
@@ -55,10 +59,11 @@
 {
    private SearchFactoryImplementor searchFactory;
    private static final Log log = LogFactory.getLog(SearchablePojoListener.class);
-   private String pojoKey = "pojoKey";
 
    private ThreadLocal<Fqn> savedFqn = new ThreadLocal<Fqn>();
 
+   private List<ThreadLocal<Fqn>> fqnCollection = new ArrayList<ThreadLocal<Fqn>>();
+
    public SearchablePojoListener(SearchFactoryImplementor searchFactory)
    {
       this.searchFactory = searchFactory;
@@ -69,35 +74,51 @@
    {
       if (!nme.isPre()) return;
       Fqn f = nme.getFqn();
-      System.out.println("Node modified called for Fqn " + f);
       if (InternalHelper.isInternalNode(f))
       {
-         System.out.println("Is internal and I dont care");
+         // do nothing because I don't want anything to do with the internal nodes
       }
       else
       {
          savedFqn.set(f);
-         System.out.println("Saved Fqn to ThreadLocal.");
+//         if (log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal for fqn " + f);
       }
    }
 
    @NodeCreated
-   public void handleNodeKreated(NodeCreatedEvent nce)
+   public void handleNodeCreated(NodeCreatedEvent nce)
    {
       if (!nce.isPre()) return;
-      Fqn f = nce.getFqn();
-      System.out.println("Node kreated called for Fqn " + f);
-      if (InternalHelper.isInternalNode(f))
+      Fqn fqn = nce.getFqn();
+      if (InternalHelper.isInternalNode(fqn))
       {
-         System.out.println("Is internal and I dont care");
+         // do nothing because I don't want anything to do with the internal nodes
       }
       else
       {
-         savedFqn.set(f);
-         System.out.println("savedFqn.set() called");
+         savedFqn.set(fqn);
+//         if (log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal for fqn " + fqn);
       }
    }
 
+   @NodeRemoved
+   public void handleNodeRemoved(NodeRemovedEvent nre)
+   {
+      if (!nre.isPre()) return;
+      Fqn fqn = nre.getFqn();
+      if (InternalHelper.isInternalNode((fqn)))
+      {
+         // do nothing because I don't want anything to do with the internal nodes
+
+      }
+      else
+      {
+         savedFqn.set(fqn);
+//         if (log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal for fqn " + fqn);
+
+      }
+   }
+
    /**
     * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the NodeModifiedEvent class.
     *
@@ -108,49 +129,123 @@
    @Attached
    public void handleAttach(AttachedEvent event) throws InvalidKeyException
    {
-      System.out.println("Pojocache.attach() called");
+      if (log.isDebugEnabled()) log.debug("@Attached annotation found.");
+
       Object added = event.getSource();
 
-      System.out.println("the object is " + event.toString());
+      if (log.isDebugEnabled()) log.debug("Added object is:- " + added);
 
-      NotificationContext notificationContext = event.getContext();
-      System.out.println("notificationContext is " + notificationContext);
+      Fqn fqn = savedFqn.get();
 
-      PojoCache pojo = notificationContext.getPojoCache();
-      System.out.println("pojo is " + pojo);
+      if (fqn == null)
+      {
+         //look through the collection of threadLocals.
 
-//      Fqn fqn = pojo.getInternalFqn(added);
-      Fqn fqn = savedFqn.get();
-      savedFqn.remove();
-      System.out.println("Fqn is " + fqn);
+         if (fqn == null)
+         {
+            throw new NullPointerException("Your fqn still null");
+         }
 
+      }
 
-      CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
-      System.out.println("new CEI created " + cacheEntityId);
+//      savedFqn.remove();
 
+      if (log.isDebugEnabled()) log.debug("Fqn is " + fqn);      
+
+      EntityId pojoEntityId = new PojoEntityId(fqn);
+
       TransactionContext ctx = new PojoTransactionContext(event);
-      System.out.println("new ctx created " + ctx);
 
-      searchFactory.getWorker().performWork(new Work(added, cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
+      searchFactory.getWorker().performWork(new Work(added, pojoEntityId.getDocumentId(), WorkType.ADD), ctx);
    }
 
    @Detached
    public void handleDetach(DetachedEvent event) throws InvalidKeyException
    {
+      if (log.isDebugEnabled()) log.debug("@Detached annotation found.");
       Object deleted = event.getSource();
-      Fqn fqn = event.getContext().getPojoCache().getInternalFqn(deleted);
 
-      CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
+      Fqn fqn = savedFqn.get();
+      savedFqn.remove();
 
+      if (log.isDebugEnabled()) log.debug("Fqn is " + fqn);
+
+      EntityId pojoEntityId = new PojoEntityId(fqn);
+
       TransactionContext ctx = new PojoTransactionContext(event);
 
-      searchFactory.getWorker().performWork(new Work(deleted, cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
+      searchFactory.getWorker().performWork(new Work(deleted, pojoEntityId.getDocumentId(), WorkType.DELETE), ctx);
    }
 
    //TODO: Sort out updating Lucene for the following annotations: -
-//   @FieldModified
-//   @ListModified
-//   @ArrayModified
-//   @SetModified
+   @FieldModified
+   public void handleFieldModified(Event event) throws InvalidKeyException
+   {
+      if (log.isDebugEnabled()) log.debug("@FieldModified annotation found.");
+      Object modified = event.getSource();
+      Fqn fqn = savedFqn.get();
+      savedFqn.remove();
 
+      if (log.isDebugEnabled()) log.debug("Fqn is " + fqn);
+
+      EntityId pojoEntityId = new PojoEntityId(fqn);
+
+      TransactionContext ctx = new PojoTransactionContext(event);
+
+      searchFactory.getWorker().performWork(new Work(modified, pojoEntityId.getDocumentId(), WorkType.DELETE), ctx);
+      searchFactory.getWorker().performWork(new Work(modified, pojoEntityId.getDocumentId(), WorkType.ADD), ctx);
+
+   }
+
+
+   @ListModified
+   public void handleListModified(ListModifiedEvent event) throws InvalidKeyException
+   {
+      if (log.isDebugEnabled()) log.debug("@ListModified annotation found.");
+
+      if (log.isDebugEnabled()) log.debug("List size is " + event.getSource().size());
+
+
+   }
+
+   @ArrayModified
+   public void handleArrayModified(ArrayModifiedEvent event) throws InvalidKeyException
+   {
+      if (log.isDebugEnabled()) log.debug("@ArrayModified annotation found.");
+
+      if (log.isDebugEnabled()) log.debug("Object array is " + event.getSource().getClass());
+
+
+   }
+
+   @SetModified
+   public void handleSetModified(SetModifiedEvent event) throws InvalidKeyException
+   {
+      if (log.isDebugEnabled()) log.debug("@SetModified annotation found.");
+
+      if (log.isDebugEnabled()) log.debug("Set size is " + event.getSource().size());      
+
+   }
+
+   @MapModified
+   public void handleMapModified(MapModifiedEvent event) throws InvalidKeyException
+   {
+      if (log.isDebugEnabled()) log.debug("@MapModified annotation found.");
+
+      if (log.isDebugEnabled()) log.debug("Set size is " + event.getSource().size());
+
+      if (log.isDebugEnabled()) log.debug("Where is the end of the thread?");
+
+
+
+   }
+
+
+   @NodeCreated
+   @NodeRemoved
+   @NodeModified
+   public void logEvent(NodeEvent e)
+   {
+      if (log.isDebugEnabled()) log.debug("Detected event of type " + e.getType() + " with Fqn " + e.getFqn());
+   }
 }

Modified: searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java	2009-02-20 15:15:26 UTC (rev 7742)
@@ -19,8 +19,8 @@
 @Test(groups = "functional")
 public class QueryResultIteratorImplTest
 {
-   List<CacheEntityId> ids;
-   Map<CacheEntityId, Object> dummyResults;
+   List<EntityId> ids;
+   Map<EntityId, Object> dummyResults;
    QueryResultIterator iterator;
    int fetchSize = 1;
 
@@ -41,10 +41,10 @@
       ids.add(new CacheEntityId(Fqn.fromString("/j"), "key10"));
 
       // create some dummy data
-      dummyResults = new HashMap<CacheEntityId, Object>();
+      dummyResults = new HashMap<EntityId, Object>();
       int counter = 0;
 
-      for (CacheEntityId id : ids)
+      for (EntityId id : ids)
       {
          // for each cache entity ID, create a dummy result that will be returned when loading it.
          dummyResults.put(id, "Result number " + counter++);
@@ -191,7 +191,7 @@
       iterator.first();
       for (int i = 0; i < ids.size(); i++)
       {
-         System.out.println("Loop number count: - " + (i+1));
+         System.out.println("Loop number count: - " + (i + 1));
          Object expectedValue = dummyResults.get(ids.get(i));
          assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
          assert expectedValue == iterator.next(); // tests next()
@@ -233,10 +233,10 @@
 
    public static class DummyEntityLoader extends CacheEntityLoader
    {
-      private List<CacheEntityId> allKnownIds;
-      private Map<CacheEntityId, Object> dummyValues;
+      private List<EntityId> allKnownIds;
+      private Map<EntityId, Object> dummyValues;
 
-      public DummyEntityLoader(List<CacheEntityId> allKnownIds, Map<CacheEntityId, Object> dummyValues)
+      public DummyEntityLoader(List<EntityId> allKnownIds, Map<EntityId, Object> dummyValues)
       {
          // use a null as a cache since we won't ever need to refer to the cache
          super(null);
@@ -246,11 +246,11 @@
       }
 
       @Override
-      public List<Object> load(List<CacheEntityId> ids)
+      public List<Object> load(List <EntityId> ids)
       {
          List<Object> resultsToReturn = new ArrayList<Object>(ids.size());
          // iterate through the list of ids we are looking for
-         for (CacheEntityId id : ids)
+         for (EntityId id : ids)
          {
             resultsToReturn.add(dummyValues.get(id));
          }
@@ -259,7 +259,7 @@
       }
 
       @Override
-      public Object load(CacheEntityId id)
+      public Object load(EntityId id)
       {
          return dummyValues.get(id);
       }

Modified: searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java	2009-02-20 15:15:26 UTC (rev 7742)
@@ -20,8 +20,7 @@
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.List;
-import java.util.Iterator;
+import java.util.*;
 
 /**
  * Same as LocalCacheTest except that you will use a POJO Cache instead and use pojoCache.attach() ad pojoCache.detach()
@@ -67,9 +66,9 @@
       person3.setName("MiniGoat");
       person3.setBlurb("Eats cheese");
 
-      pojo.attach("/a/b/c", person1);
-      pojo.attach("/a/b/d", person2);
-      pojo.attach("/c/a/t", person3);
+//      pojo.attach("/a", person1);
+//      pojo.attach("/b", person2);
+//      pojo.attach("/c", person3);
 
 
    }
@@ -90,9 +89,7 @@
 
       found = cacheQuery.list();
 
-      System.out.println("Size of list is " + found.size());
-      System.out.println("Object 1 is " + found.get(0));
-      System.out.println("Object 2 is " + found.get(1));
+      assert found.size() == 2;
    }
 
    public void testMultipleResults() throws ParseException
@@ -153,7 +150,7 @@
       person4.setName("MightyGoat");
       person4.setBlurb("Also eats grass");
 
-      pojo.attach(Fqn.fromString("/r/a/m/"), person4);
+      pojo.attach(Fqn.fromString("/d/"), person4);
 
       luceneQuery = queryParser.parse("eats");
       cacheQuery = searchableCache.createQuery(luceneQuery);
@@ -173,22 +170,43 @@
       found = cacheQuery.list();
 
       assert found.size() == 2;
-      assert found.contains(person2);
-      assert found.contains(person3) : "This should still contain object person3";
+      assert found.contains(person3);
+      assert found.contains(person2) : "This should still contain object person2";
 
-      pojo.detach("/a/b/d");
+      pojo.detach("/b");
 
       luceneQuery = queryParser.parse("eats");
       cacheQuery = searchableCache.createQuery(luceneQuery);
       found = cacheQuery.list();
 
       assert found.size() == 1;
-      assert found.contains(person2);
-      assert !found.contains(person3) : "The search should not return person3";
+      assert found.contains(person3);
+      assert !found.contains(person2) : "The search should not return person2";
 
 
    }
 
+   public void testListAdded() throws ParseException
+   {
+      List<Person> objectsToAdd = new ArrayList<Person>();
+
+      objectsToAdd.add(person1);
+      objectsToAdd.add(person2);
+      objectsToAdd.add(person3);
+
+      pojo.attach(Fqn.fromString("/d"), objectsToAdd);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      System.out.println("Size of found is " + found.size());
+
+      System.out.println(pojo.find(Fqn.fromString("/d")));
+   }
+
 }
 
 

Modified: searchable/trunk/src/test/resources/log4j.xml
===================================================================
--- searchable/trunk/src/test/resources/log4j.xml	2009-02-20 10:56:49 UTC (rev 7741)
+++ searchable/trunk/src/test/resources/log4j.xml	2009-02-20 15:15:26 UTC (rev 7742)
@@ -63,7 +63,7 @@
    <!-- ================ -->
 
    <category name="org.jboss.cache.search">
-      <priority value="WARN"/>
+      <priority value="DEBUG"/>
    </category>
 
    <category name="org.hibernate.search">




More information about the jbosscache-commits mailing list