Xplain.Db.Connection

Xplain.Db.Connection()

This class provides methods to connect to a Xplain Data database.

connect

connect([conf][, conf.configuration][, conf.async=true][, conf.cors=false][, conf.url='/'][, conf.timeout=15000][, conf.success=f(data){}][, conf.error=f(data){throw new Xplain.Db.Exception}])

Performs a login. If a configuration (aka xstartup) is being specified, it automatically loads this configuration. Depending on whether you use async requests or not, this function triggers either a callback function (loginErrorCallback or loginSuccessCallback) or waits until the request finished. If async is set to false, use the return value of login() or use isConnected() after login() to check if login was successful or not.

You might want to set some configuration defaults first. For instance, you could connect to an Xplain Data instance using something like this:

 Xplain.Db.Configuration.setDefaults({
    timeout: 30000,
    url: "myhost:8080",
    async: true,
    error: function(d) {
       alert('...ooops. Something went wrong');
    }
 });

 let conn = new Xplain.Db.Connection();
 conn.connect({
    user: "myuser",
    password: "mypassword",
    configuration: "test.xstartup",
    success: function(d) {
       alert("connected");
    },
    error: function(d) {
       alert("error");
    }
});
Parameters
  • (optional) (function conf.error=f(data){throw new Xplain.Db.Exception}) – A set of key/value pairs that configure the login request. All settings except user, password and configuration are optional. A default can be set using the Xplain.Db.Configuration.setDefaults() method.

  • (optional) – The name of the xstartup file used during this session.

  • (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 base 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 an instance of the data returned by the backend.

  • (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. will be returned. False if login was not successful and async is set to false. No return value if async is set to true.

Returns

{Xplain.Db.Session} if login was successful and async is set to false an instance of Xplain.Db.Session

fetchConfigurationsAvailable

fetchConfigurationsAvailable([conf][, conf.async=true][, conf.cors=false][, conf.url='/'][, conf.timeout=15000][, conf.success=f(data){}][, conf.error=f(data){throw new Xplain.Db.Exception}])

Fetches all available configurations from the backend. If used in async mode, you may provide a success and/or error callback function (the parameter passed to the success callback is an array of all available configurations). If used in sync mode, this method will return an array of all available configurations. In both cases (async and ``sync mode) you may use the getConfigurations() method later on to get all available configurations.

Parameters
  • (optional) (function conf.error=f(data){throw new Xplain.Db.Exception}) – A set of key/value pairs that configure the open 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 an array of available configuration files, i.e. an array of strings.

  • (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.

Returns

{array} if async=false, this method will return an array of strings (array of available configurations). If async=true, use the first parameter passed to the success function or use the this.getConfigurations() method of this class.

getConfigurations

getConfigurations()

Returns all configurations fetched by fetchConfigurationsAvailable() method.

Returns

{Array} an array of strings

getSession

getSession()

Returns the session for this connection

Returns

{Xplain.Db.Session} the session for this connection

isConnected

isConnected([conf][, conf.cors=false][, conf.url='/'][, conf.timeout=15000][, conf.success=f(data){}][, conf.error=f(data){throw new Xplain.Db.Exception}])

Check if connection has been established or not. NOTE: This is the only XplainDB ajax method that always runs synchronous (ignoring whatever you set as default using Xplain.Db.Configuration).

Parameters
  • (optional) (function conf.error=f(data){throw new Xplain.Db.Exception}) – A set of key/value pairs that configure the isConnected request. All settings are optional. A default can be set using the Xplain.Db.Configuration.setDefaults() method. Please not that currently, this request is ALWAYS set to synchronous, i.e. async:false.

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

  • (optional) – The base 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 an instance of the data returned by the backend.

  • (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.

Returns

{boolean} true if connected to Xplain Data server. False otherwise.

loadConfiguration

loadConfiguration([conf][, conf.async=true][, conf.cors=false][, conf.url='/'][, conf.timeout=15000][, conf.success=f(data){}][, conf.error=f(data){throw new Xplain.Db.Exception}])

Loads a configuration (aka xstartup). You only need to call this method if you call the connect method without a value for the configuration parameterPerforms a login.

Parameters
  • (optional) (function conf.error=f(data){throw new Xplain.Db.Exception}) – A set of key/value pairs that configure the login request. All settings except user, password and configuration 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 base 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 an instance of the data returned by the backend.

  • (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. will be returned. False if login was not successful and async is set to false. No return value if async is set to true.

Returns

{Xplain.Db.Session} if login was successful and async is set to false an instance of Xplain.Db.Session

logout

logout([conf][, conf.async=true][, conf.cors=false][, conf.url='/'][, conf.timeout=15000][, conf.success=f(data){}][, conf.error=f(data){throw new Xplain.Db.Exception}])

Performs a logout. Depending on whether you use async requests or not, this function triggers either a callback function (logoutErrorCallback or logoutSuccessCallback) or waits until the request finished. If async is set to false, use the return value of logout() or use isConnected() after logout() to check if logout was successful or not.

Parameters
  • (optional) (function conf.error=f(data){throw new Xplain.Db.Exception}) – A set of key/value pairs that configure the logout 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 base 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 an instance of the data returned by the backend.

  • (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.

Returns

{boolean} true if logout was successful and async is set to false. False if logout was successful and async is set to false. No return value if async is set to true.