public class NXQLQueryMaker extends Object implements QueryMaker
The examples below are using the NXQL statement syntax:
SELECT * FROM File WHERE dc:title = 'abc' AND uid:uid = '123' AND dc:contributors = 'bob' -- multi-valuedIf there are no proxies (ecm:isProxy = 0) we get:
SELECT hierarchy.id FROM hierarchy LEFT JOIN dublincore ON hierarchy.id = dublincore.id LEFT JOIN uid ON hierarchy.id = uid.id WHERE hierarchy.primarytype IN ('File', 'SubFile') AND dublincore.title = 'abc' AND uid.uid = '123' AND EXISTS (SELECT 1 FROM dc_contributors WHERE hierarchy.id = dc_contributors.id AND dc_contributors.item = 'bob') AND NX_ACCESS_ALLOWED(hierarchy.id, 'user1|user2', 'perm1|perm2')The data tables (dublincore, uid) are joined using a LEFT JOIN, as the schema may not be present on all documents but this shouldn't prevent the WHERE clause from being evaluated. Complex properties are matched using an EXISTS and a subselect. When proxies are matched (ecm:isProxy = 1) there are two additional FULL JOINs. Security checks, id, name, parents and path use the base hierarchy (_H), but all other data use the joined hierarchy.
SELECT _H.id FROM hierarchy _H JOIN proxies ON _H.id = proxies.id -- proxy full join JOIN hierarchy ON hierarchy.id = proxies.targetid -- proxy full join LEFT JOIN dublincore ON hierarchy.id = dublincore.id LEFT JOIN uid ON hierarchy.id = uid.id WHERE hierarchy.primarytype IN ('File', 'SubFile') AND dublincore.title = 'abc' AND uid.uid = '123' AND EXISTS (SELECT 1 FROM dc_contributors WHERE hierarchy.id = dc_contributors.id AND dc_contributors.item = 'bob') AND NX_ACCESS_ALLOWED(_H.id, 'user1|user2', 'perm1|perm2') -- uses _HWhen both normal documents and proxies are matched, we UNION ALL the two queries. If an ORDER BY is requested, then columns from the inner SELECTs have to be aliased so that an outer ORDER BY can user their names.
Modifier and Type | Class and Description |
---|---|
static class |
NXQLQueryMaker.DocKind |
QueryMaker.Query, QueryMaker.QueryCannotMatchException, QueryMaker.QueryMakerException
Modifier and Type | Field and Description |
---|---|
static String |
ECM_TAG_STAR |
static String |
RELATION_TABLE |
static String |
TYPE_DOCUMENT |
static String |
TYPE_RELATION |
static String |
TYPE_TAGGING |
Constructor and Description |
---|
NXQLQueryMaker() |
Modifier and Type | Method and Description |
---|---|
boolean |
accepts(String queryType)
Checks if this query maker accepts a given query.
|
QueryMaker.Query |
buildQuery(SQLInfo sqlInfo,
Model model,
Session.PathResolver pathResolver,
String query,
QueryFilter queryFilter,
Object... params)
Builds the query.
|
static String |
canonicalXPath(String xpath)
Canonicalizes a Nuxeo-xpath.
|
String |
getName()
Gets the name for this query maker.
|
boolean |
hasWildcardIndex(String xpath) |
static String |
simpleXPath(String xpath)
Turns the xpath into one where all indices have been replaced by *.
|
public static final String TYPE_DOCUMENT
public static final String TYPE_RELATION
public static final String TYPE_TAGGING
public static final String RELATION_TABLE
public static final String ECM_TAG_STAR
public String getName()
QueryMaker
getName
in interface QueryMaker
public boolean accepts(String queryType)
QueryMaker
Called first.
accepts
in interface QueryMaker
queryType
- the querytrue
if the query is acceptedpublic QueryMaker.Query buildQuery(SQLInfo sqlInfo, Model model, Session.PathResolver pathResolver, String query, QueryFilter queryFilter, Object... params) throws StorageException
QueryMaker
buildQuery
in interface QueryMaker
sqlInfo
- the sql infomodel
- the modelpathResolver
- the path resolverquery
- the queryqueryFilter
- the query filterparams
- additional parameters, maker-specificStorageException
public static String canonicalXPath(String xpath)
Replaces a/foo[123]/b
with a/123/b
A star or a star followed by digits can be used instead of just the digits as well.
xpath
- the xpathpublic static String simpleXPath(String xpath)
xpath
- the xpathpublic boolean hasWildcardIndex(String xpath)
Copyright © 2013 Nuxeo SA. All Rights Reserved.