[jbosscache-commits] JBoss Cache SVN: r6813 - in searchable/trunk: src/main/java/org/jboss/cache/search and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Sep 29 10:16:28 EDT 2008


Author: navssurtani
Date: 2008-09-29 10:16:28 -0400 (Mon, 29 Sep 2008)
New Revision: 6813

Modified:
   searchable/trunk/pom.xml
   searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
   searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
   searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
   searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
Log:
Trying to get pojocache compatibility

Modified: searchable/trunk/pom.xml
===================================================================
--- searchable/trunk/pom.xml	2008-09-27 23:31:53 UTC (rev 6812)
+++ searchable/trunk/pom.xml	2008-09-29 14:16:28 UTC (rev 6813)
@@ -4,7 +4,7 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <properties>
-      <jbosscache-searchable-version>1.0.0.CR1</jbosscache-searchable-version>
+      <jbosscache-searchable-version>1.0.0-SNAPSHOT</jbosscache-searchable-version>
       <!-- By default only generate Javadocs when we package the module. -->
       <javadocPhase>package</javadocPhase>
    </properties>
@@ -40,11 +40,11 @@
          <version>1.0.4</version>
       </dependency>
 
-<!--      <dependency>
+      <dependency>
          <groupId>org.jboss.cache</groupId>
          <artifactId>jbosscache-pojo</artifactId>
          <version>2.2.0.CR7</version>
