A SERVICE OF

logo

86 Chapter 9. Persistence Tutorial
String firstName;
String lastName;
String groupName;
do{
select *
from users, groups, membership
where users.user_id = membership.member_id and membership.group_id \
= groups.group_id
} map {
firstName=users.first_name;
lastName=users.last_name;
groupName=groups.group_name;
}
}
You can order this query by the user’s last name, as follows:
DataQuery query = session.retrieveQuery("UsersGroups");
query.addOrder("lastName asc");
while (query.next()) {
System.out.println("First name = " + query.get("firstName") +
"; Last name = " + query.get("lastName") +
"; Group = " + query.get("groupName"));
}
Finally, you canbuild upthe ORDERBY string inthe sameway thatyou buildup afilter. For instance:
DataQuery query = session.retrieveQuery("UsersGroups");
query.addOrder("lastName asc")
if {careAboutGroupName} {
query.addOrder("groupName");
}
while (query.next()) {
System.out.println("First name = " + query.get("firstName") +
"; Last name = " + query.get("lastName") +
"; Group = " + query.get("groupName"));
}
The ORDER BY string is any valid ORDER BY clause, except that you specify property names, not
column names.
9.5.3. Binding Parameters
Use the setParameter(String parameterName, Object value) method to bind an arbitrary
variable within a DataQuery, DataOperation,DataAssociationCursor, orDataCollection.
The method getParameter(parameterName) allows you to retrieve the value of a set parameter.
The setParametertakes in a string that should match the string within the defined SQL.The Object
it takes should specify the value.
This functionality is useful for complicated queries that involve embedding parameters. For example,
see the following DataQuery defined in PDL (bind variables are in bold):
query CategoryFamily {
Integer level;
BigDecimal categoryID;
String name;
String description;
Boolean isEnabled;
do {
select l, c.category_id, c.name, c.description, c.enabled_p