[QueueNews] Bridging the Object-Relational Divide

QueueNews queuenews at acmqueue.com
Mon Jul 14 08:00:03 PDT 2008


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
. . . . . . . . . . . . . . . . . . . . . . . .
   Queue E-Mail Newsletter
   for the Week of Jul/14/2008
. . . . . . . . . . . . . . . . . . . . . . . .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------
      Sponsored by

      ACM

/----------------------------------------------------------\

Join ACM

A Special Offer to Join ACM for Queue Readers
http://www.acm.org/joinacm2

\----------------------------------------advertisement------/


Latest Articles:


Bridging the Object-Relational Divide
ORM technologies can simplify data access, but be aware of the
challenges that come with introducing this new layer of abstraction.
http://acmqueue.com/rd.php?c.538
   (scroll down to read an excerpt from this article)


BASE: An ACID Alternative
In partitioned databases, trading some consistency for availability can
lead to dramatic improvements in scalability.
http://acmqueue.com/rd.php?c.540

/----------------------------------------------------------\

Join ACM

A Special Offer to Join ACM for Queue Readers
http://www.acm.org/joinacm2

\----------------------------------------advertisement------/

New article on ACM Queue:
Bridging the Object-Relational Divide
http://acmqueue.com/rd.php?c.538
ORM technologies can simplify data access, but be aware of the
challenges that come with introducing this new layer of abstraction.
by Craig Russell, Sun Microsystems

>From the Object-Relational Mappers issue, vol. 6, no. 3 - May/June 2008

article excerpt:
Modern applications are built using two very different technologies:
object-oriented programming for business logic; and relational
databases
for data storage. Object-oriented programming is a key technology for
implementing complex systems, providing benefits of reusability,
robustness, and maintainability. Relational databases are repositories
for persistent data. ORM (object-relational mapping) is a bridge
between
the two that allows applications to access relational data in an
object-oriented way.

ORM is a specialization of the general
concept of object persistence. In his book Object-oriented Analysis and
Design with Applications, IBM Fellow Grady Booch claimed that
persistence, defined as "data that outlives the program," is a minor
element of an object model.^1 In modern applications, however,
the amount of effort devoted to persistence can dominate the cost of a
project, and using ORM tools can significantly reduce this cost.

Other technologies can be used to access relational data from
object-oriented programs, but these technologies generally do not
exploit the object behavior of the programming language. To exploit
object behavior fully, database-access technology should support
separation of concerns, information hiding, inheritance, change
detection, uniquing, and database independence.

Separation of
concerns is the process of breaking up a program into logical parts
that
have little or no overlap. In database programming, several parts
should
be separated: business methods that find domain objects and operate on
them; methods in those domain objects that might cause internal state
changes and call methods in associated objects; generation of database
commands to implement inserts, queries, updates, and deletes of
database
rows and columns; and methods for database transaction demarcation.
Information hiding is an implementation strategy for separation of
concerns that reduces complexity and cost by defining behavior in terms
of interfaces that are implemented by specific classes. The classes
implement the behavior separate from the behavior of the callers.
Changing one side does not necessarily require changes in the other.
Inheritance allows for reuse of code where common behavior is
defined once for a number of related classes and unique behavior is
implemented only in classes where the behavior is different. Thus, the
behavior of a class might be the same or different from the behavior of
a subclass or superclass, and independent of the behavior of the
caller.

Change detection keeps track of changes made to domain
objects that are used in a database transaction so that at the end of
the transaction, changes are applied to the database.

Uniquing
is a property of database interaction in which a single domain instance
corresponds to a database row, regardless of how the user acquired the
object: via querying the database, navigating a reference from one
instance to another, or finding a distinct domain instance by providing
its primary identity. Without uniquing, changes made to one domain
instance will not be seen by other domain instances representing the
same database row; this might result in database corruption.

Database independence allows use of a common API and domain model to
operate with various databases without changing the application view of
the database.

The earliest--and still very
popular--technologies for accessing relational databases use APIs to
transmit SQL statements to the server and return the results of
executing the statements back to the application. It is left up to the
application to use the results directly or to create data structures
that represent the query results, and to copy the query results to
these
data structures.

Data structures that directly model query
results cannot model relationships that exist in the database;
therefore, associations among instances of the data structures are
poorly represented. Examples of this style of access include ODBC (Open
Database Connectivity) and JDBC (Java Database Connectivity)
interfaces.
These interfaces allow for limited separation of concerns, but most
often business logic is mixed with database programming. They do not
support information hiding, inheritance, change detection, uniquing, or
database independence.

More capable technologies provide methods
in the interface to copy the query results to user-specified data
structures. The user provides all of the SQL statements annotated so
they correspond to the data structures. The SQL statements created by
the user include all queries, plus insert, update, and delete. These
technologies handle much of the error-prone and time-consuming jobs of
analyzing the results of queries but still leave many of the difficult
tasks to the user. One example of this style of access is iBATIS, which
supports information hiding and a limited separation of concerns but
not
inheritance, change detection, uniquing, or database independence.
With ORM, data stored in relational databases is represented to the
application as objects in the native object programming language.
Programmers map domain object model classes to relational tables and
use
an API implemented by a persistence provider to access the database.
Queries against the database are expressed in terms of the domain
object
model. The provider generates SQL statements directly from the domain
model. Martin Fowler has called this approach DataMapper.^2

ORM techniques and products are available for many
object-oriented languages, including Java, C++, C#, Python, Smalltalk,
Ruby, and Groovy. The techniques and programming paradigms for ORM
apply
to many of the products that support these languages. (In this article,
examples are given in Java.)
Read the rest of this article at acmqueue.com
http://acmqueue.com/rd.php?c.538

See all the latest articles and audio interviews with Queue's RSS Feeds
http://acmqueue.com/rd.php?s.48.7

To unsubscribe to this newsletter, send an email to
queuenews-request at acmqueue.com
with the words 'unsubscribe' in the subject line.

Change your email address
http://www.acmqueue.com/mailman/options/queuenews

Subscribe to Queue in print
http://www.acmqueue.com/click.php?id=30
About Queue
http://acmqueue.com/rd.php?s.31.5
Contact Us
http://acmqueue.com/rd.php?s.32.10
Privacy policy
http://acmqueue.com/rd.php?s.27.9

For advertising information, contact advertising at acmqueue.com


© 2008 ACM, Inc. All rights reserved.




More information about the QueueNews mailing list