Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/DBWS/DBWSBasicAutoGenSchema"

Line 11: Line 11:
 
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.
 
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 <tt>SELECT</tt> statement returns <code>java.sql.ResultSet</code>'s and the java.sql.ResultSetMetaData APIs (<code>getColumnCount</code>, <code>getColumnLabel</code>, <code>getColumnType</code>, 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 <code>ResultSet</code>'s information. Unfortunately, since this document can change arbitrarily, the SXF schema is extremely 'loose' - the use of <tt>xsd:any</tt> places virtually no restriction on the document:
+
Under normal circumstances, the custom SQL <tt>SELECT</tt> statement returns <code>java.sql.ResultSet</code>'s and the <code>java.sql.ResultSetMetaData</code> APIs (<code>getColumnCount</code>, <code>getColumnLabel</code>, <code>getColumnType</code>, 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 <code>ResultSet</code>'s information. Unfortunately, since this document can change arbitrarily, the SXF schema is extremely 'loose' - the use of <tt>xsd:any</tt> places virtually no restriction on the document:
 
<source lang="xml">
 
<source lang="xml">
 
Schema:
 
Schema:
Line 50: Line 50:
  
 
=== Additional information at Design time ===
 
=== Additional information at Design time ===
As mentioned above,
+
As mentioned above, the <code>java.sql.ResultSetMetaData</code> APIs provide alot of information - if this information was available at design-time, a reasonable schema could be generated.
 +
 
 +
The DBWS <tt>'''sql'''</tt>

Revision as of 15:02, 13 June 2011


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:

Schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  >
  <xsd:complexType name="simple-xml-format">
    <xsd:sequence>
      <xsd:any minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>
Instance document:
<source lang="xml">
<?xml version = '1.0' encoding = 'UTF-8'?>
<simple-xml-format>
  <simple-xml>
    <EMPNO>7788</EMPNO>
    <ENAME>SCOTT</ENAME>
    <JOB>ANALYST</JOB>
    <MGR>7566</MGR>
    <HIREDATE>1987-04-19</HIREDATE>
    <SAL>3000</SAL>
    <DEPTNO>20</DEPTNO>
  </simple-xml>
  <simple-xml>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7902</MGR>
    <HIREDATE>1980-12-17</HIREDATE>
    <SAL>800</SAL>
    <DEPTNO>20</DEPTNO>
  </simple-xml>
</simple-xml-format>

Additional information at Design time

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

The DBWS sql