<?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 id="JCR.MultivaluePropertyComparison.RepositoryStructure">
    <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 id="JCR.MultivaluePropertyComparison.QueryExecution">
    <title>Query Execution</title>

    <para><emphasis role="bold">SQL</emphasis></para>

    <programlisting language="java">// 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 language="java">// 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 id="JCR.MultivaluePropertyComparison.FetchingResult">
    <title>Fetching the Result</title>

    <para>Let's get nodes:</para>

    <programlisting language="java">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 language="java">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>
