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 |
---|---|
protected static class |
NXQLQueryMaker.ColumnInfo
Info about a column and its property type.
|
static class |
NXQLQueryMaker.DocKind |
protected 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. |
protected class |
NXQLQueryMaker.WhereBuilder
Builds the database-level WHERE query from the AST.
|
QueryMaker.Query, QueryMaker.QueryCannotMatchException
Constructor and Description |
---|
NXQLQueryMaker() |
Modifier and Type | Method and Description |
---|---|
boolean |
accepts(String queryType)
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) |
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.
|
protected static boolean |
findFulltextIndexOrField(Model model,
String[] nameref) |
protected void |
fixInitialJoins() |
protected void |
fixSelect(Select select) |
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 contextKey,
String fragmentName,
int index,
boolean skipJoin)
Gets the table for the given fragmentName in the given contextKey, and maybe adds a join if one is not already
done.
|
String |
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 needed
|
protected static Serializable |
getSerializableLiteral(Literal literal) |
protected static List<Serializable> |
getSerializableLiterals(LiteralList list) |
protected static Set<String> |
getStringLiterals(LiteralList list) |
boolean |
hasFinalWildcardIndex(String xpath) |
boolean |
hasWildcardIndex(String xpath) |
protected static String |
keyForPos(String name) |
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 *.
|
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_SIMPLE_ACP_PRINCIPAL
public static final String ECM_SIMPLE_ACP_PERMISSION
public static final String ECM_SIMPLE_ACP_GRANT
public static final String ECM_SIMPLE_ACP_NAME
public static final String ECM_SIMPLE_ACP_POS
public static final String ECM_SIMPLE_ACP_CREATOR
public static final String ECM_SIMPLE_ACP_BEGIN
public static final String ECM_SIMPLE_ACP_END
public static final String ECM_SIMPLE_ACP_STATUS
public static final String ECM_TAG_STAR
protected static final String TABLE_HIER_ALIAS
protected static final String TABLE_FRAG_ALIAS
protected static final String SUBQUERY_ARRAY_ALIAS
protected static final String COL_ALIAS_PREFIX
protected static final String UNION_ALIAS
protected static final String WITH_ALIAS_PREFIX
protected static final String READ_ACL_ALIAS
protected static final String READ_ACL_USER_MAP_ALIAS
protected static final String DATE_CAST
protected static final String COUNT_FUNCTION
protected static final String AVG_FUNCTION
protected static final List<String> AGGREGATE_FUNCTIONS
protected Set<String> neverPerInstanceMixins
protected Session.PathResolver pathResolver
protected final Map<String,String> aliasesByName
protected Boolean proxyClause
protected String proxyClauseReason
protected Table dataHierTable
protected Table proxyTable
protected List<String> whereClauses
protected List<Serializable> whereParams
protected Map<String,Table> propertyFragmentTables
protected int fragJoinCount
protected static final Pattern HAS_WILDCARD_INDEX
protected static final Pattern HAS_FINAL_WILDCARD_INDEX
protected static final Pattern INDEX_SLASH
protected static final Pattern NON_CANON_INDEX
public NXQLQueryMaker()
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)
QueryMaker
buildQuery
in interface QueryMaker
sqlInfo
- the sql infomodel
- the modelpathResolver
- the path resolverquery
- the queryqueryFilter
- the query filterparams
- additional parameters, maker-specificprotected void addJoin(int kind, String alias, Table table, String column, Table contextTable, String contextColumn, String name, int index, String primaryType)
protected Table getFragmentTable(Table contextHier, String contextKey, String fragmentName, int index, boolean skipJoin)
LEFT JOIN fragmentName _F123 ON contextHier.id = _F123.id
protected Table getFragmentTable(int joinKind, Table contextTable, String contextKey, String fragmentName, String fragmentColumn, int index, boolean skipJoin, String primaryType)
(LEFT) JOIN fragmentName _F123 ON contextTable.id = _F123.fragmentColumn
protected void fixInitialJoins()
protected String getSelectColName(Column col)
protected String getSelectColName(Column col, String key)
protected void fixWhatColumns(List<Column> whatColumns)
protected static boolean findFulltextIndexOrField(Model model, String[] nameref)
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)
public boolean hasFinalWildcardIndex(String xpath)
protected NXQLQueryMaker.QueryAnalyzer newQueryAnalyzer(FacetFilter facetFilter)
protected static Set<String> getStringLiterals(LiteralList list)
protected static Serializable getSerializableLiteral(Literal literal)
protected static List<Serializable> getSerializableLiterals(LiteralList list)
protected NXQLQueryMaker.WhereBuilder newWhereBuilder(boolean isProxies)
Copyright © 2017 Nuxeo. All rights reserved.