21
Oracle SOA Suite 11g - Sample SAMPLE NAME : adapters-db-102-Select COMPONENT : DB Adapter SAMPLE NAME : adapters-db-102-Select ..................................................................... 1 COMPONENT : DB Adapter ...................................................................................... 1 OVERVIEW ....................................................................................................................... 1 PROVIDED FILES............................................................................................................. 2 STEP BY STEP INSTRUCTIONS .................................................................................... 2 RUNNING THE PREBUILT SAMPLE ........................................................................ 2 INSTALLING & CONFIGURING ............................................................................ 2 RUNNING THE SAMPLE......................................................................................... 2 VERIFYING EXECUTION ....................................................................................... 3 BUILDING THE SAMPLE............................................................................................ 4 CREATE THE SOA PROJECT ................................................................................. 4 CREATE THE BPEL PROCESS ............................................................................... 4 CREATE THE QUERYBYEXAMPLE REFERENCE ............................................. 7 CREATE THE SELECT REFERENCE (ALTERNATIVE) ..................................... 9 CREATE THE PURE SQL REFERENCE (ALTERNATIVE) ............................... 12 COMPLETE THE BPEL PROCESS........................................................................ 17 FURTHER DBADAPTER SAMPLES ............................................................................ 21 OVERVIEW The Select tutorial shows how to invoke a DML select/insert/update/delete as part of a larger BPEL process or independently as a web service call. It is intended as the second tutorial for the DatabaseAdapter and is a companion to MasterDetail, which shows an end to end process using Mediator. Select is a popular choice for processes that at some point need some information stored in a database. There are really three ways to do a select: importing the tables and either modeling an expression or using query by example, or choosing pure sql and entering any sql. All three will be shown, but QueryByExample will be highlighted; it may ultimately be the least practical but is the most fun to play with when learning the product.

DBAdapters

Embed Size (px)

Citation preview

Oracle SOA Suite 11g - Sample

SAMPLE NAME : adapters-db-102-Select

COMPONENT : DB Adapter SAMPLE NAME : adapters-db-102-Select..................................................................... 1 COMPONENT : DB Adapter ...................................................................................... 1 OVERVIEW ....................................................................................................................... 1 PROVIDED FILES............................................................................................................. 2 STEP BY STEP INSTRUCTIONS .................................................................................... 2

RUNNING THE PREBUILT SAMPLE ........................................................................ 2 INSTALLING & CONFIGURING ............................................................................ 2 RUNNING THE SAMPLE......................................................................................... 2 VERIFYING EXECUTION ....................................................................................... 3

BUILDING THE SAMPLE............................................................................................ 4 CREATE THE SOA PROJECT ................................................................................. 4 CREATE THE BPEL PROCESS ............................................................................... 4 CREATE THE QUERYBYEXAMPLE REFERENCE ............................................. 7 CREATE THE SELECT REFERENCE (ALTERNATIVE) ..................................... 9 CREATE THE PURE SQL REFERENCE (ALTERNATIVE) ............................... 12 COMPLETE THE BPEL PROCESS........................................................................ 17

FURTHER DBADAPTER SAMPLES ............................................................................ 21

OVERVIEW The Select tutorial shows how to invoke a DML select/insert/update/delete as part of a larger BPEL process or independently as a web service call. It is intended as the second tutorial for the DatabaseAdapter and is a companion to MasterDetail, which shows an end to end process using Mediator. Select is a popular choice for processes that at some point need some information stored in a database. There are really three ways to do a select: importing the tables and either modeling an expression or using query by example, or choosing pure sql and entering any sql. All three will be shown, but QueryByExample will be highlighted; it may ultimately be the least practical but is the most fun to play with when learning the product.

Oracle SOA Suite 11g - Sample

The MasterDetail tutorial shows running the SQL scripts, deploying samples from Jdev, creating the SOA project and DBAdapter services and references, and finally using the transform tool. This tutorial will only show modeling the different selects, creating the BPEL process, and using the Web Services test page.

PROVIDED FILES This sample contains the SOA Project that you can deploy along with the sql scripts.

STEP BY STEP INSTRUCTIONS

RUNNING THE PREBUILT SAMPLE INSTALLING & CONFIGURING

• Go to sql/oracle and execute the SQL in setup.sql • Open the jpr file in Jdeveloper, and deploy the sample to a running

WebLogic Server. For screen shots please see the MasterDetail sample

RUNNING THE SAMPLE

• Go to host:8001/soa-console • Click on the Select composite and then on Test:

• Enter some values for what you want to match to records in the database. The test page form is a little restrictive for dateTime and decimal values, so best is just to uncheck “Include in Message” for those you don’t wish to specify:

Oracle SOA Suite 11g - Sample

VERIFYING EXECUTION

• After hitting invoke from the test page you should then see something like this:

Oracle SOA Suite 11g - Sample

BUILDING THE SAMPLE Please see the Database Adapter documentation, specifically the Database Adapter Wizard Walkthrough. Please also see the previous MasterDetail tutorial, as many screen shots from there are not duplicated here. CREATE THE SOA PROJECT

• Create a new SOAProject, with an empty composite in Jdeveloper. Don’t forget to name it.

CREATE THE BPEL PROCESS

• Drag and drop a BPEL process onto the composite.xml:

Oracle SOA Suite 11g - Sample

• Choose Synchronous BPEL Process, and check ‘Expose as a SOAP Service’.

• Now double click on the BPEL process:

Oracle SOA Suite 11g - Sample

• Drag two assigns and an invoke onto the flow:

• Now click on BPEL Services and drag and drop a Database Adapter onto the right swim lane:

Oracle SOA Suite 11g - Sample

CREATE THE QUERYBYEXAMPLE REFERENCE

• Call the DBAdapter reference SelectMovies

• Choose the connection SOADemo that you created for MasterDetail • Choose ‘Perform an Operation on a Table and unselect all but ‘Query By

Example’ (you can select multiple but for clarity will choose only one here).

Oracle SOA Suite 11g - Sample

• Import the tables MOVIES and MOVIE_REVIEWS. • Possibly edit which columns you wish to appear in the XML record. Note

if you exclude a column, it cannot be used in the where clause either:

Oracle SOA Suite 11g - Sample

• Query By Example returns an XML representing a collection of queried

records. It takes as input an XML element representing a single instance of the output collection, an example XML.

• It is very easy to model and use, but down sides are the SQL is generated differently each time which can be costly, it does not support complex expressions, or even operators like not or like.

CREATE THE SELECT REFERENCE (ALTERNATIVE)

• Choose perform operation on a table and go with Select instead of Query By Example:

• Import the tables MOVIES and MOVIE_REVIEWS • On the Selection Criteria page click on edit:

Oracle SOA Suite 11g - Sample

• Now you want to Add an Expression, which will be title like a new parameter, called title_param:

Oracle SOA Suite 11g - Sample

• After hitting hit Add click on Ok, your SQL at runtime should now look like:

Oracle SOA Suite 11g - Sample

• Creating the select this way still lets you import and select multiple tables, and return nested XML records. And the expression creation tool is simplistic but lets you use the basics: parameter binding, AND, OR, NOT, LIKE, EQUALS, etc.

CREATE THE PURE SQL REFERENCE (ALTERNATIVE)

• Finally instead choose ‘Execute Pure SQL’:

Oracle SOA Suite 11g - Sample

• As you type any SQL expression the matching XSD is generated:

Oracle SOA Suite 11g - Sample

• This approach lets you generate any arbitrary SQL and have the matching XSD generated. Some examples of things that would be impossible with the previous two approaches are shown here:

• Select count (aggregate functions)

Oracle SOA Suite 11g - Sample

• Group by aggregates:

• Functions and order by:

Oracle SOA Suite 11g - Sample

• Complex sub queries:

• The benefits to Pure SQL is that you can use it whenever you encounter a

SQL that is too difficult to model with the previous two approaches. The downsides are that: you must know the name of the tables to import; SQL is hard to maintain, and not always easily portable to different database platforms; and the output XML is never nested, you cannot model complex relationships.

Oracle SOA Suite 11g - Sample

COMPLETE THE BPEL PROCESS

• After creating the Select DatabaseAdapter reference hook up the invoke to the select:

• Click on automatically create variable for both input and output:

Oracle SOA Suite 11g - Sample

• Now click on the BPEL process, and expand on the Structure Panel on the

bottom left corner:

• Click on Edit Message Part… And change the Request Payload type to be the type of the input to selectMovies:

Oracle SOA Suite 11g - Sample

• Now do the same for SelectResponseMessage, but this time choose <.> MoviesCollection, as that is the output from selectMovies.

• Now the assigns should be very simple. It may not always be this easy to change the Message types of other variables in BPEL. In those cases you can use transforms. For Assign_1:

• Create this copy operation:

Oracle SOA Suite 11g - Sample

• Click Ok. For Assign_2 (after the invoke), create:

• Hit save all and you are now ready to deploy! This is the final result:

Oracle SOA Suite 11g - Sample

FURTHER DBADAPTER SAMPLES This and MasterDetail complete the introductory tutorials for the Database Adapter. Further tutorials will focus on specific adapter features, like different polling strategies, ADT and XMLType support, and topics like performance and scalability.