Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 AnchorCusDSTypeCusDSTypeThe actual type of the custom datasource can be either DS_CUSTOM_TABULAR or DS_CUSTOM_QUERY. There are two options

    This topic explains the purpose of using custom datasources and how you can define custom datasource implementations using the management console. Alternatively, you can simply create datasources using the default RDBMS configuration provided in WSO2 products.

    Table of Contents
    maxLevel3
    minLevel3

    About custom datasources

    Custom datasources allows you to define 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  Tabular datasources are used to connect to a source that represents its data using
    • datasources: Used to represent data in tables, where a set of named tables
    contains
    • contain 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
    •  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 .An example configuration datasource of type DS_CUSTOM_TABULAR is shown below:

    Image Removed

    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
    • .datasource.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 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
    and add it. This type of a datasource supports any NoSQL source of data.Custom query datasources are implemented using the interface 
    • . For example, you can support any NoSQL type datasource this way.  For a sample implementation of a query-based custom datasource, see org.wso2.carbon.dataservices.core.custom.datasource.EchoDataSource. This is supported in Carbon datasources with the following datasource reader implementation:  org.wso2.carbon.dataservices.core.custom.datasource.CustomQueryDataSourceReader. 

    Creating custom datasources

    You can create custom data sources as shown below.

    1. Go to the Configure tab on the management console and click Data Sources to open the Data Sources screen.
    2. Then click Add Data Source. The following screen will open:
      Image Added
    3. Enter "Custom" as the datasource
    .CustomQueryBasedDS. See EchoDataSource for a sample implementation. See InMemoryDSSample for a sample data service descriptor with custom query datasources.  In the init methods
    1. type.
    2. In the Custom Data Source Type field, enter "DS_CUSTOM_TABULAR" (to store data in tables) or "DS_CUSTOM_QUERY" (to store non-tabular data accessed through a query).
    3. In the Name and Description fields, enter a unique name for the datasource.
    4. In the Configuration section, specify the xml configuration of the datasource. See the examples given below.
      • XML configuration for a custom tabular datasource (DS_CUSTOM_TABULAR type):

        Code Block
        <configuration>
        	<customDataSourceClass>org.wso2.carbon.dataservices.core.custom.datasource.InMemoryDataSource</customDataSourceClass>
        	 <customDataSourceProps>
              <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>
            </customDataSourceProps>
        </configuration>
      • XML configuration for a custom query datasource (DS_CUSTOM_QUERY):

        Code Block
        <configuration>
        	<customDataSourceClass>org.wso2.carbon.dataservices.core.custom.datasource.EchoDataSource</customDataSourceClass>
            	<customDataSourceProps>
                    <property name="p1">val1</property>
                    <property name="p2">val2</property>
                </customDataSourceProps>
        </configuration>

    In the "init" methods of all custom datasources, user-

    specified

    supplied properties

    are

    will be parsed to initialize the

    datasources

    datasource accordingly.

    In addition

    Also, a property

    named 

    named "__DATASOURCE_ID__", which contains a UUID to uniquely identify the current datasource,

    is

    will be passed.

    Custom

    This can be used by custom datasource authors

    use this property

    to identify the datasources

    . For example, in situations where

    accordingly, such as datasource instances

    communicate

    communicating within a server cluster for data synchronization.

    After creating datasources, they appear on the Data Sources page. You can edit and delete them as needed by clicking the Edit or Delete links.