|
Business Components | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.jbo.common.BaseObject | +--oracle.jbo.server.RowImpl | +--oracle.jbo.server.EntityImpl
This class implements the middle-tier representations of database rows.
An Entity Object provides an object-oriented representation of the data it caches from a database object, such as a table or view. Database rows are presented as individual entities, in which attributes typically correspond to a columns in the corresponding table.
The status of an Entity Object's data, relative to the corresponding database data, are indicated by its current post-state and entity-state.
States are set to one of STATUS_NEW
, STATUS_MODIFIED
,
STATUS_DELETED
and STATUS_DEAD
based on whether the
Entity Object is being
created, updated, deleted, or rolled back,
respectively. These operations set either or both the post-state and the
entity-state.
Post-states indicate the state of the Entity Object's data relative to
the transaction's corresponding database-data.
The post-state is reset to STATUS_UNMODIFIED
when a
post operation is invoked.
Entity-states indicate the state of the Entity Object's data relative to the
actual database data, and the state of the transaction itself.
The entity-state is reset
to STATUS_UNMODIFIED
when the Entity Object's data is committed
or rolled back.
Field Summary | |
protected static int |
DML_DELETE
Identifies that a Delete operation is to be performed in the doDML() method. |
protected static int |
DML_INSERT
Identifies that an Insert operation is to be performed in the doDML() method. |
protected static int |
DML_UPDATE
Identifies that an Update operation is to be performed in the doDML() method. |
protected static int |
MAXATTRCONST
Attribute constants are declared relative to their parent. |
protected static java.lang.String |
ORACLE_ROWID_COLUMN
Identifies the column name for ROWID columns in a table. |
Fields inherited from class oracle.jbo.common.BaseObject |
TRACE_EVERY_ALLOC,
TRACE_NONE,
TRACE_OCCASIONAL,
TRACE_UNINITIALIZED |
Fields inherited from interface oracle.jbo.server.Entity |
STATUS_DEAD,
STATUS_DELETED,
STATUS_MODIFIED,
STATUS_NEW,
STATUS_UNMODIFIED |
Constructor Summary | |
EntityImpl()
Internal: Applications should not use this constructor. |
Method Summary | |
protected void |
addToTransactionManager()
Adds this entity object to it's transaction manager (either another entity object based on the containership model, or the transaction object for this session). |
void |
addToValidationListeners(ValidationListener listener)
Adds a listener to the list of validation listeners and marks this Entity Object invalid. |
void |
addTransactionPostListener(TransactionPostListener listener)
Adds a listener to the list of post operation listeners. |
void |
addTransactionPostListenerNoCheck(TransactionPostListener listener)
Adds a listener to the list of post operation listeners without first checking it the Entity Object is already present. |
void |
afterCommit(TransactionEvent e)
Called to report that a Commit operation has occurred. |
void |
afterRemove(TransactionEvent e)
A cleanup routine to be invoked by transaction manager when this transaction listener is removed from the manager's list. |
void |
afterRollback(TransactionEvent e)
Called to report that a Rollback operation has occurred. |
void |
beforeCommit(TransactionEvent e)
Called to report that a Commit operation is imminent. |
void |
beforeRollback(TransactionEvent e)
Called to report that a Rollback operation is imminent. |
protected void |
create(AttributeList nameValuePair)
This method should be subclassed to supply programmatic default values to various attributes of a new Entity Object. |
protected void |
doDML(int operation,
TransactionEvent e)
Performs INSERT/UPDATE/DELETE processing for the row. |
protected void |
doDMLWithLOBs(int operation,
TransactionEvent e)
|
void |
domainToBeModified(DomainInterface d)
|
protected void |
doSelect(boolean lock)
Advanced: Most applications should not use this method. Performs SELECT/SELECT FOR UPDATE processing for the row. |
java.lang.Object |
getAttribute(int index)
Gets the value of an attribute. |
java.lang.Object |
getAttribute(java.lang.String name)
Gets the value of the named attribute. |
int |
getAttributeCount()
Counts the number of attributes in this Entity Object. |
int |
getAttributeIndexOf(java.lang.String name)
Finds the index of the named attribute. |
protected java.lang.Object |
getAttributeInternal(int index)
Gets the attribute value by index. |
protected java.lang.Object |
getAttributeValue(AttributeDefImpl attr)
Internal Applications should not use this method. |
protected java.lang.Object |
getChangeIndicator()
Gets the Change indicator attribute's value. |
DBTransaction |
getDBTransaction()
Retrieves this Entity Object's database transaction. |
protected EntityDefImpl |
getEntityDef()
Gets the Entity Definition Object which governs the structure of this Entity Object. |
byte |
getEntityState()
Gets this Entity Object's current entity-state. |
Key |
getKey()
Gets the Entity Object's Primary Key. |
protected java.lang.Object |
getPostedAttribute(int index)
Gets the value originally read for this attribute from the database. |
byte |
getPostState()
Gets this Entity Object's current post-state. |
Key |
getPrimaryKey()
Gets the primay key for this Entity Object's row. |
protected java.util.Vector |
getTransactionListeners()
Returns a copy of the list of "detail" entities associated to this Entity Object by composition association, participating in a transaction post and commit operations. |
int |
getTransPostHandle()
Advanced: Most applications should not use this method. |
protected java.util.Vector |
getValidationListeners()
Return a copy of the list of validation listeners This list contains modified children entities which are to be validated before this Entity Object is validated. |
protected void |
handlePostChangesError()
Called when a problem occurs while posting changes and restores an EntityImpl's state. |
boolean |
isAttributeUpdateable(int index)
Checks if the attribute is updateable. |
boolean |
isInvalid()
Reports this Entity Object's validity. |
boolean |
isLocked()
Reports whether this Entity Object is locked. |
boolean |
isTransientTransactionListener()
Tests whether this Entity Object's transaction listener is transient or permanent. |
boolean |
isTransientTransactionPostListener()
Tests whether this Entity Object's TransactionPostListener is transient or permanent. |
boolean |
isValid()
Reports this Entity Object's validity. |
void |
lock()
Locks the row. |
protected void |
lockTopLevelEntity()
Locks the top-most Entity Object by getting the Master Entity Object defined by composition associations, and walking-up the chain of containership. |
protected void |
populateAttribute(int index,
java.lang.Object value)
Advanced method: Applications typically should not call this method from their subclasses. |
protected void |
populateAttributeAsChanged(int index,
java.lang.Object value)
Advanced method: Applications should typically not call this method from their subclasses. |
void |
postChanges(TransactionEvent e)
Notifies a listener to post any cached changes to the database. |
void |
remove()
Marks the row for deletion. |
void |
removeTransactionPostListener(TransactionPostListener listener)
Removes a listener from the list of post operation listeners. |
void |
revert()
Reverts the row to the database's state. |
void |
setAttribute(int index,
java.lang.Object val)
Sets the value of an attribute. |
void |
setAttribute(java.lang.String name,
java.lang.Object val)
Sets the value of the named attribute. |
protected void |
setAttributeInternal(int index,
java.lang.Object val)
Validates and sets the value of an attribute by index. |
protected void |
setInvalid()
A helper method that marks this Entity Object invalid and adds it to the ValidationListeners list of the validation manager this Entity Object belongs to. |
void |
setTransPostHandle(int hdl)
Advanced: Most applications should not use this method. |
java.lang.String |
toString()
|
void |
validate()
Validate this Entity Object. |
protected void |
validateEntity()
Validates the entities and other listeners that are members of ValidationListeners list. |
protected void |
vetoRemoveWithDetails(AttributeDef associationDef)
|
Methods inherited from class oracle.jbo.server.RowImpl |
getAttributeInternal,
setAttributeInternal |
Methods inherited from class oracle.jbo.common.BaseObject |
dumpState,
setTraceLevel,
setTraceWriter |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected static final int DML_INSERT
doDML()
method.protected static final int DML_UPDATE
doDML()
method.protected static final int DML_DELETE
doDML()
method.protected static final java.lang.String ORACLE_ROWID_COLUMN
protected static final int MAXATTRCONST
Constructor Detail |
public EntityImpl()
Creates an Entity Object instance. Note that initialization of most of the internal state attributes are performed in the init method invoked by the framework after an instance of this class is created. Most applications need not invoke this constructor directly.
Method Detail |
protected void create(AttributeList nameValuePair)
Instances of subclasses should call super.create()
before performing any operations.
By default, if this Entity Object is part of a composition, and is a detail, this method checks for a valid foreign-key value in the given nameValuePair and sets the foreign-key value into it's attributes appropriately. This logic validates that a detail Entity Object has a master Entity Object if the two are related by composition association.
nameValuePair
- a name providing access to an attribute list.oracle.jbo.InvalidOwnerException
- if an attempt is made to create a
detail row without a master, when the association between the
master and detail is marked as composition.public java.lang.Object getAttribute(java.lang.String name)
If there is a get method for this attribute in a subclass of this Entity Object, that method is invoked. The get method name is derived from the attribute name: for example, the method getDeptNo() pertains to an attribute named "Deptno".
name
- the name of the attribute.public java.lang.Object getAttribute(int index)
If there is a get method for this attribute in a subclass of this Entity Object, that method is invoked. The get method name is derived from the attribute name: for example, the method getDeptNo() pertains to an attribute named "Deptno".
index
- the index of the attribute.public final void setAttribute(java.lang.String name, java.lang.Object val)
If there is a set method for this attribute in a subclass of this Entity Object, that method is invoked. The set method name is derived from the attribute name: for example, the method getDeptNo() pertains to an attribute named "Deptno".
name
- the name of the attribute.val
- the value to be assigned to the attribute. The class of the returned
value a Java type determined by this Entity Object's definition
object.public final void setAttribute(int index, java.lang.Object val)
If there is a set method for this attribute in a subclass of this Entity Object, that method is invoked. The set method name is derived from the attribute name: for example, the method getDeptNo() pertains to an attribute named "Deptno".
name
- the index of the attribute.val
- the value to be assigned to the attribute. The class of the returned
value a Java type determined by this Entity Object's definition
object.protected void setAttributeInternal(int index, java.lang.Object val)
name
- the name of the attributevalue
- the value.protected EntityDefImpl getEntityDef()
protected java.util.Vector getTransactionListeners()
protected java.util.Vector getValidationListeners()
protected void validateEntity()
JboMandatoryAttributesValidator
(if applicable) will be invoked here to perform null-value checks on mandatory attributes.
Application should subclass this method to perform cuatom entity-level validation
and call super.validateEntity()
to enable the framework to coordinate
validation of detail entities and validation via the declarative validators.
public final void validate() throws JboException
This method is invoked by the framework during any currency change and during the commit process.
If this Entity Object is marked invalid, validation is performed as follows:
Once all listeners are validated, this Entity Object is then marked valid.
Custom validation logic should be implemented by overriding
validateEntity() method, which may be invoked before or after calling
super.validateEntity()
.
oracle.jbo.JboException
- if this Entity Object is found
to be invalid.public void addToValidationListeners(ValidationListener listener)
Subsequent invocation of validate()
will invoke
validate()
on each of the listeners in the list.
listener
- the listener to be added.ValidationManager.
protected void setInvalid()
public boolean isValid()
This Entity Object is valid if it has been validated and not subsequently modified or set invalid.
true
if this Entity Object is valid.public boolean isInvalid()
This Entity Object is valid if it has been validated and not subsequently modified or set invalid.
true
if this Entity Object is invalid.protected final java.lang.Object getAttributeValue(AttributeDefImpl attr)
attr
- name of the attribute definition.protected final java.lang.Object getChangeIndicator()
Change indicator columns can be used to indicate that a change has occurred to the underlying Entity Object since we last queried against it. They are typically implemented as TimeStamp or Version (number) columns in the underlying table that are changed by the Database each time the row is updated.
Obtain the value for the change indicator column. This method returns NULL if:
OR
public Key getPrimaryKey()
public final int getAttributeCount()
The count includes persistent, transient, and association attributes. Attributes need not presently have values.
This method will return the same value for all the Entity Object's rows.
protected java.lang.Object getAttributeInternal(int index)
public final DBTransaction getDBTransaction()
protected java.lang.Object getPostedAttribute(int index)
If the attribute value at the index been changed (whether to the same value or a new value), return the original value as read from the database on first query. Invoke getAttributeInternal to return the original value.
index
- index of the attribute.public boolean isLocked()
An Entity Object is locked if its corresponding database row is locked.
true
if the row is locked.public byte getEntityState()
STATUS_UNMODIFIED
- if this Entity Object originated in
the database and is unmodified,
or if modifications have been committed to the database.STATUS_MODIFIED
- if this Entity Object originated in the
database, and has been modified in the current transaction.STATUS_NEW
- if this Entity Object is new in the current
transaction.STATUS_DELETED
- if this Entity Object has been deleted
in the current transaction.STATUS_DEAD
- if this Entity Object is new in the current
transaction and has been deleted.public byte getPostState()
STATUS_UNMODIFIED
- if this Entity Object has been
queried from the database and is unchanged,
or if it has been posted to the database.STATUS_MODIFIED
- if this Entity Object has been
queried from the database and has changed.STATUS_NEW
- if this Entity Object is new and not yet
posted to the database.STATUS_DELETED
- if this Entity Object has been marked
for deletion.STATUS_DEAD
- if this Entity Object is new, but has been
deleted.protected void handlePostChangesError()
For example when a user performs an operation (such as a commit) that posts changes, the framework will go through each EntityImpl instance that was modified during this transaction and call postChanges() to post the changes to database. If something goes wrong during this process and an exception is caught, then the framework notifies those EntityImpls by calling handlePostChangesError. The default implementation of handlePostChangesError essentially restores the EntityImpl's state.
A user can create a custom EntityImpl (by extending EntityImpl), and handle such an error differently from the default implemention by overriding handlePostChangesError and adding custom error-handling logic.
If this method is overridden, then the default implementation must be called with super.handlePostChangesError() to restore the entity post states, as well as notify posted "child" entities to handle post changes errors.
public int getAttributeIndexOf(java.lang.String name)
name
- an attribute name.name
.public void revert()
Calling this method will either reset the attribute values to their database values or revert them to their default values. If the Entity Object is posted, all the attributes revert to the to unread state, so that a subsequent getAttribute() call will refresh all attributes from the database.
public void lock()
If the row is new or already locked by this Entity Object, or if the transaction's locking mode is LOCK_NONE, this method has no effect.
If this Entity Object is contained by another (that is, it is part of a composition association and has a master Entity Object), this method locks the top-most Entity Object in the chain of containers before attempting to lock itself.
protected void lockTopLevelEntity()
public void addTransactionPostListener(TransactionPostListener listener)
listener
- the listener to be added.public void addTransactionPostListenerNoCheck(TransactionPostListener listener)
listener
- the listener to be added.protected void addToTransactionManager()
public void removeTransactionPostListener(TransactionPostListener listener)
listener
- the listener to be removed.DBTransaction
,
ValidationManager.
public void postChanges(TransactionEvent e)
This method is useful for Entity Objects that perform data manipulation operations such as UPDATE, INSERT or DELETE.
e
- a transaction event.protected void populateAttribute(int index, java.lang.Object value)
Sets an attribute's value but does not mark it as updated. This method is called by query collection when populating a row with data. This is a framework-internal function and must not be called directly in client code except in the case of a composite entity.
In a composite entity, one enitity is comprised of two or more other entities. An example of a composite entity would be an Employee entity which is comprised of a Person entity and an Assignment entity. The populateAttribute method could be used to populate Person and Assignment attributes when the Employee attributes are read-in.
index
- the index of the attribute to populate.value
- the value to place in the attribute.protected void populateAttributeAsChanged(int index, java.lang.Object value)
Sets an attribute's value and also marks it as updated. This method is called by query collection when populating a row with data. This is a framework-internal function and must not be called directly in client code except in the case of a composite entity.
In a composite entity, one enitity is comprised of two or more other entities. An example of a composite entity would be an Employee entity which is comprised of a Person entity and an Assignment entity. The populateAttribute method could be used to populate Person and Assignment attributes when the Employee attributes are read-in.
index
- the index of the attribute to populate.value
- the value to place in the attribute .public void afterCommit(TransactionEvent e)
e
- a transaction event.public void afterRollback(TransactionEvent e)
e
- a transaction event.public void afterRemove(TransactionEvent e)
e
- a transaction event.public boolean isTransientTransactionListener()
Transient listeners are automatically removed at the end of the transaction cycle; permanent listeners remain.
true
if the listener is transient.public void beforeCommit(TransactionEvent e)
e
- a transaction event.public int getTransPostHandle()
Implements the getTransPostHandle method for the transaction post listener (TransactionPostListener) interface.
Transaction post handle is a handle identifying a row object in the transaction post listener list. If the object does not have a transaction post handle, this method returns -1.
public void setTransPostHandle(int hdl)
Implements the setTransPostHandle method for the transaction post listener (TransactionPostListener) interface.
Transaction post handle is a handle identifying a row object in the transaction post listener list.
hdl
- the transaction post handle.public boolean isTransientTransactionPostListener()
TransactionPostListener
is transient or permanent.
Transient listeners are automatically removed at the end of the transaction cycle; permanent listeners remain.
true
if the listener is transient.TransactionPostListener
public void beforeRollback(TransactionEvent e)
e
- a transaction event.protected void doSelect(boolean lock)
lock
- true generates a "SELECT for UPDATE"protected void doDML(int operation, TransactionEvent e)
operation
- DML_INSERT, DML_UPDATE or DML_DELETEe
- this Entity Object's transaction event.protected void doDMLWithLOBs(int operation, TransactionEvent e)
protected void vetoRemoveWithDetails(AttributeDef associationDef)
public void remove()
public Key getKey()
public boolean isAttributeUpdateable(int index)
READ_ONLY
, UPDATEABLE_WHILE_NEW
, or
UPDATEABLE
.index
- the attribute's index.false
if the attribute is READ_ONLY
.
true
if attribute is UPDATEABLE_WHILE_NEW
and the current row is new.
true
if attribute is UPDATEABLE
.
public java.lang.String toString()
public void domainToBeModified(DomainInterface d)
|
Business Components | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |