RemoteDataAdapter

Overview

The RemoteDataAdapter component provides client-side access to a set of data tables published on the server. It encapsulates all the information needed to communicate with the server (via a Remote Service) and to encode and decode data for the wire via a Data Streamer.

Creation

Create an instance of RemoteDataAdapter before actually getting the data from the server.

New API:

var rda = new RemObjects.DataAbstract.RemoteDataAdapter("http://" + window.location.host + "/JSON");
//Defautls are:
//data service name = "DataService"
//login service name = "LoginService"
//sreamer class = Bin2DataStreamer
var rda = new RemObjects.DataAbstract.RemoteDataAdapter("http://" + window.location.host + "/JSON", "MyDataService", "MyLoginService", RemObjects.DataAbstract.JSONDataStreamer);

Old API:

var channel = new RemObjects.SDK.HTTPClientChannel("http://" + window.location.host + "/JSON");
var message = new RemObjects.SDK.JSONMessage();
var service = new RemObjects.SDK.RemoteService(channel, message, "DASampleService");
var loginService = new RemObjects.SDK.RemoteService(channel, message, "LoginService");
var rda = new RemObjects.DataAbstract.RemoteDataAdapter(service, loginService, RemObjects.DataAbstract.Bin2DataStreamer);

Retrieving the data

var workersTable = new RemObjects.DataAbstract.DataTable("workers");

rda.getData([workersTable], RemObjects.DataAbstract.Util.createRequestInfo(true, -1, `, []), function() {
    alert("Table Workers has " workersTable.rows.length + " records";
}, RemObjects.UTIL.showError);

Updating the data

workersTable.first();
workersTable.setFieldValue("FirstName", "John");

rda.applyUpdates([workersTable], function() {
    alert("Updated successfully";
}, RemObjects.UTIL.showError);

DA SQL

var workersTable = new RemObjects.DataAbstract.DataTable("workers");

rda.getSQLData(workersTable, "select * from workers where name ='John'", function() {
    if (workersTable.rows.length > 0) 
        alert("found!")
    else
        alert("not found");
}, RemObjects.UTIL.showError);

Please note that getSQLData can accept TableRequestInfoV6 as a second parameter where you can set SQL query and params.

var userTable = new RemObjects.DataAbstract.DataTable("");
var param = new DataParameter();
param.Name.value = "p_name";
param.Value.value = "John Smith";
adapter.getSQLData(userTable,
    RemObjects.DataAbstract.Util.createRequestInfoV6("select id from users where displayname = :p_name", -1, "", [param]),
    function () {
        userTable.first();
        alert(userTable.getFieldValue("id"));
}, RemObjects.UTIL.showError);

Location

DataAbstract.js


Instance Methods


constructor RemoteDataAdapter

Creates an instance.

function constructor RemoteDataAdapter(aURL, aDataServiceName, aLoginServiceName, aStreamerClass)

Parameters:

  • aURL: string
  • aDataServiceName: string
  • aLoginServiceName: string
  • aStreamerClass: class (RemObjects.DataAbstract.Bin2DataStreamer or RemObjects.DataAbstract.JSONDataStreamer)

applyUpdates

Applies cached updates to the server.

function applyUpdates(aTable, onSuccess, onError)

Parameters:

  • aTable: DataTable
  • onSuccess: function()
  • onError: function()

createStreamer

Used internally.

function createStreamer()

createTableFromSchema

Retrieves Schema from the server and fills table structure.

function createTableFromSchema(aTableName, aTable, aCallback)

Parameters:

  • aTableName: string
  • aTable: DataTable
  • aCallback: function()

executeCommand

function executeCommand(aName, aParameters, onSuccess, onError)

Parameters:

  • aName:
  • aParameters:
  • onSuccess:
  • onError:

getAutoGetScripts beta

Getter for fAutoGetScripts.

function getAutoGetScripts()

getData

Retrieves data from the server.

function getData(aTable, aRequestInfo, onSuccess, onError)

Parameters:

  • aTable: DataTable
  • aRequestInfo: TableRequestInfo
  • onSuccess: function()
  • onError: function(aMessage, anException)

getDataService

function getDataService()

getLoginService

function getLoginService()

getSchema

Retrieves Schema from the server.

function getSchema(aFilter, aCallback, onFailure)

Parameters:

  • aFilter: string
  • aCallback: function
  • onFailure: function

getSQLData

function getSQLData(aTable, aSQL, onSuccess, onError)

Parameters:

  • aTable:
  • aSQL:
  • onSuccess:
  • onError:

login

Logs into the server.

function login(aUserID, aPassword, aConnectionName, onSuccessFunction, onErrorFunction)

Parameters:

  • aUserID: string
  • aPassword: string
  • aConnectionName: string
  • onSuccessFunction: function
  • onErrorFunction: function

logout

function logout(onSuccessFunction, onErrorFunction)

Parameters:

  • onSuccessFunction:
  • onErrorFunction:

onChangeFail

function Assign onChangeFail handler to process applyUpdates failures.

function onChangeFail(aData)

Parameters:

  • aData: change data

onLoginNeeded

Initially holds a stub. Assign this property with a function that performs actual login. Example:

adapter.onLoginNeeded = function (aCallback) { 
    this.login("John", "John", function(msg) {
        if (aCallback)
                aCallback();
    }, RemObjects.UTIL.showError);
}
function onLoginNeeded(aCallback)

Parameters:

  • aCallback: function

setAutoGetScripts beta

Setter for fAutoGetScripts.

function setAutoGetScripts(aValue)

Parameters:

  • aValue: boolean

setSendReducedDelta

sendReducedDelta setter.

function setSendReducedDelta(aValue)

Parameters:

  • aValue: boolean