Executing Queries

CMIS 1.0 CMIS 1.1 Spec 2.1.14

OpenCMIS (Java)

ItemIterable<QueryResult> results = session.query("SELECT * FROM cmis:document", false);

for(QueryResult hit: results) {  
    for(PropertyData<?> property: hit.getProperties()) {

        String queryName = property.getQueryName();
        Object value = property.getFirstValue();

        System.out.println(queryName + ": " + value);
    }
    System.out.println("--------------------------------------");
}

PortCMIS (C#)

IItemEnumerable<IQueryResult> results = Session.Query("SELECT * FROM cmis:document", false);

foreach (IQueryResult hit in results) {
    foreach (PropertyData property in hit.Properties) {

        string queryName = property.QueryName;
        object value = property.FirstValue;

        Console.WriteLine(queryName + ": " + value);
    }
    Console.WriteLine("--------------------------------------");
}

Querying Objects

OpenCMIS (Java)

OperationContext oc = ...

// find all folders starting with 'a' or 'A'
ItemIterable<CmisObject> results =
    session.queryObjects("cmis:folder", "cmis:name LIKE 'a%' OR cmis:name LIKE 'A%'", false, oc);

for (CmisObject cmisObject : results) {
    Folder folder = (Folder) cmisObject; // it can only be a folder
    System.out.println(folder.getName());
}

Using a Query Statement

Query statements are very similar to prepared statements.

OpenCMIS (Java)

Calendar cal = ...
Folder folder = ...

QueryStatement qs = session.createQueryStatement("SELECT ?, ? FROM ? WHERE ? > TIMESTAMP ? AND IN_FOLDER(?) OR ? IN (?)");

qs.setProperty(1, "cmis:document", "cmis:name");
qs.setProperty(2, "cmis:document", "cmis:objectId");
qs.setType(3, "cmis:document");

qs.setProperty(4, "cmis:document", "cmis:creationDate");
qs.setDateTime(5, cal);

qs.setId(6, folder);

qs.setProperty(7, "cmis:document", "cmis:createdBy");
qs.setString(8, "bob", "tom", "lisa"); 

// get the compiled query statement
String statement = qs.toQueryString();

// ... or execute the query directly
ItemIterable<QueryResult> results = qs.query(false);

Query Performance

Many aspects influence the query performance. Most of them are related to the server implementation and the server setup. Here are some generic hints how clients can influence the query performance.