Objectivity for Java Reference

com.objy.db.app
Class ooObj

java.lang.Object
  |
  +--com.objy.db.app.ooAbstractObj
        |
        +--com.objy.db.app.ooObj
All Implemented Interfaces:
IooObj, Persistent, PersistentEvents
Direct Known Subclasses:
ooCollection, ooCompare, ooContObj, ooMap

public class ooObj
extends ooAbstractObj
implements IooObj

Superclass for all persistence-capable classes with the ability to respond to persistent events, a public API that supports all persistent operations, and default implementation for persistent operations.

API Summary

Classes that are derived from ooObj are called persistence-capable classes because their instances can be made persistent and saved with their application-specific data in a database. Two general kinds of objects can be saved persistently: basic objects and containers.

You never create an instance of this class; instead, you create instances of its subclasses.

When you instantiate a class derived from ooObj, the newly created object is transient. If you want to save the object, you must make it persistent. Every persistent object belongs to the session that is in a transaction when the object is made persistent or retrieved. Objectivity for Java does not allow a persistent object to interact with objects that belong to different sessions; see Object Isolation.

Most methods defined on ooObj can be called only after the object has been made persistent and only while the session that owns the object is in a transaction. See Persistent Objects for details on how to make an object persistent and how to work with persistent objects.

This class provides methods that enable you to:

Related Interfaces

Alternative ways to define a persistence-capable class are:

For additional information, see Defining Persistence-Capable Classes.

API Summary

Functionality
Locking lock(int)
lockNoProp(int)
Fetching Persistent Data fetch()
fetch(int)
markModified()
clearModified()
markFetchRequired()
isFetchRequired()
Modifying markModified()
move(Object)
delete()
deleteNoProp()
clearModified()
write()
Copying copy(Object)
Getting Information getContainer()
getSession()
getOid()
Testing isPersistent()
isModified()
isDead()
isValid()
isFetchRequired()
Clustering cluster(Object)
Working With Scope-Named Objects nameObj(Object, String)
unnameObj(Object)
lookupObj(String)
lookupObj(String, int)
lookupObjName(Object)
scopedObjects()
Handling Persistent Events activate(ActivateInfo)
deactivate(DeactivateInfo)
preWrite(PreWriteInfo)
Finding Scope Objects scopedBy()
Working With Indexes updateIndexes()
Managing Internal Persistent Objects deleteReference(Object)
dropCachedReference(Object)


Constructor Summary
ooObj()
          Reserved for internal use; you create instances of subclasses of ooObj, not instances of ooObj itself.
 
Method Summary
 void activate(ActivateInfo info)
          Default implementation for handling an activate event.
 void clearModified()
          Removes the modified mark from this object.
 void cluster(Object object)
          Makes the specified object persistent, clustering it near this object.
 Object copy(Object near)
          Copies this basic object, clustering the new object with the specified object.
 void deactivate(DeactivateInfo info)
          Default implementation for handling a deactivate event.
 void delete()
          Deletes this object from the database and propagates the deletion operation to related objects.
 void deleteNoProp()
          Deletes this object from the database.
 void deleteReference(Object object)
          Deletes the specified internal persistent object from this persistent object.
 void dropCachedReference(Object object)
          Drops the specified internal persistent object from the Objectivity for Java cache.
 void fetch()
          Locks this object for read and fetches its persistent data.
 void fetch(int mode)
          Fetches this object's persistent data after obtaining the specified lock.
 ooContObj getContainer()
          Gets the container in which this object is stored.
 ooId getOid()
          Gets the object identifier of this object.
 PooObj getPersistor()
          Reserved for internal use; you should not call this method.
 Session getSession()
          Gets the session in which this object was made persistent or retrieved.
 boolean isDead()
          Tests whether this object is dead.
 boolean isFetchRequired()
          Tests whether this object's persistent data needs to be fetched.
 boolean isModified()
          Tests whether this object has been marked as modified.
 boolean isPersistent()
          Tests whether this object is persistent.
 boolean isValid()
          Tests whether this object represents a valid persistent object.
 void lock(int mode)
          Explicitly locks this object and propagates the lock to related objects.
 void lockNoProp(int mode)
          Explicitly locks this object for the specified access.
 Object lookupObj(String scopeName)
          Retrieves the object with the specified scope name in the scope defined by this object.
 Object lookupObj(String scopeName, int lockMode)
          Retrieves the object with the specified scope name in the scope defined by this object, locking the retrieved object as specified.
 String lookupObjName(Object object)
          Looks up the name of the specified object in the scope defined by this persistent object.
 void markFetchRequired()
          Marks this object as needing to have its persistent data fetched.
 void markModified()
          Locks this object for write, fetches its persistent data if it is not already fetched, and marks it as modified.
 void move(Object near)
          Moves this basic object, clustering it with the specified object.
 void nameObj(Object object, String scopeName)
          Names the specified scope object in the scope of this object.
