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

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Oct 1 06:53:41 EDT 2009


Author: navssurtani
Date: 2009-10-01 06:53:40 -0400 (Thu, 01 Oct 2009)
New Revision: 895

Added:
   trunk/query/src/test/java/org/infinispan/query/backend/
   trunk/query/src/test/java/org/infinispan/query/backend/QueryHelperTest.java
Modified:
   trunk/query/infinispan-query.iml
   trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
Log:
[ISPN-202] Bug fixed. Tests written and pass.

Modified: trunk/query/infinispan-query.iml
===================================================================
--- trunk/query/infinispan-query.iml	2009-09-30 22:18:26 UTC (rev 894)
+++ trunk/query/infinispan-query.iml	2009-10-01 10:53:40 UTC (rev 895)
@@ -18,33 +18,42 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/jboss/jbossts/jbossts-common/4.6.1.GA/jbossts-common-4.6.1.GA.jar!/" />
         </CLASSES>
         <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.14/log4j-1.2.14.jar!/" />
+        </CLASSES>
+        <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.14/log4j-1.2.14.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
@@ -128,22 +137,22 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/river/1.2.0.CR3/river-1.2.0.CR3.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/river/1.2.0.CR4/river-1.2.0.CR4.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/river/1.2.0.CR3/river-1.2.0.CR3-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/river/1.2.0.CR4/river-1.2.0.CR4-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/marshalling-api/1.2.0.CR3/marshalling-api-1.2.0.CR3.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/marshalling-api/1.2.0.CR4/marshalling-api-1.2.0.CR4.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/marshalling-api/1.2.0.CR3/marshalling-api-1.2.0.CR3-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/jboss/marshalling/marshalling-api/1.2.0.CR4/marshalling-api-1.2.0.CR4-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
@@ -183,50 +192,90 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymockclassextension/2.4/easymockclassextension-2.4.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/jboss/jbossts/jbossjta/4.4.0.GA/jbossjta-4.4.0.GA.jar!/" />
         </CLASSES>
         <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar!/" />
+        </CLASSES>
+        <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymockclassextension/2.4/easymockclassextension-2.4-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymock/2.4/easymock-2.4.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/jboss/jbossts/jbossjts/4.6.1.GA/jbossjts-4.6.1.GA.jar!/" />
         </CLASSES>
         <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2.jar!/" />
+        </CLASSES>
+        <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymock/2.4/easymock-2.4-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymockclassextension/2.4/easymockclassextension-2.4.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES>
-          <root url="jar://$MAVEN_REPOSITORY$/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0-sources.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymockclassextension/2.4/easymockclassextension-2.4-sources.jar!/" />
         </SOURCES>
       </library>
     </orderEntry>
     <orderEntry type="module-library">
       <library>
         <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymock/2.4/easymock-2.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymock/2.4/easymock-2.4-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3-sources.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
           <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/hibernate-search/3.1.0.GA/hibernate-search-3.1.0.GA.jar!/" />
         </CLASSES>
         <JAVADOC />

Modified: trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2009-09-30 22:18:26 UTC (rev 894)
+++ trunk/query/src/main/java/org/infinispan/query/backend/QueryHelper.java	2009-10-01 10:53:40 UTC (rev 895)
@@ -3,6 +3,7 @@
 import org.hibernate.search.cfg.SearchConfiguration;
 import org.hibernate.search.engine.SearchFactoryImplementor;
 import org.hibernate.search.impl.SearchFactoryImpl;
+import org.infinispan.AdvancedCache;
 import org.infinispan.Cache;
 import org.infinispan.CacheException;
 import org.infinispan.factories.ComponentRegistry;
@@ -13,6 +14,7 @@
 import org.infinispan.util.logging.LogFactory;
 
 import java.lang.reflect.Field;
