文档库 最新最全的文档下载
当前位置:文档库 › service-data-objects-sdo2380

service-data-objects-sdo2380

STREAM 8 - SOA IN FOCUS
Service Data Objects (SDO): Handling Data Consistently in a SOA Environment
Kelvin Goodson, IBM UK – kelvin_goodson@uk.ibm.com SW Engineer Open Source SOA, Apache Tuscany
2007 ? 2008 IBM Corporation
SDO Session
SDO 2.1 Spec Introduction
2
? 2008 IBM Corporation
SDO Session
What are Service Data Objects?
Service Data Objects (SDO) provide:
– Uniform access to data from heterogeneous sources ? XML, RDB, EJB, LDAP, SOAP etc... – Has both static (strongly typed) and dynamic programming models – Disconnected “data graph” capable of tracking changes – Meta-data for easy introspection of data types – Relationship integrity enforcement – Language neutral APIs with implementations in Java, C++ and PHP
3
Page
? 2008 IBM Corporation
SDO Session
SDO for COBOL
4
? 2008 IBM Corporation
SDO Session
Instance and Model
5
Page
? 2008 IBM Corporation
SDO Session
How do I store and retrieve SDOs ?
XML Documents
– SDO specification describes serialisation to and de-serialisation from XML documents.
SDO specification discusses a Data Access Service (DAS)
– DAS is a mediator between data sources and SDO applications – Apache Tuscany currently implements an RDB DAS, and some work done on an LDAP DAS
6
Page
? 2008 IBM Corporation
SDO Session
Combining SDO and DAS
RDB
Data Graph
DataObject
JDBC
XML DB
XPath / XQuery
SDO Client
Data Access Service
:
Local
EJB: EJB: Invoice Customer
XML/HTTP Change Summary Web service CCI / Proprietary
JCA
7
Page
? 2008 IBM Corporation
SDO Session
Combining SDO with SCA
SCA SCA SCA Web Server
Component Service Account Service Component Account DataService Component
RDB
SDO .Net Web Service
SDO
Account Service Component
Reference
SDO
Composite AccountComposite
StockQuote Service
SCA is the component model Components may be wired together SDO DataObjects are data passed between and manipulated by Components DAS is a SCA component with a special implementation type (implementation:das)
8
Page
? 2008 IBM Corporation
I6
SDO Session
SDO Components and Key Features
Generated data API: POJO beans Dynamic data API: DataObject Change summary API: ChangeSummary Introspection API: Type and Property Sequence API where instance order is preserved Relationship Integrity XML and XSD Integration
– XPath Navigation through Graphs of Data
XML-based serialization for transferring data sets on the wire
– Can conform to pre-defined XML Schema – Can generate XML Schema
9 Page ? 2008 IBM Corporation
幻灯片 9 I6 slide on relationship integrity slide on Sequence
IBM_USER, 2008-3-4
SDO Session
The Strongly Typed SDOs also Implement the Dynamic API
10
? 2008 IBM Corporation
SDO Session
Static (Generated) Data API
POJO interfaces/classes Strong-typed accessors
public interface Person { String getName(); void setName(String name); Address getAddress(); void setAddress(Address address); } Person p = (Person) dataFactory.create(

Person.class); p.setName("John"); Address a = (Address) dataFactory.create(Address.class); p.setAddress(a);
11
Page
? 2008 IBM Corporation
SDO Session
Dynamic Data API (commonj.sdo.DataObject)
The Dynamic SDO API provides a reflective way to introspect and manipulate data
– Recall: Static SDO can be cast to DataObject

Customer c = CustomerFactory.createCustomer(); ((DataObject)c).setString("name", "John"); // Set name
12
? 2008 IBM Corporation
SDO Session
Example 1 – Accessing DataObjects
// use SDO API to find the employee, at index 1 in the list. List departments = company.getList("departments"); DataObject department = (DataObject) departments.get(0); List employees = department.getList("employees"); DataObject employeeFromList = (DataObject) employees.get(1); DataObject employee = company.getDataObject ("departments[1]/employees[2]");
// Get an employee using an SDO xpath expression DataObject employee = company.getDataObject (“departments[number=123]/employees[SN=0002]”);
13
Page
? 2008 IBM Corporation
SDO Session
Example 2 – Updating DataObjects
company.setString(“companyName", "ACME"); // create a new employee DataObject newEmployee = department.createDataObject("employees"); newEmployee.set("name", "Al Smith"); newEmployee.set("SN", "0004"); newEmployee.setBoolean("manager", true); // Set employeeOfTheMonth company.set("employeeOfTheMonth", newEmployee);

14 Page ? 2008 IBM Corporation
SDO Session
SDO Meta-Model
SDO provides a simple, universal meta-model
– Used across JavaBeans, XML, or any data source – Useful for tools and IDE’s (Model in MVC)
SDO
Type Property
Java
Class Field
XSD
Type Element Attribute
Meta-data Classes
– Type
? Has name, URI, instance class, and properties
– Property
? Has name, type, default value, etc.
DataObject obj = …; Type type = obj.getType(); Collection c = type.getProperties(); Iterator i = c.iterator(); while (i.hasNext()) { Property prop = (Property) i.next(); System.out.println(prop.getName()); }
15
? 2008 IBM Corporation
SDO Session
Type System Scopes
HelperContext
– Agent of scoping for Types – provides access to ? TypeHelper ? DataFactory ? XSDHelper ? XMLHelper ? EqualityHelper ? CopyHelper ? DataHelper – HelperProvider.getDefaultContext() – Application can create new HelperContexts
16
? 2008 IBM Corporation
SDO Ses

sion
XML/XSD integration
Key interfaces: XMLHelper and XSDHelper Direct correspondence between XML and DataObjects
– commonj.sdo.XMLHelper ? Load and save DataObjects to XML streams
XSD mapping to and from SDO
– commonj.sdo.XSDHelper ? Get XML Schema specific information: – isElement, isMixed, local name, appinfo – Define Types and Properties from XSDs ? Annotations or XSLT for mapping control – Generate XSDs from Types and Properties
17
? 2008 IBM Corporation
SDO Session
Create SDO types from an XML schema
XSD model can be directly used to define SDO types
XSDHelper xsdHelper = …; TypeHelper typeHelper = …; // Populate the SDO types from the XSD URL url = XMLSample.class.getResource(“/stockquote.xsd”); InputStream inputStream = url.openStream(); xsdHelper.define(inputStream, url.toString()); inputStream.close(); // Look up the SDO Type Type type = typeHelper.getType(“http://stock”, “Quote”); // Get the XSD namespace URI for a SDO type String ns = xsdHelper.getNamespaceURI(type);
18
? 2008 IBM Corporation
SDO Session
Registering Type-System for SDO Runtime
Register types dynamically from XSD
→ Data Object instantiation: DataObject employee = dataFactory.create(NAMESPACE, “Employee”);
Register types statically (strongly typed)
→ Data Object instantiation: Employee empl = (Employee)dataFactory.create(Employee.class); Or DataObject empl = dataFactory.create(NAMESPACE, “Employee”);
Instance is still of type Employee
19 ? 2008 IBM Corporation
SDO Session
CreateCompany Example
20
? 2008 IBM Corporation
SDO Session
SDO API for Programatic Type Creation
Uses DataObject API Build data graph describig Typs system – then compile Type TypeHelper.define(DataObject) List TypeHelper.define(List)
– Permits circular references in metadata (Properties of Type as yet not “defined”)
DataObject cType = scope.getDataFactory().create("commonj.sdo", "Type"); cType.set("uri", "http://example.com/customer"); cType.set("name", "Customer"); Type intType = typeHelper().getType("commonj.sdo", "Int"); DataObject cNumProperty = customerType.createDataObject("property"); cNumProperty.set("name", "custNum"); cNumProperty.set("type", intType); …… Type registeredType = typeHelper.define(cType);
21
? 2008 IBM Corporation
SDO Session
Load/Save XML documents
XMLHelper can load SDO from XML or save SDO to XML
DataObject quote = …; XMLHelper xmlHelper = …; ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Save the data object as an XML document xmlHelper.save(quote, "http://www.example.com/simple", "stockQuote", baos);
byte[] xml = baos.toByteArray(); // Load the XML bytes as an XMLDocument XMLDocument document = xmlHelper.load(new ByteArrayInputStream(xml)); // Get the root DataObject quote = document.getRootObject();
22
? 2008 IBM Corporation
SDO Session
XML / SDO Mapping
XML
PurchaseOrder Type
SDO

相关文档