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

SQL Anywhere 11.0.1 (Français) » MobiLink - Server Administration » MobiLink Server APIs » Writing synchronization scripts in Java » MobiLink server API for Java reference

 

DownloadTableData interface

Syntax
public ianywhere.ml.script.DownloadTableData
Remarks

Encapsulates table operations for MobiLink direct downloads. Use this interface to set the data operations that are downloaded to the client. To obtain DownloadTableData instances for the current synchronization, use the DownloadData interface. You can use the DownloadTableData.getUpsertPreparedStatement and getDeletePreparedStatement methods to obtain Java prepared statements for insert and update, and delete operations, respectively. The java.sql.PreparedStatement.executeUpdate method registers an operation for download.

Note

You must set all column values for insert and update prepared statements. For delete operations you set primary key values.

You cannot have both the delete and upsert prepared statements open at the same time.

Consult your Java SDK documentation for more information about java.sql.PreparedStatement.

See also
Members

All members of ianywhere.ml.script.DownloadTableData, including all inherited members.

Example

Assume you use a table called remoteOrders in MobiLink client databases.

CREATE TABLE remoteOrders (
    pk INT NOT NULL,
    col1 VARCHAR(200),
    PRIMARY KEY (pk)
);

The following example uses the DownloadData.getDownloadTableByName method to return a DownloadTableData instance representing the remoteOrders table.

Note

This example assumes you have a DBConnectionContext instance called _cc.

// The method used for the handle_DownloadData event
public void handleDownload() throws SQLException {

    // Get the DownloadData for the current synchronization.
    DownloadData my_dd = _cc.getDownloadData();
 
    // Get the DownloadTableData for the remoteOrders table.
    DownloadTableData td = my_dd.getDownloadTableByName("remoteOrders");

    // User defined-methods to set download operations.
    setDownloadInserts(td);
    setDownloadDeletes(td); 

    // ... 
}

In this example, the setDownloadInserts method uses the DownloadTableData.getUpsertPreparedStatement to obtain a prepared statement for rows you want to insert or update. The PreparedStatement.setInt and PreparedStatement.setString methods set the column values you want to insert into the remote database.

void setDownloadInserts(DownloadTableData td) { 
    java.sql.PreparedStatement insert_ps = td.getUpsertPreparedStatement();

    // The following method calls are the same as the following SQL statement:
    // INSERT INTO remoteOrders(pk, col1) values(2300, "truck");
    insert_ps.setInt(1, 2300); 
    insert_ps.setString(2, "truck");

    int update_result = insert_ps.executeUpdate();
    if (update_result == 0) {
        // Insert was filtered because it was uploaded
        // in the same synchronization.
    } 
    else {
        // Insert was not filtered.
    }
}

The setDownloadDeletes method uses the DownloadTableData.getDeletePreparedStatement to obtain a prepared statement for rows you want to delete. The java.sql.PreparedStatement.setInt method sets the primary key values for rows you want to delete in the remote database and the java.sql.PreparedStatement.executeUpdate method registers the row values for download.

void setDownloadDeletes(DownloadTableData td) { 
    java.sql.PreparedStatement delete_ps = td.getDeletePreparedStatement();

    // The following method calls are the same as the following SQL statement:
    // DELETE FROM remoteOrders  where pk=2300;
    delete_ps.setInt(1, 2300); 
    delete_ps.executeUpdate();
}

getDeletePreparedStatement method
getUpsertPreparedStatement method
getName method
getMetaData method
getLastDownloadTime method