ActiveRecord and SDO: Adding new data models beneath your Rails applications

37
1 © Copyright 2007 IBM Corporation. ActiveRecord and SDO: ActiveRecord and SDO: Adding new data models beneath Adding new data models beneath your Rails applications your Rails applications Doug Tidwell, IBM [email protected]

description

ActiveRecord and SDO: Adding new data models beneath your Rails applications. Doug Tidwell, IBM [email protected]. Objectives. Discuss emerging technologies (SDO and SCA) Compare SDO to ActiveRecord Discuss impedence mismatches between SDO and ActiveRecord - PowerPoint PPT Presentation

Transcript of ActiveRecord and SDO: Adding new data models beneath your Rails applications

Page 1: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

1© Copyright 2007 IBM Corporation.

ActiveRecord and SDO: ActiveRecord and SDO: Adding new data models beneath Adding new data models beneath your Rails applicationsyour Rails applications

Doug Tidwell, [email protected]

Page 2: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

2© Copyright 2007 IBM Corporation.

ObjectivesObjectives

• Discuss emerging technologies (SDO and SCA) • Compare SDO to ActiveRecord• Discuss impedence mismatches between SDO

and ActiveRecord• Build bridges between the SCA/SDO and

Rails communities

Page 3: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

3© Copyright 2007 IBM Corporation.

Speaker profileSpeaker profile

• Doug Tidwell is a Senior Software Engineer at IBM.

• He was a speaker at the first XML conference in 1997, and has spoken on technical topics around the world.

• He works in IBM’s Software Strategy group, evangelizing emerging XML standards such as XForms, SCA and SDO.

• You can reach him at [email protected].

Page 4: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

4© Copyright 2007 IBM Corporation.

Speaker profileSpeaker profile

• Doug Tidwell is a Senior Software Engineer at IBM.

• He was a speaker at the first XML conference in 1997, and has spoken on technical topics around the world.

• He works in IBM’s Software Strategy group, evangelizing emerging XML standards such as XForms, SCA and SDO.

• You can reach him at [email protected].

Page 5: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

5© Copyright 2007 IBM Corporation.

Emerging technologiesEmerging technologies

Service Component Architecture andService Data Objects

Page 6: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

6© Copyright 2007 IBM Corporation.

Why SDO makes life simplerWhy SDO makes life simpler

• One way to look at SDO is that it takes all of the details of access methods, implementations, and moves them into the middleware layer. – Application developers write business logic, code

that actually builds value for your organization. – The details of using data sources are handled by

SDO.– As the details change, your applications (and the

developers who wrote them) aren’t affected.

• SCA does the same thing, but includes encryption, authentication, etc. in addition to other details.

Page 7: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

7© Copyright 2007 IBM Corporation.

The underlying design patternThe underlying design pattern

• We’re taking a physical data source and abstracting out its details.

• Our code works with things like:– DataObjects– DataGraphs– ChangeSummary(ies)

• Hmmm…– This sounds familiar, doesn’t it?

Page 8: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

8© Copyright 2007 IBM Corporation.

The underlying design patternThe underlying design pattern

• SDO gives your developers a single single programming model for using data programming model for using data sourcessources. – As your applications get more complicated, you have

to integrate more and more data sources. – What happens if they’re not RDBs?

• Similarly, SCA gives your developers a single single programming model for using servicesprogramming model for using services.– As your applications get more complicated, your

developers have to learn more and more interfaces.

Page 9: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

9© Copyright 2007 IBM Corporation.

Using a componentUsing a component

• When dealing with a component, there are three important pieces of information:– The interface of the component– The implementation of the component– The access method to invoke the component

• We’ll consider how we use this information to invoke components.

Page 10: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

10© Copyright 2007 IBM Corporation.

The bad old daysThe bad old days

• Originally, most components were hardwired into an application:– The application knew the details of the component’s

interface at build time.– The application accessed the component’s

implementation at build time.– The application knew the details of the component’s

access method at build time.

• This worked (and still does), but the application is relatively brittle. – If the implementation or access method changes, we

have to modify our code, rebuild it, retest it and redeploy it.

Page 11: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

11© Copyright 2007 IBM Corporation.

The early days of Web servicesThe early days of Web services

• SOAP introduced a way to invoke a remote service with an XML envelope.

• The SOAP infrastructure built the envelope and sent it to a particular URL; the SOAP service’s host invoked a service and sent XML back to us.– The application knew the details of the component’s

