Lesson 2: Specify class methods to handle events

CustdbScripts.class, created in the previous lesson, encapsulates the methods UploadInsert and DownloadCursor. These methods contain implementations for the ULCustomer upload_insert and download_cursor events, respectively.

In this section, you specify class methods for table-level events using two approaches:

  • Using the MobiLink Admin mode in Sybase Central:

    Connect to the CustDB database with Sybase Central, change the language for the upload_insert script to Java, and specify CustdbScripts.UploadInsert to handle the event.

  • Using the ml_add_java_table_script stored procedure:

    Connect to the CustDB database with Interactive SQL and execute ml_add_java_table_script, specifying CustdbScripts.DownloadCursor to handle the download_cursor event.

To specify CustdbScripts.UploadInsert to handle the ULCustomer upload_insert event

  1. Connect to the sample database using the Sybase Central MobiLink Admin mode:

    • Start Sybase Central.
    • From the View menu, ensure that Folders is selected.
    • From the Connections menu, choose Connect With MobiLink 11.
    • On the Identification tab, choose the ODBC Data Source Name SQL Anywhere 11 CustDB.
    • Click OK to Connect.
    • Sybase Central should now display the CustDB data source under the MobiLink 11 plug-in.
  2. Delete the existing upload_insert event for the ULCustomer table:

    • In the left pane, open the Synchronized Tables folder and select the ULCustomer table. A list of table-level scripts appears in the right pane.
    • Select the table script associated with the custdb 11.0 upload_insert event. From the Edit menu, choose Delete. The Confirm Delete window appears. You must confirm that you want to delete the object.
    • Select Yes. The custdb 11.0 upload_insert event is removed from the ULCustomer table.
  3. Create a new upload_insert event for the ULCustomer table:

    • With the ULCustomer table selected in the Synchronized Tables folder, choose File » New » Table Script.
    • Select custdb 11.0 as the script version.
    • Select upload_insert as the event to create and click Next.
    • Select Create A New Script Definition, and choose Java.
    • Click Finish.
  4. Instruct the MobiLink server to run the CustdbScripts.UploadInsert method on an upload_insert event.

    • Select the custDB 11.0 - upload_insert script.
    • In the right pane, enter the following code:
      CustdbScripts.UploadInsert
    • From the File menu, choose Save.
  5. Exit Sybase Central.

This step used Sybase Central to specify a Java method as the script for the ULCustomer upload_insert event.

Alternatively, you can use the ml_add_java_connection_script and ml_add_java_table_script stored procedures. Using these stored procedures is more efficient if you have a large number of Java methods to handle synchronization events.

See ml_add_java_connection_script system procedure and ml_add_java_table_script system procedure.

To specify CustdbScripts.DownloadCursor() to handle the ULCustomer download_cursor event

  1. Connect to the sample database with Interactive SQL.

    • Open Interactive SQL.

      Choose Start » Programs » SQL Anywhere 11 » Interactive SQL, or run the following command:

      dbisql

      The Connect window appears.

    • On the Identification tab, choose the ODBC Data Source Name SQL Anywhere 11 CustDB.
    • On the Database tab, ensure that the following option is not selected: Search Network For Database Servers.
    • Click OK to connect.
  2. Run the following command in Interactive SQL:

    CALL ml_add_java_table_script(
    'custdb 11.0',
    'ULCustomer',
    'download_cursor',
    'CustdbScripts.DownloadCursor');
    COMMIT;

    Following is a description of each parameter:

    Parameter Description
    custdb 11.0 The script version.
    ULCustomer The synchronized table.
    download_cursor The event name.
    CustdbScripts.DownloadCursor The fully qualified Java method.
  3. Exit Interactive SQL.

In this lesson, you specified your Java methods to handle ULCustomer table-level events. The next lesson ensures that the MobiLink server loads the appropriate class files and the MobiLink server API.

Further reading

For more information about adding scripts with stored procedures, see ml_add_java_connection_script system procedure and ml_add_java_table_script system procedure.

For general information about adding and deleting synchronization scripts, see Adding and deleting scripts.