Writing Synchronization Scripts in Java
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
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.
When compiling the class, you must include the JAR file java\mlscript.jar.
For example,
javac MyClass.java -classpath %ASANY9%\java\mlscript.jar
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:
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:
Use the dbmlsrv9 -sl java -cp option to specify a set of directories or jar files in which to search for classes. For example, at the command line, enter:
dbmlsrv9 -c "dsn=consolidated1" -sl java (-cp %classpath%;c:\local\Java\myclasses.jar)
The MobiLink synchronization server automatically appends the location of the MobiLink Java API classes (java\mlscript.jar) to the set of directories or jar files. The -sl java option also forces the Java VM to load on server startup.
For more information about the available Java options, see -sl java option.
Explicitly set the classpath. To set the classpath for user-defined classes, use a statement such as the following:
SET classpath=%classpath%;c:\local\Java\myclasses.jar
If your system classpath includes your Java synchronization logic classes, you do not need to make changes to your MobiLink synchronization server command line.
You can use the -sl java option to force the Java virtual machine to load at server startup. Otherwise, the Java virtual machine is started when the first Java method is executed.
For more information about the available Java options, see -sl java option.
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.
SQL Anywhere Studio 9.0.2
Copyright © 1989–2004 Sybase, Inc. Portions copyright © 2001–2004 iAnywhere Solutions, Inc. All rights reserved.