Tuesday Apr 16, 2013

Partial Rollback on Middle Tier using State Management

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.
About

ADF Tips and Tricks

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today