Click "Browse" to select a root directory, and point to the folder containing this example. After selecting the directory, you should see the project name in the "Projects" list. Click "Finish".

This project is configured to use a classpath variable, ECLIPSELINK_JLIB, to point to the required JAR files. After the project is imported, you should define a variable called ECLIPSELINK_JLIB to point to your EclipseLink jlib directory.

Running the SDO Compiler

The SDO compiler can be run to generate Static SDO Java files from an XML Schema:

For each complex type in the schema, the compiler will generate both an interface (e.g. CustomerType.java), and a concrete implementation which subclasses org.eclipse.persistence.sdo.SDODataObject (e.g. CustomerTypeImpl.java). For this example we will only deal with the generated interfaces.

In this example, the SDO Compiler is run from the "run.sdo.compiler" task in the ANT build file.

Initializing the Types from XML Schema

The first thing that needs to be done in an SDO application is to set up the metadata for the Types and Properties. This is most commonly done by loading an XML schema, although it may also be done programmatically.

Tracking Object Modifications using Change Summary

SDO's Change Summary provides access to change history information for the DataObjects in a data graph. A change history covers any modifications that have been made to a data graph starting from the point when logging was activated.

In order to use Change Summary, we have defined an element of type "sdo:ChangeSummaryType" on our root complex type:

Marshalling the DataObjects

The following code segment demonstrates how to marshal DataObjects wrapped in a commonj.sdo.helper.XMLDocument back to XML. In this example the stream we are saving to is System.out, so the XML text will be printed to the console.

XMLHelper.INSTANCE.save(xmlDocument, System.out, null);

Interpreting the Change Summary

When the document is saved to System.out, we can see the change summary information in the XML:

For DataObjects with modified data type properties, the Change Summary element contains a copy of the DataObject from the data graph, but containing only the properties which have changed, and showing their old values. In our example, we see a "shipping-address" element which references "#/ns1:contact-info/shipping-address" (the element that was modified), along with its old value, "12345".

DataObjects which are currently in the data graph, but were not present when logging was started are indicated in the change summary with a "create" attribute. If more than one DataObject had been created, the attribute would contain a space-separated list of references, one for each DataObject. In our example, we see a "create" attribute indicating that "#/ns1:contact-info/ns1:phone-number\[2\]" (the second phone number in the XML) is the newly created one.

DataObjects deleted during logging are flagged with the "delete" attribute. In this case the change summary also contains a deep copy of the object which was deleted, as it no longer appears in the data graph. Here, we see a "delete" attribute indicating that "#/changeSummary/ns1:contact-info/ns1:phone-number\[2\]" (the second phone number in the Change Summary) is the one that was deleted from the XML.

Download

Download the "Examples Zip" from the EclipseLink Downloads page. Code for this example will be found in the org.eclipse.persistence.example.sdo.staticapi.zip file.