59
SAP How-to Guide Mobile Technology Sybase Unwired Platform Applicable Releases: Sybase Unwired Platform 2.x Version 1.0 March 2012 Result Set Filters for Mobile Business Objects (Sybase Unwired Platform)

4. Result Sets for SUP Mobile Business Objects

Embed Size (px)

DESCRIPTION

Result Sets for SUP Mobile Business Objects official manual for SAP

Citation preview

Page 1: 4. Result Sets for SUP Mobile Business Objects

SAP How-to Guide

Mobile Technology

Sybase Unwired Platform

Applicable Releases:

Sybase Unwired Platform 2.x

Version 1.0

March 2012

Result Set Filters for Mobile Business Objects(Sybase Unwired Platform)

Page 2: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

© Copyright 2012 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in

any form or for any purpose without the express permission of

SAP AG. The information contained herein may be changed

without prior notice.

Some software products marketed by SAP AG and its distributors

contain proprietary software components of other software

vendors.

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered

trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System

p, System p5, System x, System z, System z10, System z9, z10,

z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS,

S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server,

PowerVM, Power Architecture, POWER6+, POWER6, POWER5+,

POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter,

System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF,

Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner,

WebSphere, Netfinity, Tivoli and Informix are trademarks or

registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the U.S. and

other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either

trademarks or registered trademarks of Adobe Systems

Incorporated in the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the

Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame,

VideoFrame, and MultiWin are trademarks or registered

trademarks of Citrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or registered

trademarks of W3C®, World Wide Web Consortium,

Massachusetts Institute of Technology.

Java is a registered trademark of Sun Microsystems, Inc.

JavaScript is a registered trademark of Sun Microsystems, Inc.,

used under license for technology invented and implemented by

Netscape.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP

BusinessObjects Explorer, StreamWork, and other SAP products

and services mentioned herein as well as their respective logos

are trademarks or registered trademarks of SAP AG in Germany

and other countries.

Business Objects and the Business Objects logo, BusinessObjects,

Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and

other Business Objects products and services mentioned herein as

well as their respective logos are trademarks or registered

trademarks of Business Objects Software Ltd. Business Objects is

an SAP company.

Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL

All other product and service names mentioned are the

trademarks of their respective companies. Data contained in this

document serves informational purposes only. National product

specifications may vary.

The information in this document is proprietary to SAP. No part of

this document may be reproduced, copied, or transmitted in any

form or for any purpose without the express prior written

permission of SAP AG.

This document is a preliminary version and not subject to your

license agreement or any other agreement with SAP. This

document contains only intended strategies, developments, and

functionalities of the SAP® product and is not intended to be

binding upon SAP to any particular course of business, product

strategy, and/or development. Please note that this document is

subject to change and may be changed by SAP at any time

without notice.

SAP assumes no responsibility for errors or omissions in this

document. SAP does not warrant the accuracy or completeness of

the information, text, graphics, links, or other items contained

within this material. This document is provided without a warranty

of any kind, either express or implied, including but not limited to

the implied warranties of merchantability, fitness for a particular

purpose, or non-infringement.

SAP shall have no liability for damages of any kind including

without limitation direct, special, indirect, or consequential

damages that may result from the use of these materials. This

limitation shall not apply in cases of intent or gross negligence.

The statutory liability for personal injury and defective products is

not affected. SAP has no control over the information that you

may access through the use of hot links contained in these

materials and does not endorse your use of third-party Web pages

nor provide any warranty whatsoever relating to third-party Web

pages.

SAP “How-to” Guides are intended to simplify the product

implementtation. While specific product features and procedures

typically are explained in a practical business context, it is not

implied that those features and procedures are the only approach

in solving a specific business problem using SAP NetWeaver.

Should you wish to receive additional information, clarification or

support, please refer to SAP Consulting.

Any software coding and/or code lines / strings (“Code”) included

in this documentation are only examples and are not intended to

be used in a productive system environment. The Code is only

intended better explain and visualize the syntax and phrasing

rules of certain coding. SAP does not warrant the correctness and

completeness of the Code given herein, and SAP shall not be liable

for errors or damages caused by the usage of the Code, except if

such damages were caused by SAP intentionally or grossly

negligent.

Disclaimer

Some components of this product are based on Java™. Any code

Page 3: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Anywhere, and other Sybase products and services mentioned

herein as well as their respective logos are trademarks or

registered trademarks of Sybase, Inc. Sybase is an SAP company.

change in these components may cause unpredictable and severe

malfunctions and is therefore expressively prohibited, as is any

decompilation of these components.

Any Java™ Source Code delivered with this product is only to be

used by SAP’s Support Services and may not be modified or

altered in any way.

Page 4: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Document HistoryDocument Version Description

1.00 First official release of this guide

Page 5: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Page 6: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Table of Contents

1. Business Scenario.............................................................................2

2. Use Cases for Result Set Filters.........................................................3

2.1 Advanced filtering.......................................................................................32.2 Adding or combining columns.....................................................................32.3 Combining data sources..............................................................................4

3. Background......................................................................................5

4. Prerequisites....................................................................................6

5. Step-by-Step Procedure....................................................................7

5.1 Example Scenario........................................................................................75.2 Step-by-Step procedure..............................................................................8

5.2.1 Define Mobile Business Object and custom Result Set Filter............85.2.2 Create HWC app.............................................................................315.2.3 Test the app...................................................................................37

6. Appendix........................................................................................39

6.1 Debugging.................................................................................................396.1.1 Filter Class Debugging...................................................................396.1.2 Enabling JPDA.................................................................................396.1.3 Setting Debug Breakpoints in Result Set Filter Classes..................406.1.4 Setting Up the Debug Session........................................................40

6.2 References................................................................................................416.3 Example Source Code...............................................................................41

April 2023 1

Page 7: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

1. Business Scenario

On the Sybase Unwired Platform, the mobile data can be defined, deployed and manipulated by using Mobile Business Objects (MBO’s).

Each Mobile Business Object references a data source (SAP, JDBC, web service) and can fetch data from those data sources, for example to store in the Consolidated Database (CDB).

At development time, the Sybase Unwired Workspace (part of Sybase Mobile SDK) allows to define the data set to be retrieved by each MBO.

For example, if the data source of the MBO is a database table, the Unwired Workspace allows a developer to define which table and table fields should be fetched from the database by the MBO implementation at runtime.

In certain cases, not all the data from a data source needs to be retrieved by the MBO.

To filter the data that is retrieved from the data source at runtime, certain options exist like for example attribute filters. These options can be configured in the Unwired Workspace and do not require any coding by the developer.

However, for more advanced filtering needs these options like attribute filters are not sufficient.

In more advanced filtering scenarios a developer can use Result Set Filters.

These are custom developed Java classes that allow to implement specific filtering functionality for the data retrieved by MBO’s.

Furthermore, Result Set Filters can be used to connect multiple data sources to one MBO and to add additional columns to an MBO that are not present in the data source.

April 2023 2

Page 8: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

2. Use Cases for Result Set Filters

Different use cases exist for Result Set Filters. Different Result Set filters can also be chained in a sequence where each of these filters applies its own filtering functionality to the data set that gets passed in (by the previous Result Set filter).

2.1 Advanced filtering

Advanced filtering logic can be implemented in the Java source of the Result Set Filter class.

April 2023 3

Page 9: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Adding or combining columns

Additional columns (MBO attributes) can be added to the columns existing in the data source. The logic for filling up these columns is defined in the Java source of the Result Set Filter.

2.2 Combining data sources

By using Result Set Filters, additional data sources can be called when retrieving data for the MBO.

April 2023 4

Page 10: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

3. Background

A ResultSetFilter is a custom Java class deployed to Unwired Server that manipulates the rows or columns of data returned to Unwired Server from the enterprise information system (EIS) by an MBO read operation.

The Result Set Filter class needs to implement following interfaces;

com.sybase.uep.eis.ResultSetFilter

Method getArguments

This method allows the developer to specify the names and types of input arguments that will be used by the filter.

Method filter

The actual filtering logic is implemented in this method.

This method takes a ResultSet as input parameter and a list of the (filled in) input arguments of the filter. The method also returns a (modified) ResultSet.

The Result set input parameter contains the data as it has been retrieved from the data source.

The input ResultSet is of type java.sql.ResultSet , but this standard JDBC interfaces tends to be a read-only implementation. This input ResultSet should not be modified.

