Java classes encapsulate synchronization logic in methods.
In this lesson, you compile a class associated with the CustDB sample database.
SQL Anywhere ships with a SQL Anywhere sample database (CustDB) that is already set up for synchronization, including the SQL scripts required for synchronization. The CustDB ULCustomer table, for example, is a synchronized table that supports a variety of table-level events.
CustDB is designed to be a consolidated database server for both UltraLite and SQL Anywhere clients. The CustDB database has a DSN called SQL Anywhere 11 CustDB.
In this section, you create a Java class called CustdbScripts with logic to handle the ULCustomer upload_insert and download_cursor events. You enter the CustdbScripts code in a text editor and save the file as CustdbScripts.java.
Create a directory for the Java class and assembly.
This tutorial assumes the path c:\mljava.
Using a text editor, enter the CustdbScripts code:
public class CustdbScripts { public static String UploadInsert() { return("INSERT INTO ULCustomer(cust_id,cust_name) values (?,?)"); } public String DownloadCursor(java.sql.Timestamp ts,String user ) { return("SELECT cust_id, cust_name FROM ULCustomer where last_modified >= ' " + ts + " ' "); } } |
When creating your own custom scripts, make sure that the classes and associated methods are defined as public.
Save the file as CustdbScripts.java in c:\mljava.
To execute Java synchronization logic, the MobiLink server must have access to the classes in mlscript.jar. This JAR file contains a repository of MobiLink server API classes to use in your Java methods.
When compiling Java source code for MobiLink, you must include mlscript.jar to make use of the MobiLink server API. In this section, you use the javac utility's -classpath option to specify mlscript.jar for the CustdbScripts class.
At a command prompt, navigate to the folder containing CustdbScripts.java (c:\mljava).
Run the following command.
javac custdbscripts.java -classpath "%sqlany11%\java\mlscript.jar" |
The CustdbScripts.class file is generated.
For more information about the MobiLink server API for Java, see MobiLink server API for Java reference.
For more information about Java methods, see Methods.
For more information about the CustDB sample database, and using alternate RDBMS servers, see Setting up the CustDB consolidated database.
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |