CentraSite 10.3 | CentraSite Developer's Guide | Application Framework | Querying the Registry | Application Framework Simple Search | Restricting the Search Results by Adding Search Predicates
 
Restricting the Search Results by Adding Search Predicates
The predicate is an object representation of a query criterion used to restrict the search results. Predicates can be created from a factory-like class called Predicates (com.softwareag.centrasite.appl.framework.persistence.search.Predicates).
It provides two static methods for creating each specific predicate:
*Without specifying Bean Type:
Predicates.eq(String propertyName, Object value)
*By specifying a Bean Type:
Predicates.eq(String propertyName, Object value,
Class<? extends RegistryBean> beanType)
where
method name
The comparison operator:
and
logical conjunction
eq
equal
ge
greater than or equal to
gt
greater than
le
less than or equal to
like
matches a string that can include wildcards
lt
less than
ne
not equal
or
logical disjunction
property name
The name of the property to be compared. This property name is a string value representing the name of the Java property (getName() corresponds to “name”). The search functionality supports adding a sequence of properties. This is accomplished by knowing the searched RegistryBean property hierarchy and by separating following properties with a dot ..
Example:
Predicates.eq( "externalLink.uri ", value)
The predicate is created for the URI property of the externalLinks of the searched RegistryBean, which should be equal to the given value.
value
The value to compare against. Most methods expect an Object value because the search can handle a variety of objects including String, Number, Date, Calendar, Key, RegistryBean, and others. There are also methods that expect a specific value type. An example is like (String propertyName, String value), which supports wildcards and therefore the expected value type is String. Other object types that are worth mentioning are the so-called support types (TelephoneNumbers, InternationalString, LocalizedString, EmailAddress, PostalAddress). They can be used for search criteria but not as a searched object because they are not registry beans. For example, the following search is valid:
Search search = beanPool.createSearch(User.class);
Predicates.eq("telephoneNumbers.countryCode",
"someCountryCode");
But the following search is not valid:
Search search = beanPool.createSearch(EmailAddress.class);
beanType
The bean type for which the predicate is applied.
Important:
If no beanType is specified then the predicate is applied to the first bean type in the Search object's list of bean types. Note that the first item of that list must support the property passed to the predicate, otherwise the search fails. In cases where the search object is created for all supported bean types, the list is filled randomly so the user must be aware of all common properties supported by these RegistryBean types.
Each predicate can be added to the search object by invoking the search method:
addPredicate(Predicate predicate);
A search object can add multiple predicates, which can be treated as predicates joined by an and operator. For example:
Search search = beanPool.createSearch();
search.addPredicate(predicate1);
search.addPredicate(predicate2);
search.addPredicate(predicate3);
is equal to predicate1 and predicate2 and predicate3 in the query to be executed.
There are two more methods in the Predicates class: and(Predicate p1, Predicate p2) and or(Predicate p1, Predicate p2). These methods create a so-called combine predicate. They join two predicates by logical conjunction or logical disjunction respectively. This predicate can be added to the search object in the same way as the common predicates explained above.
Supported predicates description
All supported predicates are created from methods in the Predicates class (com.softwareag.centrasite.appl.framework.persistence.search.Predicates).
Like Predicate
A predicate that supports usage of wildcards. The value field of the creating methods:
like(String propertyName, String value)
like(String propertyName, String value, Class<? extends
RegistryBean> beanType)
is of Type String, so the user may add strings (possibly including wildcards).
Example:
like("name","%partOfExpectedName");
Wildcards
The like predicate supports wildcards in the manner of SQL and UDDI. The wildcard characters are as follows:
Wildcard character
Indicates
%
Any value for any number of characters
_
Any value for a single character
The following special cases are supported:
To represent...
use the character string...
%
\%
_
\_
\
\\
Greater Than Predicate
A predicate that compares Number, Date, or Calendar, returning true if the compared object value is greater than the value given in the predicate's creating method “value” field:
gt(String propertyName, Object value)
gt(String propertyName, Object value, Class<? extends
RegistryBean> beanType)
The value must be one of the following types: Number, Date, Calendar.
Example:
Calendar calendar = Calendar.getInstance();
Predicate predicate = Predicates.gt("requestDate",calendar);
Less Than Predicate
A predicate that compares Number, Date, or Calendar, returning true if the compared object value is less than the value given in the predicate's creating method “value” field:
lt(String propertyName, Object value)
lt(String propertyName, Object value, Class<? extends
RegistryBean> beanType)
The value must be one of the following types: Number, Date, Calendar.
Example:
Predicate predicate = Predicates.lt("copyNumber",203);
Greater or Equal Predicate
A predicate that compares Number, Date or Calendar, returning true if the compared object value is greater than or equal to the value given in the predicate's creating method “value” field:
ge(String propertyName, Object value)
ge(String propertyName, Object value, Class<? extends
RegistryBean> beanType)
The value must be one of the following types: Number, Date, Calendar.
Example:
Predicate predicate = Predicates.ge("copyNumber",203);
Less or Equal Predicate
A predicate that compares Number, Date or Calendar, returning true if the compared object value is less than or equal to the value given in the predicate's creating method “value” field:
le(String propertyName, Object value)
le(String propertyName, Object value, Class<? extends
RegistryBean> beanType)
The value must be one of the following types: Number, Date, Calendar.
Example:
Predicate predicate = Predicates.le("copyNumber",203);
Equal Predicate
A predicate that returns true if the compared object value is equal to the value given in the predicate's creating method “value” field:
eq(String propertyName, Object value)
eq (String propertyName, Object value, Class<? extends
RegistryBean> beanType)
The value must be one of the following types: Number, Date, Calendar, String, Key, RegistryBean.
If the value is of type RegistryBean then the comparison is made by the RegistryBean's key.
Example:
Predicate predicate = Predicates.eq("name","somePropertyname");
Not Equal Predicate
A predicate that returns true if the compared object value is not equal to the value given in the predicate's creating method “value” field:
ne(String propertyName, Object value)
ne (String propertyName, Object value, Class<? extends
RegistryBean> beanType)
The value must be one of the following types: Number, Date, Calendar, String, Key, RegistryBean.
If the value is of type RegistryBean then the comparison is made by the RegistryBean's key.
Example:
Predicate predicate = Predicates.ne("name","somePropertyname");
AND Predicate
A predicate that joins two predicates in a logical conjunction. The method that creates this predicate:
public static Predicate and(Predicate p1, Predicate p2)
expects two predicates as arguments.
Example:
Predicate predicate1 = Predicates.eq("name","somePropertyname");
Predicate predicate2 = Predicates.eq("name","somePropertyname2");
Predicate andPredicate = Predicates.and(predicate1, predicate2);
OR Predicate
A predicate that joins two predicates in a logical disjunction. The method that creates this predicate:
public static Predicate or(Predicate p1, Predicate p2)
expects two predicates as arguments.
Example:
Predicate predicate1 = Predicates.eq("name","somePropertyname");
Predicate predicate2 = Predicates.eq("name","somePropertyname2");
Predicate orPredicate = Predicates.or(predicate1, predicate2);