interface at build time.– The application did not access the The application did not access the

component’s implementation at build time; the component’s implementation at build time; the component is invoked at run time by the SOAP component is invoked at run time by the SOAP infrastructure. infrastructure.

– The application knew the details of the component’s access method at build time (usually SOAP/HTTP).

Page 12: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

12© Copyright 2007 IBM Corporation.

Next-generation applicationsNext-generation applications

• An application built with SCA and SDO is even more dynamic:– The application knows the details of the component’s

interface at build time.– The application does not access the component’s The application does not access the component’s

implementation at build time; the component is implementation at build time; the component is invoked by the SCA and SDO frameworks. invoked by the SCA and SDO frameworks.

– The application does not know the details of the The application does not know the details of the component’s access method at build time; this is component’s access method at build time; this is also handled by the SCA and SDO frameworks. also handled by the SCA and SDO frameworks.

• SCA and SDO move the implementation and access method details out of your application and into the middleware.

Page 13: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

13© Copyright 2007 IBM Corporation.

Next-generation applicationsNext-generation applications

• We mentioned the three important pieces of information:– The interfaceinterface of the component– The implementationimplementation of the component– The access methodaccess method to invoke the component

• With SDO and SCA, the implementation and the access method are determined at runtime by the infrastructure.– Our code isn’t involved in this determination, so we

don’t have to write it or maintain it.

Page 14: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

14© Copyright 2007 IBM Corporation.

Service Data ObjectsService Data Objects

Page 15: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

15© Copyright 2007 IBM Corporation.

Service Data ObjectsService Data Objects

• Started as a research project between IBM and BEA several years ago.

• SCA grew out of this work as well.• The standards have been developed in the

open and were recently turned over to OASIS.

Page 16: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

16© Copyright 2007 IBM Corporation.

Service Data ObjectsService Data Objects

• SDO gives you a single API to a wide variety of data sources.

• You and I as developers focus on CRUD operations.

• We don’t know what the data source actually is. – Relational database– XML database or XML file– EJB– Web service– JCA– LDAP directory

Page 17: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

17© Copyright 2007 IBM Corporation.

The goal of SDOThe goal of SDO

• I have some data.• I use the data wherever and however it’s

stored (RDBMS, XML file, LDAP, etc.)• I use the most convenient language for CRUD

operations on the data (SQL, XQuery, modified XPath, etc.)

Page 18: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

18© Copyright 2007 IBM Corporation.

A disconnected interface to many A disconnected interface to many kinds of data sourceskinds of data sources

Application

Data AccessService

RDB

XMLDB

EJB

Webservice

JCA

Data objectData graph

Change summary

JDBC,ODBC

XPath/XQuery

Local

XML/HTTP

CCI/Proprietary

Page 19: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

19© Copyright 2007 IBM Corporation.

Data Access Services (DAS)Data Access Services (DAS)

• To use SDO, another technology is needed.• DAS does the work of synchronizing the data

graph with a particular kind of data store.• Tuscany has DAS implementations in Java and

C++.

Page 20: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

20© Copyright 2007 IBM Corporation.

SamplesSamples

• We’ll look at a quick sample that uses the same code to access different data sources underneath.

• Changing the data source doesn’t require us to change our code at allat all.

Page 21: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

21© Copyright 2007 IBM Corporation.

ConfigurationConfiguration

• Here’s the DAS configuration file for a relational database:

<Config xmlns...><ConnectionInfo dataSource="..."/><Command name="allCompanies" SQL="select * from COMPANY" kind="Select"/><Table tableName="COMPANY"> <Column columnName="ID" primaryKey="true" generated="true"/></Table>

. . .

Page 22: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

22© Copyright 2007 IBM Corporation.

Accessing the SDO dataAccessing the SDO data

• Here’s how to execute a query:public class CompanyClient {private DAS das = DAS.FACTORY. createDAS(getConfig ("CompanyConfig.xml"));

public final List getCompanies { Command read = Command read = das.getCommand("allCompanies"); das.getCommand("allCompanies"); DataObject root = DataObject root = read.executeQuery(); read.executeQuery();

return root.getList("COMPANY");return root.getList("COMPANY");}

}

Page 23: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

23© Copyright 2007 IBM Corporation.

Accessing data with Tuscany SDOAccessing data with Tuscany SDO

• Tuscany SDO development has taken two significant turns in the last few weeks– Adding more data sources: A beta of LDAP support

