|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.dna.graph.query.parse.SqlQueryParser
public class SqlQueryParser
A QueryParser
implementation that parses a subset of SQL select and set queries.
This grammar is equivalent to the SQL grammar as defined by the JCR 2.0 specification, with some useful additions:
... (UNION|INTERSECT|EXCEPT) [ALL] ...
" to combine and merge results from multiple queriesSELECT DISTINCT ...
" to remove duplicatesLIMIT count [OFFSET number]
" clauses to control the number of results returned as well as the number of rows
that should be skippedFULL OUTER JOIN
" and "CROSS JOIN
"DEPTH([<selectorName>])
" and "PATH([<selectorName>])
" that
enables placing constraints on the node depth and path, respectively, and which can be used in a manner similar to "
NAME([<selectorName>])
" and "LOCALNAME([<selectorName>])
. Note in each of these cases, the
selector name is optional if there is only one selector in the query. on the node depth<dynamicOperand> [NOT] IN (<staticOperand> {, <staticOperand>})
"<dynamicOperand> [NOT] BETWEEN <lowerBoundStaticOperand> [EXCLUSIVE] AND
<upperBoundStaticOperand> [EXCLUSIVE]
"
WHERE
criteria and ORDER BY
clauses: "WHERE <dynamicOperand> + <dynamicOperand> ...
" or "ORDER BY (<dynamicOperand> + <dynamicOperand>) [ASC]
".
Note that standard operator precedence is used, but grouping by (potentially nested) parentheses is also supported.
This section defines the complete grammar for the SQL dialect supported by this parser.
QueryCommand ::= Query | SetQuery SetQuery ::= Query ('UNION'|'INTERSECT'|'EXCEPT') [ALL] Query { ('UNION'|'INTERSECT'|'EXCEPT') [ALL] Query } Query ::= 'SELECT' ['DISINCT'] columns 'FROM' Source ['WHERE' Constraint] ['ORDER BY' orderings] [Limit]
Source ::= Selector | Join Selector ::= nodeTypeName ['AS' selectorName] nodeTypeName ::= Name
Join ::= left [JoinType] 'JOIN' right 'ON' JoinCondition // If JoinType is omitted INNER is assumed. left ::= Source right ::= Source JoinType ::= Inner | LeftOuter | RightOuter | FullOuter | Cross Inner ::= 'INNER' ['JOIN'] LeftOuter ::= 'LEFT JOIN' | 'OUTER JOIN' | 'LEFT OUTER JOIN' RightOuter ::= 'RIGHT OUTER' ['JOIN'] RightOuter ::= 'FULL OUTER' ['JOIN'] RightOuter ::= 'CROSS' ['JOIN'] JoinCondition ::= EquiJoinCondition | SameNodeJoinCondition | ChildNodeJoinCondition | DescendantNodeJoinCondition
EquiJoinCondition ::= selector1Name'.'property1Name '=' selector2Name'.'property2Name selector1Name ::= selectorName selector2Name ::= selectorName property1Name ::= propertyName property2Name ::= propertyName
SameNodeJoinCondition ::= 'ISSAMENODE(' selector1Name ',' selector2Name [',' selector2Path] ')' selector2Path ::= Path
ChildNodeJoinCondition ::= 'ISCHILDNODE(' childSelectorName ',' parentSelectorName ')' childSelectorName ::= selectorName parentSelectorName ::= selectorName
DescendantNodeJoinCondition ::= 'ISDESCENDANTNODE(' descendantSelectorName ',' ancestorSelectorName ')' descendantSelectorName ::= selectorName ancestorSelectorName ::= selectorName
Constraint ::= ConstraintItem | '(' ConstraintItem ')' ConstraintItem ::= And | Or | Not | Comparison | Between | PropertyExistence | SetConstraint | FullTextSearch | SameNode | ChildNode | DescendantNode
And ::= constraint1 'AND' constraint2 constraint1 ::= Constraint constraint2 ::= Constraint
Or ::= constraint1 'OR' constraint2
Not ::= 'NOT' Constraint
Comparison ::= DynamicOperand Operator StaticOperand Operator ::= '=' | '!=' | '<' | '<=' | '>' | '>=' | 'LIKE'
Between ::= DynamicOperand ['NOT'] 'BETWEEN' lowerBound ['EXCLUSIVE'] 'AND' upperBound ['EXCLUSIVE'] lowerBound ::= StaticOperand upperBound ::= StaticOperand
PropertyExistence ::= selectorName'.'propertyName 'IS' ['NOT'] 'NULL' | propertyName 'IS' ['NOT'] 'NULL' /* If only one selector exists in this query */
SetConstraint ::= selectorName'.'propertyName ['NOT'] 'IN' | propertyName ['NOT'] 'IN' /* If only one selector exists in this query */ '(' firstStaticOperand {',' additionalStaticOperand } ')' firstStaticOperand ::= StaticOperand additionalStaticOperand ::= StaticOperand
FullTextSearch ::= 'CONTAINS(' ([selectorName'.']propertyName | selectorName'.*')
',' ''' fullTextSearchExpression''' ')'
/* If only one selector exists in this query, explicit specification of the selectorName
preceding the propertyName is optional */
fullTextSearchExpression ::= /* a full-text search expression, see FullTextSearchParser
*/
SameNode ::= 'ISSAMENODE(' [selectorName ','] Path ')' /* If only one selector exists in this query, explicit specification of the selectorName preceding the propertyName is optional */
ChildNode ::= 'ISCHILDNODE(' [selectorName ','] Path ')' /* If only one selector exists in this query, explicit specification of the selectorName preceding the propertyName is optional */
DescendantNode ::= 'ISDESCENDANTNODE(' [selectorName ','] Path ')' /* If only one selector exists in this query, explicit specification of the selectorName preceding the propertyName is optional */
Name ::= '[' quotedName ']' | '[' simpleName ']' | simpleName quotedName ::= /* A JCR Name (see the JCR specification) */ simpleName ::= /* A JCR Name that contains only SQL-legal characters (namely letters, digits, and underscore) */ Path ::= '[' quotedPath ']' | '[' simplePath ']' | simplePath quotedPath ::= /* A JCR Path that contains non-SQL-legal characters */ simplePath ::= /* A JCR Path (rather Name) that contains only SQL-legal characters (namely letters, digits, and underscore) */
StaticOperand ::= Literal | BindVariableValue
Literal ::= CastLiteral | UncastLiteral CastLiteral ::= 'CAST(' UncastLiteral ' AS ' PropertyType ')' PropertyType ::= 'STRING' | 'BINARY' | 'DATE' | 'LONG' | 'DOUBLE' | 'DECIMAL' | 'BOOLEAN' | 'NAME' | 'PATH' | 'REFERENCE' | 'WEAKREFERENCE' | 'URI' /* 'WEAKREFERENCE' is not currently supported in JCR 1.0 */ UncastLiteral ::= UnquotedLiteral | ''' UnquotedLiteral ''' | '"' UnquotedLiteral '"' UnquotedLiteral ::= /* String form of a JCR Value, as defined in the JCR specification */
BindVariableValue ::= '$'bindVariableName bindVariableName ::= /* A string that conforms to the JCR Name syntax, though the prefix does not need to be a registered namespace prefix. */
DynamicOperand ::= PropertyValue | Length | NodeName | NodeLocalName | NodePath | NodeDepth | FullTextSearchScore | LowerCase | UpperCase | Arithmetic | '(' DynamicOperand ')'
PropertyValue ::= [selectorName'.'] propertyName /* If only one selector exists in this query, explicit specification of the selectorName preceding the propertyName is optional */
Length ::= 'LENGTH(' PropertyValue ')'
NodeName ::= 'NAME(' [selectorName] ')' /* If only one selector exists in this query, explicit specification of the selectorName is optional */
NodeLocalName ::= 'LOCALNAME(' [selectorName] ')' /* If only one selector exists in this query, explicit specification of the selectorName is optional */
NodePath ::= 'PATH(' [selectorName] ')' /* If only one selector exists in this query, explicit specification of the selectorName is optional */
NodeDepth ::= 'DEPTH(' [selectorName] ')' /* If only one selector exists in this query, explicit specification of the selectorName is optional */
FullTextSearchScore ::= 'SCORE(' [selectorName] ')' /* If only one selector exists in this query, explicit specification of the selectorName is optional */
LowerCase ::= 'LOWER(' DynamicOperand ')'
UpperCase ::= 'UPPER(' DynamicOperand ')'
Arithmetic ::= DynamicOperand ('+'|'-'|'*'|'/') DynamicOperand
orderings ::= Ordering {',' Ordering} Ordering ::= DynamicOperand [Order] Order ::= 'ASC' | 'DESC'
columns ::= (Column ',' {Column}) | '*' Column ::= ([selectorName'.']propertyName ['AS' columnName]) | (selectorName'.*') /* If only one selector exists in this query, explicit specification of the selectorName preceding the propertyName is optional */ selectorName ::= Name propertyName ::= Name columnName ::= Name
Limit ::= 'LIMIT' count [ 'OFFSET' offset ] count ::= /* Positive integer value */ offset ::= /* Non-negative integer value */
Nested Class Summary | |
---|---|
static class |
SqlQueryParser.SqlTokenizer
A TokenStream.Tokenizer implementation that parses words, quoted phrases, comments, and symbols. |
Field Summary | |
---|---|
static String |
LANGUAGE
|
Constructor Summary | |
---|---|
SqlQueryParser()
|
Method Summary | |
---|---|
boolean |
equals(Object obj)
|
String |
getLanguage()
Get the name of the language that this parser is able to understand. |
QueryCommand |
parseQuery(String query,
TypeSystem typeSystem)
Parse the supplied query from a string representation into a QueryCommand . |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String LANGUAGE
Constructor Detail |
---|
public SqlQueryParser()
Method Detail |
---|
public String getLanguage()
getLanguage
in interface QueryParser
QueryParser.getLanguage()
public String toString()
toString
in class Object
Object.toString()
public boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public QueryCommand parseQuery(String query, TypeSystem typeSystem)
QueryCommand
.
parseQuery
in interface QueryParser
query
- the query in string form; may not be nulltypeSystem
- the type system used by the query; may not be null
QueryParser.parseQuery(String, TypeSystem)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |