How to Use RQL in JAVA,ATG
ATG Repository & Query Building
As a part of sticking on to a single programming language the Repository concept is used in ATG framework, in which there is a class called QUERYBUILDER. This helps the programmer in querying the database without using SQL statements, which means the programmer needs to know only java. For explaining this first of all i will explain the pre-requisites. Without understanding the pre-requisites there is no point going through the sample code.
PRE_REQUISITES
1. What is a “repository.xml” & Item-Descriptor?
The “repository.xml” is analogous to a database. This is actually an xml file, it has a tag called say “Item-Descriptor” with a property “name”, this is used to identify the item-descriptor. Inside the Item-Descriptor there are tags which represents actual table names and column names, these tags will be used whenever the columns are needed or these tags act as column aliases.
2. Relation between the JSP, and the Form handler.
Form handlers as the name indicates hold the functionalities of the form. It helps in handling the events in the form. Every operations related to form is done through the form handlers. Every code other than design is written in form handlers.
3. A table named “employeeTB” with fields as EName, age, EmployeeId(Primary Key).
How a query is created and executed?
Hopefully you read the pre-requisites. I will explain the whole thing taking “employee” table as reference. First thing we need to do is to make a repository xml file (“SampleRepository.xml”). The item-descriptor tag explains the table. Inside that there is table tag which describes the table, id-column-name specifies the primary key field. The property name=”eid” aliases the column in the table, which is specified as column-name=”employeeId”.
The form handler class below does the respective operations for any JSP that calls it. The getView() method will create a view for the item descriptor specified inside the quotes. The view is similar to a database view on which we can work on. Rql(Repository Query Language), helps you to write queries. (“eid = ?0″) :- Zero in this code implies there is just one parameter to be passed into the query. The parameter which is supplied is given in the Object array. statement.executeQuery (rview, params) :- will execute the query with the parameters specified in the object array (params) and taking repository specified in rview. “items” is a repository item array, which is separated using the repositoryItem (ritem) for using easily.
Now to get each columns of the table from the repository item, check out this piece of code. “ritem.getPropertyValue(“employeename”).toString() ;”
Where employeename is the corresponding property name in the repository.xml
For the custom repository to be used it needs to be registered with the atg. The next few lines explains how that is done.
How to register a repository with the dynamo??
Create “/config/atg/registry/ContentRepositories.properties” file and append our repository file (XML )name to the “initialRepositories” property
Eg: initialRepositories+= /ourModule/SampleRepository
import atg.repository.Repository;
import atg.repository.RepositoryItem;
import atg.repository.RepositoryView;
import atg.repository.rql.RqlStatement;
import atg.servlet.ServletUtil;
public class sampleFormHandler extends GenericFormHandler
{
private String eid;
public String getEid() {return eid;}
public void setEid(String eid) {this.eid = eid;}
public boolean sampleMethod(DynamoHttpServletRequest dRequest,DynamoHttpServletResponse dResponse) throws ServletException,IOException
{
Repository repository = (Repository)ServletUtil.getCurrentRequest().resolveName("/ourModule/SampleRepository.xml");
RepositoryView rview = repository.getView(“employeeItemDescriptor”);
RqlStatement statement = RqlStatement.parseRqlStatement("eid = ?0");
Object params[] = new Object[1];
params[0] = new String(getEid());
RepositoryItem[] items = statement.executeQuery (rview, params);
RepositoryItem ritem =items[0];
}// end of the method
}// end of the class.
Instead of specifying the repository name in the properties file we can specify the same in our Java(Our eg: doesn’t have a property file we have specified the repository name straight away in the Java class).
SampleRepository.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
<header>
<name> Three2tango </name>
<author>Three2tango</author>
<description>
This is a sample repository
</description>
</header>
<item-descriptor name="employeeItemDescriptor" id-space-name='employee ' display-name-resource="itemDescriptor employee">
<table name="employeeTB" type="primary" id-column-name="EmployeeId">
<property name="eid" column-name="EmployeeId" data-type="string" />
<property name="employeename" column-name="EName" data-type="string" />
<property name="employeeage" column-name="age" data-type="string" />
</table>
</item-descriptor>
</template>
Related posts:








very good but tell some more clarity
the thing is even i am new to this technology..not a big atg guy…
I am out of words to thank u really awesome .. good work keep going..
I don’t know atg.so tell somthing about atg
the data which you have given is very userfull for those who are new to atg frame work…..
Thank You Very much.
I tried the code, somehow I tried some cases with ‘space’ for the query and it does not work. Any idea for this?
will you be more specific on your doubt..??i might be of some help….
Cool site so far I have seen on ATG….Good docs and for a Rookie like me it is so useful and I get to lot of things..and much appreciated for the gud work..you do keep going
I used an RqlQuery just like above on orderRepository and I got the array of RepositoryItem in result.
Now I am not able to cast that to an Order object. Can you please advice?
Thanks
Hi,
I am new to ATG
Its really good site to have some key points on ATG.
If there are any good sites for ATG please let me know.
Thanks
Leave your response!
RelatedTopics
Recent Posts
Categories
Meta
Pages
Blogroll
Recent Comments
Most Commented
Popular Tags