Welcome!

Java Authors: Pat Romanski, Liz McMillan, Elizabeth White, Trevor Parsons, Jason Bloomberg

Related Topics: Java

Java: Article

An Introduction to Service Data Objects

Integrating relational data into Web applications

Late last year, IBM Corp., and BEA Systems, Inc., introduced Service Data Objects (SDO), a new data programming specification that complements existing Java 2 Enterprise Edition technologies and enables service-oriented architectures by providing uniform data access for a wide variety of service and resource types. Not only does SDO enable a consistent approach to data access, but it also provides features that simplify common application tasks, such as allowing data browsing and update while the application is disconnected from the data source.

In this article we explain how SDO works and where it may fit into your own applications. We also take a closer look at how you can use SDO to retrieve and modify data stored in a relational database.

SDO Concepts
At the core of SDO are DataGraphs and Data Mediator Services (DMS). In simple terms, an application program obtains a DataGraph from a DMS that is specific to some back-end data store. The program can then examine and/or update the data contained in the graph. Optionally the program can employ a DMS to propagate the entire set of updates back to the original data source.

DataGraph
As a program object, a DataGraph provides an in-memory, nonpersistent copy of data. A program can work with this data even when there's no connection to the original data source. The data in a DataGraph is organized as a group of DataObjects, which may be linked together (i.e., the data is structured as a "graph"). A DataGraph also contains a schema that describes the structure of the DataObject type(s) contained in the DataGraph. To handle updates, a DataGraph also maintains a change history to track all modifications made to the graph.

Each DataObject contains a set of properties, which can be primitive values or references to other DataObjects contained in the DataGraph. If a DataObject's schema is known at development time, a developer can use automated tools to generate typed interfaces that simplify DataObject access. Alternatively, the application can define the schema at runtime, allowing dynamic access of DataObjects. With either static or dynamic access, linked data can be accessed in either a breadth-first or depth-first manner. For example, if a DataGraph contains customers and related orders, then orders can be obtained directly from the DataGraph or from their parent customer DataObject. SDO also allows for accessing data through XML Path Language (XPath) subset expressions.

Disconnected Programming Model
The DataGraph's disconnected, data source-independent nature provides a simple programming model, supports common application patterns, and offers a potential performance advantage.

Today, J2EE application developers have a wide variety of persistence frameworks to choose from, such as JDBC, EJB, or JDO. These frameworks have different APIs and are often complex, requiring developers to spend a great deal of time learning multiple APIs rather than developing applications. Since SDO provides a single data access API regardless of the persistence mechanism, developers can choose the framework that best fits an application without using different APIs.

Some developers strive for similar independence by developing custom Java objects to encapsulate data from different data sources. This tactic makes use of the Data Access Object design pattern. SDO inherently supports this pattern, freeing developers from the need to develop their own infrastructure.

To improve performance, some types of applications can exploit the DataGraph's support for applying multiple updates in one method call to reduce the number of connections and/or database operations. By storing data from multiple database rows and tables in a DataGraph, applications can make changes to the data without making additional round-trips to the database.

Mediators
An SDO DataGraph must be populated from a data source or a service. The SDO component that populates a DataGraph is called a data mediator service (DMS). A DMS also propagates changes to the in-memory DataGraph back to the originating data source. Note that the current SDO specification does not define a specific API for DMSs - beyond a few basic requirements, each DMS provider is free to design the DMS that best suits the associated data source.

Typically, a DMS accesses a single type of data source, for example, JDBC resources or entity EJBs. All DMSs require the developer to provide a description of the data to be accessed. This data description (or metadata) typically consists of a schema and a query over the associated data source.

Figure 1, from the SDO specification, illustrates the flow of data during a typical interaction between an SDO client and a DMS. The client makes a request to the DMS to return a DataGraph. The DMS reads the requested data from the data source, constructs a DataGraph of related DataObjects, and returns the DataGraph to the application. The SDO client makes changes to the DataGraph in-memory and then sends the modified DataGraph back to the DMS. The DMS examines the ChangeSummary contained in the graph and propagates the changes back to the original data source.

