Many times we use
entity.refresh(REFRESH_FORGET_NEW_ROWS | REFRESH_UNDO_CHANGES) to prevent any changes we made to that entity from getting committed to the DB. What the
refresh() method effectively does is change the post state of the entity. (See difference between entity-state and post-state.) The post-state is later used to decided which DML operation to use for the entity, i.e.
I recently came across a code which called
refresh() from the entity’s
prepareForDML() but that had no effect. ADF documentation says nothing about such a behaviour. I read the
EntityImpl code and got my answer there. When we are saving data to DB the call chain is like –
transaction.postChanges() -> entity.postChanges() -> entity.prepareForDML() -> entity.doDML().
doDML() have first argument
operation; this is the DML operation to undertake. The code to decide which DML operation to perform based on entity’s post-state is in
EntityImpl.postChanges(). That method invokes
prepareForDML() method with the DML operation to undertake. Changing post-state from
doDML() is useless. So, post-state needs to be set no later than
postChanges(). However, if you do need to do this from
doDML() then you could modify the
operation param’s value appropriately.
Leave a Reply