db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: bug or misunderstood feature?
Date Mon, 23 Jan 2006 16:14:57 GMT
I suggest updating to version 3.2.  I looked at the 
forgiegn key collection code generated by this 
version and it does check to see if the criteria 
has changed.  I suspect it was one of the bugs 
fixed.

> -----Original Message-----
> From: Andrea Papotti
> 
> Using Torque 3.1.1 we have found this strange behaviour:
> 
> having three records with
> 
> idtessera, price, idproduct
> 1, 1000, 0
> 1, 2000, 1
> 1, 3000, 2
> 
> and this piece of code
> 
> <snip>
>         int price = 0;
>         Criteria criteria = new Criteria();
>         criteria.add( BaseDtessereinPeer.IDPRODUCT, 0 );
>         List in = tessera.getDtessereins( criteria );
> 
>         for (int idx = 0; idx < in.size(); idx++)
>         {
>             Dtesserein dtessera = (Dtesserein) in.get( idx );
> 
>             price+= dtessera.getPrice();
>         }
> 
>        Context.put( "Price",  price )
> 
>        Context.put( "FullList", tessera.getDtessereins() ); </snip>
> 
> results in
> 
> Price = 1000
> FullList = only the first record (the one with idtessera = 1)
> 
> 
> Since the two calls of tessera.getDtesserein() have different 
> Criteria 
> (the last has Criteria = all record = no criteria), I would espect to 
> get a different list of records (i.e. three records in the 
> latter call 
> to the method).
> Poking around in the Peer code generated via "maven 
> torque:om" , we have 
> found this:
> 
> -----------------------------------------------------
> public List getDtessereins() throws TorqueException
>     {
>         if (collDtessereins == null)
>         {
>             collDtessereins = getDtessereins( new Criteria( 10 ) );
>         }
>         return collDtessereins;
>     }
> ----------------------------------------------------
> 
> which can be translated to: "if you have already readed the db, never 
> read it again"
> 
> We think that the correct code should be:
> 
> ----------------------------------------------------
> public List getDtessereins() throws TorqueException
>    {
>         Criteria criteria = new Criteria( 10 );
>        
>         if (collDtessereins == null || 
> !lastDtessereinsCriteria.equals( 
> criteria ) )
>         {
>             collDtessereins = getDtessereins( criteria );
>         }
>        
>         return collDtessereins;       
>     }
> ----------------------------------------------------
> 
> which can bet translated to "if you have already readed the 
> db AND the 
> criteria is unchanged, do not read the db again"
> 
> or even better:
> 
> ----------------------------------------------------
> public List getDtessereins() throws TorqueException
>     {
>         return getDtessereins( new Criteria( 10 ));   
>     }
> ----------------------------------------------------
> 
> leaving to getDtessereins(Criteria criteria) the control on the 
> equalness of the criteria (control already present in the 
> generated code)
> 
> 
> 
> Have we misunderstood the pourpose of  getDtessereins() or has it a 
> (subtle) bug ??
> Shoul we use getDtessereins( new Criteria( 10 ) ) every time 
> we need the 
> _complete_ list of objects ?
> 
> 
> Andrea Papotti
> Alchimie Digitali S.r.l.
> Italy.
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication
or may otherwise be privileged or confidential and are intended solely for the individual
or entity to whom they are addressed.  If you are not the intended recipient you may not rely
on the contents of this email or any attachments, and we ask that you  please not read, copy
or retransmit this communication, but reply to the sender and destroy the email, its contents,
and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying
of this communication is strictly prohibited.



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


Mime
View raw message