Because the DataGraph is disconnected from the data source, it's possible that another application will update the data (in the data source) that was used to populate a DataGraph before the application requests the DMS to propagate the application's changes back to the data source. To handle such potential update conflicts, a DMS typically implements some form of "optimistic" concurrency control and throws an exception to the application when a data collision occurs. At that point, it is the application's responsibility to recover from the collision, for example, by rereading the data and restarting the transaction.

Too-frequent collisions under an optimistic concurrency approach can degrade performance as well as aggravate end users. In applications where multiple applications will often attempt concurrent changes to the same data, optimistic concurrency control may not be a good choice. However, for applications without this behavior, optimistic concurrency control can improve performance by reducing lock contention.

Metamodel
The SDO specification assumes the presence of a metamodel and metadata API for the DataGraph, but does not specify one explicitly. Today, SDO could be implemented with a variety of metamodels and schema languages such as XML Schema or the Essential Meta Object Facility (EMOF). The metamodel implementation does not affect SDO end users.

XML Serialization
SDO defines the XML format for DataGraphs and DataObjects, and specifies that the format can be customized by an XSD. This same format is used for Java serialization. The serialized form of a DataGraph includes the DataObjects as well as the schema and change summary. This capability allows data to be easily transferred over the wire as would be required by a Web service invocation.

Relationship to Other J2EE Technologies
SDO can complement or simplify existing J2EE technologies. SDO complements JDBC by providing a more powerful framework and API for data access. In a typical relational database, data is normalized into multiple tables. When this data is read using a join query through JDBC, it's returned to the application in a tabular format that includes some data redundantly (e.g., an order number may be repeated with all individual line items for the same order). This format doesn't directly correspond to Java's object-oriented data model and can complicate navigation and update operations. A JDBC DMS can restructure this tabular data into a graph of related DataObjects. For example, an order might be represented by a DataObject that contains a list of references to other DataObjects containing line-item data. This allows an application to use standard Java techniques to access and modify the data.

Data access via EJBs can also be enhanced by using SDO. To implement a disconnected Data Access Object design pattern with EJBs alone, an application must use some combination of copy helper objects, session beans, and EJB access beans. An EJB DMS provides a ready-to-use disconnected architecture and frees developers from having to implement their own framework or custom artifacts.

SDO could also be used to complement other related technologies. For example:

  • JSR 227: Declaratively binding and accessing data in J2EE applications. SDO could be used as the mechanism to return results from the data source.
  • JSR 225: XQuery API for Java (XQJ). A Data Mediator Service could use the provided API to return SDOs.
  • JDO 2.0: SDO could provide data transfer objects from JDO persistent objects.
  • WEB UI Data Binding: JSF can use SDOs as a data binding. JSTL can use an SDO DataObject impl that implements the map interface.
Security
Security is not part of the current SDO model, so security in an SDO-based application is provided at the edges. For example, if an SDO-based application is developed that employs an EJB session bean and a JDBC connection, then security is provided at the boundaries of the application by these two J2EE components.

SDO with JDBC
SDO provides a uniform model for accessing data from a variety of services or data sources, including JDBC. Figure 2 shows interactions among the main artifacts involved when an application uses SDO over JDBC. Notice how the application code calls mediator and DataGraph methods, while the mediator calls JDBC and DataGraph methods, thus insulating the application from JDBC.

There are three central aspects to using a JDBC mediator: metadata, connections, and transaction handling.

Metadata
The application must supply the JDBC DMS with a metadata object that specifies the data to be retrieved. For a JDBC mediator, the metadata contains an augmented relational database schema that defines a set of tables, their relationships, and selection and ordering criteria. The JDBC DMS creates a DataGraph that corresponds to the provided schema definition. Each DataObject type within the DataGraph corresponds to a table definition in the schema, and each DataObject property corresponds to a table column.

The JDBC DMS uses the metadata to generate a SQL Select statement to retrieve data for the DataGraph. The simplest metadata example would describe a single table and no selection or ordering. For this specification, the JDBC mediator would retrieve all rows of the table and create a DataGraph that contains a list of DataObjects, with each DataObject containing the data from one row in the table. Each DataObject will have a set of values corresponding to the values from each column.

A more complex example might involve two related tables; say Customers and their respective Orders. In this case, the metadata must specify the relationship between the two tables, which will subsequently be reflected in a corresponding relationship between two types of DataObjects.

The DataGraph returned in this case would contain a list of Customer DataObjects and each of these Customer DataObjects would have a list of related Order DataObjects. The DataGraph will contain all Customers and Orders; they are organized as a tree with Customers at the "root" of the tree and related Orders branching off of each Customer.

Applications will frequently want data only from specified rows of a table. In this case, the metadata for a JDBC DMS specifies selection criteria. For example, customers might be selected from a particular zip code or with a particular last name. Also, the DataObjects in the graph can optionally be ordered by specifying "order by" columns in the metadata.

Normally the JDBC DMS generates SQL select, insert, update, and delete statements to read and update the associated relational database. However, an application can optionally provide an explicit Select statement for the mediator to use. If this option is used, the DMS will then generate only the complementary insert, update, and delete statements and will use the provided select statement as is.

Connections
In addition to specifying what data to retrieve, an application must specify which data source the DMS should access. For a JDBC DMS, this can be done by specifying a JDBC Connection object. The DMS will use this connection for all database interactions.

Transactions
As mentioned earlier, SDO provides a disconnected programming model and, accordingly, DMSs will typically connect to a data store only to read data for graph creation or to write data to reflect changes back to the store.

When an application requests the JDBC DMS to retrieve data and produce a DataGraph, the DMS starts a transaction, reads the data, creates the graph, and ends the transaction. The DataGraph is returned to the application and is "disconnected" in the sense that it is not associated with any connection or transaction; there are no locks held on the data.

The client can now read data from the DataGraph and make changes to it while it is in memory and disconnected from the data source. All changes made to the graph are recorded by the DataGraph. At some point the client will want to push these changes back to the data source and call the JDBC DMS "applyChanges" API.

As part of the "applyChanges" function, the JDBC DMS will reflect to the data store all changes made to the graph as part of a single transaction; this is true whether there is a single change to the graph or an entire batch of changes.

The disconnected programming model generally implies the use of an optimistic concurrency control scheme to push changes back to the data store; this is the approach taken by the JDBC DMS.

When the DMS attempts to apply DataGraph changes back to the data store, each row being updated is checked to ensure it has not been modified since it was originally read. If no intervening modifications have taken place, the update proceeds. If a row has been modified since the data was read, a collision has occurred; the update transaction is rolled back and an exception is thrown to the client.

There is also an option to use the DMS within a larger transaction. If this option is used, the DMS will assume that the client is controlling the transaction and will not perform any commit or rollback operations.

An Example
The following simple example demonstrates JDBC database access with SDO employing the JDBC DMS. This example has six steps, each illustrated by a code snippet.

Step 1: Create the JDBC mediator metadata instance
Create the metadata instance to represent the Customer table. This example demonstrates the creation of the JDBC DMS metadata programmatically. This is an obvious candidate for tooling support. Remember that the JDBC DMS uses a simple mapping scheme whereby each table definition results in a DataObject type and each table column results in a DataObject type property (see Listing 1).

Step 2: Create the DMS instance as in Listing 2

Step 3: Read the DataGraph from the database


//Create the "lastName" argument for the filter predicate
DataObject arguments = mediator.getParameterDataObject();
arguments.put("CUSTLASTNAME", "Pavick");
DataObject graph = mediator.getGraph(arguments);

