Contents Index Introduction Running Java synchronization logic

MobiLink Synchronization User's Guide
  Writing Synchronization Scripts in Java

Setting up Java synchronization logic


When you install SQL Anywhere Studio, the installer automatically sets the location of the MobiLink Java API classes. When you start the MobiLink synchronization server, it automatically includes these classes in your classpath. The MobiLink Java API classes are installed to Java\mlscript.jar in your SQL Anywhere Studio installation directory. MobiLink uses the ASANYSH* environment variables to determine the shared component path.

For more information, see ASANYSH9 environment variable.

To implement synchronization scripts in Java

  1. Create your own class or classes. Write a method for each required synchronization script. These methods must be public. The class must be public in the package.

    For more information about methods, see Methods.

    Each class with non-static methods should have a public constructor. The MobiLink synchronization server automatically instantiates each class the first time a method in that class is called. The class constructor may have one of two signatures, as described below.

    For more information about constructors, see Constructors.

  2. When compiling the class, you must include the JAR file java\mlscript.jar.

    For example,

    javac MyClass.java -classpath %asany9%\java\mlscript.jar
  3. In your consolidated database, specify the name of the package, class, and method to call for each script. One class is permitted per script version.

    This information is stored in the MobiLink system tables. The script_language column of the ml_script table must contain the word java. The string in the script column, which contains a statement for scripts implemented in SQL, must instead contain the qualified name of a public Java method.

    The easiest way to add this information to the MobiLink system tables is to use the ml_add_java_connection_script stored procedure or the ml_add_java_table_script stored procedure. You can also add this information using Sybase Central.

    For more information, see ml_add_java_connection_script and ml_add_java_table_script.

    For example, the following statement, when run in an Adaptive Server Anywhere database, specifies that myPackage.myClass.myMethod should be run whenever the authenticate_user connection-level event occurs.

    call ml_add_java_connection_script( 'version1',
    'authenicate_user', 'myPackage.myClass.myMethod' )

    The example code below, for use with the Sample application, calls Java procedures to add connection and table script data to the MobiLink system tables.

    call ml_add_java_connection_script('ver1', 'authenticate_user',
          'CustEmpScripts.authenticateUser')
    call ml_add_java_connection_script('ver1', 'end_connection',
          'CustEmpScripts.endConnection')
    call ml_add_java_table_script('ver1', 'emp', 'upload_cursor',
          'CustEmpScripts.empUploadCursor')
    call ml_add_java_table_script('ver1', 'emp',
          'download_cursor', 'CustEmpScripts.empDownloadCursor')
    call ml_add_java_table_script('ver1', 'cust', 'upload_cursor',
          'CustEmpScripts.custUploadCursor')
    call ml_add_java_table_script('ver1', 'cust',
          'download_cursor', 'CustEmpScripts.custDownloadCursor')
  4. A vital part of setting up for using Java synchronization logic is to establish a classpath to tell the virtual machine where to look for Java classes. There are two ways to do this:


Contents Index Introduction Running Java synchronization logic