Ordering using non-property values

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Ordering using non-property values

Musall, Maik
Hi all,

I have a UI with a list of objects and user-configurable filters and sorting criteria. Most of the sorting criteria are plain db path expressions, so I can just feed them into Ordering.orderedList(objects).

A couple of them however are path expressions with the last segment being not a Property, but a method name that is supposed to be invoked, which would then return a String, after which the list is to be ordered. This worked fine in the past using EOF and EOSortOrdering, but Cayenne's ordering throws an ExpressionException on evaluate().

What is the usual way in Cayenne to deal with this?

Thanks
Maik

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Ordering using non-property values

John Huss
Expressions will work with non-modeled properties as long as the methods
look like getters - have the "get" prefix and no arguments.

But I would use this:

Collections.sort(list, (a,b) -> a.getSomeProp().compareTo(b.getSomeProp()));



On Mon, Jul 17, 2017 at 8:08 AM Musall, Maik <[hidden email]> wrote:

> Hi all,
>
> I have a UI with a list of objects and user-configurable filters and
> sorting criteria. Most of the sorting criteria are plain db path
> expressions, so I can just feed them into Ordering.orderedList(objects).
>
> A couple of them however are path expressions with the last segment being
> not a Property, but a method name that is supposed to be invoked, which
> would then return a String, after which the list is to be ordered. This
> worked fine in the past using EOF and EOSortOrdering, but Cayenne's
> ordering throws an ExpressionException on evaluate().
>
> What is the usual way in Cayenne to deal with this?
>
> Thanks
> Maik
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Ordering using non-property values

Musall, Maik
Hi John,

> Am 17.07.2017 um 16:08 schrieb John Huss <[hidden email]>:
>
> Expressions will work with non-modeled properties as long as the methods
> look like getters - have the "get" prefix and no arguments.

Unfortunately not:

Caused by: java.lang.IllegalArgumentException: Property 'getCustomerNameForSorting' is not readable
        at org.apache.cayenne.reflect.BeanAccessor.<init>(BeanAccessor.java:92)
        at org.apache.cayenne.reflect.PropertyUtils.createSegmentAccessor(PropertyUtils.java:115)
        at org.apache.cayenne.reflect.PropertyUtils.getOrCreateSegmentAccessor(PropertyUtils.java:102)
        at org.apache.cayenne.reflect.PropertyUtils$PathAccessor.getValue(PropertyUtils.java:232)
        at org.apache.cayenne.reflect.PropertyUtils.getProperty(PropertyUtils.java:124)
        at org.apache.cayenne.CayenneDataObject.readSimpleProperty(CayenneDataObject.java:161)
        at org.apache.cayenne.CayenneDataObject.readNestedProperty(CayenneDataObject.java:127)
        at org.apache.cayenne.CayenneDataObject.readNestedProperty(CayenneDataObject.java:147)
        at org.apache.cayenne.exp.parser.ASTObjPath.evaluateNode(ASTObjPath.java:60)
        at org.apache.cayenne.exp.parser.SimpleNode.evaluate(SimpleNode.java:417)

Signature is: public String getCustomerNameForSorting()


> But I would use this:
>
> Collections.sort(list, (a,b) -> a.getSomeProp().compareTo(b.getSomeProp()));

Thought of that, but it would require me to re-implement the path segment tokenization and everything.

Maik


> On Mon, Jul 17, 2017 at 8:08 AM Musall, Maik <[hidden email]> wrote:
>
>> Hi all,
>>
>> I have a UI with a list of objects and user-configurable filters and
>> sorting criteria. Most of the sorting criteria are plain db path
>> expressions, so I can just feed them into Ordering.orderedList(objects).
>>
>> A couple of them however are path expressions with the last segment being
>> not a Property, but a method name that is supposed to be invoked, which
>> would then return a String, after which the list is to be ordered. This
>> worked fine in the past using EOF and EOSortOrdering, but Cayenne's
>> ordering throws an ExpressionException on evaluate().
>>
>> What is the usual way in Cayenne to deal with this?
>>
>> Thanks
>> Maik
>>
>>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Ordering using non-property values

Lon Varscsak
Is your key “customerNameForSorting”?

On Mon, Jul 17, 2017 at 7:40 AM, Musall, Maik <[hidden email]> wrote:

> Hi John,
>
> > Am 17.07.2017 um 16:08 schrieb John Huss <[hidden email]>:
> >
> > Expressions will work with non-modeled properties as long as the methods
> > look like getters - have the "get" prefix and no arguments.
>
> Unfortunately not:
>
> Caused by: java.lang.IllegalArgumentException: Property
> 'getCustomerNameForSorting' is not readable
>         at org.apache.cayenne.reflect.BeanAccessor.<init>(
> BeanAccessor.java:92)
>         at org.apache.cayenne.reflect.PropertyUtils.createSegmentAccessor(
> PropertyUtils.java:115)
>         at org.apache.cayenne.reflect.PropertyUtils.
> getOrCreateSegmentAccessor(PropertyUtils.java:102)
>         at org.apache.cayenne.reflect.PropertyUtils$PathAccessor.
> getValue(PropertyUtils.java:232)
>         at org.apache.cayenne.reflect.PropertyUtils.getProperty(
> PropertyUtils.java:124)
>         at org.apache.cayenne.CayenneDataObject.readSimpleProperty(
> CayenneDataObject.java:161)
>         at org.apache.cayenne.CayenneDataObject.readNestedProperty(
> CayenneDataObject.java:127)
>         at org.apache.cayenne.CayenneDataObject.readNestedProperty(
> CayenneDataObject.java:147)
>         at org.apache.cayenne.exp.parser.ASTObjPath.evaluateNode(
> ASTObjPath.java:60)
>         at org.apache.cayenne.exp.parser.SimpleNode.evaluate(
> SimpleNode.java:417)
>
> Signature is: public String getCustomerNameForSorting()
>
>
> > But I would use this:
> >
> > Collections.sort(list, (a,b) -> a.getSomeProp().compareTo(b.
> getSomeProp()));
>
> Thought of that, but it would require me to re-implement the path segment
> tokenization and everything.
>
> Maik
>
>
> > On Mon, Jul 17, 2017 at 8:08 AM Musall, Maik <[hidden email]>
> wrote:
> >
> >> Hi all,
> >>
> >> I have a UI with a list of objects and user-configurable filters and
> >> sorting criteria. Most of the sorting criteria are plain db path
> >> expressions, so I can just feed them into Ordering.orderedList(objects).
> >>
> >> A couple of them however are path expressions with the last segment
> being
> >> not a Property, but a method name that is supposed to be invoked, which
> >> would then return a String, after which the list is to be ordered. This
> >> worked fine in the past using EOF and EOSortOrdering, but Cayenne's
> >> ordering throws an ExpressionException on evaluate().
> >>
> >> What is the usual way in Cayenne to deal with this?
> >>
> >> Thanks
> >> Maik
> >>
> >>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Ordering using non-property values

Musall, Maik
Yep.

> Am 17.07.2017 um 17:50 schrieb Lon Varscsak <[hidden email]>:
>
> Is your key “customerNameForSorting”?
>
> On Mon, Jul 17, 2017 at 7:40 AM, Musall, Maik <[hidden email]> wrote:
>
>> Hi John,
>>
>>> Am 17.07.2017 um 16:08 schrieb John Huss <[hidden email]>:
>>>
>>> Expressions will work with non-modeled properties as long as the methods
>>> look like getters - have the "get" prefix and no arguments.
>>
>> Unfortunately not:
>>
>> Caused by: java.lang.IllegalArgumentException: Property
>> 'getCustomerNameForSorting' is not readable
>>        at org.apache.cayenne.reflect.BeanAccessor.<init>(
>> BeanAccessor.java:92)
>>        at org.apache.cayenne.reflect.PropertyUtils.createSegmentAccessor(
>> PropertyUtils.java:115)
>>        at org.apache.cayenne.reflect.PropertyUtils.
>> getOrCreateSegmentAccessor(PropertyUtils.java:102)
>>        at org.apache.cayenne.reflect.PropertyUtils$PathAccessor.
>> getValue(PropertyUtils.java:232)
>>        at org.apache.cayenne.reflect.PropertyUtils.getProperty(
>> PropertyUtils.java:124)
>>        at org.apache.cayenne.CayenneDataObject.readSimpleProperty(
>> CayenneDataObject.java:161)
>>        at org.apache.cayenne.CayenneDataObject.readNestedProperty(
>> CayenneDataObject.java:127)
>>        at org.apache.cayenne.CayenneDataObject.readNestedProperty(
>> CayenneDataObject.java:147)
>>        at org.apache.cayenne.exp.parser.ASTObjPath.evaluateNode(
>> ASTObjPath.java:60)
>>        at org.apache.cayenne.exp.parser.SimpleNode.evaluate(
>> SimpleNode.java:417)
>>
>> Signature is: public String getCustomerNameForSorting()
>>
>>
>>> But I would use this:
>>>
>>> Collections.sort(list, (a,b) -> a.getSomeProp().compareTo(b.
>> getSomeProp()));
>>
>> Thought of that, but it would require me to re-implement the path segment
>> tokenization and everything.
>>
>> Maik
>>
>>
>>> On Mon, Jul 17, 2017 at 8:08 AM Musall, Maik <[hidden email]>
>> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I have a UI with a list of objects and user-configurable filters and
>>>> sorting criteria. Most of the sorting criteria are plain db path
>>>> expressions, so I can just feed them into Ordering.orderedList(objects).
>>>>
>>>> A couple of them however are path expressions with the last segment
>> being
>>>> not a Property, but a method name that is supposed to be invoked, which
>>>> would then return a String, after which the list is to be ordered. This
>>>> worked fine in the past using EOF and EOSortOrdering, but Cayenne's
>>>> ordering throws an ExpressionException on evaluate().
>>>>
>>>> What is the usual way in Cayenne to deal with this?
>>>>
>>>> Thanks
>>>> Maik
>>>>
>>>>
>>
>>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Ordering using non-property values

Andrus Adamchik
From the stack, some code somewhere passes 'getCustomerNameForSorting' instead of 'customerNameForSorting' to Cayenne. Can it be a typo in the property name?

Andrus

> On Jul 18, 2017, at 1:26 PM, Musall, Maik <[hidden email]> wrote:
>
> Yep.
>
>> Am 17.07.2017 um 17:50 schrieb Lon Varscsak <[hidden email]>:
>>
>> Is your key “customerNameForSorting”?
>>
>> On Mon, Jul 17, 2017 at 7:40 AM, Musall, Maik <[hidden email]> wrote:
>>
>>> Hi John,
>>>
>>>> Am 17.07.2017 um 16:08 schrieb John Huss <[hidden email]>:
>>>>
>>>> Expressions will work with non-modeled properties as long as the methods
>>>> look like getters - have the "get" prefix and no arguments.
>>>
>>> Unfortunately not:
>>>
>>> Caused by: java.lang.IllegalArgumentException: Property
>>> 'getCustomerNameForSorting' is not readable
>>>       at org.apache.cayenne.reflect.BeanAccessor.<init>(
>>> BeanAccessor.java:92)
>>>       at org.apache.cayenne.reflect.PropertyUtils.createSegmentAccessor(
>>> PropertyUtils.java:115)
>>>       at org.apache.cayenne.reflect.PropertyUtils.
>>> getOrCreateSegmentAccessor(PropertyUtils.java:102)
>>>       at org.apache.cayenne.reflect.PropertyUtils$PathAccessor.
>>> getValue(PropertyUtils.java:232)
>>>       at org.apache.cayenne.reflect.PropertyUtils.getProperty(
>>> PropertyUtils.java:124)
>>>       at org.apache.cayenne.CayenneDataObject.readSimpleProperty(
>>> CayenneDataObject.java:161)
>>>       at org.apache.cayenne.CayenneDataObject.readNestedProperty(
>>> CayenneDataObject.java:127)
>>>       at org.apache.cayenne.CayenneDataObject.readNestedProperty(
>>> CayenneDataObject.java:147)
>>>       at org.apache.cayenne.exp.parser.ASTObjPath.evaluateNode(
>>> ASTObjPath.java:60)
>>>       at org.apache.cayenne.exp.parser.SimpleNode.evaluate(
>>> SimpleNode.java:417)
>>>
>>> Signature is: public String getCustomerNameForSorting()
>>>
>>>
>>>> But I would use this:
>>>>
>>>> Collections.sort(list, (a,b) -> a.getSomeProp().compareTo(b.
>>> getSomeProp()));
>>>
>>> Thought of that, but it would require me to re-implement the path segment
>>> tokenization and everything.
>>>
>>> Maik
>>>
>>>
>>>> On Mon, Jul 17, 2017 at 8:08 AM Musall, Maik <[hidden email]>
>>> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> I have a UI with a list of objects and user-configurable filters and
>>>>> sorting criteria. Most of the sorting criteria are plain db path
>>>>> expressions, so I can just feed them into Ordering.orderedList(objects).
>>>>>
>>>>> A couple of them however are path expressions with the last segment
>>> being
>>>>> not a Property, but a method name that is supposed to be invoked, which
>>>>> would then return a String, after which the list is to be ordered. This
>>>>> worked fine in the past using EOF and EOSortOrdering, but Cayenne's
>>>>> ordering throws an ExpressionException on evaluate().
>>>>>
>>>>> What is the usual way in Cayenne to deal with this?
>>>>>
>>>>> Thanks
>>>>> Maik
>>>>>
>>>>>
>>>
>>>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Ordering using non-property values

