Download O2 Java Binding Guide
Transcript
4 Managing Persistent Java Objects reference immediately to nil with the method storeObject of the class Database, see Section 5.1. For example, suppose objects paul and mary point to each other through the attribute spouse. To delete mary from the database, write the following : ... // connection is established, base is opened // and transaction begins; Person paul,mary; ... // paul and mary are loaded from the // database; paul.setSpouse(null); // reference to mary is removed; database.storeObject(paul); // paul is immediately updated; Database.delete(mary); // mary can be deleted, assuming the only // reference to it has been removed; ... transaction.commit(); // Everything is made persistent in // the database; Deleted objects remain in memory as transient objects. With JB/O2, any persistent object may be deleted. Deletion is performed immediately as opposed to writing objects. If references to a deleted object still remain in the database, they behave as nil references. 4.11 Locking objects JB uses three types of locks on objects: shared locks, update locks and exclusive locks. No locks are acquired on objects in a read-only mode. Different concurrent transactions can acquire shared locks on the same object. Shared locks are automatically acquired when objects are loaded from the database inside a transaction. They are released when the transaction terminates (abort, commit or validate). A transaction must request an exclusive lock on an object in order to be able to update it. In JB, such locks are acquired at commit time, when the objects are actually written from the cache to the database. 66 Java Binding User Manual