ART#215 - What are transient properties in ATG?

Back



Next



Properties which are not associated with any tables are called transient properties.
Now, the question arises, why would we not want a property to be associated with a table? If our property is not associated with a table, how (or where) would we store data corresponding to this property?

Let us take an example: in "user" item-descriptor of ProfileAdapterRepository, there is a property called "registrationDate" of type Timestamp. This property, like any other property, is mapped to a table's column. Pretty much straightforward till now?

Now, consider a situation, when on the website's MyAccount section, you need to display the number of days/months/years, the user has been a part of your website.
Something like:
Ankit Jain, registered since 4 days, 4 months and 2 years. 
Now, you have two options,

OPTION#1: In the JSP (or a droplet), read the user's registrationDate property, and calculate the days, months, years and then display it.
Drawback: Workable, but the calculation logic goes into the droplet. Not much of a good coding standard.

OPTION#2: Transient Property. Let us see this in a moment.

How to we declare a property as transient?

Let us backtrack a little and remember the process of creating a normal property for an item-descriptor. For people who do not know this, can revisit the concept HERE. It goes something like this-
<item-descriptor name="user" .. some other stuff.. >
 <table name="TABLE_NAME" type="primary or auxiliary or whatever">
  <property name="registrationDate" column-name="SOME_COLUMN" />
 </table>
</item-descriptor>

Since a transient property is not mapped to any table, it is simple declared outside of a table tag. Let us assume, we are creating a new transient property "registeredSince" of the type string in user item-descriptor. The <property>tag is same, but the only difference is that, it is declared OUTSIDE of the <table> tag. Since there is no table for this property, there is no column-name attribute in this property. So, the XML goes something like:-
<item-descriptor name="user" .. some other stuff.. >
<property name="registeredSince" data-type="string" />
 <table name="TABLE_NAME" type="primary or auxiliary or whatever">
  <property name="registrationDate" column-name="SOME_COLUMN" />
 </table>
</item-descriptor>

Now, we have simply created a new transient property in existing item-descriptor.
This being done, the question arises, how do we make this property calculate and return the number of  (days/month/years), the user is registered since? The answer follows in the next article - How to add functionality to a transient property?

Back



Next



5 comments:

  1. missing article: How to add functionality to a transient property?

    ReplyDelete
    Replies
    1. Thanks for pointing out. The link has been fixed.

      Delete
  2. Hi Monis, firstly appreciate all your work.
    I was wondering where and how long will the transient properties, live and be accessible ? I believe they live in memory but not sure how long. Can you clarify or point to the article to read through for details.

    ReplyDelete
    Replies
    1. Please read this article and the subsequent article, there is no concept of living in the "memory".

      Delete
    2. In the example of this article, the value of the transient property is derived from persisted properties , but consider a scenario where a transient property is set to a constant value (some random value independent of persisted properties ) how long will it live ? ex: create a item and set its transient property "isActive" to "true", and at some point in future access the item, what will be the value of the property "isActive" (assuming I didn't set any default value to the transient property in the item definition file).

      May be this questions the right usage of transient property but curious to know if the value set still exists ?, and for how long ?

      Delete

Subscribe

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

Flickr