You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Oliver Heger <Ol...@t-online.de> on 2004/01/11 19:52:35 UTC

[dbutils]QueryInterface

Hello,

I am working on a kind of SQL SELECT generator library. The basic idea 
is that you have an object representing the query to be performed. You 
add objects for the fields to be retrieved and feed it with condition 
objects. Finally it returns a fully initialized PreparedStatement object.

I would now like to use [dbutils] to execute the queries, but I have the 
problem that none of the query() methods of QueryRunner really fits my 
needs because I have already a PreparedStatement. To solve this, would 
it be possible to introduce a Query interface in [dbutils], which could 
look as follows:

public interface Query {
    PreparedStatement getStatement(Connection conn) throws SQLException;
}

Then there could be an additional query() method in QueryRunner that 
expects such a Query object as argument. It would fetch the statement 
from this object and execute it.

I know that you try to keep [dbutils] small. This interface would not 
really add new functionality to this component, but may extent its 
usage. What do you think?

If there is interest, I can try to provide a patch.

Regards
Oli


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


Re: [dbutils]QueryInterface

Posted by Oliver Heger <he...@med.uni-marburg.de>.
David,

thanks for your response. Well, what I intend to do is to use DbUtils 
for resource management, I only need a hook for creating a specialized 
statement. (The prepareStatment() method you mentioned does not seem to 
work for this purpose because of its limited arguments.)

It's a bit tricky: DbUtils does everything I need, including management 
of the connection and processing of the PreparedStatement object. If I 
only had a chance to feed in my own statement.

Oli

David Graham schrieb:

> QueryRunner has a protected prepareStatement method that can be overridden
> with custom handling:
> 
> http://jakarta.apache.org/commons/dbutils/xref/org/apache/commons/dbutils/QueryRunner.html#140
> 
> DbUtils isn't about modeling various SQL components as objects.  IMO, the
> real benefit of using DbUtils is the automatic resource cleanup.  Since
> you are handling Connection and Statement objects outside of DbUtils, the
> library can't clean them up for you.  You could handle the resource
> cleanup yourself (not use QueryRunner) and still use BasicRowProcessor to
> process ResultSets into objects.
> 
> David
> 
> --- Oliver Heger <Ol...@t-online.de> wrote:
> 
>>Hello,
>>
>>I am working on a kind of SQL SELECT generator library. The basic idea 
>>is that you have an object representing the query to be performed. You 
>>add objects for the fields to be retrieved and feed it with condition 
>>objects. Finally it returns a fully initialized PreparedStatement
>>object.
>>
>>I would now like to use [dbutils] to execute the queries, but I have the
>>
>>problem that none of the query() methods of QueryRunner really fits my 
>>needs because I have already a PreparedStatement. To solve this, would 
>>it be possible to introduce a Query interface in [dbutils], which could 
>>look as follows:
>>
>>public interface Query {
>>    PreparedStatement getStatement(Connection conn) throws SQLException;
>>}
>>
>>Then there could be an additional query() method in QueryRunner that 
>>expects such a Query object as argument. It would fetch the statement 
>>from this object and execute it.
>>
>>I know that you try to keep [dbutils] small. This interface would not 
>>really add new functionality to this component, but may extent its 
>>usage. What do you think?
>>
>>If there is interest, I can try to provide a patch.
>>
>>Regards
>>Oli
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> http://hotjobs.sweepstakes.yahoo.com/signingbonus
> 
> ---------------------------------------------------------------------
> 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]QueryInterface

Posted by David Graham <gr...@yahoo.com>.
QueryRunner has a protected prepareStatement method that can be overridden
with custom handling:

http://jakarta.apache.org/commons/dbutils/xref/org/apache/commons/dbutils/QueryRunner.html#140

DbUtils isn't about modeling various SQL components as objects.  IMO, the
real benefit of using DbUtils is the automatic resource cleanup.  Since
you are handling Connection and Statement objects outside of DbUtils, the
library can't clean them up for you.  You could handle the resource
cleanup yourself (not use QueryRunner) and still use BasicRowProcessor to
process ResultSets into objects.

David

--- Oliver Heger <Ol...@t-online.de> wrote:
> Hello,
> 
> I am working on a kind of SQL SELECT generator library. The basic idea 
> is that you have an object representing the query to be performed. You 
> add objects for the fields to be retrieved and feed it with condition 
> objects. Finally it returns a fully initialized PreparedStatement
> object.
> 
> I would now like to use [dbutils] to execute the queries, but I have the
> 
> problem that none of the query() methods of QueryRunner really fits my 
> needs because I have already a PreparedStatement. To solve this, would 
> it be possible to introduce a Query interface in [dbutils], which could 
> look as follows:
> 
> public interface Query {
>     PreparedStatement getStatement(Connection conn) throws SQLException;
> }
> 
> Then there could be an additional query() method in QueryRunner that 
> expects such a Query object as argument. It would fetch the statement 
> from this object and execute it.
> 
> I know that you try to keep [dbutils] small. This interface would not 
> really add new functionality to this component, but may extent its 
> usage. What do you think?
> 
> If there is interest, I can try to provide a patch.
> 
> Regards
> Oli
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

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