User's Manual

80 Chapter 9. Persistence Tutorial
9.5.1. Filtering
9.5.1.1. Overview
The filtering system is complex, in that it allows developers to create complex expressions by com-
bining filters, yet simple in that it provides convenience methods for developers with simple needs.
It is important to realize that by default, Filters simply filter the resulting data from the query. For
instance, if you have the following:
query myDataQuery {
BigDecimal articleID;
do {
select max(article_id) from articles
} map {
articleID = articles.article_id;
}
}
and then add the filter "lower(title) like ’b%’", the new query will be:
select *
from (select max(article_id) from articles) results
where lower(title) like ’b%’
and not:
select max(article_id) from articles where lower(title) like ’b%’
This can clearly lead to different results.
9.5.1.2. Simple Filters
For simple filters, you should use the addEqualsFilter(String attributeName, Object
value) or the addNotEqualsFilter(String attributeName, Object value) methods to
filter a DataQuery, DataOperation, DataCollection, or a DataAssociationCursor object.
These methods take the name of the attribute and its value, create the correct SQL fragment, and bind
the variable. If the system is using Oracle or Postgres and the value is null, the system will create the
correct is null or is not null syntax.
In order to specify the filter, you must use the name of the Java Attribute, not the name of the database
column. The persistence layer automatically converts the property names to column names using the
property mappings defined in the PDL. This layer of abstraction is one of the features that allows de-
velopers to change column names without having to update Java code. For example, see the following
DataQuery defined in PDL (remove the "\" and make it all one line):
query UsersGroups {
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;