-      </dependency>   -->
+      </dependency>
 
 
       <!-- Test dependencies -->

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java	2008-09-27 23:31:53 UTC (rev 6812)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java	2008-09-29 14:16:28 UTC (rev 6813)
@@ -1,72 +1,72 @@
-///*
-// * 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.jboss.cache.search;
-//
-//import org.hibernate.search.backend.TransactionContext;
-//import org.jboss.cache.pojo.notification.event.Event;
-//
-//import javax.transaction.Synchronization;
-//import javax.transaction.Transaction;
-//
-///**
-// * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
-// */
-//public class PojoTransactionContext implements TransactionContext
-//{
-//   Event event;
-//
-//   public PojoTransactionContext(Event event)
-//   {
-//      if (event == null) throw new NullPointerException("event cannot be null");
-//      this.event = event;
-//
-//   }
-//   public boolean isTransactionInProgress()
-//   {
-//      return (event.getContext().getTransaction() != null);
-//
-//   }
-//
-//   public Object getTransactionIdentifier()
-//   {
-//      return event.getContext().getTransaction();
-//   }
-//
-//   public void registerSynchronization(Synchronization synchronization)
-//   {
-//      Transaction transaction = event.getContext().getTransaction();
-//
-//      if (transaction != null)
-//      {
-//
-//         try
-//         {
-//            transaction.registerSynchronization(synchronization);
-//         }
-//         catch (Exception e)
-//         {
-//            throw new RuntimeException(e);
-//         }
-//      }
-//   }
-//}
+/*
+ * 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.jboss.cache.search;
+
+import org.hibernate.search.backend.TransactionContext;
+import org.jboss.cache.pojo.notification.event.Event;
+
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+public class PojoTransactionContext implements TransactionContext
+{
+   Event event;
+
+   public PojoTransactionContext(Event event)
+   {
+      if (event == null) throw new NullPointerException("event cannot be null");
+      this.event = event;
+
+   }
+   public boolean isTransactionInProgress()
+   {
+      return (event.getContext().getTransaction() != null);
+
+   }
+
+   public Object getTransactionIdentifier()
+   {
+      return event.getContext().getTransaction();
+   }
+
+   public void registerSynchronization(Synchronization synchronization)
+   {
+      Transaction transaction = event.getContext().getTransaction();
+
+      if (transaction != null)
+      {
+
+         try
+         {
+            transaction.registerSynchronization(synchronization);
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+   }
+}

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java	2008-09-27 23:31:53 UTC (rev 6812)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java	2008-09-29 14:16:28 UTC (rev 6813)
@@ -18,7 +18,7 @@
  * 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.jboss.cache.search;
 
@@ -27,6 +27,7 @@
 import org.hibernate.search.engine.SearchFactoryImplementor;
 import org.jboss.cache.Cache;
 import org.jboss.cache.CacheStatus;
+import org.jboss.cache.pojo.PojoCache;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -35,23 +36,24 @@
 
 /**
  * Factory class used to create the searchable-cache like so: -
- *
  * <p/>
- *   SearchableCache searchableCache = SearchableCacheFactory.createSearchableCache(coreCache, class[]);
+ * <p/>
+ * SearchableCache searchableCache = SearchableCacheFactory.createSearchableCache(coreCache, class[]);
+ * <p/>
+ * <p/>
  *
- * <p/>
  * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
  */
 public class SearchableCacheFactory
 {
    private static final Log log = LogFactory.getLog(SearchableCacheFactory.class);
 
-   
+
    /**
     * 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                           
+    * @param c       - the Cache
+    * @param classes - Class array to be added
     * @return a SearchableCache
     */
    public SearchableCache createSearchableCache(Cache<?, ?> c, Class... classes)
@@ -62,18 +64,18 @@
    /**
     * This method creates a searchable cache as well but requires the properties object.
     *
-    * @param c - the Cache
+    * @param c          - the Cache
     * @param properties - java.util.properties
-    * @param classes - a class array
+    * @param classes    - a class array
     * @return a SearchableCache
     */
    public SearchableCache createSearchableCache(Cache<?, ?> c, Properties properties, Class... classes)
    {
+
       //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.getCacheStatus() != CacheStatus.STARTED)
@@ -92,30 +94,93 @@
       // set classes in the cfg
 
       SearchFactoryImplementor searchFactory = new SearchFactoryImpl(cfg);
-//       boolean isPojoCache = c instanceof PojoCache; keep this for later usage
 
-      // Step 2: Add cache listener to listen for events happening in the cache.
-      //SearchableListener listener = isPojoCache ? new SearchablePojoListener(searchFactory) : new SearchableCoreListener(searchFactory);
 
-      SearchableCoreListener listener = new SearchableCoreListener(searchFactory);
-      c.addCacheListener(listener);
+      // Okay, create the core listener
+      SearchableCoreListener coreListener = new SearchableCoreListener(searchFactory);
+      c.addCacheListener(coreListener);
 
-
-      // step 3: create the searchable cache delegate.
+      //Create the searchableCache and pass it on.
       SearchableCache sc = new SearchableCacheImpl(c, searchFactory);
       return sc;
    }
 
 
+   /**
+    * This method creates a searchable cache as well but requires the properties object.
+    *
+    * @param pojo          - the pojoCache
+    * @param properties - java.util.properties
+    * @param classes    - a class array
+    * @return a SearchableCache
+    */
+
+   public SearchableCache createSearchableCache(PojoCache pojo, Properties properties, Class... classes)
+   {
+
+      System.out.println("create searchable cache called with pojo cache");
+      //TODO: Ask Manik and/or Jason if there is a way to directly check if the pojo cache is started or not
+      validateClasses(classes);
+
+      Cache coreCache = pojo.getCache();
+
+      if (coreCache.getCacheStatus() != CacheStatus.STARTED)
+      {
+         if (log.isInfoEnabled()) log.info("Cache not started.  Starting cache first.");
+         pojo.start();
+      }
+
+      if (classes.length == 0)
+      {
+         if (log.isWarnEnabled()) log.warn("You haven't passed in any classes to index.  Is this an error?");
+      }
+
+      // step 1: create hibernate search searchFactory
+      SearchConfiguration cfg = new SearchableCacheConfiguration(classes, properties);
+      // set classes in the cfg
+
+      SearchFactoryImplementor searchFactory = new SearchFactoryImpl(cfg);
+
+      //Now create the pojoListener
+      SearchablePojoListener pojoListener = new SearchablePojoListener(searchFactory);
+      pojo.addListener(pojoListener);
+
+      //TODO: - This could be a break point. But it should not be.
+      SearchableCache sc = new SearchableCacheImpl(coreCache, searchFactory);
+      return sc;
+   }
+
+   /**
+    * Creates a searchable cache from a cache object and a class array, without the properties object.
+    *
+    * @param pojo       - the pojoCache
+    * @param classes - Class array to be added
+    * @return a SearchableCache
+    */
+
+
+   public SearchableCache createSearchableCache(PojoCache pojo, Class... classes)
+   {
+      return createSearchableCache(pojo, null, classes);
+   }
+
+   //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)
+      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");
+         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())
+         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());
+            if (field.getAnnotation(org.hibernate.search.annotations.DocumentId.class) != null)
+            {
+               throw new IllegalArgumentException("Please remove the documentId annotation in " + c.getName());
+            }
          }
       }
 

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java	2008-09-27 23:31:53 UTC (rev 6812)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java	2008-09-29 14:16:28 UTC (rev 6813)
@@ -1,100 +1,112 @@
-///*
-// * 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.jboss.cache.search;
-//
-//import org.hibernate.search.impl.SearchFactoryImpl;
-//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.jboss.cache.notifications.event.NodeModifiedEvent;
-//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.PojoCache;
-//import org.jboss.cache.Fqn;
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
-//
-//import javax.transaction.Transaction;
-//
-///**
-// * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
-// */
-//
-//@PojoCacheListener
-//public class SearchablePojoListener
-//{
-//   private SearchFactoryImplementor searchFactory;
-//   private static final Log log = LogFactory.getLog(SearchablePojoListener.class);
-//   private String pojoKey = "pojoKey";
-//
-//   public SearchablePojoListener(SearchFactoryImplementor searchFactory)
-//   {
-//      this.searchFactory = searchFactory;
-//   }
-//
-//   /**
-//    * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the NodeModifiedEvent class.
-//    *
-//    * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
-//    * @throws InvalidKeyException if an invalid key is given.
-//    */
-//
-//   @Attached
-//   public void handleAttach(AttachedEvent event) throws InvalidKeyException
-//   {
-//      System.out.println("Pojocache.attach() called");
-//      Object added = event.getSource();
-//      Fqn fqn = event.getContext().getPojoCache().getInternalFqn(added);
-//
-//      CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
-//
-//      TransactionContext ctx = new PojoTransactionContext(event);
-//
-//      searchFactory.getWorker().performWork(new Work(added, cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
-//   }
-//
-//
-//   @Detached
-//   public void handleDetach (DetachedEvent event) throws InvalidKeyException
-//   {
-//      Object deleted = event.getSource();
-//      Fqn fqn = event.getContext().getPojoCache().getInternalFqn(deleted);
-//
-//      CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
-//
-//      TransactionContext ctx = new PojoTransactionContext(event);
-//
-//      searchFactory.getWorker().performWork(new Work(deleted, cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
-//   }
-//
-//
-//   //TODO: Sort out updating Lucene for the following annotations: -
-////   @FieldModified
-////   @ListModified
-////   @ArrayModified
-////   @SetModified
-//
-//}
+/*
+ * 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.jboss.cache.search;
+
+import org.hibernate.search.impl.SearchFactoryImpl;
+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.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.notifications.annotation.NodeModified;
+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.NotificationContext;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.Fqn;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.transaction.Transaction;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at PojoCacheListener
+public class SearchablePojoListener
+{
+   private SearchFactoryImplementor searchFactory;
+   private static final Log log = LogFactory.getLog(SearchablePojoListener.class);
+   private String pojoKey = "pojoKey";
+
+   public SearchablePojoListener(SearchFactoryImplementor searchFactory)
+   {
+      this.searchFactory = searchFactory;
+   }
+
+   /**
+    * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the NodeModifiedEvent class.
+    *
+    * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
+    * @throws InvalidKeyException if an invalid key is given.
+    */
+
+   @Attached
+   public void handleAttach(AttachedEvent event) throws InvalidKeyException
+   {
+      System.out.println("Pojocache.attach() called");
+      Object added = event.getSource();
+
+      System.out.println("the object is " + event.toString());
+
+      NotificationContext notificationContext = event.getContext();
+      System.out.println("notificationContext is " + notificationContext);
+
+      PojoCache pojo = notificationContext.getPojoCache();
+      System.out.println("pojo is " + pojo);
+
+      Fqn fqn = pojo.getInternalFqn(added);
+      System.out.println("Fqn is " + fqn);
+
+
+      CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
+
+      TransactionContext ctx = new PojoTransactionContext(event);
+
+      searchFactory.getWorker().performWork(new Work(added, cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
+   }
+
+   @Detached
+   public void handleDetach (DetachedEvent event) throws InvalidKeyException
+   {
+      Object deleted = event.getSource();
+      Fqn fqn = event.getContext().getPojoCache().getInternalFqn(deleted);
+
+      CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
+
+      TransactionContext ctx = new PojoTransactionContext(event);
+
+      searchFactory.getWorker().performWork(new Work(deleted, cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
+   }
+
+
+   //TODO: Sort out updating Lucene for the following annotations: -
+//   @FieldModified
+//   @ListModified
+//   @ArrayModified
+//   @SetModified
+
+}

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	2008-09-27 23:31:53 UTC (rev 6812)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java	2008-09-29 14:16:28 UTC (rev 6813)
@@ -1,188 +1,186 @@
-//package org.jboss.cache.search.blackbox;
-//
-//import org.apache.lucene.analysis.standard.StandardAnalyzer;
-//import org.apache.lucene.queryParser.ParseException;
-//import org.apache.lucene.queryParser.QueryParser;
-//import org.apache.lucene.search.Query;
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
-//import org.jboss.cache.Cache;
-//import org.jboss.cache.DefaultCacheFactory;
-//import org.jboss.cache.Fqn;
-//import org.jboss.cache.config.Configuration;
-//import org.jboss.cache.pojo.PojoCache;
-//import org.jboss.cache.pojo.PojoCacheFactory;
-//import org.jboss.cache.search.CacheQuery;
-//import org.jboss.cache.search.SearchableCache;
-//import org.jboss.cache.search.SearchableCacheFactory;
-//import org.jboss.cache.search.helper.IndexCleanUp;
-//import org.jboss.cache.search.test.Person;
-//import org.testng.annotations.AfterMethod;
-//import org.testng.annotations.BeforeMethod;
-//import org.testng.annotations.Test;
-//
-//import java.util.List;
-//
-///**
-// * Same as LocalCacheTest except that you will use a POJO Cache instead and use pojoCache.attach() ad pojoCache.detach()
-// * instead of cache.put() and cache.remove().
-// * <p/>
-// *
-// * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
-// */
-//
-//@Test(groups = "functional", enabled = false)
-//public class LocalPOJOCacheTest
-//{
-//   SearchableCache searchableCache;
-//   PojoCache pojo;
-//   Person person1;
-//   Person person2;
-//   Person person3;
-//   Person person4;
-//   QueryParser queryParser;
-//   Query luceneQuery;
-//   CacheQuery cacheQuery;
-//   List found;
-//   private static final Log log = LogFactory.getLog(LocalPOJOCacheTest.class);
-//
-//
-//   @BeforeMethod
-//   public void setUp()
-//   {
-//      boolean toStart = false;
-//      pojo = PojoCacheFactory.createCache(new Configuration(), toStart);
-//      pojo.start(); // if toStart above is true, it will starts the cache automatically.
-//      searchableCache = new SearchableCacheFactory().createSearchableCache(pojo.getCache(), Person.class);
-//
-//      person1 = new Person();
-//      person1.setName("Navin Surtani");
-//      person1.setBlurb("Likes playing WoW");
-//
-//      person2 = new Person();
-//      person2.setName("BigGoat");
-//      person2.setBlurb("Eats grass");
-//
-//      person3 = new Person();
-//      person3.setName("MiniGoat");
-//      person3.setBlurb("Eats cheese");
-//
-//      pojo.attach(Fqn.fromString("/a/b/c"), person1);
-//      pojo.attach(Fqn.fromString("/a/b/d"), person2);
-//      pojo.attach(Fqn.fromString("/a/b/c"), person3);
-//
-//
-//   }
-//
-//   @AfterMethod
-//   public void tearDown()
-//   {
-//      if (pojo != null) pojo.stop();
-//      if (searchableCache != null) searchableCache.stop();
-//      IndexCleanUp.cleanUpIndexes();
-//   }
-//
-//   public void testSimple() throws ParseException
-//   {
-//      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-//      luceneQuery = queryParser.parse("playing");
-//      cacheQuery = searchableCache.createQuery(luceneQuery);
-//
-//      found = cacheQuery.list();
-//
-//   }
-//
-//   public void testMultipleResults() throws ParseException
-//   {
-//      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-//      luceneQuery = queryParser.parse("Eats");
-//      cacheQuery = searchableCache.createQuery(luceneQuery);
-//      found = cacheQuery.list();
-//
-//      assert found.size() == 2;
-//      assert !found.get(1).equals(person2);
-//      assert !found.get(0).equals(person3);
-//
-//   }
-//
-//   public void testModified() throws ParseException
-//   {
-//      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-//      luceneQuery = queryParser.parse("playing");
-//      cacheQuery = searchableCache.createQuery(luceneQuery);
-//
-//      found = cacheQuery.list();
-//
-//      assert found.size() == 1;
-////      assert found.get(0).equals(person1);
-//
-//      person1.setBlurb("Likes pizza");
-//
-//      pojo.attach(Fqn.fromString("/a/b/c/"), person1);
-//
-//      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-//      luceneQuery = queryParser.parse("pizza");
-//      cacheQuery = searchableCache.createQuery(luceneQuery);
-//
-//      found = cacheQuery.list();
-//
-//      assert found.size() == 1;
-////      assert found.get(0).equals(person1);
-//   }
-//
-//   public void testAdded() throws ParseException
-//   {
-//      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-//      luceneQuery = queryParser.parse("eats");
-//      cacheQuery = searchableCache.createQuery(luceneQuery);
-//      found = cacheQuery.list();
-//
-//      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";
-//
-//      person4 = new Person();
-//      person4.setName("MightyGoat");
-//      person4.setBlurb("Also eats grass");
-//
-//      pojo.attach(Fqn.fromString("/r/a/m/"), person4);
-//
-//      luceneQuery = queryParser.parse("eats");
-//      cacheQuery = searchableCache.createQuery(luceneQuery);
-//      found = cacheQuery.list();
-//
-//      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";
-//   }
-//
-//   public void testRemoved() throws ParseException
-//   {
-//      queryParser = new QueryParser("blurb", new StandardAnalyzer());
-//      luceneQuery = queryParser.parse("eats");
-//      cacheQuery = searchableCache.createQuery(luceneQuery);
-//      found = cacheQuery.list();
-//
-//      assert found.size() == 2;
-//      assert found.contains(person2);
-//      assert found.contains(person3) : "This should still contain object person3";
-//
-//      pojo.detach("/a/b/d");
-//
-//      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";
-//
-//
-//   }
-//
-//}
-//
-//
-//
+package org.jboss.cache.search.blackbox;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
+import org.jboss.cache.search.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * Same as LocalCacheTest except that you will use a POJO Cache instead and use pojoCache.attach() ad pojoCache.detach()
+ * instead of cache.put() and cache.remove().
+ * <p/>
+ *
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test(groups = "functional", enabled = true)
+public class LocalPOJOCacheTest
+{
+   SearchableCache searchableCache;
+   PojoCache pojo;
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   List found;
+   private static final Log log = LogFactory.getLog(LocalPOJOCacheTest.class);
+
+
+   @BeforeMethod
+   public void setUp()
+   {
+      boolean toStart = false;
+      pojo = PojoCacheFactory.createCache(new Configuration(), toStart);
+      pojo.start(); // if toStart above is true, it will starts the cache automatically.
+      searchableCache = new SearchableCacheFactory().createSearchableCache(pojo, Person.class);
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("BigGoat");
+      person2.setBlurb("Eats grass");
+              
+      person3 = new Person();
+      person3.setName("MiniGoat");
+      person3.setBlurb("Eats cheese");
+
+      pojo.attach("/a/b/c", person1);
+      pojo.attach("/a/b/d", person2);
+      pojo.attach("/a/b/c", person3);
+
+
+   }
+
+   @AfterMethod
+   public void tearDown()
+   {
+      if (pojo != null) pojo.stop();
+      if (searchableCache != null) searchableCache.stop();
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   public void testSimple() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+   }
+
+   public void testMultipleResults() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("Eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert !found.get(1).equals(person2);
+      assert !found.get(0).equals(person3);
+
+   }
+
+   public void testModified() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+//      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+
+      pojo.attach(Fqn.fromString("/a/b/c/"), person1);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+//      assert found.get(0).equals(person1);
+   }
+
+   public void testAdded() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      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";
+
+      person4 = new Person();
+      person4.setName("MightyGoat");
+      person4.setBlurb("Also eats grass");
+
+      pojo.attach(Fqn.fromString("/r/a/m/"), person4);
+
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      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";
+   }
+
+   public void testRemoved() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person2);
+      assert found.contains(person3) : "This should still contain object person3";
+
+      pojo.detach("/a/b/d");
+
+      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";
+
+
+   }
+
+}
+
+
+




More information about the jbosscache-commits mailing list