cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Lewis <br...@maine.rr.com>
Subject Re: Record counts...
Date Mon, 29 May 2006 12:04:22 GMT
This might help:

http://objectstyle.org/confluence/display/CAYDOC/Customizing+Queries


Borut Bolčina wrote:

> Hi,
>
> is this already implemented in some generic utility class?
>
> -Borut
>
> On 14.6.2005 23:03, Andrus Adamchik wrote:
>
>>No, SQLTemplate is actually used to run arbitrary SQL. In some cases the
>>result can be mapped to an entity, but in most it will be just that - a
>>list of Map objects with each Map corresponding to a result set data. So a
>>count query would look like this:
>>
>>  String sql = "SELECT COUNT(*) FROM SOME_TABLE"
>>  DataMap queryRoot =
>>context.getEntityResolver().getDataMap("data_map_name");
>>  SQLTemplate query = new SQLTemaplate(queryRoot, sql, true);
>>  Map singleRow = (Map) context.performQuery(query).get(0);
>>  Number count = (Number) singleRow.values().next();
>>
>>As this is a bit too verbose, 1.2 will likely encapsulate this code in a
>>generic utility class. For now you can create your own.
>>
>>Andrus
>>
>>
>>
>>  
>>
>>>I read through that documentation, but it doesn't really appear to do
>>>anything different then the normal SelectQuery besdies being able to
>>>write it in SQL. I was wanting to do something like SELECT COUNT(*)
>>>FROM Object and just got the int result, with out loading all the
>>>child records etc.
>>>
>>>Just reading the docs there it doesn't appear to let me do something like
>>>that.
>>>
>>>-Nick
>>>
>>>On 6/14/05, Mike Kienenberger <mkienenb@alaska.net> wrote:
>>>    
>>>
>>>>Nick Stuart <nicholas.stuart@gmail.com> wrote:
>>>>      
>>>>
>>>>>This should be an easy one. I basically just want to find out how many
>>>>>objects of a certain type there are. Easy to do with a SelectQuery and
>>>>>user List.size() but does the cause any kind of performance issues?
>>>>>Just thinking if these objects have child objects, which has more
>>>>>child objects, will it pull all those when I Select the parent?
>>>>>        
>>>>>
>>>>If you only want the count and don't want to load any objects, just use
>>>>SQLTemplate.
>>>>
>>>>http://www.objectstyle.org/cayenne/userguide/fetch/sqltemplate.html
>>>>
>>>>      
>>>>
>>
>>  
>>
>
> -- 
> bLOG <http://www.delo.si/blog/borutb/>
> --
> Naključna *izjava tedna* iz tednika Mladina:



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message