Custom Data Sources
Follow the instructions below to create a custom data source using the management console.
1. Log on to the product's management console and select "Data Services -> Create" under the "Main" menu.
2. The "Create Data Service" page appears. Fill in the fields and click "Next" . The Data Service name is mandatory.
Note
For more information on advanced configurations, refer to Advanced Data Service Configurations.
3. The "Data Sources" page appears. Click on the "Add New Data Source" link and add the data source details. Select the data source type as "Custom".
Custom data source support helps interface data services with any data source type available. There are two options in writing a custom data source and these two options cover most of the common business use cases:
Custom Tabular Data Sources
Tabular data sources are used when there is a data source which represents its data using tables, where a set of named tables contains data rows that can be queried later.
To implement tabular data sources, the interface "org.wso2.carbon.dataservices.core.custom.datasource.TabularDataBasedDS" is used. A sample implementation of tabular custom data source can be found at InMemoryDataSource.
A tabular data source 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 data source. A sample data service descriptor on how this is done can be found at InMemoryDSSample. Also, this is supported in Carbon data sources, with the data source reader implementation "org.wso2.carbon.dataservices.core.custom.datasource.CustomTabularDataSourceReader". A sample Carbon data source configuration file can be found at <CARBON_HOME>\repository\conf\datasources\custom-datasources.xml.
Custom Query Data Sources
Custom query based data sources are created when there is a data source which has some form of a query expression support.
To implement , the interface "org.wso2.carbon.dataservices.core.custom.datasource.CustomQueryBasedDS" is used. Any non-tabular data source can be created using the query-based approach. Even if the target data source does not have a query expression format, users can create their own and it. For example, any NoSQL type data source can be supported using this type of a data source.
A sample implementation of a query-based custom data source can be seen at EchoDataSource. A sample data service descriptor with custom query data sources can be found in action in InMemoryDSSample. This is supported in Carbon data sources, with the data source reader implementation org.wso2.carbon.dataservices.core.custom.datasource.CustomQueryDataSourceReader. A sample of a Carbon data source configuration file can be found at <CARBON_HOME>\repository\conf\datasources\custom-datasources.xml.
In the "init" methods of all custom data sources, user-supplied properties will be parsed to initialize the data source accordingly. Also, a property named "__DATASOURCE_ID__", which contains a UUID to uniquely identify the current data source, will be passed. This can be used by custom data source authors to identify the data sources accordingly. For example, scenarios like data source instances communicating within a server cluster for data synchronization.