Index | OAT homepage | OpenLink Software

# OATDOCdatasource

- OATDOCdatasource
- _ _ datasource.js
- _ _ _ _ Objects
- _ _ _ _ _ _ OAT.DataSource(type)
- _ _ _ _ Properties
- _ _ _ _ _ _ OAT.DataSource::connection
- _ _ _ _ _ _ OAT.DataSource::options
- _ _ _ _ _ _ OAT.DataSource::outputFields
- _ _ _ _ Methods
- _ _ _ _ _ _ OAT.DataSource::bindRecord(recordCallback)
- _ _ _ _ _ _ OAT.DataSource::bindPage(pageCallback)
- _ _ _ _ _ _ OAT.DataSource::bindFile(fileCallback)
- _ _ _ _ _ _ OAT.DataSource::bindEmpty(emptyCallback)
- _ _ _ _ _ _ OAT.DataSource::bindHeader(headerCallback)
- _ _ _ _ _ _ OAT.DataSource::advanceRecord(recordIndex)
- _ _ _ _ Constants
- _ _ _ _ _ _ OAT.DataSourceData.TYPE_SQL
- _ _ _ _ _ _ OAT.DataSourceData.TYPE_SOAP
- _ _ _ _ _ _ OAT.DataSourceData.TYPE_REST
- _ _ _ _ _ _ OAT.DataSourceData.TYPE_SPARQL
- _ _ _ _ _ _ OAT.DataSourceData.TYPE_GDATA
- _ _ _ _ Examples
- _ _ _ _ _ _ REST Example
- _ _ _ _ _ _ SQL Example
- _ _ _ _ _ _ SPARQL Example
- _ _ _ _ _ _ GData Example

## datasource.js

Is an Ajax Database Connectivity (ADBC) layer. Provides data access support for various data sources (SQL, SPARQL, SOAP, etc.) and allows binding and execution of callbacks upon data arrival. Data are fetched on demand and cached.

### Objects

#### OAT.DataSource(type)

Creates new DataSource object. `type` is one of `TYPE_` constants.

### Properties

#### OAT.DataSource::connection

Assigns an `OAT.Connection` object to this DataSource .

#### OAT.DataSource::options

Object with various properties, dependent on DataSource `TYPE_` :

- `TYPE_SQL`
- `query` - SQL query
- `limit` - cursor limit
- `cursortype` - 0/1; 0 - snapshot, 1 - dynaset
- `TYPE_SOAP`
- `service` - name of WSDL service
- `rootelement` - name of root input WSDL element
- `inputobj` - input WSDL object (see ws.js documentation for details)
- `TYPE_REST` , `TYPE_SPARQL` , `TYPE_GDATA`
- `query` - HTTP GET querystring
- `output` - 0/1; 0 - xml, 1

json

- `xpath` - bool; how are outputFields specified? True

XPath expressions; False

node names

#### OAT.DataSource::outputFields

List of wanted fields in fetched data.

### Methods

#### OAT.DataSource::bindRecord(recordCallback)

Listens for new data records. When new record is available, `recordCallback` is executed with 2 arguments: `record data` and `record index` .

#### OAT.DataSource::bindPage(pageCallback)

Listens for new data record pages. When new data page (record set) is available, `pageCallback` is executed with 2 arguments: `page data` and `page index` .

#### OAT.DataSource::bindFile(fileCallback)

Listens for new data file. When new data file is available, `fileCallback` is executed with 1 argument: `file contents` .

#### OAT.DataSource::bindEmpty(emptyCallback)

Listens for empty dataset. When empty dataset arrives, `emptyCallback` is executed.

#### OAT.DataSource::bindHeader(headerCallback)

Listens for data header. When header arrives, `headerCallback` is executed with 1 argument: `data header` .

#### OAT.DataSource::advanceRecord(recordIndex)

Advances through records. `recordIndex` must be an integer.

### Constants

#### OAT.DataSourceData.TYPE_SQL

ToBeDone

#### OAT.DataSourceData.TYPE_SOAP

ToBeDone

#### OAT.DataSourceData.TYPE_REST

ToBeDone

#### OAT.DataSourceData.TYPE_SPARQL

ToBeDone

#### OAT.DataSourceData.TYPE_GDATA

ToBeDone

### Examples

#### REST Example

    var conn = new OAT.Connection(OAT.ConnectionData.TYPE_REST, {url:"myfile.xml"});

    var ds = new OAT.DataSource(OAT.DataSourceData.TYPE_REST);
    ds.connection = conn;
    ds.options.output = 0; /* fetch result as XML */
    ds.options.xpath = 1; /* outputFields are specified as XPATH expressions */
    ds.outputFields = ['//result/binding[@name="created"]/node()/text()',
                                            '//result/binding[@name="creator"]/node()/text()',
                                            '//result/binding[@name="item_title"]/node()/text()',
                                            '//result/binding[@name="url"]/node()/text()'];

    var recordCallback = function(data, index) {
            alert('Data at index ' + index + ':\n' + data );
    }
    ds.bindRecord(recordCallback);
    ds.advanceRecord(0);

#### SQL Example

    var conn = new OAT.Connection(OAT.ConnectionData.TYPE_XMLA, {dsn:"DSN=Local_Instance",endpoint:"/XMLA"});

    var ds = new OAT.DataSource(OAT.DataSourceData.TYPE_SQL);
    ds.connection = conn;
    ds.options.query = "SELECT OrderID, CustomerID, EmployeeID FROM Demo.demo.Orders";

    var recordCallback = function(data, index) {
            alert('Data at index ' + index + ':\n' + data );
    }
    ds.bindRecord(recordCallback);
    ds.advanceRecord(0);

#### SPARQL Example

    var connection = new OAT.Connection(OAT.ConnectionData.TYPE_REST,{url:"/sparql/"});
    var q = "SELECT ?s, ?p, ?o FROM <http://www.flickr.com/search/?q=rdf+semanticweb&s=rec> WHERE { ?s ?p ?o . }";

    var ds = new OAT.DataSource(OAT.DataSourceData.TYPE_SPARQL);
    ds.outputFields = ['//result/binding[@name="s"]/node()/text()',
       '//result/binding[@name="p"]/node()/text()',
       '//result/binding[@name="o"]/node()/text()'];

    ds.connection = connection;
    ds.options.query = "query="+encodeURIComponent(q)+"&format=xml";
    ds.options.output = 0; /* fetch result as XML */
    ds.options.xpath = 1; /* outputFields are specified as XPATH expressions */

    var recordCallback = function(data, index) {
            alert('Data at index ' + index + ':\n' + data );
    }
    ds.bindRecord(recordCallback);
    ds.advanceRecord(0);

#### GData Example

    var conn = new OAT.Connection(OAT.ConnectionData.TYPE_REST, {url:"gdata.xml"});

    var ds = new OAT.DataSource(OAT.DataSourceData.TYPE_GDATA);
    ds.connection = conn;
    ds.options.output = 0;
    ds.options.xpath = 1;
    ds.outputFields = [ "//atom:feed/atom:entry/atom:title" ];

    var recordCallback = function(data, index) {
            alert('Data at index ' + index + ':\n' + data );
    }

    ds.bindRecord(recordCallback);
    ds.advanceRecord(0);

Copyright (C) 2005-2008 OpenLink Software