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
Step 1: Setting up a datasource
Follow the steps given below to set up a MySQL database for this tutorial.
- Install the MySQL server.
- Download the JDBC driver for MySQL from here and copy it to your
- Create the following database:
Create the following table:
Enter the following data into the table:
Step 2: Creating a Carbon datasource
WSO2 EI 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.
- Log into the management console of WSO2 EI and click Datasources in the Configure tab. This will open the Datasources screen.
- Click Add Datasource and enter the following details corresponding to the 'AccountDetails' database:
- Save the datasource.
Step 3: Generating a data service
Once the datasource is created, follow the steps below to generate a data service.
- In the Carbon Datasource field, select a datasource from the drop-down list.
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.
- 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.
- Select the ACCOUNT table and click Next to open the Service Generation screen.
- 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.
- Click Next to open the Generated Services screen. A data service by the name of ACCOUNT_DataService is now generated.
- 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: Verifying the generated CRUD operations (Optional)
You can verify that the relevant queries and CRUD operations are generated accurately:
- Click the ACCOUNT_DataService service to open the service dashboard.
- Click Edit Data Service to open the service in the Create New Data Service wizard.
- Click Next until you get to the Queries screen. See the queries corresponding to CRUD operations are automatically generated:
- 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.
- Go to the Deployed Services screen.
- Click the Try this service link for the AccountDetails data service. The TryIt Tool will open with the data service.
See that the CRUD operations are generated for the datasource.
Execute the CRUD operations from the TryIt tool to see the result.