Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers Request free information on products written about or advertised in BYTE Submit a press release, or scan recent announcements Talk with BYTE's staff and readers about products and technologies

ArticlesMore Java Persistence


January 1998 / Javatalk / More Java Persistence

A look at another Java-enabled object database reveals what's in store for you.

Rick Grehan

In last month's column, I examined Poet's object-oriented DBMS (OODBMS) for Java. This month I look at the Java version of ObjectStore PSE (persistent storage engine) from Object Design.

ObjectStore PSE (PSE for short) is one of a triad of object database systems from Object Design. ObjectStore 5.0 is the company's flagship OODBMS, followed (in terms of capability) by PSE Pro. Finally, the entry-level OODBMS is PSE, which is available either as a free download from Object Design's Web site (at http://www.odi.com ) or as a bundled addition to Java development environments. BYTE reviewed ObjectStore 5.0 in the October 1997 issue (see "The Object Is to Manage Data"); in this column, I discuss Object Design's Java interface.

I examined the version of PSE bundled with Asymetrix's Supercede. Note that PSE's capabilities are essentially a subset of those found in PSE Pro and in the full-blown, multiuser ObjectStore.

PSE uses the concept of "persistence by reachability" (as does Poet). That is, an object is persistent if it's referenced by or contained in another persistent object. This naturally generates a kind of chicken-and-egg question: How does any object become persistent in the first place?

The answer is the createRoot() method. It creates a persistent object in the database and a ssociates that object with a string. This is analogous to Poet's named objects. Once you have created a persistent root, it becomes a kind of anchor to which you can attach other objects. (Or the root could be a container storing persistent objects.)

A single database can hold an arbitrary number of roots. Furthermore, the referencing and containing can be nested arbitrarily deeply. If the root references an object that in turn references another object, and so on, the entire referenced chain of objects is accessible and therefore persistent.

Objects that can be stored in the PSE database are referred to as being "persistence-capable." Objects whose class includes methods that manipulate persistence-capable objects, but that themselves are not persistent, are called "persistence-aware" objects. All other objects are "transient objects."

To confuse you even further, a persistence-capable object can be in one of three states with regard to usability of the contents of its data members. A "holl ow" object has default values in its data members. (For example, if you fetch an object from the PSE database, the objects that it references -- as yet unfetched -- are hollow.) Once you read a hollow object's contents from the database, the object becomes "active." Finally, if the object participates in an aborted transaction (I'll discuss transactions below), the object is regarded as "stale"; its contents should be treated as indeterminant.

In addition, an active object becomes "dirty" if, after its contents have been read from the database, any data member has been modified. Dirty objects are written back to the database when their enclosing transaction completes.

As implied above, all access to a PSE database occurs within the bounds of a transaction. Manipulating objects within a database follows this sequence: Begin a transaction, read and write persistent objects, and then close that transaction. New or updated objects are written to the database only if the transaction closes successfully. If the transaction is aborted, the database remains in the state it was in prior to the beginning of the transaction.

Unique to PSE is how invisibility -- as far as the programmer is concerned -- does its work. Remarkably, you need not insert any explicit method calls to fetch and store persistent objects. Consequently, if you peruse the source code to a program that uses PSE, you'll see only calls to methods for opening and closing the database, and calls to methods for starting and committing transactions.

How, then, does anything get into or out of a database? This magic is wrought by PSE's postprocessor. When you build your PSE-enabled application, you need only bracket with transaction begin and end methods, stretches of code that operate on persistent objects. You compile your code and then run the resulting class files through the postprocessor.

When a persistent object is referenced, the postprocessor precedes the reference with a call to the method to fetch that object. When a persistent object is modified, the postprocessor follows the code with a call that marks the object as "dirty." (In fact, the calls are named fetch() and dirty() .) The postprocessor also adds classes that can initialize the contents of fetched objects and write persistent objects' contents back into the database.

The postprocessor does the best job it can at deducing where to place calls to fetch() and dirty() . But sometimes it can pepper your code with more calls than are strictly necessary. A savvy programmer, knowing where those calls ought to go, can override the postprocessor and place fetch() and dirty() calls only where they must be (and thereby simultaneously reduce execution size and increase execution performance). The documentation includes guidelines that lead you through inserting explicit calls to fetch() and dirty() and exercising the final application to verify correctness of exec ution.

One side effect of the postprocessor's modifying the class file is that debuggers can become slightly confused. Fortunately, because the Java class-file format associates source code line numbers with generated code, the postprocessor can make adjustments so that a debugger never gets completely befuddled. But sometimes, if you execute a "step into" on a statement that the postprocessor has -- in the class file -- inserted a fetch() or dirty() just after, you might find yourself suddenly stepping into PSE code. Executing "step out" solves the problem.

Although the full ObjectStore product supports indexes, PSE and PSE Pro don't. PSE has a persistent hash table that you can use to index on a collection of objects. But there's a catch if you want to generate a hash from a persistent PSE object: You must define such "persistent hashable" objects so that they descend from the persistent hashable superclass supplied with PSE.

The reason for this has t o do with the fact that Java's default hashcode() method can be confused with PSE's internal goings-on. PSE creates invisible transient objects that are equivalent to persistent objects during transactions. The standard hashcode() method can return different hash values for the transient objects that represent the same persistent object in the database, potentially making a hash table unusable as an indexing scheme.

PSE's persistent hashable superclass includes a "hidden field" for holding a hashcode. PSE defines a new hashcode() method that reads that hidden field. When an instance of the object is created, PSE calculates and stores a hash value in that hidden field so that subsequent calls to hashcode() return the same hash value.

Although I might have made PSE's near-invisible interface sound unconventional, the latest releases of PSE and ObjectStore support the Java binding as defined in the Object Database Management Group (ODMG) 2.0 specification. I recomm end downloading PSE and working with it for a few weeks (it's good for files with up to tens of megabytes of data). Then, if it looks right for your application, you can graduate to PSE Pro or ObjectStore.


Where to Find


Object Design, Inc.

Burlington, MA
Phone:    781-674-5000
Internet: 
http://www.odi.com




Information on products in the data management category HotBYTEs - information on products covered or advertised in BYTE


PSE a Poseur Lac king Capabilities

screen_link (50 Kbytes)

PSE lacks ObjectStore 5.0 capabilities, such as multiuser support and the database inspector.


Rick Grehan is coauthor of The Client/Server Toolkit (NobleNet, 1996). You can contact him at rick_g@bix.com .

Up to the Javatalk section contentsGo to next article: A JVM for Embedded Real-Time AppsSearchSend a comment on this articleSubscribe to BYTE or BYTE on CD-ROM  
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network