db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject silent db hit for associated objects
Date Fri, 29 Jul 2005 13:07:40 GMT




Hi,

If one has an association between objects by foreign key, (e.g. book ->
author association in the tutorial), Torque generates methods to get the
associated objects (e.g. Book.getAuthor() and Author.getBooks()). If the
associated object has not yet been retrieved, these methods silently ask
the database for the objects, using a new connection from the database
pool.
This is not at all what one wants if one wants to use transactions in an
application, because one wants to do all reads in the same transaction. I
therefore plan to do the following
1) add a method getXXX(boolean silentDbFetch), which only hits the database
silently if silentDbFetch is set to true. If set to false and the
associated object(s) have not been retrieved yet, null is returned, even
though there might be associated objects in the database.
2 ) add a method getXXX(connection) for the n->1 direction, whcih uses the
provided connection if a db hit is necessary (in the book example, this
would be book.getAuthor(connection) (author.getBooks() was already present)
)
3) add a generator property torque.silentDbFetch, which is true by default.
If set to false, the getXXX() methods without arguments will not access the
db silently, but return null if the associated objects has not been read
yet. Also, the method does not throw a Torque exception any more (which is
the main reason why using these methods is more convenient than
getXXX(boolean silentDbFetch) with silentDbFetch set to false).

Any comments, objections, better ideas, better name for the silentDbFetch
parameter? In particular, I am not so sure if 3) is useful for the general
public, but then it helps to make sure that one does not read from the
database out of neglect if one does not want to do so.

            Thomas


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


Mime
View raw message