|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.modeshape.graph.query.parse.SqlQueryParser
org.modeshape.jcr.query.JcrSqlQueryParser
public class JcrSqlQueryParser

Parser for JCR-SQL queries that produces abstract query model (AQM) objects.
This section defines the complete grammar for the JCR-SQL dialect supported by this parser, as defined by the
JCR 1.0.1 specification. This parser actually extends the (extended) JCR-SQL2 parser,
and thus allows many of the JCR-SQL2 standard and extended features, although there are several key differences:
jcr:scoreas a pseudo-column.
jcr:pathas a pseudo-column.
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'
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 | ReferenceValue | 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 */
ReferenceValue ::= 'REFERENCE(' selectorName '.' propertyName ')' |
'REFERENCE(' selectorName ')' |
'REFERENCE()' |
/* If only one selector exists in this query, explicit specification of the selectorName
preceding the propertyName is optional. Also, the property name may be excluded
if the constraint should apply to any reference property. */
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 | |
|---|---|
protected static class |
JcrSqlQueryParser.JoinableSources
|
| Nested classes/interfaces inherited from class org.modeshape.graph.query.parse.SqlQueryParser |
|---|
SqlQueryParser.SqlTokenizer |
| Field Summary | |
|---|---|
static String |
LANGUAGE
|
| Constructor Summary | |
|---|---|
JcrSqlQueryParser()
|
|
| Method Summary | |
|---|---|
String |
getLanguage()
Get the name of the language that this parser is able to understand. |
protected SelectorName |
getSelectorNameFor(Source source)
|
protected Constraint |
parseConstraint(TokenStream tokens,
TypeSystem typeSystem,
Source source)
Parse a constraint clause. |
protected Source |
parseFrom(TokenStream tokens,
TypeSystem typeSystem)
|
protected Object |
parseLiteralValue(TokenStream tokens,
TypeSystem typeSystem)
|
protected String |
parseName(TokenStream tokens,
TypeSystem typeSystem)
Parsing behavior is overridden to that JCR-SQL style (unquoted prefixed) names are allowed. |
protected Constraint |
parsePropertyExistance(TokenStream tokens,
TypeSystem typeSystem,
Source source)
|
protected Query |
parseQuery(TokenStream tokens,
TypeSystem typeSystem)
|
protected String |
removeBracketsAndQuotes(String text)
Remove any leading and trailing single-quotes. |
protected Source |
rewrite(JcrSqlQueryParser.JoinableSources joinableSources)
|
protected Constraint |
rewriteConstraint(Constraint constraint)
|
protected boolean |
usesSelector(Join join,
SelectorName selector)
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String LANGUAGE
| Constructor Detail |
|---|
public JcrSqlQueryParser()
| Method Detail |
|---|
public String getLanguage()
getLanguage in interface QueryParsergetLanguage in class SqlQueryParserQueryParser.getLanguage()
protected Query parseQuery(TokenStream tokens,
TypeSystem typeSystem)
parseQuery in class SqlQueryParserSqlQueryParser.parseQuery(org.modeshape.common.text.TokenStream,
org.modeshape.graph.query.model.TypeSystem)
protected Source parseFrom(TokenStream tokens,
TypeSystem typeSystem)
parseFrom in class SqlQueryParserSqlQueryParser.parseFrom(org.modeshape.common.text.TokenStream,
org.modeshape.graph.query.model.TypeSystem)
protected Constraint parseConstraint(TokenStream tokens,
TypeSystem typeSystem,
Source source)
jcr:path" and "jcr:score" pseudo-columns. In these special cases, the
resulting comparison will have a NodePath or FullTextSearchScore dynamic operand.
parseConstraint in class SqlQueryParserSqlQueryParser.parseConstraint(org.modeshape.common.text.TokenStream,
org.modeshape.graph.query.model.TypeSystem, org.modeshape.graph.query.model.Source)
protected Constraint parsePropertyExistance(TokenStream tokens,
TypeSystem typeSystem,
Source source)
parsePropertyExistance in class SqlQueryParserprotected SelectorName getSelectorNameFor(Source source)
protected Constraint rewriteConstraint(Constraint constraint)
protected String parseName(TokenStream tokens,
TypeSystem typeSystem)
Parsing behavior is overridden to that JCR-SQL style (unquoted prefixed) names are allowed. This method parses the selector
name, which may be of the form "unprefixedName" (consisting of a single token) or "prefix:name"
(consisting of three tokens).
parseName in class SqlQueryParserSqlQueryParser.parseName(org.modeshape.common.text.TokenStream,
org.modeshape.graph.query.model.TypeSystem)
protected Object parseLiteralValue(TokenStream tokens,
TypeSystem typeSystem)
parseLiteralValue in class SqlQueryParserSqlQueryParser.parseLiteralValue(org.modeshape.common.text.TokenStream,
org.modeshape.graph.query.model.TypeSystem)protected String removeBracketsAndQuotes(String text)
removeBracketsAndQuotes in class SqlQueryParsertext - the input text; may not be null
text if there were no quotesprotected Source rewrite(JcrSqlQueryParser.JoinableSources joinableSources)
protected boolean usesSelector(Join join,
SelectorName selector)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||