<?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.FindNodesCaseInsensitive">
  <title>Finding Nodes in a Case-Insensitive Way</title>

  <para>Find all nodes with a mixin type 'mix:title' and where the property
  'jcr:title' equals 'casesensitive' in lower or upper case.</para>

  <section id="JCR.FindNodesCaseInsensitive.RepositoryStructure">
    <title>Repository Structure</title>

    <para>The repository contains mix:title nodes, whose jcr:title properties
    have different values.</para>

    <itemizedlist>
      <listitem>
        <para>root</para>

        <itemizedlist>
          <listitem>
            <para>document1 (mix:title) jcr:title="CaseSensitive"</para>
          </listitem>

          <listitem>
            <para>document2 (mix:title) jcr:title="casesensitive"</para>
          </listitem>

          <listitem>
            <para>document3 (mix:title) jcr:title="caseSENSITIVE"</para>
          </listitem>
        </itemizedlist>
      </listitem>
    </itemizedlist>
  </section>

  <section id="JCR.FindNodesCaseInsensitive.QueryExecution">
    <title>Query Execution</title>

    <itemizedlist>
      <listitem>
        <para>UPPER case</para>
      </listitem>
    </itemizedlist>

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

    <programlisting language="java">// make SQL query
QueryManager queryManager = workspace.getQueryManager();
// create query
String sqlStatement = "SELECT * FROM mix:title WHERE UPPER(jcr:title) = 'CASESENSITIVE'";
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(*,mix:title)[fn:upper-case(@jcr:title)='CASESENSITIVE']";
Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
// execute query and fetch result
QueryResult result = query.execute();</programlisting>

    <itemizedlist>
      <listitem>
        <para>LOWER case</para>
      </listitem>
    </itemizedlist>

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

    <programlisting language="java">// make SQL query
QueryManager queryManager = workspace.getQueryManager();
// create query
String sqlStatement = "SELECT * FROM mix:title WHERE LOWER(jcr:title) = 'casesensitive'";
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(*,mix:title)[fn:lower-case(@jcr:title)='casesensitive']";
Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
// execute query and fetch result
QueryResult result = query.execute();</programlisting>
  </section>

  <section id="JCR.FindNodesCaseInsensitive.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>NodeIterator will return "document1", "document2" and "document3"
    (in all examples).</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:title</entry>

              <entry>...</entry>

              <entry>jcr:path</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry>CaseSensitive</entry>

              <entry>...</entry>

              <entry>/document1</entry>
            </row>

            <row>
              <entry>casesensitive</entry>

              <entry>...</entry>

              <entry>/document2</entry>
            </row>

            <row>
              <entry>caseSENSITIVE</entry>

              <entry>...</entry>

              <entry>/document3</entry>
            </row>
          </tbody>
        </tgroup>
      </table></para>
  </section>
</section>