Musall, Maik
Dang, that's it. Thanks. Works fine now.

Somehow I can't stick using the get… syntax into my head. I still don't like it.

> Am 18.07.2017 um 13:05 schrieb Andrus Adamchik <[hidden email]>:
>
> From the stack, some code somewhere passes 'getCustomerNameForSorting' instead of 'customerNameForSorting' to Cayenne. Can it be a typo in the property name?
>
> Andrus
>
>> On Jul 18, 2017, at 1:26 PM, Musall, Maik <[hidden email]> wrote:
>>
>> Yep.
>>
>>> Am 17.07.2017 um 17:50 schrieb Lon Varscsak <[hidden email]>:
>>>
>>> Is your key “customerNameForSorting”?
>>>
>>> On Mon, Jul 17, 2017 at 7:40 AM, Musall, Maik <[hidden email]> wrote:
>>>
>>>> Hi John,
>>>>
>>>>> Am 17.07.2017 um 16:08 schrieb John Huss <[hidden email]>:
>>>>>
>>>>> Expressions will work with non-modeled properties as long as the methods
>>>>> look like getters - have the "get" prefix and no arguments.
>>>>
>>>> Unfortunately not:
>>>>
>>>> Caused by: java.lang.IllegalArgumentException: Property
>>>> 'getCustomerNameForSorting' is not readable
>>>>      at org.apache.cayenne.reflect.BeanAccessor.<init>(
>>>> BeanAccessor.java:92)
>>>>      at org.apache.cayenne.reflect.PropertyUtils.createSegmentAccessor(
>>>> PropertyUtils.java:115)
>>>>      at org.apache.cayenne.reflect.PropertyUtils.
>>>> getOrCreateSegmentAccessor(PropertyUtils.java:102)
>>>>      at org.apache.cayenne.reflect.PropertyUtils$PathAccessor.
>>>> getValue(PropertyUtils.java:232)
>>>>      at org.apache.cayenne.reflect.PropertyUtils.getProperty(
>>>> PropertyUtils.java:124)
>>>>      at org.apache.cayenne.CayenneDataObject.readSimpleProperty(
>>>> CayenneDataObject.java:161)
>>>>      at org.apache.cayenne.CayenneDataObject.readNestedProperty(
>>>> CayenneDataObject.java:127)
>>>>      at org.apache.cayenne.CayenneDataObject.readNestedProperty(
>>>> CayenneDataObject.java:147)
>>>>      at org.apache.cayenne.exp.parser.ASTObjPath.evaluateNode(
>>>> ASTObjPath.java:60)
>>>>      at org.apache.cayenne.exp.parser.SimpleNode.evaluate(
>>>> SimpleNode.java:417)
>>>>
>>>> Signature is: public String getCustomerNameForSorting()
>>>>
>>>>
>>>>> But I would use this:
>>>>>
>>>>> Collections.sort(list, (a,b) -> a.getSomeProp().compareTo(b.
>>>> getSomeProp()));
>>>>
>>>> Thought of that, but it would require me to re-implement the path segment
>>>> tokenization and everything.
>>>>
>>>> Maik
>>>>
>>>>
>>>>> On Mon, Jul 17, 2017 at 8:08 AM Musall, Maik <[hidden email]>
>>>> wrote:
>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I have a UI with a list of objects and user-configurable filters and
>>>>>> sorting criteria. Most of the sorting criteria are plain db path
>>>>>> expressions, so I can just feed them into Ordering.orderedList(objects).
>>>>>>
>>>>>> A couple of them however are path expressions with the last segment
>>>> being
>>>>>> not a Property, but a method name that is supposed to be invoked, which
>>>>>> would then return a String, after which the list is to be ordered. This
>>>>>> worked fine in the past using EOF and EOSortOrdering, but Cayenne's
>>>>>> ordering throws an ExpressionException on evaluate().
>>>>>>
>>>>>> What is the usual way in Cayenne to deal with this?
>>>>>>
>>>>>> Thanks
>>>>>> Maik
>>>>>>
>>>>>>
>>>>
>>>>
>>
>

Loading...