You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Hernan Silberman <hs...@pdi.com> on 2003/12/02 19:13:45 UTC

[DBUtils] Extending QueryLoader...

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?

thanks...
Hernan


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


Re: [DBUtils] Extending QueryLoader...

Posted by Juozas Baliuka <ba...@mwm.lt>.
Hernan Silberman wrote:

>>--- Hernan Silberman <hs...@pdi.com> 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.
>  
>

I have used  property files to store queries, but I found it is much 
more easy to find string in java code than in file, then I need to 
change query for performance tuning or to fix bug (stack trace can help 
to find query in code). I use DbUtils fork myself ( http://voruta.sf.net 
) and looks like it is better way, but it has the same problems with 
type and name mapping for java beans.

>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: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>  
>



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


Re: [DBUtils] Extending QueryLoader...

Posted by David Graham <gr...@yahoo.com>.
--- Hernan Silberman <hs...@pdi.com> wrote:
> 
> > --- Hernan Silberman <hs...@pdi.com> 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.

You could subclass QueryLoader but you wouldn't be gaining anything.

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

You could consider that a feature if you wanted to load an initial set of
queries from a file and then dynamically change them at runtime. 
QueryLoader doesn't depend on the state of the Maps for it to function
properly so there's no need to wrap it in an unmodifiable view.

David

> 
> 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: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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


Re: [DBUtils] Extending QueryLoader...

Posted by Hernan Silberman <hs...@pdi.com>.
> --- Hernan Silberman <hs...@pdi.com> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [DBUtils] Extending QueryLoader...

Posted by David Graham <gr...@yahoo.com>.
--- Hernan Silberman <hs...@pdi.com> 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...
> Hernan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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