Jump to: navigation, search


EclipseLink DBWS Service based on schema-formatted Results from custom SQL SELECT statements

This example shows an extension to an existing use case where the Web service exposes the results of executing some custom SQL SELECT statements; however, the 'shape' of the returned result is determined at design-time, not runtime.

Under normal circumstances, the custom SQL SELECT statement returns java.sql.ResultSet's and the java.sql.ResultSetMetaData APIs (getColumnCount, getColumnLabel, getColumnType, etc.) can be used to determine the name and datatype of the returned information. DBWS uses the Simplified XML Format (SXF) to create an XML document to describe the ResultSet's information. Unfortunately, since this document can change arbitrarily, the SXF schema is extremely 'loose' - the use of xsd:any places virtually no restriction on the document:

<?xml version="1.0" encoding="UTF-8"?>
  <xsd:complexType name="simple-xml-format">
      <xsd:any minOccurs="0"/>
Instance document:
<source lang="xml">
<?xml version = '1.0' encoding = 'UTF-8'?>

Additional information at Design time

As mentioned above, the java.sql.ResultSetMetaData APIs provide alot of information - if this information were available at design-time, a reasonable schema could be generated:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:emp" xmlns="urn:emp" elementFormDefault="qualified">
   <xsd:complexType name="empType">
         <xsd:element name="empno" type="xsd:decimal"/>
         <xsd:element name="ename" type="xsd:string" minOccurs="0" nillable="true"/>
         <xsd:element name="job" type="xsd:string" minOccurs="0" nillable="true"/>
         <xsd:element name="mgr" type="xsd:decimal" minOccurs="0" nillable="true"/>
         <xsd:element name="hiredate" type="xsd:date" minOccurs="0" nillable="true"/>
         <xsd:element name="sal" type="xsd:decimal" minOccurs="0" nillable="true"/>
         <xsd:element name="comm" type="xsd:decimal" minOccurs="0" nillable="true"/>
         <xsd:element name="deptno" type="xsd:decimal" minOccurs="0" nillable="true"/>
   <xsd:element name="empType" type="empType"/>

The DBWS sql operation is enhanced with an additional SQL statement that is executed at design-time with the foreknowledge that the statement will not return any rows (i.e. the WHERE clause evaluates to 'false'):

<?xml version="1.0" encoding="UTF-8"?>
<dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        <property name="projectName">emp</property>
        <statement><![CDATA[select * from EMP where ENAME like 'S%']]></statement>
        <build-statement><![CDATA[select * from EMP where 0=1]]></build-statement>


It is the responsibility of the user to ensure the compatibility between the design-time and runtime scenarios, no validation or pre-processing is applied to the SQL statements.

Limitation 1 - repeated labels: above it says 'set' - this points out a limitation with this feature. It is perfectly valid to have a SQL statement with multiple identical columns:

... ...

The above is admittedly nonsensical, but a SELECT statement that uses UNION could return a set of column labels where a label is repeated.
DBWSBuilder will keep track of 'already processed columns' and throw an exception when it detects a duplicate.

Limitation 2 - compatible column label sets: the primary and secondary SQL statements must return compatible column label sets. At this time, no pre-processing is done to ensure that the column sets are the same; the error will be detected at runtime when the service is invoked.