Monday, August 17, 2015

ADF Row STATUS_INITIALIZED and STATUS_NEW



First of all we should know the role of Entity Object , it’s an Business Component in Service layer represent one row within database table , contain attributes which represent  table fields .also it could contain transient attributes which aren’t persisted .

Each row in Entity's cache has a special status, we can see those statuses

0 STATUS_NEW    
            Default status when create a new row
1 STATUS_UNMODIFIED
            When current changes entity has been committed database , or when read from database.
2 STATUS_MODIFIED 
            When set or modified any attribute in entity         
3 STATUS_DELETED 
            When a row in entity flagged as deleted
4 STATUS_DEAD 
            When create new row and delete in same transaction
  

We have another entity state is Initialized,  what the different between new and initialized  ?

      When create a new row in an Entity Object the default status will be STATUS_NEW
This means row is added in the transaction's list of changes to be
validated or posted or committed.
This is fine and expected in most of the cases.
However, during complex business objects like master-detail there comes the situation where you may want to turn off these validations until both master and detail are available. For such situations to remove the row from transactions's list of changes (Pending row from Transaction’s List of changes)
 Use ADF APIs setNewRowStatus(ROW.STATUS_INITIALIZED).
It will change status to  Initialized status, until user will change attribute value

Setting row with Initialized status is useful, when we want to delay pending changes check.

For example,
Case one:
When new row is created with default values from PL/SQL functions - we don't want to consider it as candidate for pending changes in ADF, until user types value by himself.



Case Two:

When master-detail association is a composite association and situation demands to create the detail rows before the master row. In that case without setting the row status to STATUS_INITIALIZED you will face error:



JBO-25030: Detail entity  with row key null cannot find or invalidate its owning entity.





Remember :
When this row is in STATUS_INITIALIZED state and call setNewRowState(byte State) method with STATUS_NEW state then, this new row is added back into it's relevant transaction and validation manager and will then participate in validation, transaction cycle .
Note :
Note that incase of composition if a master/detail hierarchy is being created with the intention of making them temporary (STATUS_INITIALIZED) then the logic should be: Create Master row, insert Master row into a collection, create Detail row insert detail row into a relevant collection, make detail row initialized, create/insert/change-to-initialized more detail rows and at the end set the master row as initialized.

No comments:

O racle  SQL WITH Clause         subquery factoring     or         Materializing   subqueries                                 (Sim...