WSO2 Data Services Server The data integration feature in WSO2 EI supports data federation, which means that a single data service can expose data from multiple datasources. However, if you have multiple RDBMSs connected to your data service, and if you need to perform IN-ONLY operations (operations that can insert data and modify data in the datasource) in a coordinated manner, the RDBMSs need to be defined as XA datasources. Consider a scenario where you have two MySQL databases. You can define a single data service for these databases and insert data into both as explained below.
...
- Log into the management console of WSO2 EI and click Create in the under Data Service menu.
- Add a name for the data service and go to the next step.
- Select the Enable Boxcarring check box.
- Click Next to go to the Datasources screen.
- Create a datasource connection for the CompanyDetails database follows:
- Enter XAoffices as the datasource ID.
- Select RDBMS as the datasource type.
- Select External Datasource from the adjoining field.
- Select MySQL as the database engine.
- Enter the following database class corresponding to MySQL:
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
- Click Add Properties and create the connection settings for the OfficeDetails database.
URL: jdbc:mysql://localhost:3306/OfficeDetails
USER: root
- Save the XAoffices datasource.
- Create a datasource connection for the EmployeeDetails database as follows:
- Enter XAemployees as the datasource ID.
- Select RDBMS as the datasource type.
- Select External Datasource from the adjoining field.
- Select MySQL as the database engine.
- Enter the following database class corresponding to MySQL:
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
- Click Add Properties and create the connection settings for the OfficeDetails database.
URL: jdbc:mysql://localhost:3306/EmployeeDetails
USER: root
- Save the XAemployees datasource.
...
- Click Add New Query to specify an insert query for the XAoffices datasource:
Enter InsertOfficeQuery as the query ID.
Enter the following SQL dialect:
Code Block insert into Offices (OfficeCode,AddressLine1,AddressLine2,City,State,Country,Phone) values(:OfficeCode,:AddressLine1,'test','test','test','USA','test')
- Click Generate Input Mapping and an input mapping will be generated automatically for the fields in the datsource:
- Save the query.
- Click Add New Query to specify an insert query for the XAemployees datasource:
Enter InsertEmployeeQuery as the query ID.
Enter the following SQL dialect:
Code Block insert into Employees (employeeNumber,firstName,lastName,email,jobtitle,OfficeCode) values(:employeeNumber,:firstName,:lastName,'test',:OfficeCode)
- Click Generate Input Mapping and an input mapping will be generated automatically for the fields in the datsourcethe datasource:
- Save the query.
- Click Next to go to the Operations section. Define operations to invoke the two queries defined above.
- Create the InsertOfficeOp for the InsertOfficeQuery.
- Create the InsertEmployeeOp for the InsertEmployeeQuery.
- Finish creating the data service.
...
Inserting data into the distributed
...
RDBMSs
- Go to the Deployed Services page and you will see the data service listed.
- Click Try this service to open the TryIt tool.
- Select the batch operation that is created by default (request_box_operation).
- Specify the values that should be inserted to the OfficeDetails database and EmployeeDetails database respectively.
- Invoke the operation.
- See that the data is successfully inserted into the two databases.
- Now, enter another set of values for the two operations. However, you can enter an erroneous value for one field.
- Invoke the operation.
- See that no records have been entered into either database.