Jump to: navigation, search

EclipseLink/UserGuide/SDO/Using EclipseLink SDO (ELUG)

< EclipseLink‎ | UserGuide
Revision as of 10:55, 21 May 2009 by Blaise.doughan.oracle.com (Talk | contribs) (Using EqualityHelper)

This section explains where and how you use EclipseLink SDO to customize your application to meet requirements.

Performing Actions on Data Objects at Run Time

Use the following classes to perform actions on your data objects:

For more information, see EclipseLink SDO examples.

Using HelperContext

SDO defines a HelperContext interface. You use it to access related SDO helper classes that let you perform common operations such as reading and writing XML documents, defining SDO types from XML Schema, and so on.

To obtain a default context, call the HelperProvider getDefaultContext method.

You can create the local context provided by EclipseLink as follows:

HelperContext helperContext = new SDOHelperContext();

For more information, see the following:

What You May Need to Know About Local and Global HelperContext

All the helpers that you can retrieve from the INSTANCE fields are the same ones as can be accessed from HelperProvider.

XSDHelper.INSTANCE == HelperProvider.getDefaultContext().getXSDHelper()

In terms of Java serialization, both global and local HelperContexts can be used to serialize DataObjects, but the global HelperContext is always used for deserialization.

Using the EclipseLink SDOHelperContext makeDefaultContext method, you can promote your local context to become the global (default) one.

Using DataFactory

You use the DataFactory to create disconnected instances of a DataObject. That is, the newly created DataObject instances have no set properties and no container.

You can obtain the global DataFactory from the INSTANCE field or a DataFactory corresponding to a HelperContext using the getDataFactory method on HelperContext.

For more information, see the following:

Using XMLHelper

You use the XMLHelper to convert XML documents into data objects, and vice versa. The two main operations of the XMLHelper are load and save.

You can obtain the global XMLHelper from the INSTANCE field or a XMLHelper corresponding to a HelperContext using the getXMLHelper method on HelperContext.

For more information, see the following:

Using DataHelper

The main purpose of the DataHelper is to enable conversion of values used with data objects between data types.

You can obtain the global DataHelper from the INSTANCE field or a DataHelper corresponding to a HelperContext using the getDataHelper method on HelperContext.

For more information, see the following:

Using CopyHelper

You use the CopyHelper to create the following types of copies of data objects:

  • a copy of a DataObject's values with DataType properties;
  • a copy of a tree of DataObject instances.

You can obtain the global CopyHelper from the INSTANCE field or a CopyHelper corresponding to a HelperContext using the getCopyHelper method on HelperContext.

For more information, see the following:

Using EqualityHelper

An EqualityHelper provides methods to compare data objects and let you determine the following:

  • whether or not two DataObject instances have the same values for their DataType properties;
  • whether or not two trees of data objects are equal.

You can obtain the global EqualityHelper from the INSTANCE field or an EqualityHelper corresponding to a HelperContext using the getEqualityHelper method on HelperContext.

For more information, see the following:

Generating Static SDO Classes at Design Time

If you know the metadata, such as, for example, the XML schema definition or the SQL relational schema, at development time, you can use the code-generating interfaces for data objects. SDO enables static data API code generation from a variety of metamodels, including the following:

  • XML schema languages;
  • relational database schemas with queries known at the time of code generation;
  • Web services, when the message is specified by an XML schema;
  • JCA connectors;
  • JMS message formats;
  • UML models.

Note that when you use static data APIs, the dynamic data APIs are still available to you.

Information pending.

Performing Integration

You can integrate your SDO application with the following technologies:

The first step in this integration proccess is to create POJO/SDO bridge.

Integrating SDO with JAXB

For information and examples, see SDO-JAXB Integration with EclipseLink.

Integrating SDO with JPA

For information and examples, see SDO-JPA Integration with EclipseLink.

Using SDO as a Web Service Binding Layer

You can easily invoke a Web service and obtain results in the form of data objects, as the following example shows:

DataObject resultEnvelope = WebService.invoke(po, "http://werbservices.org/purchaseOrder", 
                                              soap, "Envelope");

// Get the purchase order from the result envelope
DataObject resultPo = resultEnvelope.getDataObject("Body/purchaseOrder");

You can also build a Web services client around the XMLHelper. For example, in a simple web service client, you could post an input DataObject representing an XML document using the XMLHelper, and then have the returning XML document returned to the caller as a DataObject:

public static DataObject invoke(DataObject input, String serviceUri,
                                String rootElementURI, String rootElementName) 
                                throws IOException {
URL address = new URL(serviceUri);
HttpURLConnection connection =
(HttpURLConnection) address.openConnection();
if (input != null) {
   connection.addRequestProperty("Content-Type", "text/xml; charset=utf-8");
   OutputStream os = connection.getOutputStream();
   // Add the XML document to the request
   XMLHelper.INSTANCE.save(input, rootElementURI, rootElementName, os);
// invoke the service
int code = connection.getResponseCode();
if (code != HttpURLConnection.HTTP_OK) {
   throw new IOException("HTTP "+code+" "+connection.getResponseMessage());
InputStream is = connection.getInputStream();
// Return the root DataObject from the web service response
DataObject output = XMLHelper.INSTANCE.load(is).getRootObject();
return output;

How to Use Web Service Attachments

Information pending

Executing XPath with XML

Many of the accessor methods for data objects make use of a String parameter that provides the path that identifies the property to which the method applies.

The XPath expression is an augmented subset of XPath with the additional ability to access data using 0 as a base index. You specify the path using the following syntax:

path ::= (scheme ':')? '/'? (step '/')* step
scheme ::= [^:]+
step ::= '@'? property
    | property '[' index_from_1 ']'
    | property '.' index_from_0
    | reference '[' attribute '=' value ']'
    | ".."
property ::= NCName ;; may be simple or complex type
attribute ::= NCName ;; must be simple type
reference :: NCName ;; must be DataObject type
index_from_0 ::= Digits
index_from_1 ::= NotZero (Digits)?
value ::= Literal
    | Number
    | Boolean
Literal ::= '"' [^"]* '"'
    | "'" [^']* "'"
Number ::= Digits ('.' Digits?)?
    | '.' Digits
Boolean ::= true
    | false
NotZero ::= [1-9]
Digits ::= [0-9]+
;; leading '/' begins at the root
;; ".." is the containing DataObject, using containment properties
;; Only the last step have an attribute as the property

Note that properties are always matched by name independent of their XML representation.

The following example shows how to construct an XPath that you can use to access a DataObject contained in another DataObject is to specify the index of the contained DataObject within the appropriate property:

DataObject department = company.getDataObject("departments.0");

Another way to access a contained DataObject is to identify that object by specifying the value of one of the attributes of that object. For example:

DataObject employee = department.getDataObject("employees[SN='E0002']");

You can also use XPath expressions to set or unset values of properties, including multivalued properties. Note that each step of the path before the last must return a single DataObject. When the property is a Sequence, the values returned are those of the getValue method.

Copyright Statement