BPEL Database Adapter Part 1


Overview:

Database Adapter is a partnerlink in BPEL which is used to interact with Database for read, write operations. Using Database Adapter we can perform the following functions.

1.Call a Stored Procedure of Function

2.Perform DML operations like insert, update, delete on a table

3.Perform SELECT operation

4.Execute custom SQL Statements

In this Article I will explain how to create simple synchronous BPEL process containing Database Adapter which will read the data from a table and pass the value to output parameter.

Prerequisites:

1.You need to establish a Database Connection in Connection Navigator before you proceed further. Refer to my previous article on how to create a Database Connection by clicking the following link http://erpschools.com/articles/bpel-olite-database-connection

2.If this is your first BPEL Process I suggest you to go through my hello world article first.

http://erpschools.com/articles/bpel-tutorial-for-beginners-with-helloworld-example

Create Application:

Open JDeveloper and select Applications in the JDeveloper

Right Click on ‘Application’ and select ‘New Application’

Create Application Window opens as show below

Change the Application Name to ‘DatabaseAdapterTutorial’

Leave remaining fields with default values and click OK

Click Cancel not the OK button

Create Process

Right click on the DatabaseAdapterTutorial and click New Project as show below

Select ‘BPEL Process Project’  from the projects list

Click Ok

Chang the Name which is optional and change the Template to Synchronous BPEL Process as shown below.

Click Next

Leave the default values and click Finish

DatabaseAdapterTutorial Shows up in the Applications Navigator

On the right side of the jdeveloper window select ‘Services’ in the component Palette dropdown box.

Select the Database Adapter and Drag it to right side Services portion of jdeveloper main window

Adapter Configuration Wizard screen will pop up as below

Click Next

Enter the Service Name as ‘FetchEmail’

Description field is optional

Click Next

Select the Database Connection ‘BPELOlite’ from the Connection list. This connection varies as you create Database connections in Connection Navigator

Leave the JNDI Name with default value and click next

Select ‘Perform an Operation on a Table’ option from the list

check Only ‘SELECT’ checkbox

Click Next

Click on Import Tables button

Click on the Query button to see the list of tables available in your database

Select the Table name from the list on which you want to operate the select command

I have selected the table ERPSCHOOLS. I am listing the commands below to create the table ERPSCHOOLS if you want to use

Now Click Ok

Click Next

Select all columns and click Next

I am not creating any relationship with this table so just click Next button

Click Next

SELECT command is shown in SQL box.  If you want to add any parameters to the query you can add it here. You can also directly edit your SQL statement. I am changing my SQL statement to fetch only one record.

Click Next

Click Finish

Create Partner link will pop up as shown below

Leave all fields with default values and click OK

Now your BPEL main window screen should look like the below screen

Fetch email partner link/Database Adapter will show in Service area as shown in the red circle.

Now select ‘Process Activities’ in the Component Palette

Select and Drag the Invoke activity below the receiveInput activity

Double click the Invoke_1 activity

Change the Name to Invoke_FetchEmail

Click on the Flashlight right to Partner Link Field

Select FetchEmail and click OK

Partner Link and Operation fields are populated automatically

Click on the Create Variable fields right to both input and output Variables

Click the small red circle icon, create variable window will pop up as shown below

Click Ok

Now click on red circle icon right to output variable

Click Ok

Click Apply

If you have everything correctly you should not see the errors in the red circle show in the above figure.

If you don’t have any errors click OK

Main screen should look like the above picture.

We have created the Invoke activity which will call Database Adapter(FetchEmail) and Database Adapter will query the table ERPSCHOOLS and fetches email field value. Now to catch the value fetched by Database Adapter use Assign Activity, which will transfer the value of email field fetched by Database Adapter to replyOutput field.

Drag the Assign activity from the component palette to mainwindow below the Invoke_FetchEmail activity.

Double click on Assign_1 activity to open the Assign properties window

Chang the name to Assign_Email and click on the second tab ‘Copy Operation’

Click Create button circled above and select ‘Copy Operation’ to open the Create Copy Operation window as show below

Select ns2:email on the left and client:result on the right side as show below

Click OK

Click Apply to remove the errors

Click Ok

Save your project by clicking CTRL+S

DEPLOY BPEL Process

Now we are ready to deploy the process, Start your SOA Suite and deploy the process

If you are not familiar with deploy process follow the link to see how to deploy the process

After you deploy your process successfully your Apache Ant log will show like this

Run the BPEL Process

Go to your BPEL Console

http://localhost:8888/BPELConsole
login in with oc4jadmin/welcome1 (default values)

Once you login to console you can see ‘DatabaseAdapterTutorial’ project in the Deployed BPEL Processes list.

Click on DatabaseAdapterTutorial

The initiate screen will show up

Click on Post XML Message

Click on Visual Flow

Click on Assign_Email activity to see the output

The result field contains prudhvi@erpschools.com which is my output.