is in the Tuscany code base today.– Adding more query languages: XQuery has also

been added to the Tuscany code base in the last couple of weeks.

Page 24: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

24© Copyright 2007 IBM Corporation.

Building bridgesBuilding bridges

Two great tastes that taste great together

Page 25: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

25© Copyright 2007 IBM Corporation.

Impedance mismatchesImpedance mismatches

• SDO is designed for disconnected access– Get a data graph from a data provider, work with it,

then submit a change summary to the data provider if we want.

• SDO is closer to XML Schema than the relational model– Mappings have been done to RDBs, XML / Web

services, LDAP…

• SDO is much more configuration-intensive– Tools exist to do this automatically, but…– This is completely counter to the Rails philosophy

Page 26: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

26© Copyright 2007 IBM Corporation.

Sequenced data objectsSequenced data objects

• SDO defines sequenced data objects, not something a RDB typically supports natively.

• Rails’ acts_as_list fits this perfectly; SDO uses a similar approach.

• Sequenced data objects map to XML easily.• Sequenced data objects to LDAP? Not so

much…

Page 27: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

27© Copyright 2007 IBM Corporation.

Query languagesQuery languages

• Rails “query” language is tightly integrated with Ruby– Doesn’t seem like a query language at all, really…

• SDO supports SQL, XPath (sort of) and XQuery.– XPath support in SDO is awkward, the first item in a

sequence or node set is [0], not [1].

Page 28: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

28© Copyright 2007 IBM Corporation.

Meeting in the middleMeeting in the middle

• What’s in there?

SDOActiveRecord ?

Page 29: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

29© Copyright 2007 IBM Corporation.

ChallengesChallenges

• SDO maps everything to an XML structure (DataObject).

• Rails assumes everything is in a RDB– SDO to RDB implementations are mature (although

not all are open-source)

• How substantial is the mismatch between, say, LDAP and RDB?– In theory (heh), this is a known and solved problem.– LDAP directories have been implemented on top of

RDBs.

Page 30: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

30© Copyright 2007 IBM Corporation.

QuestionsQuestions

• How much value is there in an ActiveRecord to LDAP mapping?

• How much value is there in the disconnected nature of SDO?

Page 31: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

31© Copyright 2007 IBM Corporation.

QuotesQuotes

• The idea of intelligent persistance (Liquid data or SDO) is in the category of "if I only had time I would build that, and if anyone does I would use it, but I just don't have time to give this gift to humanity"  Surprisingly, that is exactly the mindset which delayed an architecture like Rails from coming to market sooner.  We all owe a debt to the man who bit the bullet and did the heavy lifting.

Page 32: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

32© Copyright 2007 IBM Corporation.

QuotesQuotes

• I have not done any development, but have planned a "vision" of how I would implement this into an overarching application development paradigm.  The short answer for you is "I'm not independantly wealthy, but have 3 kids in college, so I work for the machine.“– George Willis, on the Ruby on Rails RIA SDK Google

Group

Page 33: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

33© Copyright 2007 IBM Corporation.

ResourcesResources

• Service Data Objects– osoa.org/display/Main/ Service+Data+Objects+Specifications

– Java and C++ specs available now, C and COBOL are in draft stage

• OASIS CSA group– oasis-opencsa.org

• Apache Tuscany– incubator.apache.org/tuscany/

• Next-generation data programming: Introduction to SDO– ibm.com/developerworks/java/library/j-sdo/

and elsewhere…

Page 34: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

34© Copyright 2007 IBM Corporation.

ResourcesResources

• SCA component for Ruby – ibm.com/alphaworks/tech/scarubycomponent/

• Other Ruby and SCA resources– See the Tuscany samples—there are examples that

use BSF to implement Ruby services inside an SCA environment.

– Work for the opposite direction is ongoing, please get involved…

Page 35: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

35© Copyright 2007 IBM Corporation.

ResourcesResources

• osoa.org: A group of 17 companies working together:

Page 36: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

36© Copyright 2007 IBM Corporation.

• The specifications work of OSOA has been turned over to OASIS.

• The Open Composite Services Architecture group is being formed now.– See oasis-opencsa.org for more details.

Page 37: ActiveRecord and SDO:  Adding new data models beneath your Rails applications

37© Copyright 2007 IBM Corporation.

Thanks!Thanks!

Doug Tidwell, [email protected]