You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by bu...@apache.org on 2011/03/18 14:04:57 UTC

svn commit: r787174 - /websites/staging/chemistry/trunk/content/java/how-to/how-to-process-query.html

Author: buildbot
Date: Fri Mar 18 13:04:57 2011
New Revision: 787174

Log:
Staging update by buildbot

Modified:
    websites/staging/chemistry/trunk/content/java/how-to/how-to-process-query.html

Modified: websites/staging/chemistry/trunk/content/java/how-to/how-to-process-query.html
==============================================================================
--- websites/staging/chemistry/trunk/content/java/how-to/how-to-process-query.html (original)
+++ websites/staging/chemistry/trunk/content/java/how-to/how-to-process-query.html Fri Mar 18 13:04:57 2011
@@ -190,6 +190,7 @@ Apache Chemistry - Query Integration
 <li><a href="#use_built-in_antlr_and_antlr_cmisql_grammar">Use built-in ANTLR and ANTLR CMISQL grammar</a></li>
 <li><a href="#use_opencmis_cmsiql_grammar_and_integrate_into_antlr_query_walker">Use OpenCMIS CMSIQL grammar and integrate into ANTLR query walker</a></li>
 <li><a href="#use_predefined_query_walker">Use predefined query walker</a></li>
+<li><a href="#using_queryobject">Using QueryObject</a></li>
 </ul>
 </li>
 </ul>
@@ -260,7 +261,46 @@ cases you will derive your implementatio
 <code>AbstractQueryConditionProcessor</code> and not directly implement the interface.</p>
 <p>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
-as outlined in the previous section.</p></div>
+as outlined in the previous section.</p>
+<h2 id="using_queryobject">Using QueryObject</h2>
+<p>The class <code>QueryObject</code> provides all the basic functionality for resolving
+types and properties and performs common validation tasks. The <code>QueryObject</code>
+processes the <code>SELECT</code> and <code>FROM</code> parts as well as all property references from
+the <code>WHERE</code> part. It maintains a list of Java objects and 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
+<code>StoreManagerImpl</code> of the InMemory Server and method <code>query()</code>.
+To be able to use this object <code>QueryObj</code> needs to get access to the types contained in your
+repository. For this purpose you need to pass an interface to a <code>TypeManager</code>
+as input parameter. The second parameter is your query walker implementing
+<code>IQueryConditionProcessor</code>. Your code will typically look like this:</p>
+<div class="codehilite"><pre><span class="n">TypeManager</span> <span class="n">tm</span> <span class="o">=</span> <span class="k">new</span> <span class="n">MyTypeManager</span><span class="o">();</span> <span class="c1">// implements interface TypeManager</span>
+
+<span class="n">IQueryConditionProcessor</span> <span class="n">myWalker</span> <span class="o">=</span> <span class="k">new</span> <span class="n">MyWalker</span><span class="o">();</span>
+                         <span class="c1">// implements interface IQueryConditionProcessor</span>
+                         <span class="c1">// or extends AbstractQueryConditionProcessor</span>
+
+<span class="n">queryObj</span> <span class="o">=</span> <span class="k">new</span> <span class="n">QueryObject</span><span class="o">(</span><span class="n">tm</span><span class="o">,</span> <span class="n">myWalker</span><span class="o">);</span>
+</pre></div>
+
+
+<p><code>queryObj</code> then will process the statement and call the interface methods of
+your walker:</p>
+<div class="codehilite"><pre><span class="k">try</span> <span class="o">{</span>
+
+    <span class="n">CmisQueryWalker</span> <span class="n">walker</span> <span class="o">=</span> <span class="n">QueryObject</span><span class="o">.</span><span class="na">getWalker</span><span class="o">(</span><span class="n">statement</span><span class="o">);</span>
+    <span class="n">walker</span><span class="o">.</span><span class="na">query</span><span class="o">(</span><span class="n">queryObj</span><span class="o">);</span>
+
+<span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">RecognitionException</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+    <span class="k">throw</span> <span class="k">new</span> <span class="nf">RuntimeException</span><span class="o">(</span><span class="s">&quot;Walking of statement failed with RecognitionException error:\n &quot;</span> <span class="o">+</span> <span class="n">e</span><span class="o">);</span>
+<span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">Exception</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+    <span class="k">throw</span> <span class="k">new</span> <span class="nf">RuntimeException</span><span class="o">(</span><span class="s">&quot;Walking of statement failed with exception:\n &quot;</span> <span class="o">+</span> <span class="n">e</span><span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>After this method returns you may for example ask your walker object
+<code>myWalker</code> for the generated SQL string.</p></div>
              <!-- Content -->
            </td>
           </tr>