You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Thomas Fischer <fi...@seitenbau.net> on 2005/06/10 09:38:47 UTC

null connections




Hi,

I would like to ask for a general opinion about Connection objects which
are set to null. In methods which access the database, we have in almost
all cases two signatures: Obe signature without a Connection object and one
with a Connection object. For example, in AuthorPeer from the tutorial, we
have

AuthorPeer.doSelect(Criteria criteria);

and

AuthorPeer.doSelect(Criteria criteria, Connection con);

The method without connection implicitly gets one from the pool configured
for the AuthorPeer and calls the method with connection.

My question is now what should happen if the connection object is set to
null, e.g. if  AuthorPeer.doSelect(criteria, null) is called.
There are two ways to handle this.

1) implicitly get a connection and proceed
2) throw an error

At the moment, 1) is implemented, but some code looks like as if 2) was
intended at some time in the development.

The argument for 1) would be
- doSelect(Criteria criteria) is just a convenience method for
doSelect(Criteria criteria, null);
The argument for 2) is
- It allows more control. If I want the connection to be handled
implicitly, I would use the method without connection. If I explicitly use
the method with connection, I indicate that I want to handle the
connections myself. In this case, Torque should throw an error if my
connection handling is incorrect and not hide it by implicitly creating a
connection, which might not have the intended effect (e.g. new transaction
started, or different database accessed)

Personally, I would favour 2). What do you think ?

       Thomas


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


Re: null connections

Posted by T E Schmitz <ma...@numerixtechnology.de>.
Thomas Fischer wrote:
> 1) implicitly get a connection and proceed
> 2) throw an error
> 
> Personally, I would favour 2). What do you think ?

2 - definitely! I don't think implicit connections are a good idea if 
one wants an explicit one.

-- 


Regards/Gruß,

Tarlika Elisabeth Schmitz

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


Re: null connections

Posted by Thomas Vandahl <th...@tewisoft.de>.
Thomas Fischer wrote:
> Personally, I would favour 2). What do you think ?

I agree. If you acquire a connection automatically, the intended 
encapsulation of database modifications in a transaction may be wrong 
and database errors or (worse) database content errors may result. It is 
better to throw an error in any case.

Bye, Thomas.


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