While building complex features in your applications,sometime you may want to do a partial rollback (such as undo and redo changes) of the functionality. In ADF BC, in order to achieve the savepoint functionality, we can use the state management API to rollback to a certain point within a transaction instead of rolling back the entire transaction.
The following three methods in oracle.jbo.ApplicationModule interface that are useful to achieve this.
public String passivateStateForUndo(String id,byte[] clientData,int flags)
public byte[] activateStateForUndo(String id,int flags)
public boolean isValidIdForUndo(String id)
Below example shows how to use these methods
try{
BindingContainer bindings = getBindings();
DCBindingContainer dc = (DCBindingContainer)bindings;
ApplicationModule am = dc.findDataControl("AppModuleDataControl").getApplicationModule();
String MyTransId = "MySavePoint1"
String transId = am.passivateStateForUndo(MyTransId,null,am.PASSIVATE_UNDO_FLAG);
//Your code
.........
.........
.........
am.getDBTransaction().committ();
}catch(Exception ex){
//Below line will rollback the changes.
byte oldValues[]= am.activateStateForUndo(transId,am.ACTIVATE_UNDO_FLAG);
}
By using these methods you can create named snapshots and restore the pending transaction state from them by name. After perfroming commit or rollback on a transaction these snapshots do not survive.
I am still verifing how isValidIdForUndo() can be used.
The following three methods in oracle.jbo.ApplicationModule interface that are useful to achieve this.
public String passivateStateForUndo(String id,byte[] clientData,int flags)
public byte[] activateStateForUndo(String id,int flags)
public boolean isValidIdForUndo(String id)
Below example shows how to use these methods
try{
BindingContainer bindings = getBindings();
DCBindingContainer dc = (DCBindingContainer)bindings;
ApplicationModule am = dc.findDataControl("AppModuleDataControl").getApplicationModule();
String MyTransId = "MySavePoint1"
String transId = am.passivateStateForUndo(MyTransId,null,am.PASSIVATE_UNDO_FLAG);
//Your code
.........
.........
.........
am.getDBTransaction().committ();
}catch(Exception ex){
//Below line will rollback the changes.
byte oldValues[]= am.activateStateForUndo(transId,am.ACTIVATE_UNDO_FLAG);
}
By using these methods you can create named snapshots and restore the pending transaction state from them by name. After perfroming commit or rollback on a transaction these snapshots do not survive.
I am still verifing how isValidIdForUndo() can be used.