Collection Contents Previous Next PDF

MobiLink Administration 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 ASANYSH9 environment variable 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.

    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 synchronization script. One class is permitted per script version.

    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.

    For example, the following SQL statement, when run in an Adaptive Server Anywhere database, specifies that for the script version ver1, myPackage.myClass.myMethod should be run whenever the authenticate_user connection-level event occurs. The method that is specified must be the fully qualified name of a public Java method, and the name is case sensitive.

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

    For more information about adding scripts, see:

  4. Instruct the MobiLink server to load classes. A vital part of setting up Java synchronization logic is to tell the virtual machine where to look for Java classes. There are two ways to do this:

  5. On UNIX, if you want to load a specific JRE, you should set the LD_LIBRARY_PATH (LIBPATH on AIX, SHLIB_PATH on HP-UX) to include the directory containing the JRE. The directory must be listed before any of the Adaptive Server Anywhere install directories.


Collection Contents Previous Next PDF