Saturday, June 04, 2005

Jumpstarting your JPDK portlets with DBPreferenceStore

JPDK Portlets are easy and fun to create. All you need is a neat idea, and a feasible solution to portletize it. Not all is fun though. There are a few caveats, which may not be visible right at the beginning. To know what exactly I am talking about, consider the following case study.

Rogue is a very innovative developer. One fine day, he gets a brilliant idea to portletize a very popular application. He publishes his portlet, and gets a very wide appreciation. The portlet is deployed on a major production site, which has thousands of employees using and customizing it, to suit their needs. The customer comes to Rogue with a very desired enhancement, and Rogue implements it and provides the new version to the customer.

But, Rogue had designed the portlet to use FilePreferenceStore for storing the user preferences. The customer, unaware about this detail, goes ahead and re-deploys the provider on his production system, and boom..... all the user customizations have been erased!!

Now, the customer, rather frantic, pulls the archived version, searches the web and identifies that he needs to copy the customizations folder back to the new deployment. Things finally work, and the customer realizes his folly, and learns his lesson the hard way.

Though the above case study is fictitious, it is a very common scenario that happens with people who are not well versed with the JPDK framework. The above scenario could be avoided if only the developer (Rogue here) had implemented the portlet solution to utilize database based preference store.

I definitely agree that it is easier to use the file system based preference store, as there are no additional configurations to perform when deploying the provider, but a little additional effort can go a long way. Using DBPreferenceStore for storing user preferences translates to the following:

  • User preferences are independent of the provider deployment
  • Easy upgrade / migration path – new portlet version, new container, different m/c, etc.
  • Technically, you could support high-availability for these portlets, by deploying them on multiple containers, and sharing the sessions across the containers.

, And other benefits that I have missed out here.

Setting up a DBPreferenceStore is as simple as deploying an .ear file. All you need to do is:

  • Install the JPDK preference store schema on a database.
  • Create a datasource within the application server container which points to the above created schema.
  • Make a reference to this datasource in your portlet’s provider.xml file.
Sample Example:
1. Provider.xml file configured to use FilePreferenceStore

<preferenceStore class="oracle.portal.provider.v2.preference.FilePreferenceStore">

2. Provider.xml file configured to use DBPreferenceStore

<preferenceStore class="oracle.portal.provider.v2.preference.DBPreferenceStore">

I am among the few people who are skeptical about working on the database, and prefer to work as much as possible via the web-based interfaces. Hence, I came up with a utility web-application (DbPrefStoreUtil), which installs the database schema required for DBPreferenceStore, on a remote database. This application is available on Knowledge Exchange under my personal folder (Search for contributor: harsha.ramesh). I have also included a detailed document on how one can setup a datasource via the OracleAS Enterprise Manager or the OC4J Admin Console on the standalone OC4J.

So the next time you decide to implement a portlet solution, try and see if you could provide a solution based on DBPreferenceStore.