A BPEL White Paper
Written by Olivier Le Diouris, Oracle Corporation
Setpember, 2005
Introduction |
Top |
When a Database operation - select, update or insert, PLSQL function or procedure call - is to be performed from a BPEL process, the way to go is to use the DB Adapter that comes with the BPEL Process Manager and Designer.
This DB Adapter uses Toplink for the Object-Relational mapping, and exposes the generated objects using WSIF - like other Adapters do.
Toplink is providing a thick abstraction layer, hiding whenever it is possible the complexity of the SQL or PLSQL statements to perform in the database.
However, it is sometime necessary to open the hood and implement a SQL statement.
Like for example:
SELECT SCOTT.EMP.EMPNO,
SCOTT.EMP.ENAME,
SCOTT.EMP.JOB,
SCOTT.EMP.MGR,
SCOTT.EMP.HIREDATE,
SCOTT.EMP.SAL,
SCOTT.EMP.COMM,
SCOTT.EMP.DEPTNO,
SCOTT.DEPT.DNAME
FROM SCOTT.EMP,
SCOTT.DEPT
WHERE SCOTT.DEPT.DEPTNO = SCOTT.EMP.DEPTNO AND
SCOTT.EMP.HIREDATE BETWEEN TO_DATE(UPPER('&dateFrom'), 'DD-MON-YYYY') AND
DECODE(NVL(LENGTH(LTRIM('&dateTo')), 0), 0, SYSDATE,
TO_DATE(UPPER('&dateTo'), 'DD-MON-YYYY'))
where dateFrom and dateTo
are provided by the user. Generating an equivalent Toplink expression
is quite a challenge. The BETWEEN, NVL, LENGTH, LTRIM, SYSDATE, UPPER,
TO_DATE operators and functions are Oracle extensions to SQL, not
handled by Toplink.
The regular path |
Top |
There is a sample coming with Oracle BPEL that explains how to customize the toplink_mapping.xml
file to reach the goal we're targeting.
This example is located in
[BPEL_HOME]\integration\orabpel\samples\tutorials\122.DBAdapter\PureSQLSelect
It is mostly about replacing some element(s) of the mapping file with a
<sql-string> element, actually containing the SQL Query to execute.
This example is clear and well-done, we are not going to go through it again. But we are going to
show how to implement its recommandations with minimum effort. Let's be lazy.
The trick and tips |
Top |
It's all about minimizing the customization to toplink_mapping.xml,
and the number of manual steps we will have to go through, so we minimize the risk
of introducing errors.
In this example, we will only talk about a query (a Select statement) in the database.
When you use the DB Adapter Wizard, the following visible operations are performed:
The trick we used is the following one:
CREATE VIEW FOR_TOPLINK AS
SELECT SCOTT.EMP.EMPNO,
SCOTT.EMP.ENAME,
SCOTT.EMP.JOB,
SCOTT.EMP.MGR,
SCOTT.EMP.HIREDATE,
SCOTT.EMP.SAL,
SCOTT.EMP.COMM,
SCOTT.EMP.DEPTNO,
SCOTT.DEPT.DNAME
FROM SCOTT.EMP,
SCOTT.DEPT
WHERE SCOTT.DEPT.DEPTNO = SCOTT.EMP.DEPTNO AND
SCOTT.EMP.HIREDATE BETWEEN TO_DATE(UPPER('01-jan-1970'), 'DD-MON-YYYY') AND
DECODE(NVL(LENGTH(LTRIM('31-dec-2010')), 0), 0, SYSDATE,
TO_DATE(UPPER('31-dec-2010'), 'DD-MON-YYYY')) AND
1 = 2;
<distinct-state>0</distinct-state>
<sql-string>
SELECT SCOTT.EMP.EMPNO,
SCOTT.EMP.ENAME,
SCOTT.EMP.JOB,
SCOTT.EMP.MGR,
SCOTT.EMP.HIREDATE,
SCOTT.EMP.SAL,
SCOTT.EMP.COMM,
SCOTT.EMP.DEPTNO,
SCOTT.DEPT.DNAME
FROM SCOTT.EMP,
SCOTT.DEPT
WHERE SCOTT.DEPT.DEPTNO = SCOTT.EMP.DEPTNO AND
SCOTT.EMP.HIREDATE BETWEEN TO_DATE(UPPER(#fromDate), 'DD-MON-YYYY') AND
DECODE(NVL(LENGTH(LTRIM(#toDate)), 0), 0, SYSDATE,
TO_DATE(UPPER(#toDate), 'DD-MON-YYYY'))
</sql-string>
<query-indirection>
<in-memory-query-indirection>
<policy>0</policy>
Notice the way to refer to a parameter, no quote, and a '#' in front.
Errors to avoid |
Top |
Resources |
Top |