A datasource is a connection set up to a storage of data, such as a database or a data file, from a server. You can create a custom datasource as follows.
- Log in to the product's management console and select Datasources sub menu from the Configure menu.
- Click Add Datasource.
- The New Datasource page opens. Select Custom as the datasource type, provide a unique name, a description and configure the rest of the fields using the information below:
- Custom Datasource Type : See below
- Configuration : XML configuration of the datasource
Custom datasource type
The actual type of the custom datasource can be either DS_CUSTOM_TABULAR
or DS_CUSTOM_QUERY
. There are two options cover most of the common business use cases.
Custom tabular datasources
Tabular datasources are used to connect to a source that represents its data using tables, where a set of named tables contains data rows that can be queried later. Tabular datasources are implemented using the interface org.wso2.carbon.dataservices.core.custom.datasource.TabularDataBasedDS
. See InMemoryDataSource
for a sample implementation of tabular custom datasources.
A tabular datasource is typically associated with an SQL data services query. This is done by internally using our own SQL parser to execute SQL against the custom datasource. See InMemoryDSSample
for a sample implementation.
An example configuration of a custom datasource of type DS_CUSTOM_TABULAR
is shown below:
Custom query datasources
Custom query datasources are used to connect to a source of non-tabular data that has query expression support. Even if the target data source does not have a query expression format, you can create your own and add it. This type of a datasource supports any NoSQL source of data.
Custom query datasources are implemented using the interface org.wso2.carbon.dataservices.core.custom.datasource.CustomQueryBasedDS
. See EchoDataSource
for a sample implementation. See InMemoryDSSample
for a sample data service descriptor with custom query datasources.
In the init
methods of all custom datasources, user-specified properties are parsed to initialize the datasources accordingly. In addition, a property named __DATASOURCE_ID__
, which contains a UUID to uniquely identify the current datasource, is passed. Custom datasource authors use this property to identify the datasources. For example, in situations where datasource instances communicate within a server cluster for data synchronization.