Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » MobiLink - Server Administration » Writing Synchronization Scripts in Java

Introduction to Java synchronization logic Next Page

Setting up Java synchronization logic


When you install SQL Anywhere, the installer automatically sets the location of the MobiLink server API for Java classes. When you start the MobiLink server, it automatically includes these classes in your classpath. The MobiLink server API for Java classes are installed to the java\mlscript.jar subdirectory of your SQL Anywhere installation.

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.

    See Methods.

    Each class with non-static methods should have a public constructor. The MobiLink server automatically instantiates each class the first time a method in that class is called.

    See Constructors.

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

    For example,

    javac MyClass.java -classpath "c:\Program Files\SQL Anywhere 10\java\mlscript.jar"
  3. In the MobiLink system tables on 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.

    For example, you can add this information to the MobiLink system tables using 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 a SQL 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 SQL Anywhere installation directories.

See also