To change data, the input ResultSet can be copied to a CachedRowSetImpl object; this class implements ResultSet but also allows to modify row data.

The method will then return the modified CachedRowSetImpl-object as a ResultSet.

It’s this modified ResultSet that will consequently be used by the MBO.

com.sybase.uep.eis.ResultSetFilterMetaData

Method getMetaData

The filter can change the number and type of the retrieved data columns in the ResultSet.

In the getMetaData method the developer can already return the updated metadata describing the number and types of columns in the returned ResultSet of the filter.

Implementation of this method is optional; if the developer does not specify the updated metadata here, it will be figured out by the system in a later stage.

Sybase strongly encourages developers to initially create filters in Unwired WorkSpace: a wizard assists by autogenerating required imports, and methods correctly generated so the implementation already compiles and runs.

This autogenerated code can serve as the start for the actual custom implementation.

Once the filter has been implemented and deployed to Unwired Server as part of an MBO package, the MBO developer can apply the filter to other MBOs from Unwired Workspace.

April 2023 5

Page 11: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

April 2023 6

Page 12: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

4. Prerequisites

Prerequisites for the steps described in this How-To Guide are:

Sybase Unwired Platform 2.x

More information can be found at http://infocenter.sybase.com

April 2023 7

Page 13: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

5. Step-by-Step Procedure

5.1 Example Scenario

The ResultSet filter functionality will be demonstrated by using a sample application.

The sample app shows a list of customers and their data.

On the first screen the user can specify a range of customer to show, based on their name.

The range will span an alphabetical sequence of the customer’s names.

If the user fills in ‘A’ and ‘C’ in the input fields on the first screen, a list of customers will be shown whose name starts with A and B.

The MBO of the sample app is based on the “customers” table of the sample database provided by Sybase with the Unwired Platform.

Two load arguments will be defined for this MBO; one for the “Name From” and one for the “Name To”.

These will correspond to two input arguments for the Result Set Filter.

Also, two personalization keys will be defined; one for the “Name From” and one for the “Name To”.

The app will be a client initiated HWC app.

The personalization keys will be bound to the two input fields on the first screen of the app.

April 2023 8

Page 14: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

5.2 Step-by-Step procedure

5.2.1Define Mobile Business Object and custom Result Set Filter...

1. Start the Sybase Unwired Tooling and switch to the Mobile Development perspective. Create a new mobile project.

2. Create an MBO based on the customer database table of the Sybase sample

database.

Result;

April 2023 9

Page 15: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

3. Select the generated MBO, go to the “Properties” tab and select the “Attributes” tab. On the attributes tab, select the “Definition” tab.

Click the “Edit” button.

The goal is now to define a ResultSet filter for this MBO.

This ResultSet will be added to this Mobile project as a Java class.

April 2023 10

Page 16: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

This Java class already has skeleton source code with the required interfaces and methods to implement.

April 2023 11

Page 17: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

4. In the popup screen, expand the “Result Set” section at the bottom and click “Create”.

Accept the dialog asking about the Java nature;

April 2023 12

Page 18: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

In Eclipse, a Java nature adds Java-specific behavior to projects.

A Java nature is recommended because you are creating a new Java project and adding a Java class to it.

By default an Unwired Platform project does not include all the required behaviors for Java development.

Clicking Yes automates this process.

5. In the popup that appears, fill in the package name and a name for the ResultSet class.

April 2023 13

Page 19: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

After filling in the package and class name, confirm this dialog with “Finish” and return to the canvas with the MBO.

6. A dialog appears;

Click “Yes”.

7. Now go the WorkSpace Navigator and look for the Java class that has been generated for this ResultSet filter.

Double click the generated Java class to have a look at the code that was generated.

April 2023 14

Page 20: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

The generated Java class implements 2 interfaces; ResultSetFilter and ResultSetFilterMetadata.

The default implementation that is generated does not implement any filtering functionality. If you would deploy the MBO with the implemented ResultSetFilter that you see above, no filtering would take place.

April 2023 15

Page 21: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

You can verify this as follows; go back to the customer MBO, select the “Properties” tab and then “Attributes” and “Definition”. Now click “Preview”.

April 2023 16

Page 22: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

In the screen that appears, click “Preview” again.

You will see the same entries as you see in the database table of the customer.

