Resolved recently

Create new archetype query language (AQL)

Description

Currently, there exists 2 ways to query archetypes:
1. Named queries
These use HQL, and can only be defined within a .hbm.xml file, and configured via applicationContext.xml

2. ArchetypeQuery
This use a series of IConstraint implementations to construct the query, and is complex to use.

A new type of query language is required that:
1. simplifies querying archetypes
2. can be linked into 3rd party reporting tools such as jasper reports

The query language should be similar to HQL, but support joins on nodes rather than class fields
E.,g:
1. Select a customer by UID
select from party.customer*
where uid = ?

2. select a customer by object reference
select from party.customer*
where linkId=?

3. select a customer person by wildcarded name, sorting on name and uid
select from party.customerperson
where name like ?
order by name asc, uid

4.select all customers with email contacts
select from party.customer* p, p.contacts
where p.contact = contact.email

5. select all customer names and their corresponding pets
select customer.name, patient.name
from entityRelationship.patientOwner owner, party.customer* customer, party.patientpet pet
where owner.source = customer and owner.target = pet
order by customer.name, pet,name

Proposed grammar (preliminary - doesn't support functions like max, min, avg etc):

statement
: selectStatement

selectStatement
: selectFrom (whereClause)? (groupByClause)? (orderByClause)?

selectFrom
: selectClause fromClause

selectClause
: "SELECT" ("DISTINCT")? ( selectedPropertiesList | selectObject )

fromClause
: "FROM" fromRange ( fromJoin | "," fromRange )*

fromRange
: path asAlias?

fromJoin
: ( ( ( "LEFT" | "RIGHT" ) ("OUTER")? ) | "INNER" )? "JOIN"
path (asAlias)? (withClause)?

withClause
: "WITH" logicalExpression

selectedPropertiesList
: aliasedExpression ( "," aliasedExpression )*

aliasedExpression
: expression ( "AS" identifier )?

path
: identifier ( "." identifier )*

asAlias
: "AS" identifier

groupByClause
: "GROUP BY" expression( "," expression )* (havingClause)?

orderByClause
: "ORDER BY" orderElement ( "," orderElement )*

orderElement
: expression ( "ASC" | "DESC")?

havingClause
: "HAVING" logicalExpression

whereClause
: "WHERE" logicalExpression

logicalExpression
: expression

expression
: logicalOrExpression

logicalOrExpression
: logicalAndExpression ( "OR" logicalAndExpression )*

logicalAndExpression
: negatedExpression ( "AND" negatedExpression )*

negatedExpression!
: "NOT" negatedExpression | equalityExpression

equalityExpression
: relationalExpression (
( "="

"IS" "NOT"?

"<>"
) relationalExpression

relationalExpression
: additiveExpression (
( ( ( "<" | ">" | "<=" | ">=" ) additiveExpression )* )

"NOT"? (
("IN" inList)

("BETWEEN" betweenList)

("LIKE" "ESCAPE"? additiveExpression)
)

)

inList
: "(" expression ("," expression)* ")"

betweenList
: additiveExpression "AND" additiveExpression

additiveExpression
: multiplyExpression ( ( "+" | "-" ) multiplyExpression )*

multiplyExpression
: unaryExpression ( ( "" | "/" ) unaryExpression )

unaryExpression
: "-" unaryExpression

"+" unaryExpression

atom

atom
: primaryExpression ("." identifier)?

primaryExpression
: identPrimary

constant

":" (identifier

paramId)

"(" (expression

subQuery) ")"

identifier
: letter (letter | '0'..'9' | '*') +

letter
: 'A..Z' | a..z

Environment

None

Status

Assignee

Tim Anderson

Reporter

Tim Anderson

Labels

None

Affects versions

Priority

Major
Configure