UltraLite Static Java User's Guide
Adding Non Data Access Features to UltraLite Applications
Adding synchronization to your application
Monitoring and canceling synchronization
The class that implements UlSynchObserver, the UlSynchStatus object holds synchronization status information. This object is filled by UltraLite with synchronization status information each time your updateSynchronizationStatus method is called.
The UlSynchStatus object has the following methods:
int getState() int getTableCount() int getTableIndex() Object getUserData() UlSynchOptions getSynchOptions() UlSqlStmt getStatement() int getErrorCode() boolean isOKToContinue() void cancelSynchronization()
getState One of the following states:
STARTING No synchronization actions have yet been taken.
CONNECTING The synchronization stream has been built, but not yet opened.
SENDING_HEADER The synchronization stream has been opened, and the header is about to be sent.
SENDING_TABLE A table is being sent.
UL_SYNCH_STATE_SENDING_DATA Schema information or data is being sent.
UL_SYNCH_STATE_FINISHING_UPLOAD The upload stage is completed and a commit is being carried out.
RECEIVING_UPLOAD_ACK An acknowledgement that the upload is complete is being received.
RECEIVING_TABLE A table is being received.
UL_SYNCH_STATE_SENDING_DATA Schema information or data is being received.
UL_SYNCH_STATE_COMMITTING_DOWNLOAD The download stage is completed and a commit is being carried out.
SENDING_DOWNLOAD_ACK An acknowledgement that download is complete is being sent.
DISCONNECTING The synchronization stream is about to be closed.
DONE Synchronization has completed successfully.
ERROR Synchronization has completed, but with an error.
For a description of the synchronization process, see The synchronization process.
getTableCount Returns the number of tables being synchronized. For each table there is a sending and receiving phase, so this number may be more than the number of tables being synchronized.
getTableIndex The current table which is being uploaded or downloaded, starting at 0. This number may skip values when not all tables are being synchronized.
getSynchOptions Returns the UlSynchOptions object.
sent.inserts The number of inserted rows that have been uploaded so far.
sent.updates The number of updated rows that have been uploaded so far.
sent.deletes The number of deleted rows that have been uploaded so far.
sent.bytes The number of bytes that have been uploaded so far.
received.inserts The number of inserted rows that have been downloaded so far.
received.updates The number of updated rows that have been downloaded so far.
received.deletes The number of deleted rows that have been downloaded so far.
received.bytes The number of bytes that have been downloaded so far.
cancelSynchronization Set this member to true to interrupt the synchronization. The SQL exception SQLE_INTERRUPTED is set, and the synchronization stops as if a communications error had occurred. The observer is always called with either the DONE or ERROR state so that it can do proper cleanup.
getUserData Returns the user data object.
getStatement Returns the statement that called the synchronization. The statement is an internal UltraLite statement, and this method is unlikely to be of practical use, but is included for completion.
getErrorCode When the synchronization state is set to ERROR, this method returns a diagnostic error code.
isOKToContinue This is set to false when cancelSynchronization is called. Otherwise, it is true.
The following code illustrates a very simple observer function:
void updateSynchronizationStatus( UlSynchStatus status ) { int state = status.getState(); System.out.println( "Sync status: " + state ); if( state == UlSynchStatus.SENDING_TABLE || state == UlSynchStatus.RECEIVING_TABLE ){ System.out.println( "send/receive table " + ( status.getTableIndex() + 1 ) + " of " + status.getTableCount() ); } }
An example of an observer function is included in the CustDB sample application. The implementation in CustDB provides a dialog that displays synchronization progress and allows the user to cancel synchronization. The user-interface component makes the observer function platform specific.
The CustDB sample code is in the Samples\UltraLite\CustDB subdirectory of your SQL Anywhere directory. The observer function is contained in the platform-specific subdirectories of the CustDB directory.