Sunday, 24 October 2010

Oracle SOA- How to use database Adapter.



I am starting with a simple example of how to use database adapter in a oracle soa application. There are some things I am assuming you are aware off....


1. Oracle database knowledge
2. Oracle Jdev.
3. Installation of oracle soa suit(jdev and weblogic server both).

If not I advice you to to first get some knowledge of all the three things above, else its will be difficult to understand what is going on in this example. Otherwise every thing will be cake walk ....

Oracle database adapter is the component which allow you to do simple or complex database activity in a oracle soa application.

This tutorial first we have four major task to be done

1. Creating the schema and configuring a database.
2. Creating the SOA application
3. Configure the weblogic server
4. Application deployment and testing.


We will be one by one go with the above stated tasks, if you have a good knowlege of the databse you can tweak the task 1 & 3 to some extent, using the database connection of your choice. In this tutorial we are following the simple objective of storing the employee name and employee number into the database. (To keep this simple I am not putting much validation in it).



1. Creating the schema and configuring a database.

I want a table which can store employee name and employee number, first in the database create a user adapterdemo identified by adapterdemo. For this you need a user with the dba privileged. Login with the user and put the user name and password as
=============================================
SQL> create user adapterdemo identified by adapterdemo;

User created.

SQL> grant connect, resource to adapterdemo ;

Grant succeeded.

SQL> grant dba to adapterdemo ;

Grant succeeded.
=====================================

Open the jdev, and go to database navigator (Menu : View -> Database -> navigator). In the database navigator click on ide connection and choose for new connection.

Add the details as below


Once you test the connection and click on your connection is ready to use in jdev. Now right click on connection and go for "open a sql work sheet" here you can write the sql and execute same way if you are familiar with the sqldevelper or toad.

Now on the sql sheet type of copy pate the syntax to create the table

create table employees
(emp_name varchar2(200),
emp_id number);

Once table created our database is ready to user.


2. Creating the SOA application
Now we are starting with the creation of the soa application in oracle jdev. (note this require oracle soa suit to be installed in the developer you are using).

2.1 Click on the new and from the popup choose oracle SOA application

2.2 Give a name to your SOA application, I have named it DatabaseAdaptersDEMO.




2.3 Choose for the project Name, I have put it as DatabaseAdapterDEMO. SOA will come as preselected for the project technology if not then select it.


2.4 Now choose for the empty composite and click ok. If you are sure to use one of the component in the composite type you can choose from here. Then composite will come the the component preselect.


2.5 Clicking on finish will create the empty composite. Now we can start with the dragging and dropping of the component to the application. The empty composite will look like this.


Before going to database connection, we need to create the xsd. This is a schema file and the communication in soa dependent on it. I am not going on detail on it. click on the xsd folder and then in the new popup select the category as xml and the items as xml schema and click ok. Now change the file name to empNameandRollnum then click ok, leave other values unchanged.

Its will open the xsd file and editor, I am not going in the xsd creation please copy and paste the content from the post. Due to issues please change < to <>.
=========================

<xml version="1.0" encoding="UTF-8">
<xsd:schema xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org" targetnamespace="http://www.example.org" elementformdefault="qualified">
<xsd:element name="Employee">
<xsd:annotation>
<xsd:documentation>
A sample element
<xsd:documentation>
<xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="empName" type="xsd:string"/>
<xsd:element name="empId" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

=================



2.7 Now drag a database adapter, to the right part of the composite, middle part we use to build the internal logic of the soa application the left and the right parts are for the exposing webservice and for the partner webservice respectively. Once you drop the component the following window will appear for the configuration of the database adapter.


2.7.1 Click on next as here nothing to change

2.7.2 Now give DatabaseInsertService as service name click on next.

2.7.3 Click on next as here nothing to be changed.

2.7.4 Now in this screen click on the search screen and then another popup will come with the database in the database navigator. choose the database we have just added click on copy connection



2.7.5 Now the screen will look like this the jndi name will be populated itself "eis/DB/adapterdemo" if you want to use some other jndi name, change it here, copy that name to some text pad.


2.7.6 Now click on next, the other screen will ask you to choose the operation, select on insert operation and click next, the next step of the wizard is based on the operation you choose here.

2.7.7 Now table selection screen will come up, this screen allow you to query all the screen where this user have the permission. Select on the query then your table will come up in the screen select and click on > button .



2.7.8 Select the primary key, we are choosing id as primary key.



2.7.9 The steps after this are straight forward, you just need to press the next only till finish.



2.7.9 Once you finish the screen will come like as given below, here database connection has been configured. Now we need to expose a webservice which accepts user name and Id and other is mediator between the webservice and database adapter.



Now our database adapter is ready, now we need to add an interface (webservice), where user can provide the input and then a mediator which is like a communication link between the component. This mediator can have some simple logic also. I am not going on detail about mediator in this post. Now starting with exposing the webservice.

Exposing the webService

Now Our dbadapter is ready to use but we can not publish it directly we have to have a webservice pointing to this database adapter. Now we start building the webservice.

2.8.1 Drag a service component to the Exposed Service area. One you drop a wizard will appear with the screen as given below.


2.8.2 Change the service name and click on the "Generate Schema from existing WSDL".


2.8.3 It will open one window for selecting the xsd file for the input for your schema. Select on the search icon and select the employee xsd

2.8.4 Select the employee schema and click on ok the webservice is ready to accept the inputs.


3.1 Now drop a mediator in the middle (component area). leave every thing default click on ok.


3.2 Now link the artifacts as given below. click on weservice and take mouse to mediator and then click on mediator and take the mouse to db adapter.



3.3 Now double click on the mediator, it will open a window like given below. Now click on the icon stating the Transform using.



3.4 Now click to create the new mapper file. Leave the default name .

3.5 Now click on employee and drag it to employee of the other side. same do for the empid.
By this way mediator is setting the communication link between the webservice and
db adapter.


3.6 It will look like this in the end.


Now our soa application is ready to use and we have to start with the deployment.

pleas follow the link given below to configure and deploy the application.