Class NXQLQueryMaker
java.lang.Object
org.nuxeo.ecm.core.storage.sql.jdbc.NXQLQueryMaker
- All Implemented Interfaces:
QueryMaker
- Direct Known Subclasses:
TagQueryMaker
Transformer of NXQL queries into underlying SQL queries to the actual database.
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.
- Author:
- Florent Guillaume
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Info about a column and its property type.static enum
protected class
Collects various info about the query AST, and rewrites the toplevel ANDPredicate
s of the WHERE clause into a singleMultiExpression
for easier analysis.protected class
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
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected Database
protected Table
protected static final String
protected Dialect
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
protected int
protected static final Pattern
protected static final Pattern
protected Table
protected static final Pattern
protected static final Pattern
protected Model
protected static final Pattern
protected Session.PathResolver
protected Boolean
Whether the query must match only proxies (TRUE), no proxies (FALSE), or not specified (null).protected String
The reason why proxyClause was set to non-null.protected Table
protected static final String
protected static final String
The select columns which we don't want to be NULL.protected SQLInfo
protected static final String
protected static final String
protected static final String
static final String
static final String
protected static final String
protected List<Serializable>
protected static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if this query maker accepts a given query.protected void
addJoin
(int kind, String alias, Table table, String column, Table contextTable, String contextColumn, String name, int index, String primaryType) 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.protected static boolean
findFulltextIndexOrField
(Model model, String[] nameref) protected void
protected void
protected void
fixWhatColumns
(List<Column> whatColumns) protected Table
getFragmentTable
(int joinKind, Table contextTable, String contextKey, String fragmentName, String fragmentColumn, int index, boolean skipJoin, String primaryType) Adds a more general JOIN:protected Table
getFragmentTable
(Table contextHier, String fragmentName) Gets the table for the given fragmentName, and maybe adds a join if one is not already done.getName()
Gets the name for this query maker.protected String
getSelectColName
(Column col) protected String
getSelectColName
(Column col, String key) key used to extract array index if neededprotected static Serializable
getSerializableLiteral
(Literal literal) protected static List<Serializable>
getStringLiterals
(LiteralList list) boolean
hasFinalWildcardIndex
(String xpath) boolean
hasWildcardIndex
(String xpath) protected static String
protected NXQLQueryMaker.QueryAnalyzer
newQueryAnalyzer
(FacetFilter facetFilter) protected NXQLQueryMaker.WhereBuilder
newWhereBuilder
(boolean isProxies) static String
simpleXPath
(String xpath) Turns the xpath into one where all indices have been replaced by *.
-
Field Details
-
TYPE_DOCUMENT
- See Also:
-
TYPE_RELATION
- See Also:
-
ECM_SIMPLE_ACP_PRINCIPAL
- See Also:
-
ECM_SIMPLE_ACP_PERMISSION
- See Also:
-
ECM_SIMPLE_ACP_GRANT
- See Also:
-
ECM_SIMPLE_ACP_NAME
- See Also:
-
ECM_SIMPLE_ACP_POS
- See Also:
-
ECM_SIMPLE_ACP_CREATOR
- Since:
- 7.4
- See Also:
-
ECM_SIMPLE_ACP_BEGIN
- Since:
- 7.4
- See Also:
-
ECM_SIMPLE_ACP_END
- Since:
- 7.4
- See Also:
-
ECM_SIMPLE_ACP_STATUS
- Since:
- 7.4
- See Also:
-
ECM_TAG_STAR
- See Also:
-
FACETED_TAG
- Since:
- 9.3
- See Also:
-
FACETED_TAG_LABEL
- Since:
- 9.3
- See Also:
-
TABLE_HIER_ALIAS
- See Also:
-
TABLE_FRAG_ALIAS
- See Also:
-
SUBQUERY_ARRAY_ALIAS
- See Also:
-
COL_ALIAS_PREFIX
- See Also:
-
UNION_ALIAS
- See Also:
-
WITH_ALIAS_PREFIX
- See Also:
-
READ_ACL_ALIAS
- See Also:
-
READ_ACL_USER_MAP_ALIAS
- See Also:
-
DATE_CAST
- See Also:
-
COUNT_FUNCTION
- See Also:
-
AVG_FUNCTION
- See Also:
-
AGGREGATE_FUNCTIONS
-
sqlInfo
-
database
-
dialect
-
model
-
neverPerInstanceMixins
-
pathResolver
-
aliasesByName
-
aliases
-
selectCollectionNotNull
The select columns which we don't want to be NULL. -
proxyClause
Whether the query must match only proxies (TRUE), no proxies (FALSE), or not specified (null). -
proxyClauseReason
The reason why proxyClause was set to non-null. -
hierTable
-
dataHierTable
-
proxyTable
-
joins
-
whereClauses
-
whereParams
-
propertyFragmentTables
-
fragJoinCount
protected int fragJoinCount -
INDEX
-
HAS_WILDCARD_INDEX
-
HAS_FINAL_WILDCARD_INDEX
-
INDEX_SLASH
-
NON_CANON_INDEX
-
-
Constructor Details
-
NXQLQueryMaker
public NXQLQueryMaker()
-
-
Method Details
-
getName
Description copied from interface:QueryMaker
Gets the name for this query maker.- Specified by:
getName
in interfaceQueryMaker
-
accepts
Description copied from interface:QueryMaker
Checks if this query maker accepts a given query.Called first.
- Specified by:
accepts
in interfaceQueryMaker
- Parameters:
queryType
- the query- Returns:
true
if the query is accepted
-
buildQuery
public QueryMaker.Query buildQuery(SQLInfo sqlInfo, Model model, Session.PathResolver pathResolver, String query, QueryFilter queryFilter, Object... params) Description copied from interface:QueryMaker
Builds the query.- Specified by:
buildQuery
in interfaceQueryMaker
- Parameters:
sqlInfo
- the sql infomodel
- the modelpathResolver
- the path resolverquery
- the queryqueryFilter
- the query filterparams
- additional parameters, maker-specific
-
addJoin
-
getFragmentTable
Gets the table for the given fragmentName, and maybe adds a join if one is not already done.LEFT JOIN fragmentName _F123 ON contextHier.id = _F123.id
-
getFragmentTable
protected Table getFragmentTable(int joinKind, Table contextTable, String contextKey, String fragmentName, String fragmentColumn, int index, boolean skipJoin, String primaryType) Adds a more general JOIN:(LEFT) JOIN fragmentName _F123 ON contextTable.id = _F123.fragmentColumn
-
fixInitialJoins
protected void fixInitialJoins() -
getSelectColName
-
getSelectColName
key used to extract array index if needed -
fixWhatColumns
-
fixSelect
-
findFulltextIndexOrField
-
canonicalXPath
Canonicalizes a Nuxeo-xpath.Replaces
a/foo[123]/b
witha/123/b
A star or a star followed by digits can be used instead of just the digits as well.
- Parameters:
xpath
- the xpath- Returns:
- the canonicalized xpath.
-
simpleXPath
Turns the xpath into one where all indices have been replaced by *.- Parameters:
xpath
- the xpath- Returns:
- the simple xpath
-
hasWildcardIndex
-
hasFinalWildcardIndex
-
keyForPos
-
newQueryAnalyzer
-
getStringLiterals
-
getSerializableLiteral
-
getSerializableLiterals
-
newWhereBuilder
-