ObjectStore Java Tutorial
Chapter 1
Benefits of ObjectStore for Java
To introduce you to ObjectStore and the benefits of using ObjectStore, this chapter discusses the following topics:
Serialization and Persistence
How ObjectStore Improves on Serialization
Serialization and Persistence
The lifetime of a persistent object exceeds the life of the application process that created the persistent object. Persistent object management is the mechanism for storing the state of objects in a nonvolatile place so that when the application shuts down, the objects continue to exist.
Description of Serialization
Java provides object serialization, which supports a basic form of object persistence. You can use object serialization to store copies of objects in a file or to ship copies of objects to an application running in another Java virtual machine. Serialization enables you to flatten objects into a stream of bytes that, when read later, can recreate objects equivalent to those that were written to the stream.
Serialization provides a simple yet extensible mechanism for storing objects persistently. The Java object type and safety properties are maintained in the serialized form and serialization only requires per-class implementation for special customization. Serialization is usually sufficient for applications that operate on small amounts of persistent data and where reliable storage is not an absolute requirement.
Disadvantages of Serialization
Serialization is not the optimal choice for applications that
Because serialization has to read/write entire graphs of objects at a time, it works best for small numbers of objects. When the byte stream is a couple of megabytes in size, you might find that storing objects by means of serialization is too slow, especially if your application is doing frequent updates that need to be saved. Another drawback is the lack of undo or abort of changes to objects.
In addition, serialization does not provide reliable object storage. If your system or application crashes when objects are being written to disk by serialization, the contents of the file are lost. To protect against application or system failures and to ensure that persistent objects are not destroyed, you must copy the persistent file before each change is saved.
How ObjectStore Improves on Serialization
The three key improvements that ObjectStore provides over serialization are
In addition, ObjectStore is easy to use, allows access to as little as a single object at a time, and allows multiple applications to read the same database at the same time.
Transactions and Recovery
A primary difference between serialization and ObjectStore is evident in the area of transactions and recovery. With serialization, persistent stores are not automatically recoverable. Consequently, in the event of an application or system failure, a file can only be recovered to the beginning of the application session and only if a copy of the file is made before the application begins.
In contrast, ObjectStore can recover from an application failure or system crash. If a failure prevents some of the changes in a transaction from being saved to disk, ObjectStore ensures that none of that transaction's changes are saved in the database. When you restart the application, the database is consistent with the way it was before the transaction started.
Ease of Use
Similar to serialization, ObjectStore provides an easy to use interface for storing and retrieving Java objects. You define persistence-capable Java classes, and their fields and methods, in the same way as transient Java classes. You use standard Java constructs to create and manipulate both persistent and transient instances. Transparent object persistence through ObjectStore enables developers to make use of the full power of Java and to easily incorporate existing class libraries with ObjectStore.
The ObjectStore for Java API provides database features that allow you to
ObjectStore automatically generates the equivalent of serialization's readObject and writeObject for each persistence-capable class. As with serialization, you can override the implementation of these methods.
Ability to Read/Update a Single Object
While serialization reads and writes complete graphs of objects, ObjectStore provides explicit, fine-grained control over object access and fetching. You can read single objects from the database and write single objects to the database. ObjectStore automatically fetches related objects when application code refers to them.
Concurrency
ObjectStore supports single-program access to databases, meaning that a database can be updated by at most one application at one time. Multiple applications can read the same database simultaneously, but only one application can be writing to the database.
[previous] [next]
Copyright © 1998 Object Design, Inc. All rights
reserved.
Updated: 10/07/98 07:05:24