|
Objectivity for Java Reference | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.objy.db.app.ooAbstractObj | +--com.objy.db.app.ooObj
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:
Alternative ways to define a persistence-capable class are:
For additional information, see Defining Persistence-Capable Classes.
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 |
public ooObj()
You should not use this constructor directly.
Method Detail |
public ooContObj getContainer()
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.
getContainer
in interface IooObj
ObjectNotPersistentException
- If the object is transient.public Session getSession()
getSession
in interface IooObj
ObjectNotPersistentException
- If the object is transient.public ooId getOid()
getOid
in interface IooObj
ObjectNotPersistentException
- If this object is transient.public boolean isDead()
An object is made dead when you delete it.
isDead
in interface IooObj
delete()
,
deleteNoProp()
public boolean isModified()
A persistent object that is marked as modified will be written to the database when the transaction is committed.
isModified
in interface IooObj
markModified()
public boolean isFetchRequired()
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.
isFetchRequired
in interface IooObj
public boolean isPersistent()
isPersistent
in interface IooObj
public boolean isValid()
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.
isValid
in interface IooObj
public void markFetchRequired()
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.
markFetchRequired
in interface IooObj
ObjectNotPersistentException
- If this
object is transient.ObjyRuntimeException
- If this object is
already marked modified.clearModified()
public void markModified()
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.
markModified
in interface IooObj
isModified()
public void clearModified()
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.
clearModified
in interface IooObj
ObjyRuntimeException
- If this object has never been written to the database
since it was made persistent.public void fetch()
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.
fetch
in interface IooObj
FetchCompletedWithErrors
- If the operation fails.public void fetch(int mode)
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.
fetch
in interface IooObj
mode
- The type of lock to obtain for this object;
one of the following constants defined in the oo interface:
FetchCompletedWithErrors
- If the fetch fails.public void write()
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.
write
in interface IooObj
ObjectNotPersistentException
- If this object is transient.public void lock(int mode)
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.
lock
in interface IooObj
mode
- The type of lock to obtain for this object;
one of the following constants defined in the oo interface:
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.
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.lockNoProp(int)
public void lockNoProp(int mode)
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.
lockNoProp
in interface IooObj
mode
- The type of lock to obtain for this object;
one of the following constants defined in the oo interface:
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.
ObjectNotPersistentException
- If this object
is transient.lock(int)
public void delete()
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.
delete
in interface IooObj
ObjectNotPersistentException
- If this object is
transient. ObjectIsDeadException
- If you attempt to perform this operation on a
dead object.deleteNoProp()
,
isDead()
public void deleteNoProp()
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.
deleteNoProp
in interface IooObj
ObjectNotPersistentException
- If this object is
transient.ObjectIsDeadException
- If you attempt to perform this operation on
a dead object.isDead()
,
delete()
public void cluster(Object object)
cluster
in interface IooObj
object
- The transient object to be made
persistent.
The object to be clustered must be an instance of a
persistence-capable class.
ObjectNotPersistentException
- If this object
is transient.ooDBObj.addContainer(com.objy.db.app.ooContObj, java.lang.String, long, long, long)
public Object copy(Object near)
You should call this method for persistent objects only. If this object is not locked, this method locks its container for read-only access.
copy
in interface IooObj
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.
public void move(Object near)
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.
move
in interface IooObj
near
- The object with which to cluster this
object; must be a database, a
persistent container, or a persistent basic object.
public void nameObj(Object object, String scopeName)
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.
nameObj
in interface IooObj
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. ObjectNotPersistentException
- If this object
is transient or if its container is not hashed.lookupObj(java.lang.String)
,
unnameObj(java.lang.Object)
public void unnameObj(Object object)
This method locks both this object and object for write.
unnameObj
in interface IooObj
object
- The object whose name is to be
removed.ObjectNotPersistentException
- If this object
is transient.ObjyRuntimeException
- If
object has no name in this object's name scope.lookupObj(java.lang.String)
,
nameObj(java.lang.Object, java.lang.String)
public Object lookupObj(String scopeName)
lookupObj
in interface IooObj
scopeName
- The scope name to look
up.ObjectNotPersistentException
- If this object
is transient.ObjyRuntimeException
- If there is no
object named scopeName in the scope of this
database.lookupObjName(java.lang.Object)
,
nameObj(java.lang.Object, java.lang.String)
public Object lookupObj(String scopeName, int lockMode)
lookupObj
in interface IooObj
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:
ObjectNotPersistentException
- If this object
is transient.ObjyRuntimeException
- If there is no
object named scopeName in the scope of this
database.lookupObjName(java.lang.Object)
,
nameObj(java.lang.Object, java.lang.String)
public String lookupObjName(Object object)
lookupObjName
in interface IooObj
object
- The object whose name is to be
looked up.ObjectNotPersistentException
- If this object
is transient.ObjyRuntimeException
- If object has
no name in this object's name scope.lookupObj(java.lang.String)
public Iterator scopedObjects()
scopedObjects
in interface IooObj
ObjectNotPersistentException
- If this object
is transient.public Iterator scopedBy()
scopedBy
in interface IooObj
ObjectNotPersistentException
- If this object
is transient.public void deleteReference(Object object)
object
- The
internal persistent object to be deleted.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).public void dropCachedReference(Object object)
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.
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.public void updateIndexes()
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.
updateIndexes
in interface IooObj
ObjectNotPersistentException
- If this object
is transient.public PooObj getPersistor()
getPersistor
in interface Persistent
public void setPersistor(PooObj persistor)
setPersistor
in interface Persistent
persistor
- Ignorepublic void activate(ActivateInfo info)
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.
activate
in interface PersistentEvents
info
- An
activate information object
containing information about any exceptions that occurred
during the fetch operation.public void deactivate(DeactivateInfo info)
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.
deactivate
in interface PersistentEvents
info
- A
deactivate information object
specifying the reason why deactivation occurred.public void preWrite(PreWriteInfo info)
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).
preWrite
in interface PersistentEvents
info
- A
pre-write information object
specifying the reason why the object is being written.protected PooObj persistor()
|
Objectivity for Java Reference | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2000 Objectivity, Inc. All rights reserved.