> --- Hernan Silberman <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> > I'm working on an application that uses "Named Queries" much like the
> > DBUtils QueryLoader class reads in from a Java properties file. The
> > queries in
> > my application are stored in a relational database on the server side
> > and I was
> > hoping I could extend QueryLoader so it fetched the NAME/SQL pairs in an
> >
> > application-specific way, something like this:
> >
> > public synchronized Map load(DataSource aDS) throws IOException;
> > public synchronized void unload(DataSource aDS);
> >
> > I'm new to DBUtils, and figured I'd ask before trying to extend this
> > class in my
> > code to accomodate something like the two methods above. Is this a sane
> > thing
> > to do? I won't get exactly what I want by extending this class, because
> > I don't
> > need the properties file versions of load and unload. Should I just
> > create an
> > alternate app-specific QueryLoader, or am I not seeing a better way of
> > leveraging the existing QueryLoader class?
>
> QueryLoader isn't used by other DbUtils classes; it's just a standalone
> helper class that loads queries from properties files. So, you won't gain
> anything by subclassing it and replacing it with a DB lookup.
>
> David
Thanks for the response. Keeping a registry of named queries seems like a
common thing to do and I see lots of utility in having a helper class like
QueryLoader to do it with. I was hoping I could easily change QueryLoader's
behavior so it would look for it's name/query mapping somewhere other than a
properties file, but alas, it's such a simple problem it's no big deal to handle
this in my own code with another class.
On another note isn't it risky to return a reference to queryMap below without
first wrapping it in Collections.unmodifiableMap( queryMap ) ? I lack trust.
public synchronized Map load(String path) throws IOException {
Map queryMap = (Map) this.queries.get(path);
if (queryMap == null) {
queryMap = this.loadQueries(path);
this.queries.put(path, queryMap);
}
return queryMap;
}
thanks...
hernan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]