cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amedeo Mantica <amedeomant...@me.com>
Subject Re: Raw query
Date Sun, 30 Apr 2017 18:02:32 GMT
Cool.
However I'm using the 3.1.2 yet
Amedeo

> On 30 Apr 2017, at 10:21, Andrus Adamchik <andrus@objectstyle.org> wrote:
> 
>> SQLTemplate query = new SQLTemplate(MyEntity.class, "SELECT COUNT(1)
>> FROM MY_ENTITY");
>> query.setFetchingDataRows(true);
>> List<DataRow> rows = (List<DataRow>) context.performQuery(query);
> 
> Or you can use SQLSelect as a type-safe and more user-friendly flavor doing the same
thing:
> 
>  List<DataRow> rows = SQLSelect.dataRowQuery("SELECT COUNT(1) FROM MY_ENTITY").select(context);
> 
>> You can also use aggregate functions directly with Cayenne API (since
>> version 4.0.M5):
>> 
>> long count = ObjectSelect.query(MyEntity.class).selectCount(context);
> 
> Yep, this one is the best option.
> 
> Andrus
> 
> 
>> On Apr 29, 2017, at 5:22 PM, Nikita Timofeev <ntimofeev@objectstyle.com> wrote:
>> 
>> Hi Amedeo,
>> 
>> For raw queries you can use SQLTemplate, like this:
>> 
>> SQLTemplate query = new SQLTemplate(MyEntity.class, "SELECT COUNT(1)
>> FROM MY_ENTITY");
>> query.setFetchingDataRows(true);
>> List<DataRow> rows = (List<DataRow>) context.performQuery(query);
>> 
>> You can also use aggregate functions directly with Cayenne API (since
>> version 4.0.M5):
>> 
>> long count = ObjectSelect.query(MyEntity.class).selectCount(context);
>> 
>> Hope this helps!
>> 
>> On Sat, Apr 29, 2017 at 4:49 PM, Amedeo Mantica <amedeomantica@me.com> wrote:
>>> Hi all,
>>> 
>>> Ho to execute a simple raw query with cayenne ?
>>> 
>>> let say: SELECT COUNT(1) FROM MY_ENTITY;
>>> 
>>> Thank you
>>> Amedeo
>> 
>> 
>> 
>> -- 
>> Best regards,
>> Nikita Timofeev
> 


Mime
View raw message