chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1086702 - /chemistry/site/trunk/content/java/how-to/how-to-process-query.mdtext
Date Tue, 29 Mar 2011 19:50:03 GMT
Author: jens
Date: Tue Mar 29 19:50:03 2011
New Revision: 1086702

URL: http://svn.apache.org/viewvc?rev=1086702&view=rev
Log:
Update the query documentation (interfaces and implementation has changed).

Modified:
    chemistry/site/trunk/content/java/how-to/how-to-process-query.mdtext

Modified: chemistry/site/trunk/content/java/how-to/how-to-process-query.mdtext
URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/how-to/how-to-process-query.mdtext?rev=1086702&r1=1086701&r2=1086702&view=diff
==============================================================================
--- chemistry/site/trunk/content/java/how-to/how-to-process-query.mdtext (original)
+++ chemistry/site/trunk/content/java/how-to/how-to-process-query.mdtext Tue Mar 29 19:50:03
2011
@@ -19,7 +19,7 @@ There are four different levels how you 
 1. Implement query in the discovery service
 1. Use the built-in ANTLR and ANTLR CMISQL grammar
 1. Use OpenCMIS CMISQL grammar and integrate into ANTLR query walker
-1. Use predefined query walker and integrate into interface `IQueryConditionProcessor`.
+1. Use predefined query walker and integrate into interface `PredicateWalker`.
 
 ## Implement query in the discovery service
 
@@ -36,7 +36,7 @@ integrate query by using the ANTLR mecha
 abstract syntax tree. Please refer to the ANTLR documentation for further
 information. This is the right level to use if you need custom parser tree
 transformations or would like to extend the grammar with your own
-constructs. For demonstration purposes OpenCMIS provides a sample extended
+constructs. For demonstration purposes OpenCMIS provides an extended
 grammar as an example.
 
 ## Use OpenCMIS CMSIQL grammar and integrate into ANTLR query walker
@@ -52,32 +52,39 @@ these common tasks. You can make use of 
 aliases and walk the resulting abstract syntax tree (AST) to evaluate the
 query. You are free to walk the AST as many times as you need and in the
 order you prefer. The basic idea is that the SELECT and FROM parts are
-processed by OpenCMIS and you are responsible for the WHERE part.  The
-CMIS InMemory server provides an example for this level of integration: For
-each object contained in the repository the tree is traversed and checked
+processed by OpenCMIS and you are responsible for the WHERE part. The
+InMemory server provides an example for this level of integration: For
+each object contained in the repository the tree is traversed and it's checked
 if it matches the current query. You can take the InMemory code as an
-example if you decide to use this integration point.
+example if you decide to use this integration level.
 
 ## Use predefined query walker
 
 For some repositories a simple and one-pass query traversal is sufficient.
 This can be the case if for example your query needs to be translated to a
 SQL query statement. Because ANTLR has some complexity OpenCMIS provides a
-predefined walker that does a simple one pass depth-first traversal. If
+predefined walker that performs a simple one pass depth-first traversal. If
 this is sufficient this interface hides most of the complexity of ANTLR.
 All you have to do is to implement a Java interface
-(`IQueryConditionProcessor`). You can refer to the unit tests for example
-code. The class `TestQueryProcessor` nested in the unit test `ProcessQueryTest`
-provides an example of such a walker. Some utility methods like for example
-parsing literals like `"abc"`, `-123` to Java objects like `String` and `Integer`
-are common tasks. Therefore this is implemented in an abstract class
-`AbstractQueryConditionProcessor`. This declares all interface methods as
-abstract and provides default implementations for common tasks. In most
-cases you will derive your implementation from
-`AbstractQueryConditionProcessor` and not directly implement the interface.
+(`PredicateWalker`). You can refer to the InMemory server for example
+code (`InMemoryWhereClauseWalker`). 
 
-Note: There is currently no predefined walker for the JOIN statements. If
-you need to support JOINS you have to build your own walker for this part
+`AbstractPredicateWalker` implements interface `PredicateWalker` and 
+implements common functionality useful for traversing the tree. For example
+parsing literals like `"abc"`, `-123` to Java objects like `String` 
+and `Integer` is handled there.
+
+If the interface of the predefined walker `PredicateWalker` does not
+fit your needs you can define your own interface. The code generated
+by ANTLR does not make any assumptions how you design the walking of
+your tree. The only dependency is contained in the interface 
+`PredicateWalkerBase` consisting of a single method. If you start 
+defining your own walker you have to implement or extend `PredicateWalkerBase`.
+The unit tests contain an example for this. See class `QueryConditionProcessor`
+in the unit tests for the InMemory server.
+
+Note: There is currently no predefined walker for JOIN statements. If
+you need to support JOINs you have to build your own walker for this part
 as outlined in the previous section.
 
 ## Using QueryObject
