users@glassfish.java.net

Re: Design Suggestions Properties/Resources

From: Cheng Fang <Cheng.Fang_at_Sun.COM>
Date: Fri, 19 Oct 2007 08:51:40 -0400

glassfish_at_javadesktop.org wrote:
> Hi,
>
> I need some advice regarding configurable properties/resources my application are using. For example, I have a kind of filter property that defines which entities to retrieve from certain queries to the database. This value rarely changes so it's nothing that I want to store within the application model. I don't want to make it a constant either because I don't want to compile and redeploy the application because we decided to change this property.
>
> Should I just add a JNDI resource and implement an ObjectFactory and then add a @Resource in the session beans where I need this property?
>
>
If you can use one of those common types (String, primitives and
wrappers), or a combination of them, you can just declare <env-entry> in
ejb-jar.xml or web-xml, and look it up anywhere in your application. Or
inject them into component classes like EJB bean class, interceptors,
servetl class, etc.

If you need to represent the configuration data as a custom type, use
<resource-env-ref> instead. I have a series of blog entries about using
custom jndi resource:
http://blogs.sun.com/chengfang/entry/a_generic_beanfactory_class_for

You may also want to take a look at @NamedQuery in JPA.

-cheng
> If you have any suggestions that would be great.
>
> Thanks!
>
> Leo
> [Message sent by forum member 'woel' (woel)]
>
> http://forums.java.net/jive/thread.jspa?messageID=241186
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>