From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, July 30, 2001 10:41 AM
Subject: Question about Velocity methods and lookup tables.
> G'day all,
> I have a utility class that has many useful methods that I use
> when building my context data structures. Now the
> time has come when I would like to call getCompanyName()
> from within my template.
>
> This is a cutdown version of my class:
>
> ------------------< class starts >-------------------------
>
> //******************************
> //* Class for helper functions
> //******************************
>
> [ imports cut ]
>
> public class helperFuncs {
>
> private static final String CLASS = "helperFuncs:";
>
> /***************************************************************
> getCompanyName:
> Params: ASX code - A string select statement
> Returns: Long name of company if it exists,
> otherwise empty string.
> ***************************************************************/
>
> public static String getCompanyName(String asxCode )
> {
> final String METHOD = "getCompanyName:";
> ResultSet rset = null;
> String name;
>
> [ body cut ]
>
> return name;
>
> } //end function
>
> } //End class
> ------------------< class ends >-------------------------
>
>
> Is it is as simple as putting a reference to the helperFuncs
> class into the velocity context?
>
> Also, are there any efficiency/multithreading issues when
> putting a utility class into the context? The reason I ask
> is because this class (helperFuncs) is used heavily throughout my
> Turbine web application.
>
> Another question I have is that the code that I cut out above was
> doing a simple 1 row select from a lookup table. This goes on
> many times per screen. I suspect it would make much more sense
> to put this into a HashMap as the keys are unique and
> there are only about 1400 values, rather than continually acessing
> the database. Is it just a matter of populating the HashMap in the
> constructor for class helperFuncs? What scope would the HashMap need?
>
> Thanks in advance,
>
> Patrick Saunders.
>
Patrick,
Note: Replying to the turbine list as it is more appropriate.
What you need to do is to have a look at the pull service stuff at:
http://jakarta.apache.org/turbine/services/pull-service.html
Using this you can create your own tool that is always available
in the context. You can define tools at different scopes and the
threading issues dependent on the scope you decide to use. In
your case you may be able to define a global scope tool that
refreshes it's list of companies say once a day but retains the
hashmap of stock codes/company names in memory.
Pull tools are actually quite easy to implement and the time
required to get the idea is very worthwhile.
This is definitely one of the major plusses of turbine. You can
define a set of pull tools and then your template designers can
just use them wherever necessary (are you still looking for ammo
to get those ASP worshippers off your back? :-) ).
BTW: What's with the odd JavaDoc comment? Why not just
use the proper tags?
Hope this helps,
Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]