Using Object-Oriented Databases: A Step-By-Step Tutorial

Performing Updates
Updates are very easy with an OODB. The object already exists in the database, so it is simply a matter of retrieving the object and then calling its mutator methods. You can also set the object's public attributes directly if you wish. Once you commit the transaction, the changes are applied transparently to the object in the database.

Code: Updating existing PhonebookEntry Objects
Transaction t = Transaction.begin(ObjectStore.UPDATE); PhonebookEntry entry = (PhonebookEntry) entries.get("555-123-4567); entry.setFirstName("Steve"); } t.commit(ObjectStore.RETAIN_HOLLOW);

In the preceding example, the code retrieves an object from the hash map using a phone number as the key. More code is usually required to handle a null return due to a non-existent object. Once the object is retrieved, it can be manipulated as a normal Java object. Once all changes have been made to the object, the transaction is committed and changes are applied to the database.

See the Code in Full
By adding only 130 statement lines of code to the application, I was able to add query, update, delete, and reporting functionality with ObjectStore PSE. A brief transcript shows the new application in action.

At the beginning of this article, I mentioned that I started out writing an application with very little consideration of the final storage approach. You can view the final code in the following files:

Red sections are the pieces of code that I added while migrating from version 1 of the application to the OODB-enabled application. Some areas that I changed to OODB-enable the application are marked by comments (beginning with "Changed:" or "Added:") explaining the modifications.

You can download the source code for the application in case you would like to try building it for yourself. Be warned though, the code is partial and buggy, and it lacks error checking. (If you receive "Out of Environment Space" errors from older versions of Windows, refer to the README.TXT file.) THe code is intended only to show basic OODB concepts–reuse pieces at your own risk.

In a Nutshell
Our phone book app demonstrates some basic features of an ObjectStore PSE OODB. Each OODB is somewhat different of course, but many of the concepts in this article apply to other products. You can easily rebuild and tailor this demonstration to your own learning purposes. OODBs are not a silver bullet, and I hope I have not given that impression. They have some important limitations that you should be aware of (see "Object-Oriented Databases Are Worth a Closer Look").

In addition to this article, you also should study the whitepapers and documentation supplied with ObjectStore PSE. They address a number of general concepts and specific examples that were very useful when I first worked with ObjectStore PSE and in developing this article.


Steve Franklin handles the architecture and project engineering responsibilities at a major software firm dealing with J2EE, client/server, command and control, and other distributed architectures. Steve Franklin's primary "off-hours" hobby can be found at Lookoff.com, a repository for Internet and research resources. He can be reached at steve@lookoff.com.



Creating A Persistent Class

Back to Introduction

In this Article
Introduction Creating A Persistent Class
Building the Application Performing Updates



Read Part 1 of the OODB series: "Object-Oriented Databases Are Worth a Closer Look"







FEATURE SOFTWARE:
SQLDC
Create SQL applications quickly and easily.
Buy Now!

FEATURE BOOK:
VBCommander
Speed app and component design time with this set of more than 20 add-in tools.
Buy Now!


The Database Development Zone has all the content and resources you need to fine-tune your data access apps.

Download the code from this article!

Read Part 1 of the OODB series: "Object-Oriented Databases Are Worth a Closer Look"

Read "XML Parsers: DOM and SAX Put to the Test" for a full discussion of XML parser options.

Join the discussions in the DevX Database Design forum





 
Sponsored Links

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers

Copyright Information/Privacy Statement