protected  PooObj persistor()
          Reserved for internal use; you should not call this method.
 void preWrite(PreWriteInfo info)
          Default implementation for handling a pre-write event.
 Iterator scopedBy()
          Initializes an iterator to find all scope objects that define scope names for this object.
 Iterator scopedObjects()
          Initializes an iterator to find all objects named in the name scope of this object.
 void setPersistor(PooObj persistor)
          Reserved for internal use; you should not call this method.
 void unnameObj(Object object)
          Removes the specified object's name from this object's name scope.
 void updateIndexes()
          Updates the indexes that include this object.
 void write()
          Transfers this object's data to the session's cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ooObj

public ooObj()
Reserved for internal use; you create instances of subclasses of ooObj, not instances of ooObj itself.

You should not use this constructor directly.

Method Detail

getContainer

public ooContObj getContainer()
Gets the container in which this object is stored.

If this object was retrieved from a database, the return value is the container in which the object is stored. If this object was created programmatically, the return value is the container in which this object will be stored when the transaction is committed.

Specified by:
getContainer in interface IooObj
Returns:
The container in which this object is stored.

Throws:
ObjectNotPersistentException - If the object is transient.

getSession

public Session getSession()
Gets the session in which this object was made persistent or retrieved.

Specified by:
getSession in interface IooObj
Returns:
The session to which this object belongs.

Throws:
ObjectNotPersistentException - If the object is transient.

getOid

public ooId getOid()
Gets the object identifier of this object.

Specified by:
getOid in interface IooObj
Returns:
The object identifier of this persistent object.

Throws:
ObjectNotPersistentException - If this object is transient.

isDead

public boolean isDead()
Tests whether this object is dead.

An object is made dead when you delete it.

Specified by:
isDead in interface IooObj
Returns:
True if this object is dead; otherwise, false.

See Also:
delete(), deleteNoProp()

isModified

public boolean isModified()
Tests whether this object has been marked as modified.

A persistent object that is marked as modified will be written to the database when the transaction is committed.

Specified by:
isModified in interface IooObj
Returns:
True if this object is persistent and marked as modified; otherwise, false.

See Also:
markModified()

isFetchRequired

public boolean isFetchRequired()
Tests whether this object's persistent data needs to be fetched.

If this object does not contain its most recent persistent data, you can call the fetch method to fetch the data.

You shouldn't need to call this method. Instead, you can simply call fetch, which will fetch the persistent data if necessary.

Specified by:
isFetchRequired in interface IooObj
Returns:
True if this object's persistent data must be fetched; false if this object already contains its most recent persistent data.

isPersistent

public boolean isPersistent()
Tests whether this object is persistent.

Specified by:
isPersistent in interface IooObj
Returns:
True if this object is persistent and false if it is transient.

isValid

public boolean isValid()
Tests whether this object represents a valid persistent object.

An object is a valid persistent object if it is neither dead nor transient. When you retrieve a persistent object, the retrieved object is guaranteed to reference a valid persistent object. However, if some other session then deletes or moves the object from the federated database, the retrieved object becomes invalid.

Note: If, for some reason, the session cannot access this object for read, this method returns false.

Specified by:
isValid in interface IooObj
Returns:
True if this object represents a valid persistent object; otherwise, false.

markFetchRequired

public void markFetchRequired()
Marks this object as needing to have its persistent data fetched.

