You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by ps...@comcen.com.au on 2001/07/30 02:41:55 UTC

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.





Re: Question about Velocity methods and lookup tables.

Posted by Scott Eade <se...@backstagetech.com.au>.
From: <ps...@comcen.com.au>
> 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,

This looks more like a turbine question rather than a velocity question
so I will post a reply over on that list.

Scott


Re: Question about Velocity methods and lookup tables.

Posted by Scott Eade <se...@backstagetech.com.au>.
Patrick,

From: <ps...@comcen.com.au>
> I just had a brief skim over the Pull machansim - very interesting.
> If I read this correctly, what I was originally proposing wasn't so much
> 'wrong', but the Pull mechanism really is the cleaner and more appropriate
> way to put utility methods in the context, right?
Yes.  The beauty with pull though is that you don't have to bother adding 
it to the context whenever you are going to use it - you can "just use it"
(what would Nike think!)

> And yes, I am still looking for ammo to target ASP lovers! :)
> Actually, the situation is nowhere as tense as it was ; they
> are continuing to do prototyping of charts using ASP, 
> and i am building the server stuff in Turbine.
> The problem is that as soon I as I mention Java or Velocity to the guy doing 
> the pages his eyes glaze over.. He's a wizard with the frontend, but has found 
> the velocity tough going for a number of reasons, not all his doing. :-/
Check out: http://jakarta.apache.org/velocity/ymtd/ymtd.html

> Back to the topic, I'm not sure what you mean by Javadoc comment, I suspect
> you're mis-interpreting my annotations to the code in my posting as Javadoc. 
> Never done any Javadoc in my life!
I was simply referring to this:

> > > /***************************************************************
> > >  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 )

The JavaDoc way would be this:
/**
 * Retrieve a company name.
 * @param asxCode The code of the company name to be retrieved.
 * @returns The long name of the company if it exists, otherwise empty string.
 */
public static String getCompanyName(String asxCode)

Which has the benefit that you can later run javadoc across your code to produce
API documentation.  Having documentation is a Good Thing (tm) & may even help 
challenge the ASP guys who may have difficulty doing something similar.

This is obviously off-topic so we should cease this particular discussion at least 
on this list anyway.

Cheers again,

Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Question about Velocity methods and lookup tables.

Posted by ps...@comcen.com.au.
Hi Scott,
Thanks for redirecting my query, I wasn't sure where it belonged,
I was beginning to wonder if I would ever regain control of this thread! ;-)

I just had a brief skim over the Pull machansim - very interesting.
If I read this correctly, what I was originally proposing wasn't so much
'wrong', but the Pull mechanism really is the cleaner and more appropriate
way to put utility methods in the context, right?

And yes, I am still looking for ammo to target ASP lovers! :)
Actually, the situation is nowhere as tense as it was ; they
are continuing to do prototyping of charts using ASP, 
and i am building the server stuff in Turbine.
The problem is that as soon I as I mention Java or Velocity to the guy doing 
the pages his eyes glaze over.. He's a wizard with the frontend, but has found 
the velocity tough going for a number of reasons, not all his doing. :-/

Back to the topic, I'm not sure what you mean by Javadoc comment, I suspect
you're mis-interpreting my annotations to the code in my posting as Javadoc. 
Never done any Javadoc in my life!

Thanks for your help Scott, your a champ.

Regards,

Patrick.


> From: <ps...@comcen.com.au>
> To: <ve...@jakarta.apache.org>
> 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: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Question about Velocity methods and lookup tables.

Posted by Scott Eade <se...@backstagetech.com.au>.
From: <ps...@comcen.com.au>
To: <ve...@jakarta.apache.org>
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: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Question about Velocity methods and lookup tables.

Posted by pat comcen <ps...@comcen.com.au>.
Thanks Geir,
Your comments about Poolman are very useful. It's almost like everytime I go
"what if...?"
someone goes "yep, it's done, just use service XX/ or some other tool".
Just amazing! The more I get  into this stuff the more impressed I am; I
can't
help but tell other guys I work with how good this is. :))

Thanks for the amazing work,

Regards,

Patrick.

----- Original Message -----
From: Geir Magnusson Jr. <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Monday, July 30, 2001 8:59 PM
Subject: Re: Question about Velocity methods and lookup tables.


> psaunder@comcen.com.au wrote:
> >
> > 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 >-------------------------
> >
> > file://******************************
> > file://*  Class for helper functions
> > file://******************************
> >
> > [ 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;
> >
> >   } file://end function
> >
> > } file://End class
> > ------------------< class ends >-------------------------
> >
> > Is it is as simple as putting a reference to the helperFuncs
> > class into the velocity context?
>
> Yep, should be.
>
> > 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.
>
> Eh... not really.  I would make it threadsafe so I wouldn't have to
> worry about it, but since a context cannot be shared across threads, it
> (in some ways) doesn't matter.
>
> > 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?
>
> Scott Eade said he would answer over in turbine-land.
>
> My opinion is that this is simply speed vs memory, and would test to see
> what kind of speed uptick you get.  Sounds reasonable.
>
> Note that I have seen things like PoolMan to SQL caching, so for things
> that aren't write intensive, or very changeable, PoolMan will cache the
> results of SQL calls, so the next time you do it, the same resultset is
> returned w/o a trip to the db.  Seems fairly useful, but I suspect that
> PoolMan is doing the same thing you propose...
>
> geir
>
> >
> > Thanks in advance,
> >
> > Patrick Saunders.
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> Be well, do good work, and keep in touch.
>


Re: Question about Velocity methods and lookup tables.

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
psaunder@comcen.com.au wrote:
> 
> 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?

Yep, should be.
 
> 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.

Eh... not really.  I would make it threadsafe so I wouldn't have to
worry about it, but since a context cannot be shared across threads, it
(in some ways) doesn't matter.

> 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?

Scott Eade said he would answer over in turbine-land.

My opinion is that this is simply speed vs memory, and would test to see
what kind of speed uptick you get.  Sounds reasonable.

Note that I have seen things like PoolMan to SQL caching, so for things
that aren't write intensive, or very changeable, PoolMan will cache the
results of SQL calls, so the next time you do it, the same resultset is
returned w/o a trip to the db.  Seems fairly useful, but I suspect that
PoolMan is doing the same thing you propose...

geir

> 
> Thanks in advance,
> 
> Patrick Saunders.

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.