If you are checking for the existence of a known primary key then yes,
retrieveByPK() would be the way to go, however checking for the existence of
a primary key would seem to indicate some kind of referential integrity
failure (somehow there is a possibility that child records exist for a
deleted parent record).

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au


> From: [EMAIL PROTECTED]
> Reply-To: "Turbine Users List" <[EMAIL PROTECTED]>
> Date: Wed, 16 Oct 2002 11:05:56 -0400
> To: Turbine Users List <[EMAIL PROTECTED]>
> Subject: Re: checking whether a data-row exists conveniently
> 
> I think the best means to do this would be to use the findByPrimaryKey
> method on your generated Peers object.
> 
> You pass it the NumberKey representing the primekey of your record.
> It believe it will throw an exception if it cannot select a record.
> 
> 
> On Wed, 16 Oct 2002, Scott Eade wrote:
> 
>> Marc,
>> 
>> We could sure use a standard mechanism for checking the existence of a
>> record.  Perhaps you could raise an enhancement request in Scarab.
>> 
>> In the mean time, here is what I do:
>> 
>> public boolean checkExists() {
>>     Criteria criteria = new Criteria();
>>     criteria.addSelectColumn(MyPeer.RANDOM_SMALL_COLUMN);
>>     // Add anything else to the criteria to limit the selection
>>     criteria.setLimit(1);
>>     List queryReault = BasePeer.doSelect(criteria);
>>     return queryResult.size() == 0;
>> }
>> 
>> Obviously this is along the lines of what you were suggesting, but it will
>> be quicker to limit the selection to a single row and to only retrieve a
>> single column.
>> 
>> Cheers,
>> 
>> Scott
>> --
>> Scott Eade
>> Backstage Technologies Pty. Ltd.
>> http://www.backstagetech.com.au
>> 
>>> From: "Marc Lustig" <[EMAIL PROTECTED]>
>>> 
>>> Hi,
>>> 
>>> I'm wondering what is the most convenient way to check whether a table-row
>>> exists or not (using a criteria as condition).
>>> I was looking for a special method (something like exists() in the Peer
>>> classes but couldn't find.
>>> So I guess I have either to build my own method or do the usual doSelect and
>>> then check whether mylist.size() is 0 or not.
>>> Or did I miss something?
>>> 
>>> TIA.
>>> Marc
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>> 
>> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to