This method is called automatically when you commit the transaction in which you set or fetched this object's persistent data. On commit, the transaction releases its locks; a different client may then modify this object's persistent data. If such a modification occurs, this object's persistent data will be out of date. To ensure that you have the most current data for an object, open the transaction again and call the object's fetch method.

Applications typically do not need to call this method explicitly.

If you modify an object and then want to force its definition to be reread from the database (overwriting your modifications), you should first call the clearModified method, then call this method.

Specified by:
markFetchRequired in interface IooObj
Throws:
ObjectNotPersistentException - If this object is transient.

ObjyRuntimeException - If this object is already marked modified.

See Also:
clearModified()

markModified

public void markModified()
Locks this object for write, fetches its persistent data if it is not already fetched, and marks it as modified.

If this object is not currently locked for write, this method locks it for write. The write lock is not propagated to related objects. If this object does not contain its most recent persistent data, this method fetches that data. There is no overhead for calling this method if this object is already locked for write and its data has already been fetched during the current transaction.

You must call this method whenever you make changes to this object's persistent fields; typically, you call this method from every access method that sets the value of a persistent field of your subclass of ooObj. Only objects that are marked as modified are written to the database when the transaction is committed.

The modified mark is removed at the end of the current transaction or by an explicit call to the write method.

This method does nothing if this object is transient.

Specified by:
markModified in interface IooObj
See Also:
isModified()

clearModified

public void clearModified()
Removes the modified mark from this object.

The modified mark indicates that this object needs to be written to the database. You can call this method if you want to prevent your changes to this object from being written to the database.

If you want to prevent a newly persistent object from being written to the database, you should either abort the transaction, or call the object's delete method.

Specified by:
clearModified in interface IooObj
Throws:
ObjyRuntimeException - If this object has never been written to the database since it was made persistent.

fetch

public void fetch()
Locks this object for read and fetches its persistent data.

If this object is not currently locked, this method locks it for read before fetching its data. The read lock is not propagated to related objects.

When an object is first brought into memory, its persistent fields are left empty. You must call this method before you can safely access the object's persistent data.

If this object is already locked and the object's persistent data is current, this method has no effect; there is no overhead for repeated calls to fetch.

This method does nothing if this object is transient.

Specified by:
fetch in interface IooObj
Throws:
FetchCompletedWithErrors - If the operation fails.

fetch

public void fetch(int mode)
Fetches this object's persistent data after obtaining the specified lock.

If this object is not currently locked as specified, this method obtains the specified lock before fetching this object's data. The lock is not propagated to related objects.

When an object is first brought into memory, its persistent fields are left empty. You must call this method before you can safely access the object's persistent data.

If this object is already locked in the specified mode and the object's persistent data is current, this method has no effect; there is no overhead for repeated calls to fetch.

This method does nothing if this object is transient.

Specified by:
fetch in interface IooObj
Parameters:
mode - The type of lock to obtain for this object; one of the following constants defined in the oo interface:
READ
Obtain a read lock.
WRITE
Obtain a write lock.

Throws:
FetchCompletedWithErrors - If the fetch fails.

write

public void write()
Transfers this object's data to the session's cache.

This method writes the object's data to its session's cache. Each session has its own cache, so the written data will not be visible to other sessions or processes. The changes will be transferred to the federated database when you commit or checkpoint the current transaction. If the transaction is aborted, the changes are never transferred to the federated database.

Only this object's data is written to the cache. If this object references other persistent objects, those referenced objects are not written.

This method removes any modified mark from this object. If you make additional changes after calling this method, you must call markModified or write again; otherwise, your changes will be lost.

You typically do not call this method. Instead, you call the session's checkpoint method, which writes all changes to the federated database. The checkpoint method makes changes accessible to all other clients, not just to other transactions of your process.

Specified by:
write in interface IooObj
Throws:
ObjectNotPersistentException - If this object is transient.

lock

public void lock(int mode)
Explicitly locks this object and propagates the lock to related objects.

This method locks this object for the specified access and propagates the lock to any objects associated with this object through relationships for which lock propagation is enabled.

Locking a basic object implicitly locks the object's container. Locking a container implicitly locks all basic objects in the container.

