Oracle Data Service Integrator implements Service Data Objects (SDO) as its data client-application programming model. This chapter discusses SDO concepts and APIs that are of interest to Oracle Data Service Integrator client application developers.
Note: | Oracle Data Service Integrator 10gR3 does not support backward compatibility with ALDSP 2.x (all ALDSP 2.x deprecated APIs are no longer supported in Oracle Data Service Integrator 10gR3). This includes all classes in the com.bea.dsp.dsmediator.client and com.bea.ld.dsmediator.update packages. |
SDO is an architecture and set of APIs for working with data objects while disconnected from their source. In Oracle Data Service Integrator, SDO-compliant data objects— whether typed or untyped data objects — are obtained from data services through Mediator APIs or through Data Service controls. (See also “Introducing Service Data Objects (SDO)” on page 1-6.)
Client applications manipulate the data objects as required for the business process at hand, and then submit changed objects to the data service, for propagation to the underlying data sources. Although the SDO specification does not define one, it does discuss the need for mediator services, in general, that can send and receive data objects; the specification also discusses the need for handling updates to data sources, again, without specifying an implementation: The SDO specification leaves the details up to implementors as to how mediator services are implemented, and how they should handle updates to data objects.
As discussed in “Introducing the Data Service Mediator API” on page 1-7, the Oracle Data Service Integrator Data Service Mediator is the process that not only handles the back-and-forth communication between client applications and data services, it also facilitates updates to the various data sources that comprise any data service.
This chapter includes information about the Oracle Data Service Integrator implementation of the SDO data programming model, as well as its update framework.
When you invoke a data service’s read operation through the Data Service Mediator API, a data object is returned. Data objects are the fundamental artifacts of the SDO data programming model.
Tip: | For information on the Mediator API, see Chapter 3, “Invoking Data Services from Java Clients.” |
Data objects represent the contents of a complex type. A data object contains properties, which represent elements and attributes. The properties can be of simple or complex types. In SDO, a simple type property is called a datatype property, while a complex type property contains a data object (which in turn has properties).
Data objects can be defined to contain a special kind of property called a change summary. A change summary is used to track changes to the data object. As changes are made to the properties (or properties of nested descendant data objects), the changes are captured in the change summary.
The change summary is used by the Mediator to derive the update plan and ultimately, to update data sources. The change summary submitted with each changed SDO remains intact, regardless of whether or not the update function succeeds, so it can support rollbacks when necessary.
A datagraph is a built-in data object type that is defined to have a change summary property. Thus it is convenient to use a datagraph to encapsulate change tracking. The datagraph has one immediate data object child, and a change summary that can track changes to this data object. Figure 2-1 shows the structure of a datagraph.
SDO specifies both static (typed) and dynamic (untyped) interfaces for data objects:
get("Customer")
or set("Customer")
. The dynamic data object API can be used with data types that have not yet been deployed at development time.
Table 2-2 summarizes the advantages of each approach.
SDO’s static data object API is a typed Java interface generated from a data service’s XML schema definition. It is similar to JAXB or XMLBean static interfaces. The interface files, packaged in a JAR, are typically generated by the data service developer using WebLogic Workshop, or by using one of the provided tools.
The generated interfaces extend the commonj.sdo.DataObject interface and provide typed getters and setters for all properties of the XML datatype.
An interface is also generated for each complex property (such as CREDIT and ORDER shown in Figure 2-3), with getters and setters for each of the properties that comprise the complex type.
For many-valued properties, a get method is generated that returns a java.util.List object. A many-valued property corresponds to an XML schema element that has maxOccurs greater than one. The List returned by a get method for a many-valued property is “live.” This means that if you modify the List object, the changes are reflected directly and immediately in the containing data object.
As an example of how static data object APIs are generated, given the CUSTOMER data type shown in Figure 2-3, generating typed client interfaces results in CUSTOMER, CREDIT, ORDER, and POITEM interfaces, each of which includes getters, setters, and factory classes (for instantiating static data objects and their properties).
When you develop Java client applications that use SDO’s static data object APIs, you will import these typed interfaces into your Java client code. For example:
import appDataServices.AddressDocument;
Table 2-4 lists static data accessor and related API methods. These methods are generated using names that match the schema names with the first letter in the name forced to be upper-case. The generated names cannot conflict with standard Java naming rules.
Oracle Data Service Integrator client application developers can use the Oracle Data Service Integrator Administration Console to view the XML schema types associated with data services (see Figure 2-3, CUSTOMER Return Type Displayed in Oracle Data Service Integrator Administration Console’s Metadata Browser, on page 2-5). The Return Type tab indicates the data type of each element—string, int, or complex type, for example. The XML schema data types are mapped to corresponding Java types using the data type mappings shown in Table 2-5.
Note: | The following XQuery types are discussed by the SDO specification and are listed in Table 2-5 but are not supported for input or output from the Mediator API: xs:ENTITIES, xs:ENTITY, xs:ID, xs:IDREF, xs:IDREFS, xs:language, xs:Name, xs:NCName, xs:NMTOKEN, xs:NMTOKENS, xs:NOTATION. The Mediator API is discussed in Chapter 3, “Invoking Data Services from Java Clients.” |
Every static (typed) data object implements the Data Object interface; therefore, you can use the DataObject (dynamic) methods as well as the static API. This API provides generic property getters and setters for specific Java data types (String, Date, List, BigInteger, and BigDecimal, for example). Table 2-6 lists representative APIs from SDO’s dynamic Data Object API. The propertyName argument indicates the name of the property whose value you want to get or set; propertyValue is the new value. The dynamic Data Object API also includes methods for setting and getting a DataObject’s property by indexValue. This includes methods for getting and setting properties as primitive types, which include setInt( ), setDate( ), getString( ), and so on.
As an example, assuming that you have a reference to a CUSTOMER data object, you can use the dynamic Data Object API to get the LAST_NAME property as follows:
String lastName = customer.getString("LAST_NAME");
The SDO APIs are standard implementations. You can read the full SDO specification, “SDO for Java Specification V2.1” here:
See also Service Data Objects on the Oracle Technology Network.
Table 2-6 lists dynamic Data Object API getters and setters.
Oracle Data Service Integrator supports a limited subset of XPath expressions called SDO path expressions. SDO path expressions offer flexibility in how you locate data objects and attributes in the dynamic Data Object API’s accessors. For example, you can filter the results of a get( ) method invocation based on data elements and values:
company.get("CUSTOMER[1]/POITEMS/ORDER[ORDERID=3546353]")
The SDO path implementation augments XPath 1.0 support by adding zero-based array index notation (“.index_from_0”) to XPath’s standard bracketed notation ([n]). As an example, Table 2-7 compares the XPath standard and SDO augmented notations to refer to the same element, the first ORDER child node under CUSTOMER (Table 2-7).
Zero-based indexing is convenient for Java programmers who are accustomed to zero-based counters, and may want to use counter values as index values without adding 1. Oracle Data Service Integrator fully supports both the traditional index notation and the augmented notation.
Keep in mind these other points regarding Oracle Data Service Integrator XPath support:
("CUSTOMER//POITEM")
In this example, the wildcard matches all purchase order arrays below the CUSTOMER root, which includes either of the following:
CUSTOMER/ORDERS/POITEM
CUSTOMER/RETURNS/POITEM
Because this notation introduces type ambiguity (types can be either ORDERS or RETURNS), it is not supported by the Oracle Data Service Integrator SDO implementation.
<ORDER ID="3434">
See also “Specifying XPath Expressions as Arguments” on page 3-59.
The dynamic Data Object API returns generic data objects. To obtain information about the properties of a data object, you can use methods available in SDO’s Type interface. The Type interface (located in the commonj.sdo
package) provides several methods for obtaining information, at runtime, about data objects, including a data object’s type, its properties, and their respective types.
According to the SDO specification, the Type interface (see Table 2-8) and the Property interface (see Table 2-9) comprise a minimal metadata API that can be used for introspecting the model of data objects. For example, the following obtains a data object’s type and prints a property’s value:
DataObject o = ...;Type type = o.getType();
System.out.println(o.getString("CUSTOMERNAME")); }
if (type.getName().equals("CUSTOMER") {
Once you have an object’s data type, you can obtain all its properties (as a list) and access their values using the Type interface’s get Properties() method, as shown in Listing 2-1.
public void printDataObject(DataObject dataObject, int indent) {
Type type = dataObject.getType();
List properties = type.getProperties();
for (int p=0, size=properties.size(); p < size; p++) {
if (dataObject.isSet(p)) {
Property property = (Property) properties.get(p);
// For many-valued properties, process a list of values
if (property.isMany()) {
List values = dataObject.getList(p);
for (int v=0; count=values.size(); v < count; v++) {
printValue(values.get(v), property, indent);
}
else { // For single-valued properties, print out the value
printValue(dataObject.get(p), property, indent);
}
}
}
}
Table 2-8 lists other useful methods in the Type interface.
Table 2-9 lists the methods of the Property interface.
In Oracle Data Service Integrator, data objects are passed between data services and client applications: when a client application invokes a read function on a data service, for example, a data object is sent to the client application. The client application modifies the content as appropriate—adds an order to a customer order, for example—and then submits the changed data object to the data service. The Data Service Mediator is an API that receives the updated data objects and propagates changes to the underlying data sources.
The Data Service Mediator is the linchpin of the update process. It uses information from submitted data objects (change summary, for example) in conjunction with other artifacts to derive an update plan for changing underlying data sources. For relational data sources, updates are automatic. The artifacts that comprise the Oracle Data Service Integrator update framework, including the Mediator, and how the default update process works, are described in more detail in “Managing Update Maps” in the Data Services Development Guide.
For detailed information on using the Mediator APIs for web services clients and Java clients, see: