3.1.4.1.2. Type constraints
Finding all nodes

Only those nodes are found to which the session has READ permission. See also Access Control.

Repository structure

Repository contains many different nodes.

  • root

    • folder1 (nt:folder)

      • document1 (nt:file)

      • folder2 (nt:folder)

        • document2 (nt:unstructured)

        • document3 (nt:folder)

Query execution

  • SQL

    // make SQL query
    
            QueryManager queryManager = workspace.getQueryManager();
            // create query
            String sqlStatement = "SELECT * FROM nt:base";
            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:base)";
    Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
    // execute query and fetch result
    QueryResult result = query.execute();

Fetching result

Let's get nodes:

NodeIterator it = result.getNodes();


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

NodeIterator will return "folder1", "folder2","document1","document2","document3", and another nodes in workspace if they are here.

You 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:pathjcr:score
/folder11000
/folder1/document11000
/folder1/folder21000
/folder1/folder2/document21000
/folder1/folder2/document31000
......

Finding all nodes by primary type

Find all nodes whose primary type is "nt:file".

Repository structure

The repository contains nodes with different primary types and mixin types.

  • root

    • document1 primarytype = "nt:unstructured" mixintype = "mix:title"

    • document2 primarytype = "nt:file" mixintype = "mix:lockable"

    • document3 primarytype = "nt:file" mixintype = "mix:title"

Query execution

  • SQL

    // make SQL query
    
    QueryManager queryManager = workspace.getQueryManager();
    // create query
    String sqlStatement = "SELECT * FROM nt:file";
    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:file)";
    Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
    // execute query and fetch result
    QueryResult result = query.execute();

Fetching result

Let's get nodes:

NodeIterator it = result.getNodes();


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

NodeIterator will return "document2" and "document3".

You 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();
}

The table content is:

jcr:pathjcr:score
/document22674
/document32674


Finding all nodes by mixin type

Find all nodes in repository that contains a "mix:title" mixin type.

Repository structure

The repository contains nodes with different primary types and mixin types.

  • root

    • document1 primarytype = "nt:unstructured" mixintype = "mix:title"

    • document2 primarytype = "nt:file" mixintype = "mix:lockable"

    • document3 primarytype = "nt:file" mixintype = "mix:title"

Query execution

  • SQL

    // make SQL query
    
    QueryManager queryManager = workspace.getQueryManager();
    // create query
    String sqlStatement = "SELECT * FROM mix:title";
    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(*,mix:title)";
    Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
    // execute query and fetch result
    QueryResult result = query.execute();

Fetching result

Let's get nodes:

NodeIterator it = result.getNodes();


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

The NodeIterator will return "document1" and "document3".

You 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:title...jcr:pathjcr:score
First document.../document12674
Second document.../document32674


Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus