Database Xpath-extension Functions in SOA 12c
In SOA, we can connect with databases using a database jca adapter and configuring the data source and connection factory in the WebLogic server. Sometimes, we may want to query the database directly within the BPEL component or XSLT without configuring a database jca adapter. For such use cases, we can take leverage of database functions that can be used within BPEL Assign Activity or XSLT transformations.
We have 3 different database functions available, that can be used in different use cases.
1. oraext:sequence-next-val()
Syntax:
sequence: Specify the sequence available in the database for which the next value needs to be extracted.
This function is used when we want to fetch the next value of defined sequence in the database. It can be used in cases where we want each request to adhere with a particular sequence id which can be used to identify each unique record where using a db adapter might create overhead and extra transformation. This function is basically an alternative to the below SQL statement.
SELECT SEQUENCE_TEST.NEXTVAL FROM DUAL;
Here, SEQUENCE_TEST is the name of the sequence defined in the database.Example usage in XSLT:
<xsl:template match="/">
<root>
<seqJDBCString><xsl:value-of select="oraext:sequence-next-val('SEQUENCE_TEST','jdbc:oracle:thin:mark1/password@localhost:1521:XE' )"/></seqJDBCString>
</root>
</xsl:template>
OUTPUT:
<root>
<seqJDBCString>2</seqJDBCString>
</root>
2. oraext:lookup-table()
Syntax
oraext:lookup-table(tableName as string, inputColumn as string, inputData as string, outputColumn as string, dataSource as string)
Suppose we have a table in our database which contains names of employee corresponding to the empIds. Now, we want to extract the name of employee corresponding to empId which we are getting in input. To do so, one way could be to have a db adapter created and use similar SQL statement as below to retrieve data.
SELECT EMP_NAME FROM EMPLOYEE_TABLE WHERE (EMP_ID=#inputId)
If we want to fetch the value directly in assign activity or xslt, we can use the oraext:lookup-table(). This can be treated as alternative approach to dvm lookup where in dvm files are stored local to composite or in MDS.
EMPLOYEE_TABLE
EMP_ID | EMP_NAME |
---|---|
1002 | DecipherMiddleware |
<input xmlns="http://test.com/tns"> <empId>1002</empId>
</input>
XSL:
<xsl:template match="/">
<root>
<empName><xsl:value-of select="oraext:lookup-table('EMPLOYEE_TABLE','EMP_ID',/ns0:input/ns0:/empId,'EMP_NAME','jdbc:oracle:thin:mark1/password@localhost:1521:XE' )"/></empName>
</root>
</xsl:template>
OUTPUT:
3. oraext:query-database()
oraext:query-database(sqlQuery as string, rowSet as boolean, row as boolean, dataSource as string)
This function can be used to execute SQL statements without configuring a JCA adapter in SOA composite. Let us assume we have a category table like below, from where we need to query all columns.
CATEGORY TABLE
CATEGORYID | CATEGORYNAME | DESCRIPTION |
---|---|---|
1 | Beverages | Soft drinks, coffees, teas, beers, and ales |
2 | Condiments | Sweet and savory sauces, relishes, spreads, and seasonings |
3 | Confections | Desserts, candies, and sweet breads |
4 | Dairy Products | Cheeses |
5 | Grains/Cereals | Breads, crackers, pasta, and cereal |
Since we have kept rowSet and row as true(), we are seeing tags coming in output from function result.
References:
Please share your valuable feedback in the comments section below 😊
Nice post
ReplyDeletegreat article !!
ReplyDeleteGood post..!
ReplyDeleteIs it possible to use SQL Server Database with oraext:lookup-table? Can you give an example?
ReplyDeleteThis is a great article and help. How can we avoid hardcoding the password? Appreciate your great help. Thank you!
ReplyDelete