[exo-jcr-commits] exo-jcr SVN: r2867 - jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Aug 3 10:40:38 EDT 2010


Author: sergiykarpenko
Date: 2010-08-03 10:40:37 -0400 (Tue, 03 Aug 2010)
New Revision: 2867

Added:
   jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/date-property-comparison.xml
   jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/multivalue-property-comparison.xml
   jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/node-name-constraint.xml
Modified:
   jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/jcr-query-usecases.xml
Log:
EXOJCR-869: jcr-query-usecases ported

Added: jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/date-property-comparison.xml
===================================================================
--- jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/date-property-comparison.xml	                        (rev 0)
+++ jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/date-property-comparison.xml	2010-08-03 14:40:37 UTC (rev 2867)
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<section id="JCR.DatePropertyComparison">
+  <title>Date Property Comparison</title>
+
+  <para>Find all nodes of primary type "nt:resource" whose jcr:lastModified
+  property value is greater than 2006-06-04 and less than 2008-06-04.</para>
+
+  <section>
+    <title>Repository Structure</title>
+
+    <para>Repository contains nt:resource nodes with different values of
+    jcr:lastModified property</para>
+
+    <itemizedlist>
+      <listitem>
+        <para>root</para>
+
+        <itemizedlist>
+          <listitem>
+            <para>document1 (nt:file)</para>
+
+            <itemizedlist>
+              <listitem>
+                <para>jcr:content (nt:resource)
+                jcr:lastModified="2006-01-19T15:34:15.917+02:00"</para>
+              </listitem>
+            </itemizedlist>
+          </listitem>
+
+          <listitem>
+            <para>document2 (nt:file)</para>
+
+            <itemizedlist>
+              <listitem>
+                <para>jcr:content (nt:resource)
+                jcr:lastModified="2005-01-19T15:34:15.917+02:00"</para>
+              </listitem>
+            </itemizedlist>
+          </listitem>
+
+          <listitem>
+            <para>document3 (nt:file)</para>
+
+            <itemizedlist>
+              <listitem>
+                <para>jcr:content (nt:resource)
+                jcr:lastModified="2007-01-19T15:34:15.917+02:00"</para>
+              </listitem>
+            </itemizedlist>
+          </listitem>
+        </itemizedlist>
+      </listitem>
+    </itemizedlist>
+  </section>
+
+  <section>
+    <title>Query Execution</title>
+
+    <para><emphasis role="bold">SQL</emphasis></para>
+
+    <para>In SQL you have to use the keyword <emphasis
+    role="bold">TIMESTAMP</emphasis> for date comparisons. Otherwise the date
+    would be interpreted as a string. The date has to be surrounded by single
+    quotes (TIMESTAMP 'datetime') and in the ISO standard format:
+    YYYY-MM-DDThh:mm:ss.sTZD ( <ulink
+    url="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</ulink>
+    and well explained in a W3C note <ulink
+    url="http://www.w3.org/TR/NOTE-datetime">http://www.w3.org/TR/NOTE-datetime</ulink>).</para>
+
+    <para>You see it can be a date only (YYYY-MM-DD) but also a complete date
+    and time with a timezone designator (TZD).</para>
+
+    <programlisting>// make SQL query
+QueryManager queryManager = workspace.getQueryManager();
+// create query
+StringBuffer sb = new StringBuffer();
+sb.append("select * from nt:resource where ");
+sb.append("( jcr:lastModified &gt;= TIMESTAMP '");
+sb.append("2006-06-04T15:34:15.917+02:00");
+sb.append("' )");
+sb.append(" and ");
+sb.append("( jcr:lastModified &lt;= TIMESTAMP '");
+sb.append("2008-06-04T15:34:15.917+02:00");
+sb.append("' )");
+String sqlStatement = sb.toString();
+Query query = queryManager.createQuery(sqlStatement, Query.SQL);
+// execute query and fetch result
+QueryResult result = query.execute();</programlisting>
+
+    <para><emphasis role="bold">XPath</emphasis></para>
+
+    <para>Compared to the SQL format you have to use the keyword <emphasis
+    role="bold">xs:dateTime</emphasis> and surround the datetime by extra
+    brackets: xs:dateTime('datetime'). The actual format of the datetime also
+    conforms with the ISO date standard.</para>
+
+    <programlisting>// make XPath query
+QueryManager queryManager = workspace.getQueryManager();
+// create query
+StringBuffer sb = new StringBuffer();
+sb.append("//element(*,nt:resource)");
+sb.append("[");
+sb.append("@jcr:lastModified &gt;= xs:dateTime('2006-08-19T10:11:38.281+02:00')");
+sb.append(" and ");
+sb.append("@jcr:lastModified &lt;= xs:dateTime('2008-06-04T15:34:15.917+02:00')");
+sb.append("]");
+String xpathStatement = sb.toString();
+Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
+// execute query and fetch result
+QueryResult result = query.execute();</programlisting>
+  </section>
+
+  <section>
+    <title>Fetching the result</title>
+
+    <para>Let's get nodes:</para>
+
+    <programlisting>NodeIterator it = result.getNodes();
+
+if(it.hasNext())
+{
+   Node foundNode = it.nextNode();
+}</programlisting>
+
+    <para>NodeIterator will return "/document3/jcr:content".</para>
+
+    <para>We can also get a table:</para>
+
+    <programlisting>String[] columnNames = result.getColumnNames();
+RowIterator rit = result.getRows();
+while (rit.hasNext())
+{
+   Row row = rit.nextRow();
+   // get values of the row
+   Value[] values = row.getValues();
+}</programlisting>
+
+    <para>The table content is: <table>
+        <title>Table content</title>
+
+        <tgroup cols="3">
+          <thead>
+            <row>
+              <entry>jcr:lastModified</entry>
+
+              <entry>...</entry>
+
+              <entry>jcr:path</entry>
+            </row>
+          </thead>
+
+          <tbody>
+            <row>
+              <entry>2007-01-19T15:34:15.917+02:00</entry>
+
+              <entry>...</entry>
+
+              <entry>/document3/jcr:content</entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </table></para>
+  </section>
+</section>

Modified: jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/jcr-query-usecases.xml
===================================================================
--- jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/jcr-query-usecases.xml	2010-08-03 14:35:40 UTC (rev 2866)
+++ jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/jcr-query-usecases.xml	2010-08-03 14:40:37 UTC (rev 2867)
@@ -161,18 +161,18 @@
         </listitem>
 
         <listitem>
-          <para><ulink url="JCR.Date Property Comparison">JCR.Date Property
-          Comparison</ulink></para>
+          <para><link linkend="JCR.DatePropertyComparison">Date Property
+          Comparison</link></para>
         </listitem>
 
         <listitem>
-          <para><ulink url="JCR.Node Name Constraint">JCR.Node Name
-          Constraint</ulink></para>
+          <para><link linkend="JCR.NodeNameConstraint">Node Name
+          Constraint</link></para>
         </listitem>
 
         <listitem>
-          <para><ulink url="JCR.Multivalue Property Comparison">JCR.Multivalue
-          Property Comparison</ulink></para>
+          <para><link linkend="JCR.MultivaluePropertyComparison">Multivalue
+          Property Comparison</link></para>
         </listitem>
       </itemizedlist>
     </section>

Added: jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/multivalue-property-comparison.xml
===================================================================
--- jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/multivalue-property-comparison.xml	                        (rev 0)
+++ jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/multivalue-property-comparison.xml	2010-08-03 14:40:37 UTC (rev 2867)
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<section id="JCR.MultivaluePropertyComparison">
+  <title>Multivalue Property Comparison</title>
+
+  <para>Find all nodes with the primary type 'nt:unstructured' whose property
+  'multiprop' contains both values "one" and "two".</para>
+
+  <section>
+    <title>Repository Structure</title>
+
+    <para>The repository contains nt:unstructured nodes with different
+    'multiprop' properties.</para>
+
+    <itemizedlist>
+      <listitem>
+        <para>root</para>
+
+        <itemizedlist>
+          <listitem>
+            <para>node1 (nt:unstructured) multiprop = [ "one","two" ]</para>
+          </listitem>
+
+          <listitem>
+            <para>node1 (nt:unstructured) multiprop = [ "one","two","three"
+            ]</para>
+          </listitem>
+
+          <listitem>
+            <para>node1 (nt:unstructured) multiprop = [ "one","five" ]</para>
+          </listitem>
+        </itemizedlist>
+      </listitem>
+    </itemizedlist>
+  </section>
+
+  <section>
+    <title>Query Execution</title>
+
+    <para><emphasis role="bold">SQL</emphasis></para>
+
+    <programlisting>// make SQL query
+QueryManager queryManager = workspace.getQueryManager();
+// create query
+String sqlStatement = "SELECT * FROM nt:unstructured WHERE multiprop = 'one' AND multiprop = 'two'";
+Query query = queryManager.createQuery(sqlStatement, Query.SQL);
+// execute query and fetch result
+QueryResult result = query.execute();</programlisting>
+
+    <para><emphasis role="bold">XPath</emphasis></para>
+
+    <programlisting>// make XPath query
+QueryManager queryManager = workspace.getQueryManager();
+// create query
+String xpathStatement = "//element(*,nt:unstructured)[@multiprop = 'one' and @multiprop = 'two']";
+Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
+// execute query and fetch result
+QueryResult result = query.execute();</programlisting>
+  </section>
+
+  <section>
+    <title>Fetching the Result</title>
+
+    <para>Let's get nodes:</para>
+
+    <programlisting>NodeIterator it = result.getNodes();
+
+if(it.hasNext())
+{
+   Node findedNode = it.nextNode();
+}</programlisting>
+
+    <para>The NodeIterator will return "node1" and "node2".</para>
+
+    <para>We can also get a table:</para>
+
+    <programlisting>String[] columnNames = result.getColumnNames();
+RowIterator rit = result.getRows();
+while (rit.hasNext())
+{
+   Row row = rit.nextRow();
+   // get values of the row
+   Value[] values = row.getValues();
+}</programlisting>
+
+    <para>Table content is: <table>
+        <title>Table content</title>
+
+        <tgroup cols="3">
+          <thead>
+            <row>
+              <entry>jcr:primarytyp</entry>
+
+              <entry>jcr:path</entry>
+
+              <entry>jcr:score</entry>
+            </row>
+          </thead>
+
+          <tbody>
+            <row>
+              <entry>nt:unstructured</entry>
+
+              <entry>/node1</entry>
+
+              <entry> 3806</entry>
+            </row>
+
+            <row>
+              <entry>nt:unstructured</entry>
+
+              <entry>/node2 </entry>
+
+              <entry> 3806</entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </table></para>
+  </section>
+</section>

Added: jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/node-name-constraint.xml
===================================================================
--- jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/node-name-constraint.xml	                        (rev 0)
+++ jcr/branches/1.12.x/docs/reference/en/src/main/docbook/en-US/modules/jcr/searching/node-name-constraint.xml	2010-08-03 14:40:37 UTC (rev 2867)
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<section id="JCR.NodeNameConstraint">
+  <title>Node Name Constraint</title>
+
+  <para>Find all nodes with primary type 'nt:file' whose node name is
+  'document'. The node name is accessible by a function called
+  "fn:name()".</para>
+
+  <note>
+    <para>fn:name() can be used ONLY with an equal('=') comparison.</para>
+  </note>
+
+  <section>
+    <title>Repository Structure</title>
+
+    <para>The repository contains nt:file nodes with different names.</para>
+
+    <itemizedlist>
+      <listitem>
+        <para>root</para>
+
+        <itemizedlist>
+          <listitem>
+            <para>document1 (nt:file)</para>
+          </listitem>
+
+          <listitem>
+            <para>file (nt:file)</para>
+          </listitem>
+
+          <listitem>
+            <para>somename (nt:file)</para>
+          </listitem>
+        </itemizedlist>
+      </listitem>
+    </itemizedlist>
+  </section>
+
+  <section>
+    <title>Query execution</title>
+
+    <para><emphasis role="bold">SQL</emphasis></para>
+
+    <programlisting>// make SQL query
+QueryManager queryManager = workspace.getQueryManager();
+// create query
+String sqlStatement = "SELECT * FROM nt:file WHERE fn:name() = 'document'";
+Query query = queryManager.createQuery(sqlStatement, Query.SQL);
+// execute query and fetch result
+QueryResult result = query.execute();</programlisting>
+
+    <para><emphasis role="bold">XPath</emphasis></para>
+
+    <programlisting>// make XPath query
+QueryManager queryManager = workspace.getQueryManager();
+// create query
+String xpathStatement = "//element(*,nt:file)[fn:name() = 'document']";
+Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
+// execute query and fetch result
+QueryResult result = query.execute();</programlisting>
+  </section>
+
+  <section>
+    <title>Fetching the Result</title>
+
+    <para>Let's get nodes:</para>
+
+    <programlisting>NodeIterator it = result.getNodes();
+
+if(it.hasNext())
+{
+   Node findedNode = it.nextNode();
+}</programlisting>
+
+    <para>The NodeIterator will return the node whose fn:name equals
+    "document".</para>
+
+    <para>Also we can get a table:</para>
+
+    <programlisting>String[] columnNames = result.getColumnNames();
+RowIterator rit = result.getRows();
+while (rit.hasNext())
+{
+   Row row = rit.nextRow();
+   // get values of the row
+   Value[] values = row.getValues();
+}</programlisting>
+
+    <para>Table content is: <table>
+        <title>Table content</title>
+
+        <tgroup cols="2">
+          <thead>
+            <row>
+              <entry>jcr:path</entry>
+
+              <entry>jcr:score</entry>
+            </row>
+          </thead>
+
+          <tbody>
+            <row>
+              <entry>/document1</entry>
+
+              <entry>3575</entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </table></para>
+  </section>
+</section>



More information about the exo-jcr-commits mailing list