Transcript
Sybase Unwired Platform 1.0 Client Object API Cookbook
DOCUMENT ID: DC00836-01-0100-01 LAST REVISED: September 2008
Copyright © 2008 by Sybase, Inc. All rights reserved.
This publication pertains to Sybase software and to any subsequent release until otherwise indicated in new editions or technical notes. Information in this document is subject to change without notice. The software described herein is furnished under a license agreement, and it may be used or copied only in accordance with the terms of that agreement. To order additional documents, U.S. and Canadian customers should call Customer Fulfillment at (800) 685-8225, fax (617) 2299845. Customers in other countries with a U.S. license agreement may contact Customer Fulfillment via the above fax number. All other international customers should contact their Sybase subsidiary or local distributor. Upgrades are provided only at regularly scheduled software release dates. No part of this publication may be reproduced, transmitted, or translated in any form or by any means, electronic, mechanical, manual, optical, or otherwise, without the prior written permission of Sybase, Inc. Sybase trademarks can be viewed at the Sybase trademarks page at http://www.sybase.com/detail?id=1011207. Sybase and the marks listed are trademarks of Sybase, Inc. ® indicates registration in the United States of America. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. All other company and product names mentioned may be trademarks of the respective companies with which they are associated. Use, duplication, or disclosure by the government is subject to the restrictions set forth in subparagraph (c)(1)(ii) of DFARS 52.227-7013 for the DOD and as set forth in FAR 52.227-19(a)-(d) for civilian agencies. Sybase, Inc., One Sybase Drive, Dublin, CA 94568.
2
Client Object API Cookbook
1.
INTRODUCTION AND REQUIREMENTS ................................................... 5
1.1. Introduction ...................................................................................................................................5 1.2. Requirements .................................................................................................................................5 1.3. Overview.........................................................................................................................................5 1.4. Code Generation from Unwired WorkSpace..............................................................................6 1.5. Code Generation API ....................................................................................................................8 1.6. Client API Dependencies ..............................................................................................................9 1.6.1. Project Setup........................................................................................................................10
2. 3.
3.1. 3.2. 3.3.
TERMINOLOGY ........................................................................................ 10 GENERAL ................................................................................................. 11
Generated and core (fixed) class organization..........................................................................11 The Managers ..............................................................................................................................11 Generic List..................................................................................................................................11
4.
MANAGING CONNECTIONS.................................................................... 11
4.1.1. 4.1.2. 4.1.3. Creating a Connection ........................................................................................................11 Retrieving a Profile..............................................................................................................12 Database Utilities .................................................................................................................13 Synchronization Parameters ..............................................................................................13 Performing MBO synchronization.....................................................................................13 Performing a file synchronization......................................................................................14 Registering for SMS or HTTP Push Notifications............................................................14 Synchronization Status Listener ........................................................................................15 Synchronization Delays.......................................................................................................17 Retrieving Data from MBO ................................................................................................17 Retrieving Relationship Data .............................................................................................19 Paging Data ..........................................................................................................................20 MBO Operations .................................................................................................................20 Update Operation ................................................................................................................21 Delete Operation..................................................................................................................22 Original State .......................................................................................................................22 Parameters and Data Column Types and Sizes ................................................................22 Linked Parameters ..............................................................................................................23 Securing Data.......................................................................................................................23 Date, DateTime, Time data types .......................................................................................23
5.
SYNCHRONIZATION ................................................................................ 13
5.1.1. 5.1.2. 5.1.3. 5.1.4. 5.1.5. 5.1.6.
6.
MBO OBJECTS......................................................................................... 17
6.1.1. 6.1.2. 6.1.3. 6.1.4. 6.1.5. 6.1.6. 6.1.7. 6.1.8. 6.1.9. 6.1.10. 6.1.11.
7.
PUSH ......................................................................................................... 24
7.1. SMS Push .....................................................................................................................................24 7.2. HTTP Push...................................................................................................................................25 7.2.1. HttpPushListener ................................................................................................................25 7.2.2. PushMessage ........................................................................................................................27
8.
8.1. 8.2.
SYBASE.UNWIREDPLATFORM.COMMONS ASSEMBLY (UNSUPPORTED)
MobileDevice................................................................................................................................27 NetworkUtilities...........................................................................................................................28
27
Sybase Unwired Platform 1.0
3
8.3. Windows.Forms .......................................................................................................................... 28 8.3.1. FormsManager.................................................................................................................... 28 8.3.2. StackFormsManager .......................................................................................................... 29 8.3.3. FormsManagerDataObject ................................................................................................ 31
9.
9.1. 9.2.
SYBASE.UNWIREDPLATFORM.CONTROLS ASSEMBLY (UNSUPPORTED) 32
Introduction................................................................................................................................. 32 Visual Studio 2005 .NET Compact Framework 2.0 Projects.................................................. 32
10.
MISCELLANEOUS ....................................................................................33
SMS Push Notification Messages........................................................................................... 33 Cleaning Up UltraLite Databases in Device Applications................................................... 34
10.1. 10.2.
4
Client Object API Cookbook
1.
1.1. Introduction
Introduction and Requirements
This programming cookbook includes a collection of solutions and examples for a variety of tasks and uses of the Sybase Unwired Platform (SUP) .NET Client API. Java will be available in a later release. 1.2. Requirements • Microsoft Visual Studio .NET 2005 Professional or higher. • Knowledge of Sybase Unwired Platform concepts and features. • The Sybase Unwired Platform 1.0 .NET API assemblies. • Sybase Unwired Platform code generation API (in Java). • .NET framework (and compact) 2.0+. Overview
1.3.
Below is an overview of the data access stack from a mobile client.
Client
SUP Object Model
Generated Client Object (Generated MBO and fixed classes) Data Persistence Library UltraLite API / Afaria API Unwired Server
UL DB
CDB
Figure 1. Mobile client data access stack.
The client application has three options as shown above to access data. However, the only supported API is the Generated Client Object API (shown in yellow). The Client Object API uses the Data Persistence Library in its implementation to access and store object data in the database on the device.
Sybase Unwired Platform 1.0
5
The SUP Code Generation API generates the Client Object API. Here is a high level view of the code generation process (Unwired WorkSpace refers to the SUP development environment – either Eclipse Edition or Visual Studio Edition):
Unwired WorkSpace/SI users
Code Gen API
TemplateJ (Code Gen Model)
SUP Client Objects
Code Generation options UEP Models in xml
Templates
Data Persistence Library
Figure 2. Client Object API is generated by SUP Code generation.
• • • • 1.4.
Unwired WorkSpace in Eclipse Edition or Visual Studio Edition builds the mobile business object (MBO), or SI scripts/manually writes the deployment unit. Unwired WorkSpace calls the Code Generation API and provides MBO models and code generation objects as inputs. The Code Generation API executes TemplateJ with the given inputs. TemplateJ applies the correct Templates based on the given code generation options and the MBO model. TemplateJ outputs the Client Objects.
Code Generation from Unwired WorkSpace
Once the Mobile Development project is completed as desired, users can right click on the project, select “Generate Code,” and follow the instructions in the dialog to generate the client object code.
6
Client Object API Cookbook
Sybase Unwired Platform 1.0
7
Note that for C#, we generate non-UI CF 2.0 compatible code regardless of what platform is selected. The generated code works with CF 2.0+ and full .NET Framework 2.0+. 1.5. Code Generation API
The Client Object API can be generated from the Java code generation API instead of Unwired WorkSpace if MBO deployment is available. The MBO deployment unit can be extracted from the Mobile Development Project.
import com.sybase.sup.codegen.client.CodeGenerator; import com.sybase.sup.codegen.client.impl.*; import java.util.HashMap; import java.io.*; public class CGMain {
8
Client Object API Cookbook
public static void main(String[] args) { CodeGenerator cg = new SUPCodeGenerator(); HashMap
cgOptions = new HashMap (); cgOptions.put(CodeGenerator.OPTION_META_DATA, CodeGenerator.META_DATA_NO); cgOptions.put(CodeGenerator.OPTION_PACKAGE_NAME, "Sybase.Test"); cgOptions.put(CodeGenerator.OPTION_LANGUAGE, CodeGenerator.LANGUAGE_CS); cgOptions.put(CodeGenerator.PLATFORM_WM_SP, CodeGenerator.PLATFORM_WM_SP); cgOptions.put(CodeGenerator.OPTION_META_DATA, CodeGenerator.META_DATA_YES); cg.generateCode (new File ("deployment_unit.xml"), "C:/tmp/SampleClientUsage", cgOptions); } }
The JavaDocs for this is included in the Sybase Unwired Platform installation directory.
1.6.
Client API Dependencies
The client API assembly DLL dependencies as well as this cookbook are installed under the Sybase Unwired Platform installation directory. The contents of the client API directory are: • • • • • • •
Afaria – Afaria assembly dependencies. apidocs – Code Generation API Javadocs. CodeGenModel – TemplateJ code generation model templates for .NET and Java. dpl\dotnet\API\bin – .NET Data Persistence Library and UltraLite assemblies. fixed – sources of the fixed classes that are used by the generated classes. lib – binaries of Code Generation API and fixed classes for .NET and Java (Rim, Java SE 5). dpl\dotnet\API\src – source code of the HTTP Push Listener included in the Sybase.UnwiredPlatform.Networking namespace. This source is included so developers can create
their own custom HTTP Push Listener if needed. The dpl\dotnet\API\bin folder contains the following directory structure: •
dpl – the Sybase Unwired Platform DPL assembly DLLs as individual files.
o ce – files for use on Windows CE based systems. o win32 – files for use on full Windows based systems like Windows XP. •
ultralite – the UltraLite assembly DLLs.
o ce - Files for use on Windows CE based systems like Windows Mobile 5+. o win32 - Files for use on full Windows based systems like Windows XP.
Sybase Unwired Platform 1.0
9
The assemblies listed above support CF 2.0+ on Visual Studio 2005 and 2008.
Visual Studio Version Visual Studio 2005 (and 2008) Project Type Full .NET Framework 2.0+ Application Windows CE .NET CF 2.0+ Application Pocket PC .NET CF 2.0+ Application Smartphone .NET CF 2.0+ Application
1.6.1. Project Setup
Add these as references in the Visual Studio project:
• • Sybase.UnwiredPlatform.Data.UltraLite.dll iAnywhere.Data.UltraLite.dll iAnywhere.Data.UltraLite.resources.dll (there are several supported languages)
•
Add these as items in the Visual Studio project, and set “Build Action” to “Content” and “Copy to Output Director” to “Copy always”.
• • ulnet10.dll mlcrsa.dll (if HTTPS protocol is used)
2.
• • •
Terminology
Remote Client – refers to a user’s PDA, Smartphone, or PC. Remote Database or Remote Client Database – refers to the UltraLite database on a remote client that will be used to store the data. MBO – Mobile Business Objects. The fundamental unit of exchange in Sybase Unwired Platform is the MBO. An MBO corresponds to a data set from a back-end data source. The data can come from a database query, a Web service operation (including Remedy and Siebel), SAP, or a file (using Afaria). An MBO contains both concrete implementation-level details and abstract interface-level details. At the implementation-level, an MBO contains read-only columns that contain metadata about the data in the implementation, and parameters that are passed to the back-end data source. At the interface-level, an MBO contains attributes that map to columns, which correspond to client properties. An MBO may have operations, which can also contain parameters and arguments, and which may be used to create, update, or delete data.
10
Client Object API Cookbook
3.
3.1.
General
Generated and core (fixed) class organization
Any classes for the client object API that are fixed and do not change will be part of the “core” classes (a.k.a fixed classes). All other classes are generated classes. Core classes will be provided in a package/namespace that is consistent with a language’s conventions. • .NET – Sybase.Persistence Note: Generated classes will not generate import statements due to issues with ambiguity. Fully qualified namespace will be used in generated classes. 3.2. The Managers
The ConnectionManager and SynchronizationManager classes provide access to their respective portions of the Sybase.Persistence assembly. These classes follow the Singleton design pattern and are referenced using a static Instance property. Below are samples on how to acquire each of the manager classes.
ConnectionManager cm = ConnectionManager.Instance; SynchronizationManager syncManager = SynchronizationManager.Instance;
3.3.
Generic List
Any part of the API that returns a generic List