Specified by:
lock in interface IooObj
Parameters:
mode - The type of lock to obtain for this object; one of the following constants defined in the oo interface:
READ
Obtain a read lock.
WRITE
Obtain a write lock.

The lock mode is limited by the open mode of this object's session.

If this object is already locked, you can call this method to upgrade a read lock to a write lock, but not to downgrade a write lock to a read lock.

Throws:
ObjectNotPersistentException - If this object is transient.

ObjyRuntimeException - If you try to set the lock mode to WRITE when the session's open mode is openReadOnly.

See Also:
lockNoProp(int)

lockNoProp

public void lockNoProp(int mode)
Explicitly locks this object for the specified access.

Unlike the lock method, this method does not propagate the lock to related objects.

Locking a basic object implicitly locks the object's container. Locking a container implicitly locks all basic objects in the container.

Specified by:
lockNoProp in interface IooObj
Parameters:
mode - The type of lock to obtain for this object; one of the following constants defined in the oo interface:
READ
Obtain a read lock.
WRITE
Obtain a write lock.

The lock mode is limited by the open mode of this object's session. If you try to set the lock mode to WRITE when the session's open mode is openReadOnly, this method throws a runtime exception.

Throws:
ObjectNotPersistentException - If this object is transient.

See Also:
lock(int)

delete

public void delete()
Deletes this object from the database and propagates the deletion operation to related objects.

This method propagates the deletion operation to any objects associated to this object through relationships for which deletion propagation is enabled.

Until the current transaction is committed, the deleted objects continue to exist in your application's memory, but they are marked dead.

Each deleted object is removed from any bidirectional relationships in which it is involved. However, if another persistent object references the deleted object in a unidirectional relationship or directly in one of its persistent fields, you are responsible for removing that reference. An exception is thrown if you attempt to write a persistent object that references a dead object.

Specified by:
delete in interface IooObj
Throws:
ObjectNotPersistentException - If this object is transient.

ObjectIsDeadException - If you attempt to perform this operation on a dead object.

See Also:
deleteNoProp(), isDead()

deleteNoProp

public void deleteNoProp()
Deletes this object from the database.

Until the current transaction is committed, this object continues to exist in your application's memory, but it is marked dead.

The deleted object is removed from any bidirectional relationships in which it is involved. However, if another persistent object references the deleted object in a unidirectional relationship or directly in one of its persistent fields, you are responsible for removing that reference. An exception is thrown if you attempt to write a persistent object that references a dead object.

Unlike the delete method, this method does not propagate the deletion operation to related objects.

Specified by:
deleteNoProp in interface IooObj
Throws:
ObjectNotPersistentException - If this object is transient.

ObjectIsDeadException - If you attempt to perform this operation on a dead object.

See Also:
isDead(), delete()

cluster

public void cluster(Object object)
Makes the specified object persistent, clustering it near this object.

Specified by:
cluster in interface IooObj
Parameters:
object - The transient object to be made persistent. The object to be clustered must be an instance of a persistence-capable class.
If object is a basic object:
This method assigns it a storage location in this object's container, close to this object. If possible, object will be stored on the same page as this object.
If object is a container:
This method assigns it a location in this object's database, adding it to that database as a hashed container with no system name, 5 initial pages, a hash value of 10, and a growth factor of 10%.

Throws:
ObjectNotPersistentException - If this object is transient.

See Also:
ooDBObj.addContainer(com.objy.db.app.ooContObj, java.lang.String, long, long, long)

copy

public Object copy(Object near)
Copies this basic object, clustering the new object with the specified object.

You should call this method for persistent objects only. If this object is not locked, this method locks its container for read-only access.

Specified by:
copy in interface IooObj
Parameters:
near - The object with which to cluster the new copy. The near object must be a database, a persistent container, or a persistent basic object.
If near is a database:
The new copy is stored in the default container of that database.
If near is a persistent container:
The new copy is stored in that container.
If near is a persistent basic object:
The new copy is stored in the same container as near. If possible, it will be stored on the same page as near or on a page close to near.

