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: CountHelper and criteria.clone()
Date Wed, 07 Jul 2010 13:51:19 GMT
The Criteria clone method comes from its Hashtable superclass.  The problem 
is probably because Hashtable is doing a shallow copy and the underlying 
objects are the same. FWIW, there is a JIRA wish list item for this to be 
redone as a deep copy.  But this probably will be a 4.0 item.

In general, it's best to create or .clear() Criteria objects for each 
action.  This is usually not a big coding / overhead issue. 

However, if you have complex queries that are done frequently, you can
look at using the Criteria.Criterion subclass to create a reusable 
query definition.  See the Using Criterion... section in the docs at:

http://db.apache.org/torque/releases/torque-3.3/runtime/reference/read-from-db.html

FYI - I have to put a plug in for the SummaryHelper class that is in the 3.x 
CVS Head but not in a release yet.  It can be used instead of the CountHelper
class and has a lot more functionality. Here's the Javadoc in the 4.0 test
site (same as in the 3.3. tree). 

http://db.apache.org/torque/releases/torque-4.0/documentation/modules/runtime/apidocs/org/apache/torque/util/SummaryHelper.html



> -----Original Message-----
> From: Luca Ciocci [mailto:l.ciocci@askweb.it]
> Sent: Tuesday, July 06, 2010 11:52 AM
> To: torque-user@db.apache.org
> Subject: CountHelper and criteria.clone()
> 
> Hello,
>  I discover the CountHelper object and I think that could be very
> usefull, but I have seen that it modify the original criteria object
> adding a select count(*) to the query.
> 
> So my question is: exist a way to real copy the criteria object before
> use the CountHelper (or exists another trick?)
> 
> A simple code like this not work:
> 
> List list=new LinkedList();
> Criteria criteria=new Criteria();
> criteria.add(MyTablePeer.MyColumn,'MyValue'); //Adding a simple column
> 
> Criteria criteriacount=(Criteria)criteria.clone(); //Important
> CountHelper counthelper=new CountHelper(criteriacount);
> int recordcount=counthelper.count();
> 
> if (recordcount<1000) {
> 	list=MyTablePeer.doSelect(criteria);
> 	//This instruction fail and throw DataSetException
> }
> 
> 
> Thanks in advance.
> Luca
> 
> 
> --
> Ing. Luca Ciocci
> ASK srl
> tel 059 271417
> fax 059 3683560
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org

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

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