|
Nuxeo Enterprise Platform 5.4 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.nuxeo.ecm.core.storage.sql.jdbc.NXQLQueryMaker
public class NXQLQueryMaker
Transformer of NXQL queries into underlying SQL queries to the actual database.
The examples below are based on the NXQL statement:
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.
Nested Class Summary | |
---|---|
class |
NXQLQueryMaker.QueryAnalyzer
Collects various info about the query AST, and rewrites the toplevel AND Predicate s of the WHERE clause into a single
MultiExpression for easier analysis. |
static class |
NXQLQueryMaker.WhereBuilder
Builds the database-level WHERE query from the AST. |
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.storage.sql.jdbc.QueryMaker |
---|
QueryMaker.Query, QueryMaker.QueryCannotMatchException, QueryMaker.QueryMakerException |
Field Summary | |
---|---|
static java.lang.String |
TYPE_DOCUMENT
|
static java.lang.String |
TYPE_RELATION
|
Constructor Summary | |
---|---|
NXQLQueryMaker()
|
Method Summary | |
---|---|
boolean |
accepts(java.lang.String queryString)
Checks if this query maker accepts a given query. |
QueryMaker.Query |
buildQuery(SQLInfo sqlInfo,
Model model,
Session.PathResolver pathResolver,
java.lang.String query,
QueryFilter queryFilter,
java.lang.Object... params)
Builds the query. |
java.lang.String |
getName()
Gets the name for this query maker. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String TYPE_DOCUMENT
public static final java.lang.String TYPE_RELATION
Constructor Detail |
---|
public NXQLQueryMaker()
Method Detail |
---|
public java.lang.String getName()
QueryMaker
getName
in interface QueryMaker
public boolean accepts(java.lang.String queryString)
QueryMaker
Called first.
accepts
in interface QueryMaker
queryString
- the query
true
if the query is acceptedpublic QueryMaker.Query buildQuery(SQLInfo sqlInfo, Model model, Session.PathResolver pathResolver, java.lang.String query, QueryFilter queryFilter, java.lang.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-specific
StorageException
|
Nuxeo Enterprise Platform 5.4 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |