You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Andrea Papotti <pa...@adigitali.it> on 2006/01/23 16:33:42 UTC
bug or misunderstood feature?
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