 | Level: Intermediate Rizwan Tejpar (rtejpar@ca.ibm.com), DB2 Management Systems Developer, IBM
20 Dec 2007
With the recent rise in popularity of Service Oriented Architecture,
particularily Web Services, there comes a need for an evolution in the database
management system. IBM® DB2® 9 represents a database solution that allows developers
to utilize the most suitable technology for their applications without having
to introduce additional middle-tier application logic to leverage design paradigms
like SOA. I use the DB2 Health Monitor Sample Application as an example to show you
how this is possible.
Design goals
When developing the concept for the DB2 Health Monitor sample application, the goal was to promote IBM's vision of bringing the benefits of Service Oriented Architecture (SOA) to the masses, and in my case, demonstrate it from a DB2 perspective. The DB2 Health Monitor sample application was built with a number of initiatives to make it a viable business solution in terms of:
-
Cost - Appropriate use of open source technologies and leveraging existing infrastructure
-
Development - Programming language and operating system independence should be maintained wherever
possible
-
Scalability - Ensure both old and new technologies can scale with minimal additional human
resources
-
Maintainability - Utilize best practices and standards to reduce future development costs
The DB2 Health Monitor Sample Application was designed to capture these initiatives
and to simultaneoulsy show application developers how to expose existing
data as a service and show business leaders the value of SOA without being overly technical.
The two part series describes the DB2 Health Monitor Sample Application
for PHP from both an SOA and an XML data usage perspective.
Service Oriented Architecture
When developing an application, typically the first thing that comes to mind
is what type of technology should be used. Traditionally, the technology that is
selected results in one of the following scenarios:
- Choosing the best technology for the task.
- Choosing sufficient technology for the task.
In either case, developers must make a trade-off between code reuse, platform independence, and performance
while attempting to avoid vendor lock-in.
To solve this problem, application developers need a solution that allows them to gain
software stack flexibility while dealing with legacy data and maintaining quality of service.
Service Oriented Architecture (SOA) does just that by using XML as a common medium through which
previously incompatible software stacks can communicate. Figure 1 shows a typical SOA
stack:
Figure 1. SOA stack
In the case of the DB2 Health Monitor Sample Application, the following software stack was used:
-
Presentation: HTML, CSS, JS (AJAX)
-
Business Logic: PHP
-
Data Sources: DB2 9 Express-C
-
Web Server: Apache HTTP Server
-
Operating System: Windows and Linux
As per the SOA theme, the software stack used for the DB2 Health Monitor Sample Application represents
the best choice of technology in accordance with the design goals:
-
At the presentation level, AJAX represents the concept of health monitoring extremely well in
that the technology can be used asynchronously to obtain frequent, periodic updates about a system.
-
At the business logic level, PHP represents a lightwight middle-tier alternative to enterprise-heavy
frameworks such as J2EE or .NET.
-
PHP, Apache, and Linux all illustrate the use of DB2 with open source technologies.
However, although the best technology was used, the SOA paradigm still presents the problem of converting
the data to XML in the first place.
In the past, and even now, developers have solved this problem by using middle-tier
programming languages such as PHP, Java, or C# in the data access or business logic layers of
their applications to manipulate and transform the data into the required form. Although acceptable,
this clearly violates software design best practices.
The reality is that it is the responsibility of the database not only to store the data, but also to use the
database manipulation language (DML) to update and return the data in the required form. Programming languages
should not be used to do this; just as you wouldn't execute two SQL queries and manually join the data
in the middle-tier, the same should apply to using existing XML data or taking SQL data and making it XML.
Historically, it comes down to the idea that with each major evolution in software architecture,
the database management system (DBMS) or data storage mechanism must also evolve. Just
as data storage
mechanisms evolved from the use of flat-files to relational databases (with the
need for multi-user and multi-tier applications), the introduction of SOA (particularly
Web services)
presents a need for the DBMS to allow for XML usage.
IBM DB2 9 software, through the use of its pureXML™ technology and hybrid database engine, addresses
this problem from two perspectives:
The main principle behind pureXML is that, regardless of the storage method, whether it be the traditional
SQL datatypes or the new XML datatype, the data can be extracted as XML.
The DB2 Health Monitor Sample Application uses the former approach. All health monitoring data is first gathered
from a series of User Defined Functions (UDFs) that already exist within the database and return standard SQL
datatypes in the form of a relational table. Using pureXML, all health monitoring data is then converted
to XML within the DB2 9 engine itself.
Architecturally, the SOA paradigm, along with the use of pureXML, translates as follows:
Figure 2. Package
architecture
As shown in the diagram above, a single, complete, SOA application is composed of two parts: a producer and a consumer. As with
the DB2 Health Monitor Sample Application for PHP, each of these components can be further subdivided into
a series of packages which distribute perfectly across the distinct presentation, business logic,
and data access layers (as described in best practice software design paradigms).
From the producer perspective, there are two packages:
-
Web Service Producer DB - A package to connect to the data source, and to build and execute
queries against it.
-
Web Service Producer - A package that contains the functions to expose on the web via
WSDL (a standardized XML document format), as well as the SOAP server through which
communication will occur.
Similarly, from the consumer perspective, there are two packages:
-
Web Service Consumer - A package that contains the SOAP client that will send requests
to the web service and will receive the XML output.
-
Web Service Consumer GUI - A package to present the XML data in a meaningful format
to the user.
What's interesting about the DB2 Health Monitor Sample Application is the propagation of the XML data
from the data source to the presentation layer. With the exception of the original storage method
for the data (as traditional SQL data types), and the final rendering to the end-user (which could have
been displayed as XML with a stylesheet) is that it is all XML.
Again, DB2 9 pureXML is converting the SQL data to XML within the database engine itself using an
XQuery statement. Just as SQL represents the DML for traditional relational structures, XQuery serves as
the DML equivalent for XML. The DB2 Health Monitor Sample Application, through the use of the Web Service Producer DB package,
simply performs data access; it builds and sends XQuery statements to the DB2 9 engine for gathering,
describing, and assembling the data as XML.
While this sample only represents a single application, imagine what it looks like at the enterprise level where there
are n-tiers, n-services, and n-applications. Even if a centralized approach is used to manage services
and share common tasks, if each application takes on the responsibility of manipulating the data from
the database to represent it as XML, as developers, we are violating the integrity of the data that
was already guaranteed by the database.
Summary
This article examined the creation of the DB2 Health Monitor Sample Application for
PHP from an SOA perspective, and you
have seen how DB2 9 supports this notion of maintaining software stack flexibility and best practice software design.
Part 2 examines the DB2 Health Monitor Sample Application from a pureXML
perspective and illustrates the benefits
that it can provide to developers, database administrators, and the business as a whole,
through detailed code samples. These code samples include PHP code snippets, SQL queries, SQL/XML queries, and XQuery statements.
Download
Note - The Health Monitor Demo has been bundled with the Web 2.0 Starter Toolkit for DB2 (PHP)
Resources
About the author  | 
|  | Rizwan Tejpar is an Industry Internship Program (IIP) student at IBM, where he develops sample applications for showcasing DB2 working with open-source technologies. He attended the ZendCon conference in 2006 and SDWest conference in 2007, where he demonstrated DB2 pureXML™capabilities to developers on the trade show floor.
Mr. Tejpar's most recent contribution was the DB2 Health Monitor Sample Application for PHP, which put an SOA spin on database health monitoring. Some of his other programming language experience includes C++, C# .NET, SQL, XQuery, and JSP. |
Rate this page
|  |