geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject [2/2] incubator-geode git commit: GEODE-11: Removed ParseException from LuceneQueryFactory.create, added LuceneQueryException
Date Thu, 16 Jun 2016 23:14:15 GMT
GEODE-11: Removed ParseException from LuceneQueryFactory.create, added LuceneQueryException

Adding a new exception to wrap lucene exceptions called LuceneQueryException. Removed lucene
exceptions from the public API.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/786c862e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/786c862e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/786c862e

Branch: refs/heads/develop
Commit: 786c862e1c158859b90d52ee0d053507b65e8a01
Parents: 28d2ce0
Author: Aparna Dharmakkan <adharmakkan@pivotal.io>
Authored: Thu Jun 16 11:20:13 2016 -0700
Committer: nabarun <nnag@pivotal.io>
Committed: Thu Jun 16 16:14:35 2016 -0700

----------------------------------------------------------------------
 .../cache/lucene/LuceneQueryException.java      | 36 ++++++++++++++++++++
 .../cache/lucene/LuceneQueryFactory.java        |  4 +--
 .../cache/lucene/LuceneQueryProvider.java       |  5 +--
 .../lucene/internal/StringQueryProvider.java    |  8 +++--
 .../internal/distributed/LuceneFunction.java    |  3 +-
 .../lucene/LuceneQueriesIntegrationTest.java    |  4 +--
 .../internal/StringQueryProviderJUnitTest.java  | 13 +++----
 .../IndexRepositoryImplPerformanceTest.java     |  5 +--
 8 files changed, 59 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryException.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryException.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryException.java
