Indexing and Query

Using CMISQL from Java

Updated: October 2, 2017 Page Information Edit on GitHub

CMISQL is the CMIS Query Language. It's possible to make CMISQL queries from Java code inside a Nuxeo bundle, much in the same way that you may used to make NXQL queries.

You can find out more about the CMIS support in Nuxeo Platform on the CMIS Page. You can find more information on the CMISQL syntax in the CMIS specification.

Note that in Nuxeo CMISQL, JOINs are not enabled by default. They are only available if you set the nuxeo.conf property org.nuxeo.cmis.joins=true, and you are using the VCS storage backend. CMISQL JOINs are not supported with the DBS storage (MongoDB), because the underlying storage cannot do relational queries.

The following is a simple example of code making a query:

Constructing the CallContext

When constructing the CallContext, you should pass the ServletContextHttpServletRequest and HttpServletResponse if available from your context. These are important for rendition URLs for instance.

Making a CMISQL Query

import java.io.Serializable;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.IterableQueryResult;
import org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisServiceFactory;
import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoCmisService;

public class CMISQuery {

    /** Threshold over which temporary files are not kept in memory. */
    public static final int THRESHOLD = 1024 * 1024;

    public CallContext getCallContext(CoreSession session) {
        ServletContext servletContext = null; // pass this if available
        HttpServletRequest request = null; // pass this if available
        HttpServletResponse response = null; // pass this if available
        ThresholdOutputStreamFactory streamFactory = ThresholdOutputStreamFactory.newInstance(
                null, THRESHOLD, -1, false);
        CallContextImpl callContext = new CallContextImpl(
                CallContext.BINDING_LOCAL, CmisVersion.CMIS_1_1,
                session.getRepositoryName(), servletContext, request, response,
                new NuxeoCmisServiceFactory(), streamFactory);
        callContext.put(CallContext.USERNAME, session.getPrincipal().getName());
        return callContext;
    }

    public void query(CoreSession session) {
        NuxeoCmisService cmisService = new NuxeoCmisService(session);
        cmisService.setCallContext(getCallContext(session)); // pass also servlet info if available
        try {
            // example CMISQL query
            String query = "SELECT cmis:objectId, dc:title FROM cmis:document WHERE dc:title LIKE 'foo%'";
            boolean searchAllVersions = true;
            IterableQueryResult result = cmisService.queryAndFetch(query, searchAllVersions);
            try {
                for (Map<String, Serializable> row : result) {
                    // do something with the result
                    System.out.println(row.get("dc:title"));
                }
            } finally { // you MUST always close result in a finally block
                result.close();
            }
        } finally { // you MUST always close cmisService in a finally block
            cmisService.close();
        }
    }
}

 

 

 

17 days ago manonlumeau Fix capitalization
2 years ago Florent Guillaume 39 | etail
2 years ago Florent Guillaume 38
3 years ago Solen Guitter 37
3 years ago Solen Guitter 35
3 years ago Solen Guitter 36
3 years ago Florent Guillaume 34
3 years ago Florent Guillaume 33
3 years ago Florent Guillaume 32
3 years ago Florent Guillaume 31
3 years ago Florent Guillaume 30
3 years ago Florent Guillaume 29
3 years ago Florent Guillaume 28
3 years ago Florent Guillaume 27
3 years ago Florent Guillaume 26
3 years ago Solen Guitter 25 | Removed 5.4 reference
6 years ago Florent Guillaume 23 | Added CallContext stuff
6 years ago Florent Guillaume 24
6 years ago Florent Guillaume 22
6 years ago Florent Guillaume 21 | Updated to OpenCMIS APIs.
6 years ago Olivier Grisel 20 | fixed broken link
7 years ago Alain Escaffre 19 | adding link to CMIS specifications for having more information on CMISQL
7 years ago Stéfane Fermigier 18
7 years ago Stéfane Fermigier 17
7 years ago Stéfane Fermigier 16
7 years ago Stéfane Fermigier 15
7 years ago Stéfane Fermigier 14
7 years ago Stéfane Fermigier 13
7 years ago Stéfane Fermigier 12
7 years ago Stéfane Fermigier 11
7 years ago Stéfane Fermigier 10
7 years ago Stéfane Fermigier 9
7 years ago Stéfane Fermigier 8
7 years ago Stéfane Fermigier 7
7 years ago Stéfane Fermigier 6
7 years ago Stéfane Fermigier 5
7 years ago Stéfane Fermigier 4
7 years ago Stéfane Fermigier 3
7 years ago Stéfane Fermigier 2
7 years ago Stéfane Fermigier 1
History: Created by Stéfane Fermigier