You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by abapseres <ab...@bapseres.fr> on 2019/06/24 08:47:54 UTC
orderBY with prefetched table
Hello,
I would like to sort query results with a prefetched table propertie, but it don't work :
ObjectSelect.query(Table1.class)
.prefetch(Table1.TO_TABLE2.joint())
.orderBy(Table1.LIBELLE1.asc())
.orderBy(Table2.LIBELLE2.asc()) --> dont work
.select(getObjectContext())
Is it possible to do something like that ?
Thank you
Re: orderBY with prefetched table
Posted by Andrus Adamchik <an...@objectstyle.org>.
Oh, I think I know what this is...
Both your orderings need to be relative to Table1, as that's the query root. So you may rewrite it like this, to create a "path" from Table1 to Table2 to LIBELLE attribute:
.orderBy(Table1.LIBELLE1.asc())
.orderBy(Table1.TO_TABLE2.dot(Table2.LIBELLE2).asc())
Andrus
> On Jun 24, 2019, at 2:10 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> Actually the original query should work. Calling "query.orderBy(x).orderBy(y)" should keep both orderings.
>
>>> .orderBy(Table1.LIBELLE1.asc())
>>> .orderBy(Table2.LIBELLE2.asc()) --> dont work
>
> Any more details what happens if you do that?
>
> Andrus
>
>
>> On Jun 24, 2019, at 12:03 PM, Maxim Petrusevich <mp...@objectstyle.com> wrote:
>>
>> As I know, Cayenne has ordering which uses list of orderings.
>>
>> orderBy(Collection<Ordering> orderings)
>>
>> You should create list with items which will have Ordering type. Something
>> like this:
>>
>> List<Ordering> orderings = new ArrayList<>();
>>
>> orderings.add(new Ordering(attribute, sortOrder))
>> ...
>>
>> // attribute here, is a string which describes your attribute in "cayenne
>> style" (e.g. Table1.SOME_FIELD.getName()) // sort order is a cayenne
>> specified type of ordering: SortOrder.ASCENDING or SorterOrder.DESCENDING,
>> see SortOrder class for details ObjectSelect.query(Table1.class)
>> .prefetch(Table1.TO_TABLE2.joint()) .orderBy(orderings)
>> .select(getObjectContext())
>>
>>
>> On Mon, Jun 24, 2019 at 11:48 AM abapseres <ab...@bapseres.fr> wrote:
>>
>>> Hello,
>>>
>>> I would like to sort query results with a prefetched table propertie, but
>>> it don't work :
>>>
>>>
>>> ObjectSelect.query(Table1.class)
>>> .prefetch(Table1.TO_TABLE2.joint())
>>> .orderBy(Table1.LIBELLE1.asc())
>>> .orderBy(Table2.LIBELLE2.asc()) --> dont work
>>> .select(getObjectContext())
>>>
>>>
>>> Is it possible to do something like that ?
>>>
>>> Thank you
>>>
>
Re: orderBY with prefetched table
Posted by Andrus Adamchik <an...@objectstyle.org>.
Actually the original query should work. Calling "query.orderBy(x).orderBy(y)" should keep both orderings.
>> .orderBy(Table1.LIBELLE1.asc())
>> .orderBy(Table2.LIBELLE2.asc()) --> dont work
Any more details what happens if you do that?
Andrus
> On Jun 24, 2019, at 12:03 PM, Maxim Petrusevich <mp...@objectstyle.com> wrote:
>
> As I know, Cayenne has ordering which uses list of orderings.
>
> orderBy(Collection<Ordering> orderings)
>
> You should create list with items which will have Ordering type. Something
> like this:
>
> List<Ordering> orderings = new ArrayList<>();
>
> orderings.add(new Ordering(attribute, sortOrder))
> ...
>
> // attribute here, is a string which describes your attribute in "cayenne
> style" (e.g. Table1.SOME_FIELD.getName()) // sort order is a cayenne
> specified type of ordering: SortOrder.ASCENDING or SorterOrder.DESCENDING,
> see SortOrder class for details ObjectSelect.query(Table1.class)
> .prefetch(Table1.TO_TABLE2.joint()) .orderBy(orderings)
> .select(getObjectContext())
>
>
> On Mon, Jun 24, 2019 at 11:48 AM abapseres <ab...@bapseres.fr> wrote:
>
>> Hello,
>>
>> I would like to sort query results with a prefetched table propertie, but
>> it don't work :
>>
>>
>> ObjectSelect.query(Table1.class)
>> .prefetch(Table1.TO_TABLE2.joint())
>> .orderBy(Table1.LIBELLE1.asc())
>> .orderBy(Table2.LIBELLE2.asc()) --> dont work
>> .select(getObjectContext())
>>
>>
>> Is it possible to do something like that ?
>>
>> Thank you
>>
Re: orderBY with prefetched table
Posted by Maxim Petrusevich <mp...@objectstyle.com>.
As I know, Cayenne has ordering which uses list of orderings.
orderBy(Collection<Ordering> orderings)
You should create list with items which will have Ordering type. Something
like this:
List<Ordering> orderings = new ArrayList<>();
orderings.add(new Ordering(attribute, sortOrder))
...
// attribute here, is a string which describes your attribute in "cayenne
style" (e.g. Table1.SOME_FIELD.getName()) // sort order is a cayenne
specified type of ordering: SortOrder.ASCENDING or SorterOrder.DESCENDING,
see SortOrder class for details ObjectSelect.query(Table1.class)
.prefetch(Table1.TO_TABLE2.joint()) .orderBy(orderings)
.select(getObjectContext())
On Mon, Jun 24, 2019 at 11:48 AM abapseres <ab...@bapseres.fr> wrote:
> Hello,
>
> I would like to sort query results with a prefetched table propertie, but
> it don't work :
>
>
> ObjectSelect.query(Table1.class)
> .prefetch(Table1.TO_TABLE2.joint())
> .orderBy(Table1.LIBELLE1.asc())
> .orderBy(Table2.LIBELLE2.asc()) --> dont work
> .select(getObjectContext())
>
>
> Is it possible to do something like that ?
>
> Thank you
>