Encapsulates information for one download table for a synchronization.
public interface DownloadTableData
All members of DownloadTableData interface, including all inherited members.
Name | Description |
---|---|
Returns a java.sql.PreparedStatement instance that allows the user to add delete operations to the download. | |
Returns last download time for this table. | |
Gets the metadata for the DownloadTableData instance. | |
Returns the table name for the DownloadTableData instance. | |
Returns a java.sql.PreparedStatement instance which allows the user to add upsert (insert or update) operations to the download of a synchronization. |
Use this interface to set the data operations that are downloaded to the client.
You can use the DownloadData interface to obtain DownloadTableData instances for the current synchronization. You can use the getUpsertPreparedStatement and getDeletePreparedStatement methods to obtain Java prepared statements for insert and update, and delete operations, respectively.
You can execute delete statement with all primary keys set to null to have the remote client truncate the table.
The java.sql.PreparedStatement.executeUpdate method registers an operation for download. Consult your Java Software Development Kit documentation for more information about java.sql.PreparedStatement.
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.
For more information about direct row handling, see Direct row handling.
This example assumes that you have a table named remoteOrders in the MobiLink client databases that was created using the following SQL statement:
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. 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 GetUpsertCommand to obtain a command for the rows you want to insert or update. The IDbCommand holds the parameters that you set to the values you want inserted on 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
getLastDownloadTime method
getMetaData method
getName method
getUpsertPreparedStatement method
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |