Client Application Developer’s Guide

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Data Programming Model and Update Framework

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.

 


Introduction

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.

 


Oracle Data Service Integrator and SDO

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.

Figure 2-1 Structure of a DataGraph

Structure of a DataGraph

Static and Dynamic Data Object APIs

SDO specifies both static (typed) and dynamic (untyped) interfaces for data objects:

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.

Table 2-2 Static and Dynamic Data Object APIs
Data Model
Advantages...
Static Data Object API
  • Easy-to-implement interface; code is easy to read and maintain.
  • Compile-time type checking.
  • Enables code-completion in Workshop for WebLogic Source View.
Dynamic Data Object API
  • Dynamic; allows discovery.
  • Runtime type checking.
  • Allows for a general-purpose coding style.

Static Data Object API

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).

Figure 2-3 CUSTOMER Return Type Displayed in Oracle Data Service Integrator Administration Console’s Metadata Browser

CUSTOMER Return Type Displayed in Oracle Data Service Integrator Administration Console’s Metadata Browser

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.

Table 2-4 Static (Typed) Data Object API Getters and Setters
Static Data Object API (Generated)
Description
Examples
Type getPropertyName()
Returns the value of the property. Generated for boolean-valued properties.
String name = getLAST_NAME()
List<Type> getPropertyName()
For multiple occurrence elements, returns all PropertyName elements.
List<ORDER> orders = getORDER()
void setPropertyName(Type newValue)
Sets the value of the property to the newValue.
setLAST_NAME(”Smith”)
boolean isPropertyName()
Determines whether the PropertyName element or attribute exists in the data object.
isSPECIAL_DELIVERY()
void createPropertyName()
Generated only for non-datatype properties. Creates a data object for the specified property. The (created) data object is initialized with no values in its properties.
createORDER()
boolean isSetPropertyName()
Determines whether the property is set to some value.
isSetLAST_NAME()
void unsetPropertyName()
Unsets the property. The property is then considered not to be set.
unsetLAST_NAME()

XML Schema-to-Java Type Mapping Reference

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.”

Table 2-5 XML Schema to Java Data Type Mapping 
XML Schema Type
SDO Java Type
XML Schema Type
SDO Java Type
xs:anyType
commonj.sdo.DataObject
xs:integer
java.math.BigInteger
xs:anySimpleType
java.lang.Object
xs:language
String
xs:anyURI
String
xs:long
long or java.lang.Long
xs:base64Binary
byte[]
xs:Name
String
xs:boolean
boolean or java.lang.Boolean
xs:NCName
String
xs:byte
byte or java.lang.Byte
xs:negativeInteger
java.math.BigInteger
xs:date
String
xs:NMTOKEN
String
xs:dateTime
String
xs:NMTOKENS
List<String>
xs:decimal
java.math.BigDecimal
xs:nonNegativeInteger
java.math.BigInteger
xs:double
double or java.lang.Double
xs:nonPositiveInteger
java.math.BigInteger
xs:duration
String
xs:normalizedString
String
xs:ENTITIES
List<String>
xs:NOTATION
String
xs:ENTITY
String
xs:positiveInteger
java.math.BigInteger
xs:float
float or java.lang.Float
xs:QName
String
xs:gDay
String
xs:short
short or java.lang.Short
xs:gMonth
String
xs:string
String
xs:gMonthDay
String
xs:time
String
xs:gYear
String
xs:token
String
xs:gYearMonth
String
xs:unsignedByte
short or java.lang.Short
xs:hexBinary
byte[]
xs:unsignedInt
long or java.lang.Long
xs:ID
String
xs:unsignedLong
java.math.BigInteger
xs:IDREF
String
xs:unsignedShort
int or java.lang.Integer
xs:IDREFS
List<String>
xs:keyref
String
xs:int
int or java.lang.Integer
   

Dynamic Data Object API

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:


http://www.osoa.org/display/Main/Service+Data+Objects+Specifications 

See also Service Data Objects on the Oracle Technology Network.

Table 2-6 lists dynamic Data Object API getters and setters.

Table 2-6 Dynamic (Untyped) Data Object API Getters and Setters
Dynamic Data Object API
Description
Example
get(int PropertyIndex)
Returns the PropertyName child element at the specified index.
get(5)
set(int PropertyIndex, Object newValue)
Sets the value of the property to the newValue.
set(5, CUSTOMER3)
set(String PropertyName, Object newValue)
Sets the value of the PropertyName to the newValue.
set("LAST_NAME", "Nimble")
set(commonj.sdo.Property property, Object newValue)
Sets the value of Property object to the newValue.
set(LASTNAME, "Nimble")
getType(String PropertyName)
Returns the value of the PropertyName. Type indicates the specific data type to obtain.
getBigDecimal("CreditScore")
unset(int PropertyIndex)
Unsets the property. The property is then considered not to be set.
unset(5)
unset(commonj.sdo.Property property)
Unsets the property. The property is then considered not to be set.
unset(LASTNAME)
unset(String PropertyName)
Unsets the property. The property is then considered not to be set.
unset("LAST_NAME")
createDataObject(commonj.
sdo.Property property)
Returns a new DataObject for the specified containment Property.
createDataObject(LASTNAME)
createDataObject(String PropertyName)
Returns a new DataObject for the specified containment property.
createDataObject("LAST_NAME")
createDataObject(int PropertyIndex)
Returns a new DataObject for the specified containment property.
createDataObject(5)
createDataObject(String PropertyName, String namespaceURI, String typeName)
Returns a new DataObject for the specified containment property.
createDataObject("LAST_NAME","http://namespaceURI_here", "String")
delete()
Removes the object from its container and unsets all writeable properties.
delete(CUSTOMER)

XPath Expressions in the Dynamic Data Object API

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).

Table 2-7 XPath Standard and SDO Augmented Notation
XPath Standard Notation
SDO Augmented Notation
get("CUSTOMER/ORDER[1]");
get("CUSTOMER/ORDER.0");

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:

See also “Specifying XPath Expressions as Arguments” on page 3-59.

Obtaining Type Information about Data Objects

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();
if (type.getName().equals("CUSTOMER") {
System.out.println(o.getString("CUSTOMERNAME")); }

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.

Listing 2-1 Using SDO’s Type Interface to Obtain Data Object Properties
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-8 Type Interface Methods
Method
Description
java.lang.Class getInstanceClass()
Returns the Java class that this type represents.
java.lang.String getName()
Returns the name of the type.
java.lang.List getProperties
Returns a list of the properties of this type.
Property getProperty(
java.lang.String propertyName)
Returns from among all Property objects of the specified type the one with the specified name. For example, dataObject.get("name") or dataObject.get(dataObject.getType().getProperty("name"))
java.lang.String getURI()
Returns the namespace URI of the type.
boolean isInstance(
java.lang.Object object)
Returns True if the specified object is an instance of this type; otherwise, returns false.

Table 2-9 lists the methods of the Property interface.

Table 2-9 Property Interface Methods
Method
Description
Type getContainingType()
Returns the containing type of this property.
java.lang.Object getDefault()
Returns the default value this property will have in a data object where the property has not been set
java.lang.String getName()
Returns the name of the property.
Type getType()
Returns the type of the property.
boolean isContainment()
Returns True if the property represents by-value composition.
boolean isMany()
Returns True if the property is many-valued.

 


Role of the Mediator API and SDO

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:


  Back to Top       Previous  Next