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 Vandahl <th...@tewisoft.de> on 2005/09/08 16:31:16 UTC

Re: silent db hit for associated objects

Thomas Vandahl wrote:
> Not without bigger changes in the AbstractBaseManager. I will have a 
> look at this. I guess the real fun starts if I want to cache the whole 
> collection of books at once (using MethodResultCache for example, not to 
> speak of invalidation).

Replying to myself is fun...

Well, I finally came up with an attempt for a solution. It was less work 
than I expected, but I guess we are only halfway through. It passes the 
runtime test, however.

It looks like this:
---8<---
public Author getAuthor(Connection connection)
     throws TorqueException
{
     if (aAuthor == null && (this.authorId != 0))
     {
         aAuthor = 
AuthorManager.getCachedInstance(SimpleKey.keyFor(this.authorId));
         if (aAuthor == null)
         {
             aAuthor = 
AuthorPeer.retrieveByPK(SimpleKey.keyFor(this.authorId), connection);
             AuthorManager.putInstance(aAuthor);
         }
     }
     return aAuthor;
}
---8<---

While I was at it I corrected a few problems PMD complained about, but 
there is still room for improvement... :-)

Any comments are welcome.

Bye, Thomas.


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


Re: silent db hit for associated objects

Posted by Thomas Fischer <fi...@seitenbau.net>.



Hi Thomas,

though I have no experience with the Cache, the code looks good to me.

   Thomas

Thomas Vandahl <th...@tewisoft.de> schrieb am 08.09.2005 16:31:16:

> Thomas Vandahl wrote:
> > Not without bigger changes in the AbstractBaseManager. I will have a
> > look at this. I guess the real fun starts if I want to cache the whole
> > collection of books at once (using MethodResultCache for example, not
to
> > speak of invalidation).
>
> Replying to myself is fun...
>
> Well, I finally came up with an attempt for a solution. It was less work
> than I expected, but I guess we are only halfway through. It passes the
> runtime test, however.
>
> It looks like this:
> ---8<---
> public Author getAuthor(Connection connection)
>      throws TorqueException
> {
>      if (aAuthor == null && (this.authorId != 0))
>      {
>          aAuthor =
> AuthorManager.getCachedInstance(SimpleKey.keyFor(this.authorId));
>          if (aAuthor == null)
>          {
>              aAuthor =
> AuthorPeer.retrieveByPK(SimpleKey.keyFor(this.authorId), connection);
>              AuthorManager.putInstance(aAuthor);
>          }
>      }
>      return aAuthor;
> }
> ---8<---
>
> While I was at it I corrected a few problems PMD complained about, but
> there is still room for improvement... :-)
>
> Any comments are welcome.
>
> Bye, Thomas.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org
>


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