+import java.util.List;
 import java.util.Properties;
 
 /**
@@ -20,8 +22,12 @@
  * This is a TEMPORARY helper class that will be used to add the QueryInterceptor to the chain and provide Classes to
  * Hibernate Search.
  * <p/>
- * This class needs to be instantiated and then have applyProperties() called on it. This class WILL be removed once
- * other hooks come into Infinispan for versions 4.1 etc.
+ * This class needs to be instantiated before adding any objects into the Cache. Any objects added before this
+ * instantiation will not be indexed.
+ * <p/>
+ * This class must be instantiated only once however.
+ * <p/>
+ * However, only one instan This class WILL be removed once other hooks come into Infinispan for versions 4.1 etc.
  *
  * @author Navin Surtani
  * @since 4.0
@@ -56,10 +62,12 @@
       // assume cache is already created and running.
       // otherwise, start the cache!!
       if (cache.getStatus().needToInitializeBeforeStart()) {
-         log.debug("Cache not started.  Starting cache first.");
+         if(log.isDebugEnabled()) log.debug("Cache not started.  Starting cache first.");
          cache.start();
       }
 
+      checkInterceptorChain(cache);
+
       if (classes.length == 0) {
          throw new IllegalArgumentException("You haven't passed in any classes to index.");
       }
@@ -197,4 +205,22 @@
          }
       }
    }
+
+
+   private void checkInterceptorChain(Cache cache) {
+      // Check if there are any QueryInterceptors already added onto the chain.
+      // If there already is one then throw a CacheException
+
+      AdvancedCache advanced = cache.getAdvancedCache();
+
+      List<CommandInterceptor> interceptorList = advanced.getInterceptorChain();
+
+      for (CommandInterceptor inter : interceptorList) {
+
+         if (inter.getClass().equals(QueryInterceptor.class) || inter.getClass().equals(LocalQueryInterceptor.class)) {
+            throw new CacheException("There is already an instance of the QueryInterceptor running");
+         }
+
+      }
+   }
 }

Added: trunk/query/src/test/java/org/infinispan/query/backend/QueryHelperTest.java
===================================================================
--- trunk/query/src/test/java/org/infinispan/query/backend/QueryHelperTest.java	                        (rev 0)
+++ trunk/query/src/test/java/org/infinispan/query/backend/QueryHelperTest.java	2009-10-01 10:53:40 UTC (rev 895)
@@ -0,0 +1,58 @@
+package org.infinispan.query.backend;
+
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.query.test.Person;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test class for the {@link org.infinispan.query.backend.QueryHelper}
+ *
+ * @author Navin Surtani
+ * @since 4.0
+ */
+
+ at Test (groups = "functional")
+public class QueryHelperTest {
+
+   @BeforeMethod
+   public void setUp(){
+      System.setProperty("infinispan.query.enabled", "true");
+      System.setProperty("infinispan.query.indexLocalOnly", "true");
+   }
+
+   @Test (expectedExceptions = IllegalArgumentException.class)
+   public void testConstructorWithNoClasses(){
+      Cache c = new DefaultCacheManager().getCache();
+      Class[] classes = new Class[0];
+      QueryHelper qh = new QueryHelper(c, null, classes);
+   }
+
+   @Test (expectedExceptions = CacheException.class)
+   public void  testCheckInterceptorChainWithIndexLocalTrue(){
+      Cache c = new DefaultCacheManager().getCache();
+      QueryHelper qh = new QueryHelper(c, null, Person.class);
+      QueryHelper qh2 = new QueryHelper(c, null, Person.class);
+
+   }
+
+   @Test (expectedExceptions = CacheException.class)
+   public void  testCheckInterceptorChainWithIndexLocalFalse(){
+      System.setProperty("infinispan.query.indexLocalOnly", "false");
+
+      Cache c = new DefaultCacheManager().getCache();
+      QueryHelper qh = new QueryHelper(c, null, Person.class);
+      QueryHelper qh2 = new QueryHelper(c, null, Person.class);
+   }
+
+   public void testTwoQueryHelpersWithTwoCaches(){
+
+      Cache c1 = new DefaultCacheManager().getCache();
+      Cache c2 = new DefaultCacheManager().getCache();
+
+      QueryHelper qh1 = new QueryHelper(c1, null, Person.class);
+      QueryHelper qh2 = new QueryHelper(c2, null, Person.class);
+   }
+}



More information about the infinispan-commits mailing list