由直接行处理使用的非 SQL 数据脚本,用来创建一组要下载的行。
无。
无。
handle_DownloadData 事件允许您确定使用直接行处理将哪些操作下载到 MobiLink 客户端。
直接行处理用于对 MobiLink 支持的统一数据库以外的数据源进行同步。 请参见直接行处理。
要创建直接下载,可以使用面向 Java 或 .NET 的 MobiLink 服务器 API 中的 DownloadData 和 DownloadTableData 类。
对于 Java,DBConnectionContext getDownloadData 方法返回当前同步的 DownloadData 实例。DownloadData 封装发送到远程客户端的所有下载操作。可以使用 DownloadData getDownloadTables 和 getDownloadTableByName 方法获得 DownloadTableData 实例。DownloadTableData 封装特定表的下载操作。可以使用 getUpsertPreparedStatement 方法获得插入和更新操作的准备语句。可以使用 DownloadTableData getDeletePreparedStatement 方法获得删除操作的准备语句。
对于 .NET,DBConnectionContext GetDownloadData 方法返回当前同步的 DownloadData 实例。DownloadData 封装发送到远程客户端的所有下载操作。可以使用 DownloadData GetDownloadTables 和 GetDownloadTableByName 方法获得 DownloadTableData 实例。DownloadTableData 封装特定表的下载操作。可以使用 GetUpsertCommand 方法获得插入和更新操作的命令。可以使用 DownloadTableData getDeleteCommand 方法获得删除操作的命令。
对于 Java,请参见DBConnectionContext 接口 [MobiLink 服务器 Java]。
对于 .NET,请参见DBConnectionContext 接口 [MobiLink 服务器 .NET]。
可以在 handle_DownloadData 或其它同步事件中创建下载。MobiLink 提供这种灵活性,使您可以在上载数据或发生特定事件时设置下载。要在 handle_DownloadData 以外的事件中创建直接下载,则必须创建一个方法不执行任何操作的 handle_DownloadData 脚本。除仅上载同步的情况外,MobiLink 服务器需要至少定义一个 handle_DownloadData 脚本以启用下载的直接行处理。
如果在 handle_DownloadData 以外的事件中创建直接下载,则该事件不得在 begin_synchronization 事件之前,也不得在 end_download 事件之后。
此事件不能作为 SQL 实现。
以下对 MobiLink 系统过程的调用在同步脚本版本 ver1 时,为 handle_DownloadData 连接事件注册名为 handleDownload 的 Java 方法。针对您的 MobiLink 统一数据库运行此系统过程。
CALL ml_add_java_connection_script( 'ver1', 'handle_DownloadData', 'MyPackage.MobiLinkOrders.handleDownload' ) |
请参见ml_add_java_connection_script 系统过程。
以下示例显示如何使用 handleDownload 方法创建下载。
以下代码在名为 MobiLinkOrders 的类的构造函数中建立了一个类级别 DBConnectionContext 实例。
import ianywhere.ml.script.*; import java.io.*; import java.sql.*; import java.lang.System; public class MobiLinkOrders{ DBConnectionContext _cc; public MobiLinkOrders( DBConnectionContext cc ) { _cc = cc; }} |
在您的 HandleDownload 方法中,您使用 DBConnectionContext getDownloadData 方法返回当前同步的 DownloadData 实例。DownloadData getDownloadTableByName 方法返回 remoteOrders 表的 DownloadTableData 实例。DownloadTableData getUpsertPreparedStatement 方法返回一个 java.sql.PreparedStatement。要将某个操作添加到下载,需要设置所有列值并调用 executeUpdate 方法。
以下是 MobiLinkOrders 类的 handleDownload 方法。它将名为 remoteOrders 的表中的两行添加到下载。
// Method used for the handle_DownloadData event. public void handleDownload() throws SQLException { // Get DownloadData instance for current synchronization. DownloadData downloadData = _cc.getDownloadData(); // Get a DownloadTableData instance for the remoteOrders table. DownloadTableData td = downloadData.getDownloadTableByName("remoteOrders"); // Get a java.sql.PreparedStatement for upsert (update/insert) operations. PreparedStatement upsertPS = td.getUpsertPreparedStatement(); // Set values for one row. upsertPS.setInt( 1, 2300 ); upsertPS.setInt( 2, 100 ); // Add the values to the download. int updateResult = upsertPS.executeUpdate(); // Set values for another row. upsertPS.setInt( 1, 2301 ); upsertPS.setInt( 2, 50 ); updateResult = upsertPS.executeUpdate(); // ... upsertPS.close(); } |
以下对 MobiLink 系统过程的调用在同步脚本版本 ver1 时将名为 HandleDownload 的 .NET 方法注册为 handle_DownloadData 连接事件的脚本。此语法用于 SQL Anywhere 统一数据库。
CALL ml_add_dnet_connection_script( 'ver1', 'handle_DownloadData', 'TestScripts.MobiLinkOrders.HandleDownload' ) |
以下是 .NET 方法 HandleDownload 示例:
using System; using System.Data; using System.IO; using iAnywhere.MobiLink.Script; using iAnywhere.MobiLink; namespace MyScripts { /// <summary> /// Tests that scripts are called correctly for most sync events. /// </summary> public class MobiLinkOrders { private DBConnectionContext _cc; public MobiLinkOrders( DBConnectionContext cc ) { _cc = cc; } ~MobiLinkOrders() { } public void handleDownload() { // Get DownloadData instance for current synchronization. DownloadData my_dd = _cc.GetDownloadData(); // Get a DownloadTableData instance for the remoteOrders table. DownloadTableData td = my_dd.GetDownloadTableByName("remoteOrders"); // Get an IDbCommand for upsert (update/insert) operations. IDbCommand upsert_stmt = td.GetUpsertCommand(); IDataParameterCollection parameters = upsert_stmt.Parameters; // Set values for one row. parameters[ 0 ] = 2300; parameters[ 1 ] = 100; // Add the values to the download. int update_result = upsert_stmt.ExecuteNonQuery(); // Set values for another row. parameters[ 0 ] = 2301; parameters[ 1 ] = 50; update_result = upsert_stmt.ExecuteNonQuery(); // ... } } } |
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2013, SAP 股份公司或其关联公司. - SAP Sybase SQL Anywhere 16.0 |