Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Custom datasources allow you to interface data services with your own datasource implementation. There are two options for writing a custom datasource, and these two options cover most of the common business use cases as follows:

  • Custom tabular datasources: Used to represent data in tables, where a set of named tables contain data rows that can be queried later. 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. You can use the org.wso2.carbon.dataservices.core.custom.datasource.TabularDataBasedDS interface to implement tabular datasources. For a sample implementation of a tabular custom datasource, see InMemoryDataSource. Also, this is supported in Carbon datasources with the following datasource reader implementation: org.wso2.carbon.dataservices.core.custom.datasource.CustomTabularDataSourceReader.
  • Custom query datasources: Used when the datasource has some form of a query expression support. Custom query datasources are implemented using the org.wso2.carbon.dataservices.core.custom.datasource.CustomQueryBasedDS interface. You can create any non-tabular datasource using the query-based approach. Even if the target datasource does not have a query expression format, you can create your own. For example, you can support any NoSQL type datasource this way. For a sample implementation of a query-based custom datasource, see EchoDataSource. This is supported in Carbon datasources, with the following datasource reader implementation: org.wso2.carbon.dataservices.core.custom.datasource.CustomQueryDataSourceReader

InMemoryDSSample is a sample data service descriptor, which contains a custom tabular datasource as well as a custom query datasource. Also, you can find a sample of a Carbon datasource configuration in <PRODUCT_HOME>\repository\conf\datasources\custom-datasources.xml.

You can create a custom data source as you create your data service as shown below.

  1. Follow the steps from 1 to 3 in creating a data service using various data sources. When you get to the Add New Data Source screen, select Custom Data Source as the data source type. The custom datasource specific options will appear as shown below. 
  2. Select the type of custom datasource to create: "Custom Tabular Data Source" or "Custom Query Data Source".
  3. In the Custom Data Source Class field, specify the interface that implements the custom data source. See the following examples:
  4. Click Add New Property to enter the properties and values which constitutes the datasource. See the following examples:
    • Property details in a custom tabular datasource implementation:

      <property name="inmemory_datasource_schema">{Vehicles:[ID,Model,Classification,Year]}</property>
      <property name="inmemory_datasource_records">
              {Vehicles:[["S10_1678","Harley Davidson Ultimate Chopper","Motorcycles","1969"],
                                           ["S10_1949","Alpine Renault 1300","Classic Cars","1952"],
                                           ["S10_2016","Moto Guzzi 1100i","Motorcycles","1996"],
                                           ["S10_4698","Harley-Davidson Eagle Drag Bike","Motorcycles","2003"],
                                           ["S10_4757","Alfa Romeo GTA","Classic Cars","1972"],
                                           ["S10_4962","LanciaA Delta 16V","Classic Cars","1962"],
                                           ["S12_1099","Ford Mustang","Classic Cars","1968"],
                                           ["S12_1108","Ferrari Enzo","Classic Cars","2001"]]}
      </property>
    • Property details in a custom query datasource implementation:

      <property name="p1">val1</property>
      <property name="p2">val2</property>
    In the init methods of all custom datasources, user-supplied properties are parsed to initialize the datasource accordingly. Also, a property named __DATASOURCE_ID__, which contains a UUID to uniquely identify the current datasource, is passed. Custom datasource authors use this to identify the datasources accordingly. For example, scenarios like datasource instances communicating within a server cluster for data synchronisation.

Find the custom connectors used in WSO2 DSS from the github project located at https://github.com/wso2/wso2-dss-connectors.

To write a query to this datasource, see Writing Data Service Queries.

  • No labels