Thursday, September 26, 2013

XSLT : Filter Child node based on Parent node value

This blog post will help you to filter child node elements based on parent node values in XSL transformation.

Given solution will help you to create master and detail relationship, when you are getting parent and child data from different sources.

Simple steps:

  • Create a variable to hold a key value from parent node to identify child nodes.(Note: The variable declared immediately after for-each tag in given sample XSLT)
  • Refer that variable value in child node to filter the results.

Sample XSLT with solution to filter employees node results by department ID:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- SOURCE 1 - Departments Data. -->
    <source type="XSD">
      <schema location="../xsd/DEPARTMENTS.xsd"/>
      <rootElement name="OutputParameters" namespace=""/>
<!-- SOURCE 2 - Employees Data. -->
    <source type="XSD">
      <schema location="../xsd/EMPLOYEES.xsd"/>
      <rootElement name="OutputParameters" namespace=""/>
      <param name="varGetEmployeesDBAdapterOutput.OutputParameters" />
    <target type="XSD">
      <schema location="../xsd/QueryDept.xsd"/>
      <rootElement name="QueryEmpResponse" namespace=""/>
<xsl:stylesheet version="1.0"
                exclude-result-prefixes="xsi xsl db ns0 ns1 xsd tns xp20 bpws aia mhdr bpel oraext dvm hwf med ids bpm xdk xref bpmn ora socket ldap">
  <xsl:param name="varGetEmployeesDBAdapterOutput.OutputParameters"/>
  <xsl:template match="/">
        <xsl:for-each select="/db:OutputParameters/db:OUT_DEPT_CUR/db:OUT_DEPT_CUR_Row">
          <xsl:variable name="DeptID" select="db:DEPT_ID"/>
                <xsl:value-of select="db:DEPT_ID"/>
                <xsl:value-of select="db:DEPT_NAME"/>
              <xsl:for-each select="$varGetEmployeesDBAdapterOutput.OutputParameters/ns1:OutputParameters/ns1:OUT_EMPLOYEE_CUR/ns1:OUT_EMPLOYEE_Row[(ns1:DEPT_ID = $DeptID)]">
                    <xsl:value-of select="ns1:EMPLOYEE_ID"/>
                    <xsl:value-of select="ns1:EMPLOYEE_NAME"/>

Friday, September 6, 2013

Resolving ORA-04061 Issue

In this post, let's discuss about fixing ORA-04061:existing state of package has been invalidated issue when calling Database standard procedure/package from SOA web service using database adapter.

Introduction, sometimes the SOA web service start returning following error message during invocation of standard procedure/package.

ORA-04061: existing state of package "HR.EMPLOYEES_API" has been invalidated
ORA-04065: not executed, altered or dropped package "HR.EMPLOYEES_API"
ORA-06508: PL/SQL: could not find program unit being called: "HR.EMPLOYEES_API"

But when I check the state of package in database, its in valid state and it worked without any issues, when I try to execute the same program unit from database.

Considering above analysis, I concluded that there is no issue with database program unit. Then I started looking into SOA Web service and Weblogic server data source configuration.

Further investigation on SOA web service testing reveals that, the database program unit is getting invoked sometimes without any issues.

During my R&D, I did resetting data source connection pool. From then, I did not faced this issue.

Final Report:
This issue raises, when the database program being altered/created/compiled by another database user and SOA web service tries to invoke it using old data source connection pool i.e. created before altering database program.

Here comes the Weblogic data source connection pooling mechanism, which holds few logical connections created before I alter the database program with different user.

When I reset the data source, it will destroy the existing connections and will re-create them with current state of the database programs and resolves the issue.

Steps to Reset Data Source in WLS:

  1. Go to the Weblogic Console > data sources and select your data source. For Ex: LocalXEDS
  2. Go to the tab ‘Control’ and select the servers to which the data source is targeted and click ‘Reset’.

Handle Table Type in PLSQL

This post is all about how to populate and retrieve data from Table type in PLSQL.

Sample Object Type:
TYPE type_employee AS OBJECT

Sample Table Array Type:
TYPE employee_array AS TABLE OF type_employee;

PLSQL Anonymous Block:
   emp_array employee_array;


-- Use Object Type to Cast the data from table and use Bulk Collect to fetch large volumes of data at once
   BULK COLLECT INTO emp_array
-- Method 1 --retrieve data from Table Array
   FOR c1 IN (
      FROM TABLE( CAST( emp_array AS employee_array)) )
      DBMS_OUTPUT.PUT_LINE('Employee ID : ' || c1.EMPLOYEE_ID);
      DBMS_OUTPUT.PUT_LINE('Employee Name : ' || c1.FIRST_NAME || ' ' || c1.LAST_NAME);
      DBMS_OUTPUT.PUT_LINE('Employee Salary : '|| c1.SALARY);
      DBMS_OUTPUT.PUT_LINE('Employee Email : '|| c1.Email);

-- Method 2 --retrieve data from Table Array
   FOR i IN 1..emp_array. COUNT LOOP
      DBMS_OUTPUT.PUT_LINE('Employee ID : ' || emp_array(i).EMPLOYEE_ID);
      DBMS_OUTPUT.PUT_LINE('Employee Name : ' || emp_array(i).FIRST_NAME || ' ' || emp_array(i).LAST_NAME);
      DBMS_OUTPUT.PUT_LINE('Employee Salary : '|| emp_array(i).SALARY);
      DBMS_OUTPUT.PUT_LINE('Employee Email : '|| emp_array(i).Email);   
   END LOOP;