Select all nodes with the 'nt:unstructured
' primary type and returns only
3 nodes starting with the second node in the list.
Common info: The QueryImpl
class has two methods: one to indicate how many results
shall be returned at most, and another to fix the starting position.
setOffset(long offset)
: Set the start offset of the result
set.
setLimit(long position)
: Set the maximum size of the result
set.
Repository structure: Repository contains mix:title nodes where jcr:title
has different
values.
root
node1 (nt:unstructured)
node2 (nt:unstructured)
node3 (nt:unstructured)
node4 (nt:unstructured)
node5 (nt:unstructured)
node6 (nt:unstructured)
SQL
// make SQL query
QueryManager queryManager = workspace.getQueryManager();
// create query
String sqlStatement = "SELECT * FROM nt:unstructured";
QueryImpl query = (QueryImpl)queryManager.createQuery(sqlStatement, Query.SQL);
//return starting with second result
query.setOffset(1);
// return 3 results
query.setLimit(3);
// execute query and fetch result
QueryResult result = query.execute();
Let's get nodes:
NodeIterator it = result.getNodes();
if(it.hasNext())
{
Node findedNode = it.nextNode();
}
In usual case (without using the setOffset
and setLimit
methods), Node
iterator returns all nodes (node1...node6). But in this case, NodeIterator
will return "node2","node3" and "node4".
\[node1 node2 node3 node4 node5 node6\]