Multivalue Property Comparison

Multivalue Property Comparison

Find all nodes with the primary type 'nt:unstructured' whose property 'multiprop' contains both values "one" and "two".

Repository Structure

The repository contains nt:unstructured nodes with different 'multiprop' properties.

  • root
    • node1 (nt:unstructured) multiprop = ["one","two"]
    • node1 (nt:unstructured) multiprop = ["one","two","three"]
    • node1 (nt:unstructured) multiprop = ["one","five"]

Query Execution

SQL

// 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();

XPath

// 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();

Fetching the Result

Let's get nodes:

NodeIterator it = result.getNodes();

if(it.hasNext())
{
   Node findedNode = it.nextNode();
}

The NodeIterator will return "node1" and "node2".

We can also get a table:

String[] columnNames = result.getColumnNames();
RowIterator rit = result.getRows();
while (rit.hasNext())
{
   Row row = rit.nextRow();
   // get values of the row
   Value[] values = row.getValues();
}

Table content is:

jcr:primarytypejcr:pathjcr:score
nt:unstructured/node13806
nt:unstructured/node23806

Tags:
Created by Sergey Karpenko on 10/14/2009
Last modified by Sören Schmidt on 11/05/2009

Products

generated on Tue Sep 07 02:51:00 UTC 2010

eXo Optional Modules

eXo Core Foundations

Recently Modified


Copyright (c) 2000-2010. All Rights Reserved - eXo platform SAS
2.4.30451