Result Set Filters

A result set filter is a custom java class an experienced developer writes in order to specifically manipulate the rows or columns of data returned from a read operation for an MBO.

To write a filter, developers must have previous experience with Java programming — particularly with the reference implementations for javax.sql.RowSet, which is used to implement the filter interface and described in the JDBC RowSet Implementations Tutorial.

Note:

Result set filters depend on the sup-ds.jar file, located at com.sybase.uep.tooling.api/lib subdirectory. For example, C:\Sybase\UnwiredPlatform\Unwired_WorkSpace\Eclipse\sybase_workspace\mobile\eclipse\plugins\com.sybase.uep.tooling.api_<version_and_timestamp>\lib.

When a read operation returns data that does not completely suit the business requirements for your MBO, you can write and add a filter to the MBO to customize the data into the form you need. Developers can write a filter to add, delete, or change columns as well as to add and delete rows.

You can chain multiple filters together. Multiple filters are processed in the order they are added, each applying an incremental change to the data. Consequently, Sybase recommends that you always preview the results. After you preview the MBO, notice that the MBO has a different set of attributes than it would have had directly from the read operation. You can map and use the altered attributes in the same way you would a regular attribute from an unfiltered read operation.

Note: The filter interfaces are defined in terms of java.sql.ResultSet and java.sql.ResultSetMetaData, but these standard JDBC interfaces tend to be read-only implementations. To change data, use a CachedRowSetImpl object instead. This object implements ResultSet but also allows you to modify row data.

Example: a simple SELECT statement filter

Suppose you have an MBO based on the following query:

SELECT * FROM sampledb.customer

However, you do not want to have "fname" and "lname" displayed in separate columns. To avoid separation, write a filter that replaces these columns with a single concatenated "commonName" column.

Note: While the above example could be more easily implemented using a stored procedure:

SELECT id, commonName=fname+' '+lname, address, city, state, zip, phone, company_name FROM customer

you may not have control of resources such as stored procedures in the enterprise information system (EIS). If Unwired Server is deployed and running in an environment where access to the EIS is limited (for example, provided only through existing stored procedures), then filters provide an Unwired Server-based solution.

Example: two separate data sources filter

Suppose you have customer data in two data sources: basic customer information is in an SAP repository, and more complete details are contained in another database on your network. You can use a result set filter to combine the SAP customer data with additional database customer data, so that the MBO displays a complete set of information in a single view. In this case, you would use a JDBC connection to each data source, and perhaps use a JoinRowSetImpl to merge the columns together, thereby joining the two sets of data against the customerID column in the SAP source.