The request box feature allows you to invoke multiple operations (consecutively) to a datasource using a single operation. Follow the steps given below to define a data service that can invoke request box operations:
Table of Contents |
---|
...
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 and copy it to your
<EI_HOME>/lib
directory. - Create a database named Company.
Create the following tables:
Offices table:
Code Block CREATE TABLE `Offices` (`OfficeCode` int(11) NOT NULL, `AddressLine1` varchar(255) NOT NULL, `AddressLine2` varchar(255) DEFAULT NULL, `City` varchar(255) DEFAULT NULL, `State` varchar(255) DEFAULT NULL, `Country` varchar(255) DEFAULT NULL, `Phone` varchar(255) DEFAULT NULL, PRIMARY KEY (`OfficeCode`));
Employees table:
Code Block CREATE TABLE `Employees` (`EmployeeNumber` int(11) NOT NULL, `FirstName` varchar(255) NOT NULL, `LastName` varchar(255) DEFAULT NULL, `Email` varchar(255) DEFAULT NULL, `JobTitle` varchar(255) DEFAULT NULL, `OfficeCode` int(11) NOT NULL, PRIMARY KEY (`EmployeeNumber`,`OfficeCode`), CONSTRAINT `employees_ibfk_1` FOREIGN KEY (`OfficeCode`) REFERENCES `OFFICES` (`OfficeCode`));
Insert the following data into the Offices table:
Code Block INSERT INTO Offices VALUES (1,"51","Glen Street","Norwich","London","United Kingdom","+441523624"); INSERT INTO Offices VALUES (2,"72","Rose Street","Pasadena","California","United States","+152346343");
...
Define a data service to invoke request box operations
Let's create a data service using the Create Data Service wizard:
- Log into the management console of the ESB profile and click Create under Data Service.
Add a name for the data service and select the Enable Boxcarring and Disable Legacy Boxcarring Mode check boxes.
Note The Enable boxcarring option enables both the legacy boxcarring and the new request box methods. You can disable the legacy boxcarring method and use the request box method by selecting the Disable Legacy Boxcarring Mode option.
- Click Next and then click Add New Datasource.
- Connect to the Company database that you defined above. For instructions, see Exposing an RDBMS as a Data Service.
- Click Save, and then click Next to go to the Queries screen.
Click Add New Query to specify the query details:
Enter addEmployeeQuery as the query ID.
Enter the following SQL dialect:
Code Block insert into Employees (employeeNumber, lastName, firstName, email,officecode) values(:employeeNumber,'test','test',:email,:officecode)
Click Generate Input Mapping and input mappings will be generated automatically:
Click Save.
Click Add New Query to Create another query for the Company datasource:
Enter selectOfficebyEmployee as the query ID.
Enter the following SQL dialect:
Code Block select officecode,addressline1,addressline2,city,state,country,phone from Offices where officecode=?
Generate input and output mappings:
Click Generate Input Mapping and input mappings will be generated automatically for the office code field:
Click Generate Response to automatically generate the output mappings for the fields in the Offices table:
Click Save.
Click Next and then click Add New Operation to create an operation for the addEmployeeQuery query as shown below.
Click Save.
Click Add New Operation to create another operation to invoke the selectOfficebyEmployee query:
Click Save and then click Finish.
Invoking the data service
The Deployed Services window allows you to manage data services. You can try the data service you created by using the TryIt tool in this screen, which is in your product by default.
...