db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henning P. Schmiedehausen" <...@intermeta.de>
Subject Re: silent db hit for associated objects
Date Tue, 02 Aug 2005 20:11:10 GMT
Thomas Fischer <fischer@seitenbau.net> writes:


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

-0 The classes are already too overloaded IMHO.

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

+0;  this is better, but still not really good. The question is: Does it
hurt? The database hit is read-only, so a rollback would only be
necessary if you have some trigger in the database which does writing
changes on a read-access. In the worst case you will get stale data,
but personally I would always recommend to run with
torque.objectIsCaching = false anyway.

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

That sounds like the best way to go.

Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

		      4 - 8 - 15 - 16 - 23 - 42

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

View raw message