Click here to close now.




















Welcome!

Java IoT Authors: Daniel Khan, Hurricane Labs, Don MacVittie, Dana Gardner, Liz McMillan

Related Topics: Java IoT

Java IoT: 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
For IoT to grow as quickly as analyst firms’ project, a lot is going to fall on developers to quickly bring applications to market. But the lack of a standard development platform threatens to slow growth and make application development more time consuming and costly, much like we’ve seen in the mobile space. In his session at @ThingsExpo, Mike Weiner, Product Manager of the Omega DevCloud with KORE Telematics Inc., discussed the evolving requirements for developers as IoT matures and conducted a live demonstration of how quickly application development can happen when the need to comply wit...
SYS-CON Events announced today that HPM Networks will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. For 20 years, HPM Networks has been integrating technology solutions that solve complex business challenges. HPM Networks has designed solutions for both SMB and enterprise customers throughout the San Francisco Bay Area.
The Internet of Everything (IoE) brings together people, process, data and things to make networked connections more relevant and valuable than ever before – transforming information into knowledge and knowledge into wisdom. IoE creates new capabilities, richer experiences, and unprecedented opportunities to improve business and government operations, decision making and mission support capabilities.
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 @ThingsExpo, James Kirkland, Red Hat's Chief Architect for the Internet of Things and Intelligent Systems, described how to revolutionize your archit...
MuleSoft has announced the findings of its 2015 Connectivity Benchmark Report on the adoption and business impact of APIs. The findings suggest traditional businesses are quickly evolving into "composable enterprises" built out of hundreds of connected software services, applications and devices. Most are embracing the Internet of Things (IoT) and microservices technologies like Docker. A majority are integrating wearables, like smart watches, and more than half plan to generate revenue with APIs within the next year.
Growth hacking is common for startups to make unheard-of progress in building their business. Career Hacks can help Geek Girls and those who support them (yes, that's you too, Dad!) to excel in this typically male-dominated world. Get ready to learn the facts: Is there a bias against women in the tech / developer communities? Why are women 50% of the workforce, but hold only 24% of the STEM or IT positions? Some beginnings of what to do about it! In her Opening Keynote at 16th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, d...
In his keynote at 16th Cloud Expo, Rodney Rogers, CEO of Virtustream, discussed the evolution of the company from inception to its recent acquisition by EMC – including personal insights, lessons learned (and some WTF moments) along the way. Learn how Virtustream’s unique approach of combining the economics and elasticity of the consumer cloud model with proper performance, application automation and security into a platform became a breakout success with enterprise customers and a natural fit for the EMC Federation.
The Internet of Things is not only adding billions of sensors and billions of terabytes to the Internet. It is also forcing a fundamental change in the way we envision Information Technology. For the first time, more data is being created by devices at the edge of the Internet rather than from centralized systems. What does this mean for today's IT professional? In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists addressed this very serious issue of profound change in the industry.
Discussions about cloud computing are evolving into discussions about enterprise IT in general. As enterprises increasingly migrate toward their own unique clouds, new issues such as the use of containers and microservices emerge to keep things interesting. In this Power Panel at 16th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the state of cloud computing today, and what enterprise IT professionals need to know about how the latest topics and trends affect their organization.
It is one thing to build single industrial IoT applications, but what will it take to build the Smart Cities and truly society-changing applications of the future? The technology won’t be the problem, it will be the number of parties that need to work together and be aligned in their motivation to succeed. In his session at @ThingsExpo, Jason Mondanaro, Director, Product Management at Metanga, discussed how you can plan to cooperate, partner, and form lasting all-star teams to change the world and it starts with business models and monetization strategies.
Converging digital disruptions is creating a major sea change - Cisco calls this the Internet of Everything (IoE). IoE is the network connection of People, Process, Data and Things, fueled by Cloud, Mobile, Social, Analytics and Security, and it represents a $19Trillion value-at-stake over the next 10 years. In her keynote at @ThingsExpo, Manjula Talreja, VP of Cisco Consulting Services, discussed IoE and the enormous opportunities it provides to public and private firms alike. She will share what businesses must do to thrive in the IoE economy, citing examples from several industry sectors.
There will be 150 billion connected devices by 2020. New digital businesses have already disrupted value chains across every industry. APIs are at the center of the digital business. You need to understand what assets you have that can be exposed digitally, what their digital value chain is, and how to create an effective business model around that value chain to compete in this economy. No enterprise can be complacent and not engage in the digital economy. Learn how to be the disruptor and not the disruptee.
Akana has released Envision, an enhanced API analytics platform that helps enterprises mine critical insights across their digital eco-systems, understand their customers and partners and offer value-added personalized services. “In today’s digital economy, data-driven insights are proving to be a key differentiator for businesses. Understanding the data that is being tunneled through their APIs and how it can be used to optimize their business and operations is of paramount importance,” said Alistair Farquharson, CTO of Akana.
Business as usual for IT is evolving into a "Make or Buy" decision on a service-by-service conversation with input from the LOBs. How does your organization move forward with cloud? In his general session at 16th Cloud Expo, Paul Maravei, Regional Sales Manager, Hybrid Cloud and Managed Services at Cisco, discusses how Cisco and its partners offer a market-leading portfolio and ecosystem of cloud infrastructure and application services that allow you to uniquely and securely combine cloud business applications and services across multiple cloud delivery models.
The enterprise market will drive IoT device adoption over the next five years. In his session at @ThingsExpo, John Greenough, an analyst at BI Intelligence, division of Business Insider, analyzed how companies will adopt IoT products and the associated cost of adopting those products. John Greenough is the lead analyst covering the Internet of Things for BI Intelligence- Business Insider’s paid research service. Numerous IoT companies have cited his analysis of the IoT. Prior to joining BI Intelligence, he worked analyzing bank technology for Corporate Insight and The Clearing House Payment...
"Optimal Design is a technology integration and product development firm that specializes in connecting devices to the cloud," stated Joe Wascow, Co-Founder & CMO of Optimal Design, in this SYS-CON.tv interview at @ThingsExpo, held June 9-11, 2015, at the Javits Center in New York City.
SYS-CON Events announced today that CommVault has been named “Bronze Sponsor” of SYS-CON's 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. A singular vision – a belief in a better way to address current and future data management needs – guides CommVault in the development of Singular Information Management® solutions for high-performance data protection, universal availability and simplified management of data on complex storage networks. CommVault's exclusive single-platform architecture gives companies unp...
Electric Cloud and Arynga have announced a product integration partnership that will bring Continuous Delivery solutions to the automotive Internet-of-Things (IoT) market. The joint solution will help automotive manufacturers, OEMs and system integrators adopt DevOps automation and Continuous Delivery practices that reduce software build and release cycle times within the complex and specific parameters of embedded and IoT software systems.
"ciqada is a combined platform of hardware modules and server products that lets people take their existing devices or new devices and lets them be accessible over the Internet for their users," noted Geoff Engelstein of ciqada, a division of Mars International, in this SYS-CON.tv interview at @ThingsExpo, held June 9-11, 2015, at the Javits Center in New York City.
Internet of Things is moving from being a hype to a reality. Experts estimate that internet connected cars will grow to 152 million, while over 100 million internet connected wireless light bulbs and lamps will be operational by 2020. These and many other intriguing statistics highlight the importance of Internet powered devices and how market penetration is going to multiply many times over in the next few years.