To synchronize data, your application must perform the following steps:
Instantiate a syncParms object, which contains information about the consolidated database (name of the server, port number), name of the database to be synchronized, and the definition of the tables to be synchronized.
Call the synchronize method from the connection object with the syncParms object to carry out the synchronization.
The data to be synchronized can be defined at the table level. You cannot configure synchronization for portions of a table.
This example demonstrates how to synchronize data with an UltraLiteJ application.
To start the MobiLink server with SQL Anywhere 11 CustDB as the consolidated database, run start_ml.bat from the samples-dir\UltraLiteJ directory.
package ianywhere.ultralitej.demo; import ianywhere.ultralitej.*; /** * Sync: sample program to demonstrate Database synchronization. * * Requires starting the MobiLink Server Sample using start_ml.bat */ public class Sync { /** * mainline for program. * * @param args command-line arguments * */ public static void main ( String[] args ) { try { Configuration config = DatabaseManager.createConfigurationFile( "Demo1.ulj" ); Connection conn = DatabaseManager.createDatabase( config ); conn.schemaCreateBegin(); TableSchema table_schema = conn.createTable( "ULCustomer" ); table_schema.createColumn( "cust_id", Domain.INTEGER ); table_schema.createColumn( "cust_name", Domain.VARCHAR, 30 ); IndexSchema index_schema = table_schema.createPrimaryIndex( "prime_keys" ); index_schema.addColumn( "cust_id", IndexSchema.ASCENDING ); conn.schemaCreateComplete(); // // Synchronization // // Version set for MobiLink 11.0.x SyncParms syncParms = conn.createSyncParms( SyncParms.HTTP_STREAM, "50", "custdb 11.0" ); syncParms.getStreamParms().setPort( 9393 ); conn.synchronize( syncParms ); SyncResult result = syncParms.getSyncResult(); Demo.display( "*** Synchronized *** bytes sent=" + result.getSentByteCount() + ", bytes received=" + result.getReceivedByteCount() + ", rows received=" + result.getReceivedRowCount() ); conn.release(); } catch( ULjException exc ) { Demo.displayException( exc ); } } } |
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |