SDO Metadata
As well as providing a standardized API for accessing data across multiple data sources, SDO also provides a common API for accessing metadata about the data source. While the SDO data access API provides DataGraph and DataObject interfaces for accessing and updating data, the SDO metadata API provides Type and Property interfaces.
A code sample speaks a thousand words, as they say, so here's an example for accessing metadata about a database table using the SDO metadata API:
|
// create the Data Access Service SQLDataAccessService das = SQLDataAccessServiceFactory.create( "sampledb" ); // select some rows from the customer table DataGraph data = das.selectRows( "customer", "state = ?", new Object[] { "MA" } ); DataObject root = data.getRootObject(); // retrieve a customer and query its type DataObject customer = root.getDataObject( "customer.0" ); Type customerType = customer.getType(); // look up a property (column) of the customer object Property idProp = customerType.getProperty( "id" ); // examine the data type of the "id" property assertEquals( "commonj.sdo", idProp.getType().getURI() ); assertEquals( "Int", idProp.getType().getName() ); |
This is a simple example, but the capability is demonstrated well enough. It is possible to query the type of any DataObject and then get a list of properties supported by that type. This makes it possible to build dynamic applications for interacting with SDO data sources (for instance, a data browser/explorer interface) regardless of the type of data source (relational database, XML repository, etc.).
SDO also defines its own data types to ensure that applications can be built in a portable way between languages and data sources. Mappings between SDO data types and Java data types are defined in the SDO for Java specification.