(to have a look at the data in the database table of the customer, go to the “Enterprise Explorer” (in left bottom corner), open your sample db, expand the “Tables” node, look for the customer table, right click on it and select “Edit Data”)

(a refresh may be required for the custom Java filter to take effect)

8. In this guide we will only extend the ResultSetFilter implementation, not the ResultSetFilterMetadata implementation.

Return to the Java implementation of the generated ResultSet filter.

First we implement the getArguments-method.

This method allows us to add some input arguments to the filter.

For our sample scenario we will need 2 input arguments; nameFrom and nameTo.

These correspond to the input parameters on the first screen of the sample application.

April 2023 17

Page 23: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

To add these input arguments to the filter, add following code;

@Overridepublic Map<String, Class> getArguments() {

HashMap<String, Class> listArgs = new HashMap<String, Class>();listArgs.put("faNameFrom", String.class);listArgs.put("faNameTo", String.class);

return listArgs;}

Result;

After adding the code, make sure you save your work.

April 2023 18

Page 24: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

To transfer these input arguments as load arguments, navigate back to the MBO and select the tab “Properties”. Click on “Attributes” and “Load Arguments” and hit the “Refresh” button.

Accept the warning dialog;

April 2023 19

Page 25: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Result;

Now, trigger a preview as was explained in Step 7.

You will see the same result as before, but this time there are two load arguments defined; faNameFrom and faNameTo. Because we have not implemented any filtering logic yet, the preview does not filter the customer data yet.

(a refresh may be required for the custom Java filter to take effect)

April 2023 20

Page 26: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

9. Now we will implement the filtering logic in the filter-method of the Result Set Filter Java class. Return to the Java implementation of the ResultSet filter class.

The filter-method has two input parameters

ResultSet arg0 : this is the input ResultSet. In the default implementation this result set gets passed back as the output of the filter-method without any change. We will make a copy of this Result Set, apply a filter and pass this copy back as the output of the filter method.

Map<String, Object> arg1; these are the input arguments of the filter. This Map will contain 2 entries; one with the nameFrom-value and one with the nameTo-value.

Modify the code as follows.

(the complete code of this class is available in the appendix)

First we will declare 2 variables who will hold the input argument values;

String nameFrom = null;String nameTo = null;

Then we read in the values from the list with input arguments;

List<String> keyList = new ArrayList<String>(arg1.keySet());List<Object> valList = new ArrayList<Object>(arg1.values());

int indexArgumentOne = keyList.indexOf("lpNameFrom"); if (indexArgumentOne >= 0) {

nameFrom = valList.get(indexArgumentOne).toString();}

int indexArgumentTwo = keyList.indexOf("lpNameTo"); if (indexArgumentTwo >= 0) {

nameTo = valList.get(indexArgumentTwo).toString();}

After this we create a copy of the input ResultSet. We will use the FilteredRowSet-implementation because it is more flexible than the ResultSet-implementation.

FilteredRowSet rows = new FilteredRowSetImpl();rows.populate(arg0);

Now we apply the filter to the copy of the ResultSet;

if (nameFrom != null && nameTo != null) {

Range nameFilter = new Range(nameFrom, nameTo, 3);rows.setFilter(nameFilter);

}(the Range-class will be implemented later)

Finally, the filtered copy of the original Result Set is returned.

return rows;

April 2023 21

Page 27: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

April 2023 22

Page 28: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

To filter the customer entries based on their name, a range class is used.

The constructor of this class takes a low value, a high value and the index of the column these values apply to.

In the case of this sample app, the low value will correspond to nameFrom argument, the high value will correspond to the nameTo argument and the column index will be 3 as this is the index of the column holding the name of the customer.

By passing an object of this range class to the filter-method of the FilteredRowSet the selection of the appropriate customers will be executed.

The implementation of the range class will be added as a private class to the code of the custom ResultSet class.

For inspiration have a look at the document mentioned in attachment JDBC RowSet Implementations Tutorial.

The implementation of the filter class is as follows;

private class Range implements Predicate, Serializable {private int idx;private Object hi;private Object lo;private String colName;

public Range(Object lo, Object hi, int idx) {this.hi = hi;this.lo = lo;this.idx = idx;this.colName = new String("");}

public Range(Object lo , Object hi , String colName, int idx) {this.lo = lo;this.hi = hi;this.colName = colName;this.idx = idx;}

public boolean evaluate(RowSet rs) {int comp;String columnVal = "";boolean bool = false;

FilteredRowSetImpl crs = (FilteredRowSetImpl) rs;

try {columnVal = crs.getString(idx);comp = columnVal.compareTo(lo.toString());if(comp < 0) {

return false;}

comp = columnVal.compareTo(hi.toString());if(comp > 0) {return false;}} catch(SQLException e) {

April 2023 23

Page 29: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

} //end catchreturn true;}

public boolean evaluate(Object value, String columnName) {int comp;if(!(columnName.equals(colName))) {

return true;}comp = (value.toString()).compareTo(lo.toString());

if ( comp < 0 ) {return false;

}comp = (value.toString()).compareTo(hi.toString());

if ( comp > 0 ) {return false;

}return true;

}

public boolean evaluate(Object value, int columnIndex) {int comp;

if(columnIndex != idx) {return true;

}comp = (value.toString()).compareTo(lo.toString());

if( comp < 0 ) {return false;

}comp = (value.toString()).compareTo(hi.toString());

if ( comp > 0 ) {return false;

}return true;

}}

After all the code has been added, make sure you save your work.

April 2023 24

Page 30: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

To test the implementation of the custom ResultSet filter class, navigate back to customer MBO and start the preview as explained in Step7.

You will now see that only results are returned with a last name between the nameFrom value and the nameTo value.

(a refresh may be required for the custom Java filter to take effect)

April 2023 25

Page 31: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

10.To complete the definition of the MBO, two personalization keys need to be added; one for the nameFrom argument and one for the nameTo argument.

Since these personalization keys will be used in a HWC app, make sure they are defined as transient.

Result;

April 2023 26

Page 32: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Don’t forget to map the personalization keys to the corresponding load arguments of the MBO;

April 2023 27

Page 33: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

11.Before deploying the mobile project, the custom ResultSet filter needs to be packaged in a jar. Navigate to the Java file containing the custom ResultSet filter, right click and select “Export”.

April 2023 28

Page 34: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

In the popup that appears, select “JAR File” as export format.

April 2023 29

Page 35: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

In the next screen, make sure only the Java class with the ResultSet filter is selected and specify a location within your project to store the JAR file in.

Verify that a JAR-file has been created in the location you specified.

April 2023 30

Page 36: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

12.Finally, deploy the mobile project.

April 2023 31

Page 37: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

On the next page, the custom ResultSet filter needs to be added.

Click “Add JAR…” and navigate to the JAR-file containing the custom result set Java class.

April 2023 32

Page 38: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Result;

Go through the next screens as you would for other projects and deploy the MBO.

Result:

April 2023 33

Page 39: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

5.2.2Create HWC app

1. Create a new Mobile Workflow Form and choose for a client initiated hwc app;

Result;

April 2023 34

Page 40: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Now drag and drop the customer MBO to the canvas of the Mobile Workflow Forms Editor.

Result;

Delete all the screens except the “Customer” screen, which displays the list of customers.

Result;

April 2023 35

Page 41: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

April 2023 36

Page 42: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

2. As a next step, add two edit boxes to the Start Screen. The first is meant to pass the value of nameFrom and the second is used to pass the value of nameTo.

Result;

April 2023 37

Page 43: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

April 2023 38

Page 44: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

3. Now, add a new MenuItem in the Menu of the Start Screen.

This new menu item will be used to call the findAll-query of the customer MBO.

April 2023 39

Page 45: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

4. Now map the personalization keys to the keys of the input fields for nameFrom and nameTo.

If the personalization keys are not visible, apply this workaround1;

1) Add an empty personalization key to empty key mapping within the properties view.

2) Open the .xbw file with a text editor.

3) Look for xmi:type="xbw:PersonalizationKeyMapping"

4) Set your personalization_key_name="abc".

5) Save

6) Reload .xbw with Forms Editor

7) Map your key (e.g. input key) to the personalization key "abc" you just specified

Please note you only have to apply this workaround if you do not see the personalization keys showing up in the Mobile Workflow Forms Editor.

5. Result;

1 Thanks to Marcel Toerpe

April 2023 40

Page 46: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

6. Finally, deploy the HWC app and start the app from a mobile device.

5.2.3Test the app

1. Install the Sybase HWC app on your device and register an MBS user in the Sybase Control Center.

2. Start the app;

April 2023 41

Page 47: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

Result;

Verify that the results only contain entries for customers with a last name within the boundaries specified in the “Name From” and “Name To” fields.

When testing the app, an error screen might appear;

April 2023 42

Page 48: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

In this case, navigate to the Sybase Control Center and go to Servers > [your server] > Log to find out what the problem is.

April 2023 43

Page 49: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

6. Appendix

6.1 Debugging

To debug a custom Result Set Filter, follow the guidelines specified in the infocenter.sybase.com;

6.1.1Filter Class Debugging

Sybase Unwired Platform supports various debugging models: instrumented code, and JPDA (Java Platform Debugger Architecture).

You can also include code by including System.out.println() in the filter class, output from the class is captured in the Unwired Server log when the filter executes in the server.

Alternatively, you can use the standard Java debugger to debug the filter class.

• Enabling JPDA

Set up JPDA and attach the Java standard debugger to Unwired Server.

• Setting Debug Breakpoints in Result Set Filter Classes

Set breakpoints in the result set filter classes from the Unwired WorkSpace project that contains the filters.

6.1.2Enabling JPDA

Set up JPDA and attach the Java standard debugger to Unwired Server.

1. Stop Unwired Server.

2. Add JPDA information from Sybase Control Center:

a. Select Servers > ServerName > Server Configuration > Performance Configuration.

b. Expand Show optional properties.

c. Add this information to the value of the User Options property. In this example 5005 is the port to which the Java debugger connects:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

3. Restart Unwired Server.

4. Once Unwired Server is restarted, verify that JPDA mode is working and available at port 5005 by running:

netstat -ano | findstr 5005

Look for these results:

TCP 0.0.0.0:<JPDAport> 0.0.0.0:0 LISTENING

5. Use a standard Java debugger and attach it to Unwired Server by specifying the correct host and the JPDA port used.

Begin debugging the result filter class with the Java debugger.

April 2023 44

Page 50: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

6.1.3Setting Debug Breakpoints in Result Set Filter Classes

Set breakpoints in the result set filter classes from the Unwired WorkSpace project that contains the filters.

Prerequisites

Add a result set filter to an Unwired WorkSpace project.

Task

1. From WorkSpace Navigator in Unwired WorkSpace, expand the project Filters to access the result set filter Java class.

2. Double-click the Java class to open it in the Java editor.

The default generated code is a filter that does nothing until you add your filter code.

3. Right-click in the grey vertical bar to the left of the actual code and select Toggle Breakpoint to set breakpoints.

4. Compile and deploy the classes to Unwired Server. Redeploy the MBO package if it has changed as part of the filtering.

• Setting Up the Debug Session

Debug the deployed result set filter from Unwired WorkSpace using breakpoints.

6.1.4Setting Up the Debug Session

Debug the deployed result set filter from Unwired WorkSpace using breakpoints.

Prerequisites

Set debug breakpoints in your filter class.

Task

1. From Unwired WorkSpace click the down-arrow next to the Debug menu, and select Debug Configurations.

2. Right-click Remote Java Application and select New.

3. Name the configuration and change the JPDA port to match that of Unwired Server:

o Use a standard connection (Socket Attach)

o Use host 0.0.0.0

o Set the the port to match the one enabled in Unwired Server (by default 5005)

4. Click Debug to save the configuration and launch the debugger.

5. Select Window > Open Perspective > Other > Debug to open the Debug perspective.

In the left pane you can view the threads running inside Unwired Server. When your filter is called, one of these threads suspends, and the code window highlights where the debugger has stopped in the server. The right pane displays the values of local variables inside your filter.

April 2023 45

Page 51: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

6.2 References

Here’s an article on ResultSet filter implementations;

JDBC RowSet Implementations Tutorial at http://java.sun.com/developer/onlineTraining/Database/jdbcrowsets.pdf

Also, on the infocenter.sybase.com, look at these links (for SUP 2.1.2) ;

Result Set Filters at

http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01781.0212/doc/html/aba1274899834402.html?resultof=%22%72%65%73%75%6c%74%22%20%22%73%65%74%22%20%22%66%69%6c%74%65%72%22%20

6.3 Example Source Code

package com.sap.belux.wv;

import java.io.Serializable;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

import java.util.Map;

import com.sun.rowset.CachedRowSetImpl;

import com.sun.rowset.FilteredRowSetImpl;

import com.sybase.uep.eis.ResultSetFilter;

import com.sybase.uep.eis.ResultSetFilterMetaData;

import java.util.HashMap;

import javax.sql.RowSet;

import javax.sql.rowset.CachedRowSet;

import javax.sql.rowset.FilteredRowSet;

import javax.sql.rowset.Predicate;

public class CustomerResultSet01 implements ResultSetFilter, ResultSetFilterMetaData {

@Override

public ResultSetMetaData getMetaData(ResultSetMetaData arg0,

Map<String, Object> arg1) throws Exception {

System.out.print("getMetaData");

return arg0;

}

@Override

April 2023 46

Page 52: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

public ResultSet filter(ResultSet arg0, Map<String, Object> arg1)

throws Exception {

// First we will declare 2 variables who will hold the input argument values

String nameFrom = null;

String nameTo = null;

// Then we read in the values from the list with input arguments

List<String> keyList = new ArrayList<String>(arg1.keySet());

List<Object> valList = new ArrayList<Object>(arg1.values());

int indexArgumentOne = keyList.indexOf("lpNameFrom");

if (indexArgumentOne >= 0) {

nameFrom = valList.get(indexArgumentOne).toString();

}

int indexArgumentTwo = keyList.indexOf("lpNameTo");

if (indexArgumentTwo >= 0) {

nameTo = valList.get(indexArgumentTwo).toString();

}

// Now we create a copy of the input ResultSet.

// We will use the FilteredRowSet-implementation because it is more flexible than the ResultSet-implementation.

FilteredRowSet rows = new FilteredRowSetImpl();

rows.populate(arg0);

// Now we apply the filter to the copy of the ResultSet

if (nameFrom != null && nameTo != null)

{

Range cityFilter = new Range(nameFrom, nameTo, 3);

rows.setFilter(cityFilter);

}

return rows;

}

@Override

public Map<String, Class> getArguments() {

System.out.print("GETaRGUMENTS ");

HashMap<String, Class> lt_arg = new HashMap<String, Class>();

lt_arg.put("lpNameFrom", String.class);

lt_arg.put("lpNameTo", String.class);

return lt_arg;

April 2023 47

Page 53: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

}

private class Range implements Predicate, Serializable {

private int idx;

private Object hi;

private Object lo;

private String colName;

public Range(Object lo, Object hi, int idx) {

this.hi = hi;

this.lo = lo;

this.idx = idx;

this.colName = new String("");

}

public Range(Object lo , Object hi , String colName, int idx) {

this.lo = lo;

this.hi = hi;

this.colName = colName;

this.idx = idx;

}

public boolean evaluate(RowSet rs) {

int comp;

String columnVal = "";

FilteredRowSetImpl crs = (FilteredRowSetImpl) rs;

try {

columnVal = crs.getString(idx);

comp = columnVal.compareTo(lo.toString());

if(comp < 0) {

return false;

}

comp = columnVal.compareTo(hi.toString());

if(comp > 0) {

return false;

}

} catch(SQLException e) {

} //end catch

return true;

}

public boolean evaluate(Object value, String columnName) {

int comp;

April 2023 48

Page 54: 4. Result Sets for SUP Mobile Business Objects

Result Set Filters for Mobile Business Objects

if(!(columnName.equals(colName))) {

return true;

}

comp = (value.toString()).compareTo(lo.toString());

if ( comp < 0 ) {

return false;

}

comp = (value.toString()).compareTo(hi.toString());

if ( comp > 0 ) {

return false;

}

return true;

}

public boolean evaluate(Object value, int columnIndex) {

int comp;

if(columnIndex != idx) {

return true;

}

comp = (value.toString()).compareTo(lo.toString());

if( comp < 0 ) {

return false;

}

comp = (value.toString()).compareTo(hi.toString());

if ( comp > 0 ) {

return false;

}

return true;

}

}

}

April 2023 49

Page 55: 4. Result Sets for SUP Mobile Business Objects