Due to a known issue do not use JDK1.8.0_151 with WSO2 products. Use JDK 1.8.0_144 until JDK 1.8.0_162-ea is released.
This documentation is for WSO2 Data Services Server version 3.5.1. For the latest documentation, see the documentation for WSO2 Enterprise Integrator.
Skip to end of metadata
Go to start of metadata

This option helps create data services automatically using a given database structure. When generating a data service, the server takes its table structure according to the structure specified in the datasource and automatically creates the SELECT, INSERT, UPDATE and DELETE operations. 

Step 1: Setting up a datasource

Follow the steps given below to set up a MySQL database for this tutorial.

  1. Install the MySQL server.
  2. Download the JDBC driver for MySQL from here and copy it to your <DSS_HOME>/repository/components/lib directory.
  3. Create the following database: AccountDetails
  4. Create the following table:

    CREATE TABLE ACCOUNT(AccountID int NOT NULL,Branch varchar(255) NOT NULL, AccountNumber varchar(255),AccountType ENUM('CURRENT', 'SAVINGS') NOT NULL,
    Balance FLOAT,ModifiedDate DATE,PRIMARY KEY (AccountID)); 
  5. Enter the following data into the table:

    INSERT INTO ACCOUNT VALUES (1,"AOB","A00012","CURRENT",231221,'2014-12-02');

Step 2: Creating a Carbon datasource

WSO2 Data Services Server comes with the datasource management feature, which allows users to create any RDBMS datasource or custom datasource that is used by the server to connect to databases or external data stores. See Managing Datasources in the WSO2 Administration Guide for instructions on how to use this feature. Note that these pre-defined datasources can also be added to a data service as Carbon datasources.

Follow the steps given below.

  1. Log into the management console of WSO2 DSS and click Datasources in the Configure tab. This will open the Datasources screen.
  2. Click Add Datasource and enter the following details corresponding to the 'AccountDetails' database:
  3. Save the datasource.

Step 3: Generating a data service

Once the datasource is created, follow the steps below to generate a data service.

  1. In the Carbon Datasource field, select a datasource from the drop down list.
  2. In the Database Name field, give the name of the database that you created. 

    Note that in most cases the database name should be the same name used when creating the datasource. If you want to find the database name for the datasource you selected in step 2 above, go to the Configure tab and click Datasources in the navigator. You can then get the details (including the database name) of a datasource by clicking View.

    However, some datasources such as Oracle and H2 may not require the exact database name.

  3. Click Next to open the Customize Service Generation screen. The tables in the AccountDetails database will be listed. We only have one table (ACCOUNT) in the database as shown below.
  4. Select the ACCOUNT table and click Next to open the Service Generation screen.
  5. You must select a service generation mode from the following two options:
    • Single Service: Creates a single data service for operations of all tables. 
    • Multiple Services: Creates a service per table, which will contain isolated operations for each table. This is only applicable if you have selected multiple tables in the previous step.
  6. Click Next to open the Generated Services screen. A data service by the name of ACCOUNT_DataService is now generated.
  7. Click Finish to complete the data service creation process.  You will now be taken to the Deployed Services screen, which shows all the data services deployed on the server.

Step 4: Verify the generated CRUD operations (Optional)

You can verify that the relevant queries and CRUD operations are generated accurately:

  1. Click the ACCOUNT_DataService service to open the service dashboard.
  2. Click Edit Data Service to open the service in the Create New Data Service wizard.
  3. Click Next until you get to the Queries screen. See the queries corresponding to CRUD operations are automatically generated:
  4. Click Next to get to the Operations screen. See the CRUD operations connected to the queries:

Step 5: Invoking your data service 

You can try the data service you created by using the TryIt tool that is in your product by default.  

  1. Go to the Deployed Services screen.
  2. Click the Try this service link for the AccountDetails data service. The TryIt Tool will open with the data service.
  3. See that the CRUD operations are generated for the datasource.

  4. Execute the CRUD operations from the TryIt tool to see the result.

  • No labels