Showing posts with label transient. Show all posts
Showing posts with label transient. Show all posts

21 Oct 2015

Passivation of Entity Transient Attributes

Everyone knows about VO transient attributes. In order to make them passivation/activation safe (capable of surviving AM passivation/activation cycle) we have to either select Passivate checkbox for each such transient attribute or select Passivate State and Including All Transient Values checkboxes for the entire view object. In that case the framework will save values of those transient attributes to the passivation storage during the passivation and read these values back during the activation. It's clear. But how about entity transient attributes? Very often this question gets ADF developers confused. There are not any "passivation" checkboxes available for the entity definition or entity attributes. Does it mean that entity transient attributes are not passivation/activation safe and their values are going to be lost during AM recycling?

Everything is going to be all right! The passivation of entities is switched on by design. The framework saves values of all dirty entity attributes to the passivation storage. This is true for transient attributes as well.
Let's assume there is DepartmentsEO entity with a transient attribute SomeTransAttribute. If value of this attribute is modified then the framework writes to the passivation storage the following structure:

      <EO Name="com.adfpractice.entitytransattrpassiv.model.entities.DepartmentsEO">
         <![CDATA[00010000000AACED000577040000000A]]>
         <DepartmentsEORow PS="2" Hdl="1">
            <SomeTransAttribute>
               <DATA>56</DATA>
               <ORIG_DATA null="true"/>
            </SomeTransAttribute>
         </DepartmentsEORow>
      </EO>
  
Actually, this is passivation data for the dirty entity instance and it contains value (56) of the modified transient attribute SomeTransAttribute.

That's it!

30 Sept 2015

Calculating VO Transient Attributes

In this post I am going to consider a use-case when we need to calculate value of a VO transient attribute according to some complicated and resource-consuming business logic.

Let's say there is a method in a ViewRowIml class:
public String getValueForSomeTransAttr()
{   
  return getBusinessLogicFactory().
           getSuperComplexBusinessLogic.evaluateForKeyValue(getPrimaryKey());
}

We could use this method either in attribute's getter method:
  public String getSomeTransAttr()
  {   
    return getValueForSomeTransAttr();
  }

or we could use it in Groovy expression for the attribute:

Both options are bad, because the method is going to be invoked every time whenever the attribute value is accessed, and that could happen a number of times within the request. Of course we'd like to avoid extra executions of our super complicated business logic. Basically, the value of the transient attribute depends on primary key only, which means that we want to calculate it only once for each row (assuming that primary key value never changes). In order to meet this requirement we have to set "false" in Refresh Expression Value:


The same thing can be done using Edit Expression Editor:


Having done that, the method will be invoked only when a VO row is created from VO result set and when a new row is created by a user in UI.

That's it!