Returns:
A new object with the same persistent data as this object. The returned object is persistent. If the transaction is aborted, the new object becomes a dead object and is not stored persistently.

move

public void move(Object near)
Moves this basic object, clustering it with the specified object.

You should call this method for persistent basic objects only. If this object is not locked, this method locks its container and the container to which it will be moved, for read-write access.

Warning: This method changes the object identifier of this object. When you move an object you should, within the same transaction, update references to the object within all relevant relationships, collections (including root-name maps), scope names, and indexes. In the case of a reference within a name map or root name, database corruption could result if the reference is not updated. See Moving a Persistent Basic Object for additional information.

Specified by:
move in interface IooObj
Parameters:
near - The object with which to cluster this object; must be a database, a persistent container, or a persistent basic object.
If near is a database:
This object is moved to the default container of that database.
If near is a persistent container:
This object is moved to that container.
If near is a persistent basic object:
This object is moved to the container in which near is stored. If possible, it will be stored on the same page as near or on a page close to near.

nameObj

public void nameObj(Object object,
                    String scopeName)
Names the specified scope object in the scope of this object.

If the specified object is transient, this method makes it persistent. If the specified object is already persistent, this method locks its container for write.

This method obtains a write lock on the name map in which this object stores its scope names.

Specified by:
nameObj in interface IooObj
Parameters:
object - The object to be named.

scopeName - The name for the specified object in the scope of this object. This name can be any valid Java string and must be unique within this object's name scope.

Throws:
ObjectNotPersistentException - If this object is transient or if its container is not hashed.

See Also:
lookupObj(java.lang.String), unnameObj(java.lang.Object)

unnameObj

public void unnameObj(Object object)
Removes the specified object's name from this object's name scope.

This method locks both this object and object for write.

Specified by:
unnameObj in interface IooObj
Parameters:
object - The object whose name is to be removed.

Throws:
ObjectNotPersistentException - If this object is transient.

ObjyRuntimeException - If object has no name in this object's name scope.

See Also:
lookupObj(java.lang.String), nameObj(java.lang.Object, java.lang.String)

lookupObj

public Object lookupObj(String scopeName)
Retrieves the object with the specified scope name in the scope defined by this object.

Specified by:
lookupObj in interface IooObj
Parameters:
scopeName - The scope name to look up.

Returns:
The object with the specified scope name in the scope of this object.

Throws:
ObjectNotPersistentException - If this object is transient.

ObjyRuntimeException - If there is no object named scopeName in the scope of this database.

See Also:
lookupObjName(java.lang.Object), nameObj(java.lang.Object, java.lang.String)

lookupObj

public Object lookupObj(String scopeName,
                        int lockMode)
Retrieves the object with the specified scope name in the scope defined by this object, locking the retrieved object as specified.

Specified by:
lookupObj in interface IooObj
Parameters:
scopeName - The scope name to look up.

lockMode - The type of lock to obtain for the object; one of the following constants defined in the oo interface:
READ
Obtain a read lock.
WRITE
Obtain a write lock.

Returns:
The object with the specified scope name in the scope of this object; the returned object is locked as specified by lockMode.

Throws:
ObjectNotPersistentException - If this object is transient.

ObjyRuntimeException - If there is no object named scopeName in the scope of this database.

See Also:
lookupObjName(java.lang.Object), nameObj(java.lang.Object, java.lang.String)

lookupObjName

public String lookupObjName(Object object)
Looks up the name of the specified object in the scope defined by this persistent object.

Specified by:
lookupObjName in interface IooObj
Parameters:
object - The object whose name is to be looked up.

Returns:
The scope name of the specified object in this object's name scope.

Throws:
ObjectNotPersistentException - If this object is transient.

ObjyRuntimeException - If object has no name in this object's name scope.

See Also:
lookupObj(java.lang.String)

scopedObjects

public Iterator scopedObjects()
Initializes an iterator to find all objects named in the name scope of this object.

Specified by:
scopedObjects in interface IooObj
Returns:
An iterator that finds the named objects.

Throws:
ObjectNotPersistentException - If this object is transient.

scopedBy

public Iterator scopedBy()
Initializes an iterator to find all scope objects that define scope names for this object.

