Xplain.Db.Batch

Xplain.Db.Batch()

Xplain.Db.Batch is a singleton class that represents a Xplain batch. A batch enables you to add multiple requests and send them in a batch to the Xplain backend (improves performance). Basic idea to use a batch:

// assuming that query1 and query2 have been defined earlier as
// instance of Xplain.Db.Query
Xplain.Db.Batch.start();
query1.open();
query2.execute();
query1.close();
Xplain.Db.Batch.stop();
Xplain.Db.Batch.run({
    success: function(data) {
       // do something here...
    }
});

A batch is not limited to query operations. Basically, you can execute any Ajax request. Another example which uses the execute method:

  var s = new Xplain.Db.Session();
Xplain.Db.Batch.start();
s.execute({
     "method": "removeObject",
     "objectName": "Prescription"
});
s.execute({
     "method": "removeObject",
     "objectName": "Hospitalization"
});
Xplain.Db.Batch.stop();
Xplain.Db.Batch.run({
    success: function(data) {
       // do something here...
    }
});

NOTE: The success and / or error functions of the individual steps within the batch job are NOT executed. This is because the individual steps are not executed one after the other, but only a single request is sent to the backend. Instead, the success and / or error function specified under Xplain.Db.Batch.run({...}) is executed.

add

add(job)

Add a job/request to the list of requests. This enables you to use an alternative syntax. Instead of this…:

Xplain.Db.Batch.start();
query1.open();
query2.execute();
query1.close();
Xplain.Db.Batch.stop();
Xplain.Db.Batch.run({
    success: function(data) {
       // do something here...
    }
});

…you may prefer this style:

Xplain.Db.Batch.start();
Xplain.Db.Batch.add(query1.open());
Xplain.Db.Batch.add(query2.execute());
Xplain.Db.Batch.add(query1.close());
Xplain.Db.Batch.stop();
Xplain.Db.Batch.run({
    success: function(data) {
       // do something here...
    }
});

Apart from the syntactic difference, there are no other differences.

Parameters

job (Xplain.Db.*) – the job/request to add

getJobs

getJobs()

Returns an array of all jobs currently assigned to this batch job. @returns {Array}

isInBatchMode

isInBatchMode()

Returns true if batch mode is currently enabled, i.e. if queuing is active.

Returns

{boolean}

reset

reset()

Resets the batch job. This will delete all queued batch jobs recorded so far.

run

run([settings])

Executes all requests added to this batch so far.

Note: Unlike other methods, this method allows you to set the parameters syncType and returnType (which makes sense here, since the batch method does not know which methods are executed in which order). For a detailed explanation of these parameters, please refer to the Web API documentation.

Parameters
  • (optional) (string settings.syncType=null) – A set of key/value pairs that configure the batch request. All settings are optional. A default can be set using the Xplain.Db.Configuration.setDefaults() method.

  • (optional) – defines if the request sent to the backend should be asynchronous or synchronous.

  • (optional) – defines if the request should support CORS (note: the backend also has to enable CORS requests).

  • (optional) – The URL used for this request.

  • (optional) – number of milliseconds until a timeout will be triggered.

  • (optional) – function what will be triggered if the Xplain Data backend reports an HTTP Status Code 200. The first parameter passed to this function will be the result of the getData() method as defined in Xplain.Db.SessionData

  • (optional) – function what will be triggered if the Xplain Data backend reports anything but a HTTP Status Code 200. The first parameter passed to this function will be an instance of the data returned by the backend.

  • (optional) – The return-type as passed to the backend. If this is set to “none”, the backend executes the request normally, but no output is sent to the frontend. This increases performance accordingly.

  • (optional) – The sync-type as passed to the backend.

Returns

{null|Xplain.Db.SessionData} if async=false, this method will return an instance of Xplain.Db.SessionData.

start

start()

Starts the batch mode. After you call this method, all consecutive requests will be queued. Stop queuing request by calling the stop method.

stop

stop()

Stops the batch mode. After you call this method, queuing will be stopped.