cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hugi Thordarson <h...@karlmenn.is>
Subject Re: Generating SQL from an Expression (for use in a utility method)
Date Wed, 20 May 2015 11:18:32 GMT
Great, thanks!

- hugi



> On 20. maí 2015, at 11:12, Andrus Adamchik <andrus@objectstyle.org> wrote:
> 
> You can still do it the 3.1 way via dataContext.performIteratedQuery(q) , which works
with any Query:
> 
> http://cayenne.apache.org/docs/3.1/cayenne-guide/performance-tuning.html#iterated-queries
> 
>> On May 20, 2015, at 1:45 PM, Hugi Thordarson <hugi@karlmenn.is> wrote:
>> 
>> Thanks, I’ll look into this as an alternative to the SQLTemplate query.
>> 
>> On a related note, is there any way to perform an iterative fetch using SQLTemplate
or EJBQL queries, rather than pulling the entire result of a fetch into memory? The ObjectContext.iterate()
and ObjectContext.iterator() methods only seem to accept queries of the type Select<T>?
>> 
>> Cheers,
>> - hugi
>> 
>> 
>>> On 19. maí 2015, at 19:34, Andrus Adamchik <andrus@objectstyle.org> wrote:
>>> 
>>> Or you can look at EJBQLQuery that allows to express your query in object terms,
and Cayenne will translate it to proper SQL:
>>> 
>>> Expression exp = ...
>>> EJBQLQuery query = new EJBQLQuery("SELECT a.name FROM Artist a WHERE " + exp.toEJBQL("a"));
>>> 
>>> This is the API to use until we provide similar (non-string-based) API in ObjectSelect
... 
>>> 
>>> Andrus  
>>> 
>>> 
>>>> On May 19, 2015, at 6:36 PM, Michael Gentry <mgentry@masslight.net>
wrote:
>>>> 
>>>> Hi Hugi,
>>>> 
>>>> Perhaps this can help you:
>>>> 
>>>> https://github.com/mrg/cbe/tree/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/utilities
>>>> 
>>>> AggregateUtils uses AggregateTranslator to construct the SQL for a query
>>>> (getting the SQL from Cayenne) and then manipulates it to run a COUNT(*)
or
>>>> SUM(...) type function based upon your original SelectQuery.  Especially
>>>> look at AggregateTranslator.createSqlString().
>>>> 
>>>> The example code using it might also help you:
>>>> 
>>>> https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/Aggregates.java
>>>> 
>>>> mrg
>>>> 
>>>> 
>>>> On Tue, May 19, 2015 at 11:21 AM, Hugi Thordarson <hugi@karlmenn.is>
wrote:
>>>> 
>>>>> Hi all.
>>>>> 
>>>>> I’m creating a little utility method to emulate functionality from
EOF,
>>>>> i.e. to allow me to fetch distinct values for specified columns. This
is
>>>>> what I have so far:
>>>>> 
>>>>> https://gist.github.com/hugith/05de4ad2f3d6f2cdc16a <
>>>>> https://gist.github.com/hugith/05de4ad2f3d6f2cdc16a>
>>>>> 
>>>>> However, I would like to be able to provide an expression to the query.
>>>>> Does Cayenne have something to generate the SQL from an expression for
me?
>>>>> 
>>>>> Am I perhaps going totally wrong about this?
>>>>> 
>>>>> Cheers,
>>>>> - hugi
>>> 
>> 
>> 
> 


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