@@ -85,38 +92,46 @@ as outlined in the previous section.
 The class `QueryObject` provides all the basic functionality for resolving
 types and properties and performs common validation tasks. The `QueryObject`
 processes the `SELECT` and `FROM` parts as well as all property references from
-the `WHERE` part. It maintains a list of Java objects and interface that you
+the `WHERE` part. It maintains a list of Java objects and an interface that you
 can use to access the property and type definitions given your current
 position in the statement. For an example refer to the class
 `StoreManagerImpl` of the InMemory Server and method `query()`.
 To be able to use this object `QueryObj` needs to get access to the types contained in your
 repository. For this purpose you need to pass an interface to a `TypeManager`
-as input parameter. The second parameter is your query walker implementing
-`IQueryConditionProcessor`. Your code will typically look like this:
+as input parameter. Your code will typically look like this:
 
     :::java
+	public class MyWalker extends AbstractPredicateWalker {
+                             // extends AbstractPredicateWalker
+                             // or implements interface PredicateWalker
+							 // or implements interface PredicateWalkerBase
+	  // . . .
+	}
+
     TypeManager tm = new MyTypeManager(); // implements interface TypeManager
-    
-    IQueryConditionProcessor myWalker = new MyWalker();
-                             // implements interface IQueryConditionProcessor
-                             // or extends AbstractQueryConditionProcessor
-    
-    queryObj = new QueryObject(tm, myWalker);
+    MyWalker myWalker = new MyWalker();    
+    queryObj = new QueryObject(tm);
+    QueryUtil queryUtil = new QueryUtil();
+
+    CmisQueryWalker queryProcessor = queryUtil.traverseStatementAndCatchExc(statement, queryObj,
myWalker);
 
 
-`queryObj` then will process the statement and call the interface methods of
-your walker:
+`queryUtil` then will process the statement and call the interface methods of
+your walker (Note: This code is in opencmis, you don't have to implement it
+yourself.):
 
     :::java
     try {
-    
-        CmisQueryWalker walker = QueryObject.getWalker(statement);
-        walker.query(queryObj);
-    
-    } catch (RecognitionException e) {
-        throw new RuntimeException("Walking of statement failed with RecognitionException
error:\n " + e);
-    } catch (Exception e) {
-        throw new RuntimeException("Walking of statement failed with exception:\n " + e);
+        walker = getWalker(statement);
+        walker.query(queryObj, pw);
+        return walker; 
+	} catch (RecognitionException e) {
+		String errorMsg = queryObj.getErrorMessage();
+		throw new CmisInvalidArgumentException("Walking of statement failed with RecognitionException
error: \n   " + errorMsg);
+	} catch (CmisBaseException e) {
+		throw e;
+	} catch (Exception e) {
+		throw new CmisInvalidArgumentException("Walking of statement failed with exception: \n
  " + e);
     }
 
 
@@ -133,20 +148,20 @@ example the statement
     `... WHERE x < 123`
 
 
-will result in calling the method `onLessThan()` in your walker callback
+will result in calling the method `walkLessThan()` in your walker callback
 implementation:
 
     :::java
-    public void onLessThan(Tree ltNode, Tree leftNode, Tree rightNode) {
+    public Boolean walkLessThan(Tree ltNode, Tree leftNode, Tree rightNode) {
     
-        Object rVal = onLiteral(rightChild);
+        Object rVal = walkLiteral(rightChild);
         ColumnReference colRef;
     
         CmisSelector sel = queryObj.getColumnReference(columnNode
 			     .getTokenStartIndex());
     
         if (null == sel)
-           throw new RuntimeException("Unknown property query name " +
+           throw new CmisInvalidArgumentException("Unknown property query name " +
 		          columnNode.getChild(0));
         else if (sel instanceof ColumnReference)
            colRef = (ColumnReference) sel;
@@ -161,7 +176,7 @@ implementation:
 
 
 The right child node is a literal and you will get an Integer object with
-value 123. The left node is a reference to property and
+value 123. The left node is a reference to a property and
 `getColumnReference()` will either give you a function (currently the only
 supported function is `SCORE()`) or a reference to a property in a type of
 your type system. The query object maintains several maps to resolve
@@ -182,3 +197,9 @@ the requested information:
 
 Key of the map is the query name and value is the alias if an alias was
 used in the statement or the query name otherwise.
+
+## Limitations
+
+Currently the query parser does not include the full text search part
+of the grammar. Support for JOIN is limited. This will be enhanced in a
+future version



Mime
View raw message