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.

Monday Apr 15, 2013

Using setter with Transient VO attribute

I was invoking setAttribute("MyTransientAttributeName", MyTransientAttributeValue) in AMImpl. Later, I was accessing MyTransientAttributeName inside the expression of another transient attribute. But I was not getting expected result. On investigation, I found that the value of MyTransientAttributeName was coming out to be null.

But why? I was setting the same in AMImpl. To verify if the setter was setting the value correctly, I printed getAttribute("MyTransientAttributeName") and it gave back the expected MyTransientAttributeValue.

Where was the problem then? 

The problem lied in the fact that this transient attribute was not there in the EO on which this VO was based. That's not a problem otherwise. But if setter is to be used, you should make sure that your transient attribute is there in the EO.

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