Step 4 : Retrieve data from the graph


//Iterate through all returned customers and print the first name
Iterator i = graph.getList("CUSTOMER").iterator();
	while (i.hasNext()) {
	DataObject cust = (DataObject) i.next();
	System.out.println(cust.getString("CUSTFIRSTNAME"));
	}

Step 5: Change the DataGraph


List customers = graph.getList("CUSTOMER");
//Get the first customer in the graph and update the name
DataObject customer = (DataObject)customers.get(0);
	customer.setString("CUSTFIRSTNAME", "Kevin");

Step 6: Apply DataGraph changes back to the database

mediator.applyChanges(graph);

Variations on the Example
Metadata File

In Step 1 we created the mediator metadata programmatically. An alternative is to provide the metadata in the form of an XML file. Listing 3 is the XML representation of the Customer metadata.

Using this file, Step 1 would not be necessary and Step 2 would become:

Step 2: Create the mediator instance as shown in Listing 4

Static Types
The example provided above uses the dynamic access APIs of DataOb-ject. The JDBC DMS also supports the use of static SDO types. To use the static API access to DataObjects, a set of static types is generated at development time and tools are provided for this purpose. Using static types provides a cleaner user API as well as a performance boost at runtime. The generation step is beyond the scope of this article, but this is what Step 4 looks like when using a static customer DataObject.

Step 4: Retrieve data from the graph


//Iterate through all returned customers and print the first name
Iterator i = graph.getCustomers().iterator();
	while (i.hasNext()) {
	Customer cust = (Customer) i.next();
	System.out.println(cust.getFirstName());
	}

Paging
The JDBC Data Mediator Service also provides a paging capability that can be useful for marching through large data sets. A pager interface provides a cursor-like next() capability. The next() function returns a graph representing the next page of data from the entire data set specified by the mediator metadata; a previous() function is also available. A CountingPager is also provided that allows the retrieval of a specified page from the data set.

Listing 5 illustrates paging through a large set of customer instances using a Counting Pager.

Conclusion
In this article we have explored some of the key SDO concepts and also drilled down into a specific use of the technology for relational database access employing a JDBC Data Mediator.

SDO is a standard from IBM and BEA and there is a reference implementation under development at www.eclipse.org/emf. This EMF-based implementation of SDO will also be delivered with WebSphere Application Server 6.0 and will be complemented by:

  • JDBC Data Mediator Service
  • EJB Data Mediator Service
It is anticipated that the 6.0 version of WebSphere Studio will contain complete support for creating applications that leverage SDO; this will include visual tooling to configure the JDBC DMS. With the power of SDO, relational data can be integrated into Web applications more easily than ever.

Acknowledgments
We would like to thank Stephen Brodsky and Tom Schneider for their assistance with this article.

More Stories By Kevin Williams

Kevin Williams is a software developer with IBM and is leading IBM’s participation in the DAS subproject of the Apache Tuscany incubator.

More Stories By Brent Daniel

Brent Daniel is a software developer with IBM. He currently works on a JDBC data mediator service for WebSphere Application Server.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Brahm van Niekerk 10/12/04 08:41:38 AM EDT

JeeWiz implemented a similar technology last year in 2003 known as DataViews. DataViews became necessary for performance reasons when reading large data sets from Data Sources in Web Systems. JeeWiz is an MDA implementation that generates code for MS .NET and J2EE Application Servers, such as WebSphere, WebLogic, Oracle and JBoss. True portability as a design pattern was proven for us when we implemented it in both J2EE (JDBC) and in MS .NET implementation as Datasets. We have found that being able to generate systems for both J2EE and .NET from the same specification is hugely advantageous especially for vendors having to support these platforms. More information can be seen at http://www.jeewiz.com.

Rost Vashevnik 10/11/04 07:43:53 PM EDT

The capabilities described in this article are already implemented in MetaBoss - an Open Source MDA tool suite. It includes generation of Data Objects, data base schemas etc. from the UML model. The produced code is "technology independent" - meaning that it will work with WebSphere, JBoss or even just non-J2EE Tomcat deployment. You can see it for yourself at www.metaboss.com

@ThingsExpo Stories
How do APIs and IoT relate? The answer is not as simple as merely adding an API on top of a dumb device, but rather about understanding the architectural patterns for implementing an IoT fabric. There are typically two or three trends: Exposing the device to a management framework Exposing that management framework to a business centric logic Exposing that business layer and data to end users. This last trend is the IoT stack, which involves a new shift in the separation of what stuff happens, where data lives and where the interface lies. For instance, it's a mix of architectural styles ...
We are reaching the end of the beginning with WebRTC, and real systems using this technology have begun to appear. One challenge that faces every WebRTC deployment (in some form or another) is identity management. For example, if you have an existing service – possibly built on a variety of different PaaS/SaaS offerings – and you want to add real-time communications you are faced with a challenge relating to user management, authentication, authorization, and validation. Service providers will want to use their existing identities, but these will have credentials already that are (hopefully) i...
The Internet of Things will put IT to its ultimate test by creating infinite new opportunities to digitize products and services, generate and analyze new data to improve customer satisfaction, and discover new ways to gain a competitive advantage across nearly every industry. In order to help corporate business units to capitalize on the rapidly evolving IoT opportunities, IT must stand up to a new set of challenges. In his session at @ThingsExpo, Jeff Kaplan, Managing Director of THINKstrategies, will examine why IT must finally fulfill its role in support of its SBUs or face a new round of...
Connected devices and the Internet of Things are getting significant momentum in 2014. In his session at Internet of @ThingsExpo, Jim Hunter, Chief Scientist & Technology Evangelist at Greenwave Systems, examined three key elements that together will drive mass adoption of the IoT before the end of 2015. The first element is the recent advent of robust open source protocols (like AllJoyn and WebRTC) that facilitate M2M communication. The second is broad availability of flexible, cost-effective storage designed to handle the massive surge in back-end data in a world where timely analytics is e...
Cultural, regulatory, environmental, political and economic (CREPE) conditions over the past decade are creating cross-industry solution spaces that require processes and technologies from both the Internet of Things (IoT), and Data Management and Analytics (DMA). These solution spaces are evolving into Sensor Analytics Ecosystems (SAE) that represent significant new opportunities for organizations of all types. Public Utilities throughout the world, providing electricity, natural gas and water, are pursuing SmartGrid initiatives that represent one of the more mature examples of SAE. We have s...
"Matrix is an ambitious open standard and implementation that's set up to break down the fragmentation problems that exist in IP messaging and VoIP communication," explained John Woolf, Technical Evangelist at Matrix, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
The Internet of Things will greatly expand the opportunities for data collection and new business models driven off of that data. In her session at @ThingsExpo, Esmeralda Swartz, CMO of MetraTech, discussed how for this to be effective you not only need to have infrastructure and operational models capable of utilizing this new phenomenon, but increasingly service providers will need to convince a skeptical public to participate. Get ready to show them the money!
One of the biggest challenges when developing connected devices is identifying user value and delivering it through successful user experiences. In his session at Internet of @ThingsExpo, Mike Kuniavsky, Principal Scientist, Innovation Services at PARC, described an IoT-specific approach to user experience design that combines approaches from interaction design, industrial design and service design to create experiences that go beyond simple connected gadgets to create lasting, multi-device experiences grounded in people's real needs and desires.
P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at @ThingsExpo, Robin Raymond, Chief Architect at Hookflash, will walk through the shifting landscape of traditional telephone and voice services ...
Scott Jenson leads a project called The Physical Web within the Chrome team at Google. Project members are working to take the scalability and openness of the web and use it to talk to the exponentially exploding range of smart devices. Nearly every company today working on the IoT comes up with the same basic solution: use my server and you'll be fine. But if we really believe there will be trillions of these devices, that just can't scale. We need a system that is open a scalable and by using the URL as a basic building block, we open this up and get the same resilience that the web enjoys.
The Internet of Things is tied together with a thin strand that is known as time. Coincidentally, at the core of nearly all data analytics is a timestamp. When working with time series data there are a few core principles that everyone should consider, especially across datasets where time is the common boundary. In his session at Internet of @ThingsExpo, Jim Scott, Director of Enterprise Strategy & Architecture at MapR Technologies, discussed single-value, geo-spatial, and log time series data. By focusing on enterprise applications and the data center, he will use OpenTSDB as an example t...
The Domain Name Service (DNS) is one of the most important components in networking infrastructure, enabling users and services to access applications by translating URLs (names) into IP addresses (numbers). Because every icon and URL and all embedded content on a website requires a DNS lookup loading complex sites necessitates hundreds of DNS queries. In addition, as more internet-enabled ‘Things' get connected, people will rely on DNS to name and find their fridges, toasters and toilets. According to a recent IDG Research Services Survey this rate of traffic will only grow. What's driving t...
Enthusiasm for the Internet of Things has reached an all-time high. In 2013 alone, venture capitalists spent more than $1 billion dollars investing in the IoT space. With "smart" appliances and devices, IoT covers wearable smart devices, cloud services to hardware companies. Nest, a Google company, detects temperatures inside homes and automatically adjusts it by tracking its user's habit. These technologies are quickly developing and with it come challenges such as bridging infrastructure gaps, abiding by privacy concerns and making the concept a reality. These challenges can't be addressed w...
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at Internet of @ThingsExpo, James Kirkland, Chief Architect for the Internet of Things and Intelligent Systems at Red Hat, described how to revolutioniz...
Bit6 today issued a challenge to the technology community implementing Web Real Time Communication (WebRTC). To leap beyond WebRTC’s significant limitations and fully leverage its underlying value to accelerate innovation, application developers need to consider the entire communications ecosystem.
The definition of IoT is not new, in fact it’s been around for over a decade. What has changed is the public's awareness that the technology we use on a daily basis has caught up on the vision of an always on, always connected world. If you look into the details of what comprises the IoT, you’ll see that it includes everything from cloud computing, Big Data analytics, “Things,” Web communication, applications, network, storage, etc. It is essentially including everything connected online from hardware to software, or as we like to say, it’s an Internet of many different things. The difference ...
Cloud Expo 2014 TV commercials will feature @ThingsExpo, which was launched in June, 2014 at New York City's Javits Center as the largest 'Internet of Things' event in the world.
SYS-CON Events announced today that Windstream, a leading provider of advanced network and cloud communications, has been named “Silver Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Windstream (Nasdaq: WIN), a FORTUNE 500 and S&P 500 company, is a leading provider of advanced network communications, including cloud computing and managed services, to businesses nationwide. The company also offers broadband, phone and digital TV services to consumers primarily in rural areas.
"There is a natural synchronization between the business models, the IoT is there to support ,” explained Brendan O'Brien, Co-founder and Chief Architect of Aria Systems, in this SYS-CON.tv interview at the 15th International Cloud Expo®, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
The major cloud platforms defy a simple, side-by-side analysis. Each of the major IaaS public-cloud platforms offers their own unique strengths and functionality. Options for on-site private cloud are diverse as well, and must be designed and deployed while taking existing legacy architecture and infrastructure into account. Then the reality is that most enterprises are embarking on a hybrid cloud strategy and programs. In this Power Panel at 15th Cloud Expo (http://www.CloudComputingExpo.com), moderated by Ashar Baig, Research Director, Cloud, at Gigaom Research, Nate Gordon, Director of T...