new file mode 100644
index 0000000..683b799
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryException.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.gemstone.gemfire.cache.lucene;
+
+import com.gemstone.gemfire.GemFireCheckedException;
+
+/**
+ * Thrown when a lucene query fails.
+ */
+public class LuceneQueryException extends GemFireCheckedException {
+
+  public LuceneQueryException(final String message) {
+    super(message);
+  }
+
+  public LuceneQueryException(final String message, final Throwable cause) {
+    super(message, cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
index a7844a2..8e36bbb 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
@@ -80,10 +80,8 @@ public interface LuceneQueryFactory {
    * @param <K> the key type in the query results
    * @param <V> the value type in the query results
    * @return LuceneQuery object
-   * @throws ParseException
    */
-  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
String queryString, String defaultField)
-      throws ParseException;
+  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
String queryString, String defaultField);
 
   /**
    * Creates a wrapper object for Lucene's Query object. This {@link LuceneQuery} builder
method could be used in

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
index 92a3a1c..7f1c269 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
@@ -39,8 +39,9 @@ public interface LuceneQueryProvider extends Serializable {
   /**
    * @return A Lucene Query object which could be used for executing Lucene Search on indexed
data
    * @param index local lucene index the query is being constructed against.
-   * @throws QueryException if the provider fails to construct the query object
+   * @throws LuceneQueryException if the provider fails to construct the query object
    */
-  public Query getQuery(LuceneIndex index) throws QueryException;
+
+  public Query getQuery(LuceneIndex index) throws LuceneQueryException;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
index 3f121ec..c5d145e 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
@@ -29,7 +29,10 @@ import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser;
 import org.apache.lucene.search.Query;
 
 import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.GemFireCheckedException;
+import com.gemstone.gemfire.GemFireException;
 import com.gemstone.gemfire.cache.lucene.LuceneIndex;
+import com.gemstone.gemfire.cache.lucene.LuceneQueryException;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
 import com.gemstone.gemfire.cache.query.QueryException;
 import com.gemstone.gemfire.internal.DataSerializableFixedID;
@@ -64,10 +67,9 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
   }
 
   @Override
-  public synchronized Query getQuery(LuceneIndex index) throws QueryException {
+  public synchronized Query getQuery(LuceneIndex index) throws LuceneQueryException {
     if (luceneQuery == null) {
       String[] fields = index.getFieldNames();
-
       LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
       StandardQueryParser parser = new StandardQueryParser(indexImpl.getAnalyzer());
       try {
@@ -77,7 +79,7 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
         }
       } catch (QueryNodeException e) {
         logger.debug("Query node exception:" + query, e);
-        throw new QueryException(e);
+        throw new LuceneQueryException("Malformed lucene query: " + query, e);
       }
     }
     return luceneQuery;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
index 9567305..3c6c0d2 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
@@ -32,6 +32,7 @@ import com.gemstone.gemfire.cache.execute.FunctionContext;
 import com.gemstone.gemfire.cache.execute.FunctionException;
 import com.gemstone.gemfire.cache.execute.RegionFunctionContext;
 import com.gemstone.gemfire.cache.execute.ResultSender;
+import com.gemstone.gemfire.cache.lucene.LuceneQueryException;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
 import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
@@ -80,7 +81,7 @@ public class LuceneFunction extends FunctionAdapter implements InternalEntity
{
     Query query = null;
     try {
       query = queryProvider.getQuery(index);
-    } catch (QueryException e) {
+    } catch (LuceneQueryException e) {
       logger.warn("", e);
       throw new FunctionException(e);
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index 674bc9c..bfb8c88 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -208,7 +208,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
     //Create a query that throws an exception
     final LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory().create(INDEX_NAME,
REGION_NAME,
       (index) -> {
-        throw new QueryException("Bad query");
+        throw new LuceneQueryException("Bad query");
       });
 
 
@@ -217,7 +217,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
     try {
       query.search();
     } catch(FunctionException e) {
-      assertEquals(QueryException.class, e.getCause().getClass());
+      assertEquals(LuceneQueryException.class, e.getCause().getClass());
       throw e;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
index a08875a..332ce35 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
@@ -32,7 +32,8 @@ import org.junit.experimental.categories.Category;
 import org.mockito.Mockito;
 
 import com.gemstone.gemfire.CopyHelper;
-import com.gemstone.gemfire.cache.query.QueryException;
+
+import com.gemstone.gemfire.cache.lucene.LuceneQueryException;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
@@ -52,7 +53,7 @@ public class StringQueryProviderJUnitTest {
   }
 
   @Test
-  public void testQueryConstruction() throws QueryException {
+  public void testQueryConstruction() throws LuceneQueryException {
     StringQueryProvider provider = new StringQueryProvider("foo:bar", DEFAULT_FIELD);
     Query query = provider.getQuery(mockIndex);
     Assert.assertNotNull(query);
@@ -61,15 +62,15 @@ public class StringQueryProviderJUnitTest {
 
   @Test
   @Ignore("Custom analyzer not yet supported, this is a duplicate test right now")
-  public void usesCustomAnalyzer() throws QueryException {
+  public void usesCustomAnalyzer() throws LuceneQueryException {
     StringQueryProvider provider = new StringQueryProvider("findThis", DEFAULT_FIELD);
     Query query = provider.getQuery(mockIndex);
     Assert.assertNotNull(query);
     assertEquals("field-1:findthis field-2:findthis", query.toString());
   }
 
-  @Test(expected = QueryException.class)
-  public void errorsOnMalformedQueryString() throws QueryException {
+  @Test(expected = LuceneQueryException.class)
+  public void errorsOnMalformedQueryString() throws LuceneQueryException {
     StringQueryProvider provider = new StringQueryProvider("invalid:lucene:query:string",
DEFAULT_FIELD);
     provider.getQuery(mockIndex);
   }
@@ -83,7 +84,7 @@ public class StringQueryProviderJUnitTest {
   }
 
   @Test
-  public void defaultFieldParameterShouldBeUsedByQuery() throws QueryException {
+  public void defaultFieldParameterShouldBeUsedByQuery() throws LuceneQueryException {
     StringQueryProvider provider = new StringQueryProvider("findThis",  "field-2");
     Query query = provider.getQuery(mockIndex);
     Assert.assertNotNull(query);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/786c862e/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
index 5e1a104..61f0ec4 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
@@ -32,7 +32,6 @@ import com.gemstone.gemfire.cache.lucene.internal.filesystem.ChunkKey;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.File;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystemStats;
 import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
-import com.gemstone.gemfire.cache.query.QueryException;
 import com.gemstone.gemfire.test.junit.categories.PerformanceTest;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
@@ -50,6 +49,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
@@ -59,6 +59,7 @@ import java.util.concurrent.TimeUnit;
 
 import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
 
+
 /**
  * Microbenchmark of the IndexRepository to compare an
  * IndexRepository built on top of cache with a 
@@ -190,7 +191,7 @@ public class IndexRepositoryImplPerformanceTest {
         LuceneQuery<Object, Object> luceneQuery = service.createLuceneQueryFactory().create("index",
"/region", new LuceneQueryProvider() {
           
           @Override
-          public Query getQuery(LuceneIndex index) throws QueryException {
+          public Query getQuery(LuceneIndex index) throws LuceneQueryException {
             return query;
           }
         });


Mime
View raw message