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.
Connect to the sample database using the Sybase Central MobiLink Admin mode:
Start Sybase Central.
Click the View menu and ensure that Folders is selected.
From the Connections menu, choose Connect with MobiLink 10.
On the Identification tab, choose the ODBC Data Source name SQL Anywhere 10 CustDB.
Click OK to Connect.
Sybase Central should now display the CustDB data source under the MobiLink 10 plug-in.
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.
Click the table script associated with the custdb 10.0 upload_insert event. From the Edit menu, choose Delete. You will need to confirm that you want to delete the object.
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 upload_insert as the event to create and click Next.
Choose to create a new script definition using the Java language.
Double-click the upload_insert script to open it. Replace the contents of the script with the fully qualified method name CustdbScripts.UploadInsert and save the script. From the file menu, choose Save.
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, especially if you have a large number of Java methods to handle synchronization events.
See ml_add_java_connection_script and ml_add_java_table_script.
Connect to the sample database with Interactive SQL.
Open Interactive SQL.
The Connect dialog appears.
On the Identification tab, choose the ODBC Data Source SQL Anywhere 10 CustDB.
On the Database tab, ensure that the following option is not selected: Search Network for Database Servers.
Click OK to connect.
Execute the following command in Interactive SQL:
CALL ml_add_java_table_script( 'custdb 10.0', 'ULCustomer', 'download_cursor', 'CustdbScripts.DownloadCursor'); COMMIT;
Following is a description of each parameter:
|custdb 10.0||The script version.|
|ULCustomer||The synchronized table.|
|download_cursor||The event name.|
|CustdbScripts.DownloadCursor||The fully qualified Java method.|
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.
For more information about adding scripts with stored procedures, see ml_add_java_connection_script and ml_add_java_table_script.
For general information about adding and deleting synchronization scripts, see Adding and deleting scripts.