Tuesday, 5 August 2014

meaning of a transient word in ADF

In plain Java applications there is a transient keyword that you could use to notice the JVM that values are from some sensitive and they shouldn't be persisted. ADF is an J2EE framework, so while developing Java code in your application you have an ability to use transient keyword. Such values won't be serialized. Even more, there are situations where you must to use the transient keyword. If your application needs to work in a clustered environment, the object needs to implement Serializable interface. But object in the framework don't implement it. That's why almost each time when you bind an UI component to a bean, you must to mark the references as transient.


There is only one exception to that rule. And it depends on scope within your bean is defined. If the scope is request or less (shorter/more precise like backing bean) the rule doesn't apply. Because the user won't notice that the previous request server is now down.

(image source: http://docs.oracle.com/cd/E16162_01/web.1112/e16182/adf_lifecycle.htm)

There are also another places in the ADF application where you can find transient values. In the BC4J model layer there are view objects. An attribute of a view object could be entity-based, calculated in the SQL query or ... Transient. It is possible to mark an java.lang.String attribute as transient, but does it mean that it won't be serialized? It will be. To visualize the concept of the keyword, transient means that the attribute value won't be persisted in the database. But that sentence needs more clarification. As ADF developer you make a decision if the attribute value is being recalculated all the time (i.e. using Groove) or if it stores some values during the session - in other words you're making a decision if the attribute will be passivated or not. You can achieve it on the attribute level:


or globally for each transient value in the view object. You change settings in the Tuning section in General tab.


Saving the state requires that the class type of an attribute must be serializable, for example the java.lang.String is. To clarify the previous sentence - if your passivation store is set to the database (default), the value will be stored there.

You can easily recognize if the view object contains transient attributes or not. Just check the value in the Info column next to the attribute name and class.


As we talk about view objects, a VO itself can be transient. Please review the first page of wizard when you want to create a new one.


The third option is for transient view objects. Please go through the wizard. Remember to add at least one primary key attribute. You must to perform additional steps to make it works as any other type. Go to view object's General tab and expand the Tuning section. In Retrieve from the Database group select No rows option and check mentioned Including All Transient Values checkbox.


If it is not done yet automatically, please create the ViewObjectImpl implementation class for that view object.

While editing Java class, click on Override Methods in the toolbar Source menu. Override beforeRollback and afterRollback methods. Comment the super calls.



Transient attributes are one of the approach as value holders for web service invocation results.

There is another place to define ADF-meaning transient values, at the entity attribute level. As you can see on the screen below, it is possible not to persist it.



The attribute is not mapped to the database table. There is no such thing like passivation available on the entity level. So what is going to happen with it? Do I loose the value between requests? The answer is no. You are not going to loose the value. Furthermore you're able to share the value between view objects based on that entity. The persistence store here is the entity cache.

(image source: http://download.oracle.com/otn_hosted_doc/jdeveloper/1012/bc4j/intro/bc_acaches.html)

Just to summarize - ADF meaning of transient keyword is not to persist directly in the database. View objects can be whole transient or contain transient attributes (in addition to entity-based and calculated attributes). Entities can have their own transient attributes that are stored in entity cache and can be consumed and shared by view objects.

No comments:

Post a Comment