cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
68
Views
0
Helpful
0
Comments
cdnadmin
Level 11
Level 11
This document was generated from CDN thread

Created by: Shahzad Munir on 12-09-2008 10:12:39 AM
I am developing an application comprising Action Elements for CVP 4.1. I need to communicate with the database and have to use Apache DBCP pool. I am initializing this pool (a static BasicDataSource object) in the Starup class which implements StartApplicationInterface. My Action class and Startup classes are bundled in the same jar and this jar along with dbcp related jars is placed in the application\java\lib folder.

Now Pool is initialized successfully in Startup but I find this pool un-initialized in my CustomAction class, thus, I am unable to get connection from BasicDataSource initialized in Startup.

One thing, DataSource reference is not in Startup class but its static member of another class.

I have done a work around for it and re-initialized pool first time my custom action is called. But I really didnt feel good bout this.

Under Design Considerations heading, its mentioned that static variables are static within the application only. Both Startup and CustomAction classes are bundled in the same jar, helping jars have been placed in the same dir, I am programming within the same application, and this makes me sure that I shouldnt be facing this problem.

Can any body please help me on this ??? It's urgent. How & where should I initialize my Apache DBCP Pool.

Thanking in anticipation

Edited by: shahzadmunir on Sep 12, 2008 6:16 AM

Subject: Re: Problem with Static Variables
Replied by: Janine Graves on 12-09-2008 01:52:04 PM
You may be confusing Start of App with Start of Call (and perhaps
confusing application data with session data).

Start of App only executes when the app is first loaded into a
classloader (reboot, or 'updateApp.bat'). This class doesn't have access
to the Session API, since there are no sessions yet.

So, if it's necessary for the Start of App class to pass information to
the application (like a pointer to the pool), you'll have to store it
into 'application data'.

Then in your Studio application, you'll have to create some Java to
access that 'application data' (as Studio doesn't provide ANY access to
the application or global data in 4.1). You might want to create a
Java element to copy the App Data into a Session Data variable, so that
you can then access it in Studio. Accessing application data in an
action element's doAction() method is through the session api.

For example, assume that actionData is the session API object passed to
the doAction() and that the name of the application data you want to
access is named 'pool'. Then you can store it into a Java object this way:

(Object) pool = actionData.getApplicationAPI.getApplicationData("pool");

Or turn it into Session data this way:
actionData.setSessionData("pool",actionData.getApplicationAPI.getApplicationData("pool"));

From the javadocs for class APIBase: "getApplicationAPI() - This
method gives the component access to the Global API, which allows for
the getting and setting of global data and application data. Returns:
ApplicationAPI"

Hope this helps.
Janine

www.TrainingTheExperts.com

Subject: Re: Problem with Static Variables
Replied by: Shahzad Munir on 15-09-2008 04:56:57 AM
Thanks for the reply Janine.
But I am not trying to play with App Data or Session Data. Let me put my question some different way:
I have three classes:
  • MyCustomAction class which extends ActionElementBase
  • Startup Class which implements StartApplicationInterface
  • DbHandler which contains a static variable of BasicDataSource (pool)

MyCustomAction and Startup are bundled in the same jar where as DbHandler is in another jar.
Now initialize pool in DbHandler class which is done successfully. But when I try to get a connection from this pool, I find it un-initialized. I am not accessing any thing out of application. And I dont wanna set pool ref in application etc. It loaded within the same application and should be available to all classes of that very same application.

Hope I could clear my question.

Subject: Re: Problem with Static Variables
Replied by: Janine Graves on 15-09-2008 01:32:04 PM
Who calls the DbHandler class to make it run ("Now initialize pool in
DbHandler class which is done successfully")?

Perhaps the problem is that you shouldn't be storing the pool in a
"static variable" - maybe you should store it into "Application Data"
(or "Global Data") which are available to every phone call to the App
(or in the case of Global Data, to every phone call). They really seem
to warn against using Static Variables unless they are Final.

Janine
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links