SDO Tutorial
The objective of this SDO Tutorial is to provide a general introduction to the Service Data Objects (SDO) specification, which defines a generic API for accessing and manipulating data as part of a Service Oriented Architecture (SOA). Currently, SDO specifications exist for Java and C++ but other anguages may be supported in the future. This tutorial demonstrates how to use the Java SDO API and the code samples in the tutorial have been tested with Apache Tuscany SDO
SDO provides an API for accessing and manipulating structured data. The SDO API is independent of the actual data source. For example, SDO can be used to access XML data or SQL data. Typically, a Data Access Service (DAS) is used to populate SDO objects from some data store.
One of the main benefits of SDO is that it actually tracks changes made to a dataset and can pass that change summary to other services by serializing it to XML.
SDO Tutorial: SDO Main Classes
| Type | Definition of a simple or complex data type. SDO contains a number of built-in data types, including commonj.sdo#String and commonj.sdo#DataObject but users can define their own types. |
| Property | Definition of a property within an SDO Type. |
| DataObject | DataObject is the fundamental representation of a piece of data and lies at the core of the SDO API. DataObject provides get/set methods for accessing and manipulating its properties. A DataObject's properties can contain simple values, other DataObjects, or Lists of simple values of DataObjects. DataObjects can contain references to other DataObjects or they can contain them. This makes DataObject suitable for hierarchical data models (XML) as well as relational models (SQL). |
| DataGraph | Container object for a tree of DataObjects. |
SDO Tutorial: The SDO Environment and HelperContext
SDO defines a HelperContext interface for accessing a set of related SDO Helper classes for performing common operations such as reading and writing XML documents, defining SDO types from XML Schema, and so on. All SDO implementations provide a default context, which can be obtained by calling HelperProvider.getDefaultContext(). Some implementations offer methods for creating new isolated contexts but this is not currently required by the SDO specification.
Obtaining a default HelperContext
HelperContext helperContext = HelperProvider.getDefaultContext() |
SDO Tutorial: SDO Types and Properties
SDO provides type-safe access to data through the use of types and properties. SDO types can be created programatically but typically are created by parsing an XML Schema (using the XSDHelper class) or are defined automatically by the Data Access Service.
SDO types can be accessed via the TypeHelper interface.
Type stringType = helperContext.getTypeHelper().getType( "commonj.sdo", "String" ); |
SDO Tutorial: Reading XML Documents (Without Schema)
For XML documents with no schema and where no SDO types have been explicitly defined for the document structure, there are some simple rules for how the XML gets mapped to SDO. Each XML element becomes an SDO DataObject and each attribute becomes an SDO Property.
Simple XML Example
| <?xml version="1.0"?> <test> <person name="Andy Grove" /> </test> |
Java source code
HelperContext ctx = HelperProvider.getDefaultContext(); |
SDO Tutorial: Defining Types programatically
SDO types can be created by populating a "{commonj.sdo}Type" DataObject.
HelperContext ctx = HelperProvider.getDefaultContext(); |
SDO Tutorial: Defining Types from XSD
Rather than programmatically defining SDO types it is possible to load them from an XML Schema using the SDO XSDHelper class, as shown in the following code fragment.
HelperContext ctx = HelperProvider.getDefaultContext(); |
SDO Tutorial: Serializing SDO to XML
The XMLHelper interface provides methods for serializing DataObject or XMLDocument instances to XML.


