Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/DBWS/Creating EclipseLink DBWS Services (ELUG)"

(Using the DBWSBuilder utility to create an EclipseLink DBWS Service from a Database Table)
m (Replacing page with 'Image:Elug draft icon.png '''For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/ ''' For the latest EclipseLink DBWS doc...')
 
(40 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<b>Note: A basic overview of EclipseLink Database Web Services (DBWS) can be found</b> [[EclipseLink/FAQ/WhatIsDBWS|here]]
+
[[Image:Elug draft icon.png]] '''For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/ '''
__TOC__
+
  
==Creating Deployable EclipseLink DBWS Services==
+
For the latest EclipseLink DBWS documentation, see
This section describes how to automatically generate a <tt>.war</tt> file containing the EclipseLink DBWS service descriptor along with all required deployment artifacts for a JAX-WS 2.0 Web service (WSDL, XML schema, web.xml, EclipseLink ORM and OXM native Project XML files, etc.)
+
'''[http://www.eclipse.org/eclipselink/documentation/2.4/dbws/toc.htm Developing Persistence Architectures Using EclipseLink Database Web Services, Release 2.4]'''
<onlyinclude>
+
<source lang="text">
+
root of war file
+
    \---web-inf
+
    |
+
    |  web.xml
+
    |
+
    +---classes
+
    |  +---foo                              -- optional domain classes (typically not required)
+
    |  |  \---bar                             
+
    |  |          Address.class
+
    |  |          Employee.class
+
    |  |          PhoneNumber.class
+
    |  |
+
    |  +---META-INF
+
    |  |      eclipselink-dbws.xml
+
    |  |      eclipselink-dbws-or.xml
+
    |  |      eclipselink-dbws-ox.xml
+
    |  |      eclipselink-dbws-sessions.xml -- name can be overridden by <sessions-file> entry in eclipselink-dbws.xml
+
    |  |
+
    |  \---_dbws
+
    |          DBWSProvider.class            -- auto-generated JAX-WS 2.0 Provider
+
    |
+
    \---wsdl
+
            eclipselink-dbws-schema.xsd
+
            eclipselink-dbws.wsdl
+
            swaref.xsd                               
+
</source>
+
{| class="RuleFormalWideMax" dir="ltr" title="<b>EclipseLink DBWS Service <code>.war</code> File Contents</b>" width="100%" border="1" frame="border" rules="all" cellpadding="3" frame="border" rules="all"
+
|+ <b>EclipseLink DBWS Service <code>.war</code> File Contents</b>
+
|- align="left" valign="top"
+
! id="r1c1-t2" align="left" valign="bottom" | '''File'''
+
! id="r1c2-t2" align="left" valign="bottom" | '''Description'''
+
|- align="left" valign="top"
+
| align="left" |
+
|-
+
|<code>web.xml</code>
+
|The Web application deployment file (required for deployment as a JAX-WS Web service)
+
|-
+
|<code>eclipselink-dbws.xml</code>
+
|[[EclipseLink/UserGuide/DBWS/Overview/EclipseLink_DBWS_Service_Descriptor_File_(ELUG)|The EclipseLink DBWS service descriptor file (described in full in the User Guide)]]
+
|-
+
|<code>eclipselink-dbws-or.xml</code>
+
|The EclipseLink ORM Project XML file. For more information, see [[Introduction to Relational Projects (ELUG)]]
+
|-
+
|<code>eclipselink-dbws-ox.xml</code>
+
|The EclipseLink OXM Project XML file. For more information, see [[Introduction to XML Projects (ELUG)]]
+
|-
+
|<code>eclipselink-dbws-sessions.xml</code>
+
|The EclipseLink sessions.xml file for the EclipseLink DBWS service. It contains references to the EclipseLink ORM and OxM Project XML files. For more information, see [[Introduction to EclipseLink Sessions (ELUG)]]
+
|-
+
|<code>eclipselink-dbws-schema.xsd</code>
+
|Contains XML type definitions for operation arguments and return types. The <tt>DBWSBuilder</tt> utility automatically generates this file from the database metadata to derive element-tag names and types
+
|-
+
|<code>eclipselink-dbws.wsdl</code>
+
|Contains entries for all operations in the EclipseLink DBWS service (required for deployment as a JAX-WS Web service)
+
|-
+
|<code>swaref.xsd</code>
+
|(optional) Contains XML type definitions for SOAP attachments
+
|-
+
|}
+
NB - the files <tt>swaref.xsd</tt> and <tt>web.xml</tt> have names and content determined by their roles in web deployment and cannot be changed.
+
</onlyinclude>
+
The deployable <tt>.war</tt> file has been verified to work with the [http://www.oracle.com/technology/software/products/ias/htdocs/wls_main.html?rssid=rss_otn_soft Oracle WebLogic Server 10.3 JavaEE container]. An alternate deployable <tt>.jar</tt> file has been <br />
+
verified to work as a JavaSE 6 'container-less' [http://java.sun.com/javase/6/docs/api/javax/xml/ws/Endpoint.html EndPoint].
+
<br />
+
  
This section describes the following:
 
*[[#How to Create EclipseLink DBWS Services Using the DBWSBuilder utility|How to Create EclipseLink DBWS Services Using the <tt>DBWSBuilder</tt> utility]]
 
*[[#How to Customize an EclipseLink DBWS Service|How to Customize an EclipseLink DBWS Service]]
 
*[[#How to Use DBWSBuilder an an API|How to Use <tt>DBWSBuilder</tt> an an API]]
 
  
===How to Create EclipseLink DBWS Services Using the <tt>DBWSBuilder</tt> utility===
+
<b>Note: A basic overview of EclipseLink Database Web Services (DBWS) can be found</b> [[EclipseLink/FAQ/WhatIsDBWS|here]]
You can use the EclipseLink DBWS design-time tool <tt>DBWSBuilder</tt> to create deployment files. <tt>DBWSBuilder</tt> is a Java application that processes the operations described in an [[EclipseLink dbws-builder.xml File (ELUG)#eclipselink-dbws-builder.xml|EclipseLink DBWS builder XML file]] to produce all the required deployment artifacts.
+
 
+
Be sure to set the following environment variables in the <tt><ECLIPSELINK_HOME>\utils\dbws\setenv.cmd</tt> (or <tt>setenv.sh</tt> file) before invoking <tt>DBWSBuilder</tt>:
+
*$JAVA_HOME
+
*$DRIVER_CLASSPATH
+
There are script files provided for invoking <tt>DBWSBuilder</tt>. They are located in <tt><ECLIPSELINK_HOME>\utils\dbws</tt>. The scripts are '''dbwsbuilder.cmd''' for Windows usage and '''dbwsbuilder.sh''' for other operating systems.
+
<source lang="text">
+
DBWSBuilder usage - [] indicates optional argument:
+
prompt > dbwsbuilder.cmd -builderFile {path_to_builder.xml} -stageDir {path_to_stageDir} -packageAs[:archive_flag] {packager} [additional args]
+
Available packagers:
+
  -packageAs:[default=archive] javase [jarFilename]
+
  -packageAs:[default=archive] wls [warFilename]
+
</source>
+
 
+
Using <tt>DBWSBuilder</tt>, you can generate an EclipseLink DBWS service from the following sources:
+
*an existing relational database table;
+
*one or more SQL <code>SELECT</code> statements;
+
*a stored procedure.
+
 
+
====Using the <tt>DBWSBuilder</tt> utility to create an EclipseLink DBWS Service from a Database Table====
+
Create an EclipseLink DBWS builder XML File with a <tt>&lt;table&gt;</tt> <b>query operation</b>:
+
<span id="Example 9-1"></span>
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
  <properties>
+
    <property name="projectName">table_test</property>
+
    ... database properties ...
+
  </properties>
+
  <table
+
    schemaPattern="%"
+
    tableNamePattern="dbws_crud"
+
  />
+
</dbws-builder>
+
</source>
+
For more information, see the basic example [[EclipseLink/Examples/DBWS/DBWSBasicTable| Creating EclipseLink DBWS Service based on Database Table]].
+
 
+
====Using the <tt>DBWSBuilder</tt> utility to create an EclipseLink DBWS Service from a SQL statement====
+
Create an EclipseLink DBWS builder XML File with a <tt>&lt;sql&gt;</tt> <b>query operation</b>:
+
<span id="Example 9-2"></span>
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+
  <properties>
+
    <property name="projectName">sql_test</property>
+
    ...
+
    <property name="wsdlLocationURI">http://localhost:7001/sql_test/sql_test?wsdl</property>
+
  </properties>
+
  <sql name="employeeInfo" simpleXMLFormatTag="employee-info" xmlTag="aggregate-counts">
+
    <text>
+
      <![CDATA[select count(*) as "COUNT", max(SAL) as "MAX-Salary" from EMP]]>
+
    </text>
+
  </sql>
+
</dbws-builder>
+
</source>
+
For more information, see [[whatever]].
+
 
+
====Using the <tt>DBWSBuilder</tt> utility to create an EclipseLink DBWS Service from a Stored Procedure====
+
Create an EclipseLink DBWS builder XML File with a <tt>&lt;procedure&gt;</tt> <b>query operation</b>:
+
<span id="Example 9-3"></span>
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+
  <properties>
+
    <property name="projectName">procedure_test</property>
+
    ...
+
    <property name="wsdlLocationURI">http://localhost:7001/procedure_test/procedure_test?wsdl</property>
+
    </properties>
+
  <procedure
+
    returnType="empType"
+
    catalogPattern="SOME_PKG"
+
    schemaPattern="SCOTT"
+
    procedurePattern="GetEmployeeByEMPNO_DEPTNO"/>
+
  </procedure>
+
</dbws-builder>
+
</source>
+
For more information, see [[whatever]].
+
 
+
===How to Customize an EclipseLink DBWS Service===
+
There are a number use-cases that require an EclipseLink DBWS Service to be customized. The use-cases can be sub-divided into
+
* simple - changing an &lt;element-tage&gt; to an "attribute"
+
* intermediate - customizing the EclipseLink ORM Project
+
* advance - hand-generating all required deployment artifacts
+
 
+
====Simple EclipseLink DBWS Customization====
+
 
+
 
+
====Intermediate EclipseLink DBWS Customization====
+
 
+
with an EclipseLink SessionCustomizer as follows:
+
<ol>
+
<li>Implement a '''org.eclipse.persistence.config.SessionCustomizer''', as the following example shows. <br>
+
<span id="Example 9-4"></span><br>
+
''''' Implementing a SessionCustomizer '''''
+
<source lang="java5">
+
import org.eclipse.persistence.config.SessionCustomizer;
+
import org.eclipse.persistence.sessions.Session;
+
import org.eclipse.persistence.sessions.DatabaseLogin;
+
 
+
public class MySessionCustomizer implements SessionCustomizer {
+
 
+
  public void customize(Sesssion session) {
+
    DatabaseLogin login = (DatabaseLogin)session.getDatasourceLogin();
+
    login.setTransactionIsolation(DatabaseLogin.TRANSACTION_READ_UNCOMMITTED);
+
  }
+
}
+
</source>
+
In the builder XML file, specify if the customization applies to the ORM Project or the OXM Project:
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+
  <properties>
+
    <property name="projectName">customize_test</property>
+
    ...
+
    <property name="orSessionCustomizerClassName">some.java.package.MyORSessionCustomizer</property>
+
</source>
+
or
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+
  <properties>
+
    <property name="projectName">customize_test</property>
+
    ...
+
    <property name="oxSessionCustomizerClassName">some.java.package.MyOXSessionCustomizer</property>
+
</source>
+
 
+
====Advanced EclipseLink DBWS Customization====
+
You can customize an EclipseLink DBWS service by creating your own '''project.xml''' and '''sessions.xml''' files.
+
 
+
Before you can deploy the EclipseLink database Web service, you must package the WAR in the appropriate Java EE archive for your application, such as an EAR.
+
 
+
===== Unstructured Data =====
+
In some circumstances, an EclipseLink database Web services operation may return unstructured data rather than a persistent entity. For example:
+
*a resultSet from a custom SQL SELECT statement;
+
*information returned by a Stored Procedure;
+
*scalar results such as from a Stored Function or a count of updated-rows from an update operation.
+
 
+
The OC4J Web services provider will return such unstructured data as documents that
+
conform to the Simple XML Format (SXF) schema shown in this example.
+
 
+
<span id="Example 9-6"></span>
+
'''''Simple XML Format XSD for Unstructured Data '''''
+
 
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
<xsd:complexType name="sxfType">
+
<xsd:sequence>
+
<xsd:any minOccurs="0"/>
+
 
+
 
+
</xsd:sequence>
+
 
+
 
+
</xsd:complexType>
+
 
+
 
+
<xsd:element name="simple-xml-format" type="sxfType"/>
+
</xsd:schema>
+
</source>
+
 
+
The following example shows a typical unstructured data document. Note the following:
+
*Element tag names are direct copies of table column names.
+
*The default root-element tag name is simple-xml-format and each row uses the tag name simple-xml. You can customize these element tag names using simpleXMLFormatTagand xmlTag attributes of builder operations (see [[#Table 9-5|Common Attributes of Builder Operations]]).
+
*Columnar data uses tag names taken either from the database schema (the actual database column name) or from the stored procedure, stored function, or trigger.
+
 
+
 
+
<span id="Example 9-7"></span>
+
 
+
''''' Example Unstructured Data Document '''''
+
<source lang="xml">
+
 
+
<simple-xml-format>
+
<simple-xml>
+
<ENAME>SCOTT</ENAME>
+
<JOB>ANALYST</JOB>
+
<MGR>7566</MGR>
+
<HIREDATE>1987-04-19T00:00:00.000-0400</HIREDATE>
+
<SAL>3000</SAL>
+
<DEPTNO>20</DEPTNO>
+
</simple-xml>
+
<simple-xml>
+
<ENAME>SMITH</ENAME>
+
<JOB>CLERK</JOB>
+
<MGR>7902</MGR>
+
<HIREDATE>1980-12-17T00:00:00.000-0400</HIREDATE>
+
<SAL>800</SAL>
+
<DEPTNO>20</DEPTNO>
+
</simple-xml>
+
 
+
 
+
</simple-xml-format>
+
</source>
+
 
+
 
+
===== EclipseLink Database Web Services Customization =====
+
To customize an EclipseLink database Web service, you can do the following:
+
*Implement an EclipseLink SessionCustomizer class.
+
<blockquote>
+
A SessionCustomizer is a Java class that implements the eclipselink.tools.sessionconfiguration.SessionCustomizer interface and provides a default (zero-argument) constructor.
+
 
+
Use this class's customizemethod, which takes an eclipselink.sessions.Session, to programmatically access advanced EclipseLink session API. Using this API you can get object relational and XML descriptors and from descriptors, you can get object relational and XML mappings.
+
 
+
In this way, you can access all session, descriptor, and mapping API to customize any part of the EclipseLink runtime that the EclipseLink database Web service generates. For example, to turn off the session cache. This approach is best when you just want to customize a few details.
+
 
+
You specify the SessionCustomizerusing DBWSBuilder properties (see [[EclipseLink dbws-builder.xml File (ELUG)#eclipselink-dbws-builder.xml|eclipselink-dbws-builder.xml]] and [[#DBWSBuilder]]).
+
 
+
By default, the session names are defined based on the eclipselink-dbws.xml
+
file (see [[EclipseLink dbws-builder.xml File (ELUG)#eclipselink-dbws.xml File|eclipselink-dbws.xml File]]) name attribute as follows:
+
*relational session name: name-dbws-or-session
+
*object-xml session name: name-dbws-ox-session
+
</blockquote>
+
*Manually generate project.xml files and sessions.xml file.
+
<blockquote>
+
Using your preferred tool you can map your objects to your relational database in an EclipseLink relational project, map your objects to your XML schema in an EclipseLink XMl project, and create an EclipseLink sessions.xmlfile that references both projects.
+
 
+
In this way, you can control all aspects of the relational and XML mapping. This
+
approach is best when you want to customize most or all details.
+
 
+
</blockquote>
+
 
+
 
+
=== Binding ===
+
The binding nested element of the sqlbuilder operation is an EclipseLink database Web services function that you use to bind an argument in an SQL statement to an XSD data type (see [[#Table 9-8|Attributes of the sql Operation]]). You define this element in the eclipselink-dbws-build.xml file (see [[#Example 9-5|eclipselink-dbws-build.xml File]]).
+
 
+
 
+
<span id="Table 9-2"></span>
+
''''' Attributes of the binding Element '''''
+
 
+
Attribute Description Required
+
name The name of the stored procedure, stored function, or trigger to execute. The parent
+
builder operation specifies the database that provides the stored procedure, stored
+
function, or trigger.
+
Yes
+
type The XSD data type to bind to the argument name. Yes
+
 
+
 
+
This example shows a typical sql operation that specifies arguments using nested bindingelements. The order in which you define bindingelements must match the order of the arguments in your SQL statement.
+
 
+
<span id="Example 9-8"></span>
+
''''' SQLOperation Task: With Binding Elements for Arguments '''''
+
 
+
<source lang="xml">
+
...
+
 
+
 
+
<sql name="findXREmpByName" isCollection="true" returnType="xr_empType">
+
<text>
+
<![CDATA[select * from EMP where EMPNO = ? and LAST_NAME = ?]]>
+
</text>
+
<binding name="EMPNO" type="xsd:int"/>
+
<binding name="LAST_NAME" type="xsd:string"/>
+
 
+
 
+
</sql>
+
...
+
</source>
+
 
+
For more information, see [[EclipseLink dbws-builder.xml File (ELUG)#eclipselink-dbws-builder.xml|eclipselink-dbws-builder.xml]].
+
 
+
=== DBWSBuilder ===
+
The EclipseLink database Web service design-time tool, DBWSBuilder, is a Java application that produces EclipseLink database Web service files and assembles them into a Web Archive (WAR) file.
+
 
+
You set the DBWSBuilder’s properties (see [[EclipseLink dbws-builder.xml File (ELUG)#Table 9-4|eclipselink-dbws-builder.xml File Elements (DBWSBuilder Properties)]]) to define features of your EclipseLink database Web service.
+
 
+
You can also set the design-time tool’s properties, add table and procedure definitions, and SQL operations programmatically through the API. Use the eclipselink.tools.dbws.DBWSBuilder class’s methods such as setDriver, setProjectName, setURL, and so on, to set properties; the addDbTableand addDbStoredProceduremethods-to add table and procedure definitions; and the addSQLOperation method-to add SQL operations.
+
 
+
{| class="Note oac_no_warn" width="80%" border="1" frame="hsides" rules="groups" cellpadding="3" frame="hsides" rules="groups"
+
| align="left" |
+
'''Note''': Before adding a table or procedure definition, ensure that the definitions are supported by calling the checkTablesand checkStoredProcedures methods.
+
|}
+
 
+
Once you set all the data and definitions, invoke the builder using its build method.
+
 
+
 
+
 
+
 
+
----
+
''[[EclipseLink User's Guide Copyright Statement|Copyright Statement]]''
+
 
+
 
+
[[Category: EclipseLink User's Guide]]
+
[[Category: Release 1.1]]
+
[[Category: DBWS]]
+

Latest revision as of 06:33, 14 August 2012

Elug draft icon.png For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/

For the latest EclipseLink DBWS documentation, see Developing Persistence Architectures Using EclipseLink Database Web Services, Release 2.4


Note: A basic overview of EclipseLink Database Web Services (DBWS) can be found here