Tuesday 1 March 2016

RQL in ATG (Repository Query Language)



ATG’s Repository Query Language, or RQL, is a generic language for formulating queries that map to any repository implementation, such as SQL or LDAP. The repository connectors translate those queries into a syntax that the underlying data store understands. 
Advantages of RQL over SQL
         Not specific to databases, can be used with any supported data source
         Understands relationships between repository items
         Higher level than SQL
         Designed to support more than just relational databases
         A generic language for formulating queries 
Repository Query Language
 We can use RQL in several different ways: 
1.      RQL servlet beans

2.      RQL filter

3.      Include RQL queries in <query-items> tags in the XML repository definition file        mainly used for unit testing queries

4.      Use RQL directly by creating an atg.repository.rql.RqlStatement object. Get an RqlQuery object from the RqlStatement object, and in turn get an atg.repository.Query object from the RqlQuery object. This approach can be simpler than using the QueryBuilder class to create the Query object.

All of the standard comparison operators can be used, as well as logical operators like AND, OR, and NOT

·         Collection Queries

Use the INCLUDES, INCLUDES ANY, or INCLUDES ALL operators only for querying multi-   valued properties

·         Includes Item Queries

repositories support properties that are arrays or collections of items belonging to another (or the same) item descriptor

·         Is Null Queries

Seeing whether an expression evaluates to null should be done with an IS NULL query. For example

·         Count Expressions

COUNT (addresses) > 3

·         Full Text Search Queries

firstName  MATCHES "abr “

·         ID-based Queries

ID IN { ["dept2", "emp345"], ["dept2", "emp346"], ["dept2", "emp347"] }

·         Order By Directives

age > 30 ORDER BY firstName SORT ASC CASE IGNORECASE

·         Range Directives

age > 30 RANGE 40+10

·         Parameterized Field Queries

name = ?0.name AND age = ?0.age 





RQL JAVA Examples 


RepositoryView view = repository.getView ("person");
RqlStatement statement = RqlStatement.parseRqlStatement ("age > ?0");
Object params[] = new Object[1];
params[0] = new Integer(23);
RepositoryItem [] items =statement.executeQuery (view, params);

Here is another example that demonstrates a text comparison query:

RqlStatement statement = RqlStatement.parseRqlStatement("lastName STARTS WITH ?0");
Object params[] ={new String ("m")};
items = statement.executeQuery (view, params);)


0 comments:

Post a Comment

 
;