Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/SDO/Using EclipseLink SDO (ELUG)"
m (→Using SDO as a Web Service Binding Layer) |
m (→Using SDO as a Web Service Binding Layer) |
||
Line 137: | Line 137: | ||
You can easily invoke a Web service and obtain results in the form of data objects, as the following example shows: | 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"); | + | DataObject resultEnvelope = WebService.invoke(po, "http://werbservices.org/purchaseOrder", |
+ | soap, "Envelope"); | ||
// Get the purchase order from the result envelope | // Get the purchase order from the result envelope |
Revision as of 14:42, 1 May 2009
This section explains where and how you use EclipseLink SDO to customize your application to meet requirements.
Contents
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:
- EclipseLink SDOHelperContext API
- EclipseLink HelperContext examples
What You May Need to Know About Local and Global HelperContext
All the helpers that you can retrieve using accessor methods or instance fields of the global HelperContext have visibility to the global SDO metadata, that is, their scope of execution is global.
The opposite is true for the local HelperContext, such as the SDOHelperContext provided by EclipseLink: you can use it to obtain helpers that have visibility to the local SDO metadata.
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 default DataFactory from the INSTANCE field or from the getDataFactory method of the default HelperContext.
You can also define and retrieve the HelperContext from your EclipseLink SDODataFactory.
For more information, see the following:
- EclipseLink SDODataFactory API
- EclipseLink DataFactory examples
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 default XMLHelper from the INSTANCE field or from the getXMLHelper method of the default HelperContext.
The EclipseLink SDOXMLHelper initializeDescriptor method allows you to define an XML descriptor for your application.
For more information, see the following:
- EclipseLink SDOXMLHelper API
- EclipseLink XMLHelper examples
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 default DataHelper from the INSTANCE field or from the getDataHelper method of the default HelperContext.
You can also define and retrieve the HelperContext from your EclipseLink SDODataHelper.
For more information, see the following:
- EclipseLink SDODataHelper API
- EclipseLink DataHelper examples
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 default CopyHelper from the INSTANCE field or from the getCopyHelper method of the default HelperContext.
You can also define and retrieve the HelperContext from your EclipseLink SDOCopyHelper.
For more information, see the following:
- EclipseLink SDOCopyHelper API
- EclipseLink CopyHelper examples
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 default EqualityHelper from the INSTANCE field or from the getEqualityHelper method of the default HelperContext.
You can also define and retrieve the HelperContext from your EclipseLink SDOEqualityHelper.
For more information, see the following:
- EclipseLink SDOEqualityHelper API
- EclipseLink EqualityHelper examples
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.setRequestMethod("POST"); connection.setDoOutput(true); 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); os.flush(); } // invoke the service connection.connect(); 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
Information pending