Specified by:
scopedBy in interface IooObj
Returns:
An iterator that finds the scope objects.

Throws:
ObjectNotPersistentException - If this object is transient.

deleteReference

public void deleteReference(Object object)
Deletes the specified internal persistent object from this persistent object.

Parameters:
object - The internal persistent object to be deleted.

Throws:
ObjyRuntimeException - If object is not referenced by this persistent object or is not an array, a string element of an array, or a scalar type that is stored in the federated database as an internal persistent object (java.util.Date, java.sql.Date, or java.sql.Time, java.sql.Timestamp).

dropCachedReference

public void dropCachedReference(Object object)
Drops the specified internal persistent object from the Objectivity for Java cache.

The object to be released is an internal persistent object that is referenced by some persistent object.

Note: You should call this method only if the memory consumed by Objectivity for Java prevents your application from running to completion. In that situation, you should call this method only when the persistent object that references object has itself been released and is waiting to be garbage collected.

Parameters:
object - The internal persistent object to be deleted; must be an instance of java.util.Date, java.sql.Date, java.sql.Time, or java.sql.Timestamp.

updateIndexes

public void updateIndexes()
Updates the indexes that include this object.

If a session's index mode is EXPLICIT_UPDATE, indexes are not updated automatically to reflect changes to indexed fields. You must call this method after creating an object and initializing its indexed fields, and after modifying the indexed fields of an existing object.

Specified by:
updateIndexes in interface IooObj
Throws:
ObjectNotPersistentException - If this object is transient.

getPersistor

public PooObj getPersistor()
Reserved for internal use; you should not call this method.

Specified by:
getPersistor in interface Persistent
Returns:
Ignore

setPersistor

public void setPersistor(PooObj persistor)
Reserved for internal use; you should not call this method.

Specified by:
setPersistor in interface Persistent
Parameters:
persistor - Ignore
Returns:
Ignore

activate

public void activate(ActivateInfo info)
Default implementation for handling an activate event.

Objectivity for Java calls this method after the object is fetched. It is called after execution of this object's fetch or markModified method if the object has not yet been fetched.

If info indicates that errors occurred during the check operation, this method throws a FetchCompletedWithErrors exception.

You should not call this method directly; however, you may override its behavior. For example, your implementation might initialize the persistent object's transient fields or perform application-specific registration of the object.

Specified by:
activate in interface PersistentEvents
Parameters:
info - An activate information object containing information about any exceptions that occurred during the fetch operation.

deactivate

public void deactivate(DeactivateInfo info)
Default implementation for handling a deactivate event.

Objectivity for Java calls this method after the current transaction of this object's session is successfully committed or aborted.

The default implementation is empty.

You should not call this method directly; however, you may override its behavior. In a work-flow application, for example, your implementation might check the reason for deactivation to see whether changes were accepted (commit) or not (abort).

If an error occurs during the execution of this method, it does not affect the state of commit or abort operations. The database operation completes normally.

If an exception is thrown during an abort, there are two special cases to consider:

In either case, this object's deactivate method is executed.

If this object has been deleted, it has been removed from its session, so this method is not called when the transaction commits or aborts.

Specified by:
deactivate in interface PersistentEvents
Parameters:
info - A deactivate information object specifying the reason why deactivation occurred.

preWrite

public void preWrite(PreWriteInfo info)
Default implementation for handling a pre-write event.

Objectivity for Java calls this method before this object is written to the database. This method can be called by any method that causes the object to be written, namely:

The default implementation is empty.

If an error occurs during the execution of this method, the encompassing operation does not complete. The state of this object is not changed; that is, it is still marked as modified.

You should not call this method directly; however, you may override its behavior. For example, your implementation might encrypt some persistent fields and make other persistent fields null. Your implementation could throw an exception to prevent this object from being written (and terminate the encompassing operation with that exception).

Specified by:
preWrite in interface PersistentEvents
Parameters:
info - A pre-write information object specifying the reason why the object is being written.

persistor

protected PooObj persistor()
Reserved for internal use; you should not call this method.

Objectivity for Java Reference

Copyright © 2000 Objectivity, Inc. All rights reserved.