You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Musall, Maik" <ma...@selbstdenker.ag> on 2017/04/12 15:48:33 UTC
in-memory filter by Expression accessing regular methods
Hi,
when filtering a list of objects by expression.filterObjects( list ), is there a way for the expression to access regular methods instead of Cayenne db properties?
Use Case: I have a class A that has several relationships to class B, and it depends on a number of factors which is relevant in this case. So there is a method that returns either this or that relation to class B. I would like to include the method name in the expression path. (This was possible in EOF, and I just found that it doesn't work in Cayenne.)
Thanks
Maik
Re: in-memory filter by Expression accessing regular methods
Posted by Maik Musall <ma...@selbstdenker.ag>.
Hi Michael,
in the meantime I remembered I had already implemented NSKeyValueCodingAdditions for my DataObject subclass, so I just used that :-)
Maik
> Am 18.04.2017 um 18:23 schrieb Michael Gentry <bl...@gmail.com>:
>
> Hi Maik,
>
> I'm late to this, but you likely could've used
> obj.readProperty("responsibleUser") as well.
>
> mrg
>
>
>> On Sun, Apr 16, 2017 at 7:13 AM, Musall, Maik <ma...@selbstdenker.ag> wrote:
>>
>> Wow, Mark, good guess!
>>
>> That's it. Added a get… method around each part of the path's accessed
>> methods, and it works. Didn't occur to me at all, because those methods are
>> not getters in the strict sense. But I could have discovered this before,
>> by looking at the BeanAcccessor implementation. Dang.
>>
>> I suppose there is no way in Cayenne to inject a different behaviour for
>> this, through DI or something? It doesn't look like it from the code
>> (BeanAccessor, PropertyUtils, and the readSimpleProperty() method in
>> CayennDataObject is even marked final). Because I know I will run into this
>> again and again, given the existing large code base.
>>
>> Maik
>>
>>
>>
>>> Am 15.04.2017 um 23:18 schrieb Mark Wardle <ma...@wardle.org>:
>>>
>>> Can't try it as only have phone at the moment but have you tried adding
>> "get" as a prefix to your method declaration?
>>>
>>> I still find it difficult to not name getters without the get.
>>>
>>> --
>>> Dr. Mark Wardle
>>> Consultant Neurologist, Cardiff, UK
>>> (Sent from my mobile)
>>>
>>>
>>>> On 13 Apr 2017, at 10:44, Musall, Maik <ma...@selbstdenker.ag> wrote:
>>>>
>>>> Hi John,
>>>>
>>>> can you elaborate that on this example?
>>>>
>>>> Previously, I did this to filter:
>>>>
>>>> result = ExpressionFactory.matchExp( filterPath, filterValue
>> ).filterObjects( result );
>>>>
>>>> Now I tried:
>>>>
>>>> result = result.stream()
>>>> .filter( obj -> PropertyUtils.getProperty( obj, filterPath
>> ).equals( filterValue ) )
>>>> .collect( Collectors.toList() );
>>>>
>>>> Both times, I get:
>>>>
>>>> java.lang.IllegalArgumentException: Property 'responsibleUser' is not
>> readable
>>>>
>>>> where "result" is like a List<Foo> with Foo being a DataObject that has
>> a method called "responsibleUser", returning another DataObject subclass.
>>>>
>>>> Maik
>>>>
>>>>
>>>>> Am 12.04.2017 um 19:11 schrieb John Huss <jo...@gmail.com>:
>>>>>
>>>>> Ok, you can use property utils in conjunction to call a method using
>>>>> reflection (with a string name)
>>>>>> On Wed, Apr 12, 2017 at 6:07 PM Musall, Maik <ma...@selbstdenker.ag>
>> wrote:
>>>>>>
>>>>>> Hi John,
>>>>>>
>>>>>> how do you mean that? Those filter paths come from the UI, passed on
>> by
>>>>>> the user assembling filter criteria. I wouldn't use string filter
>> paths if
>>>>>> the criteria would be constant.
>>>>>>
>>>>>> Maik
>>>>>>
>>>>>>> Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
>>>>>>>
>>>>>>> Just use a java 8 stream and lambda in addition or instead of.
>>>>>>> On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag>
>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> when filtering a list of objects by expression.filterObjects( list
>> ), is
>>>>>>>> there a way for the expression to access regular methods instead of
>>>>>> Cayenne
>>>>>>>> db properties?
>>>>>>>>
>>>>>>>> Use Case: I have a class A that has several relationships to class
>> B,
>>>>>> and
>>>>>>>> it depends on a number of factors which is relevant in this case. So
>>>>>> there
>>>>>>>> is a method that returns either this or that relation to class B. I
>>>>>> would
>>>>>>>> like to include the method name in the expression path. (This was
>>>>>> possible
>>>>>>>> in EOF, and I just found that it doesn't work in Cayenne.)
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>> Maik
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>
>>
>>
Re: in-memory filter by Expression accessing regular methods
Posted by Michael Gentry <bl...@gmail.com>.
Hi Maik,
I'm late to this, but you likely could've used
obj.readProperty("responsibleUser") as well.
mrg
On Sun, Apr 16, 2017 at 7:13 AM, Musall, Maik <ma...@selbstdenker.ag> wrote:
> Wow, Mark, good guess!
>
> That's it. Added a get… method around each part of the path's accessed
> methods, and it works. Didn't occur to me at all, because those methods are
> not getters in the strict sense. But I could have discovered this before,
> by looking at the BeanAcccessor implementation. Dang.
>
> I suppose there is no way in Cayenne to inject a different behaviour for
> this, through DI or something? It doesn't look like it from the code
> (BeanAccessor, PropertyUtils, and the readSimpleProperty() method in
> CayennDataObject is even marked final). Because I know I will run into this
> again and again, given the existing large code base.
>
> Maik
>
>
>
> > Am 15.04.2017 um 23:18 schrieb Mark Wardle <ma...@wardle.org>:
> >
> > Can't try it as only have phone at the moment but have you tried adding
> "get" as a prefix to your method declaration?
> >
> > I still find it difficult to not name getters without the get.
> >
> > --
> > Dr. Mark Wardle
> > Consultant Neurologist, Cardiff, UK
> > (Sent from my mobile)
> >
> >
> >> On 13 Apr 2017, at 10:44, Musall, Maik <ma...@selbstdenker.ag> wrote:
> >>
> >> Hi John,
> >>
> >> can you elaborate that on this example?
> >>
> >> Previously, I did this to filter:
> >>
> >> result = ExpressionFactory.matchExp( filterPath, filterValue
> ).filterObjects( result );
> >>
> >> Now I tried:
> >>
> >> result = result.stream()
> >> .filter( obj -> PropertyUtils.getProperty( obj, filterPath
> ).equals( filterValue ) )
> >> .collect( Collectors.toList() );
> >>
> >> Both times, I get:
> >>
> >> java.lang.IllegalArgumentException: Property 'responsibleUser' is not
> readable
> >>
> >> where "result" is like a List<Foo> with Foo being a DataObject that has
> a method called "responsibleUser", returning another DataObject subclass.
> >>
> >> Maik
> >>
> >>
> >>> Am 12.04.2017 um 19:11 schrieb John Huss <jo...@gmail.com>:
> >>>
> >>> Ok, you can use property utils in conjunction to call a method using
> >>> reflection (with a string name)
> >>>> On Wed, Apr 12, 2017 at 6:07 PM Musall, Maik <ma...@selbstdenker.ag>
> wrote:
> >>>>
> >>>> Hi John,
> >>>>
> >>>> how do you mean that? Those filter paths come from the UI, passed on
> by
> >>>> the user assembling filter criteria. I wouldn't use string filter
> paths if
> >>>> the criteria would be constant.
> >>>>
> >>>> Maik
> >>>>
> >>>>> Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
> >>>>>
> >>>>> Just use a java 8 stream and lambda in addition or instead of.
> >>>>> On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag>
> >>>> wrote:
> >>>>>
> >>>>>> Hi,
> >>>>>>
> >>>>>> when filtering a list of objects by expression.filterObjects( list
> ), is
> >>>>>> there a way for the expression to access regular methods instead of
> >>>> Cayenne
> >>>>>> db properties?
> >>>>>>
> >>>>>> Use Case: I have a class A that has several relationships to class
> B,
> >>>> and
> >>>>>> it depends on a number of factors which is relevant in this case. So
> >>>> there
> >>>>>> is a method that returns either this or that relation to class B. I
> >>>> would
> >>>>>> like to include the method name in the expression path. (This was
> >>>> possible
> >>>>>> in EOF, and I just found that it doesn't work in Cayenne.)
> >>>>>>
> >>>>>> Thanks
> >>>>>> Maik
> >>>>>>
> >>>>>>
> >>>>
> >>>>
> >>
>
>
Re: in-memory filter by Expression accessing regular methods
Posted by Mark Wardle <ma...@wardle.org>.
Glad it worked!
Mark
--
Dr. Mark Wardle
Consultant Neurologist, Cardiff, UK
(Sent from my mobile)
> On 16 Apr 2017, at 12:13, Musall, Maik <ma...@selbstdenker.ag> wrote:
>
> Wow, Mark, good guess!
>
> That's it. Added a get… method around each part of the path's accessed methods, and it works. Didn't occur to me at all, because those methods are not getters in the strict sense. But I could have discovered this before, by looking at the BeanAcccessor implementation. Dang.
>
> I suppose there is no way in Cayenne to inject a different behaviour for this, through DI or something? It doesn't look like it from the code (BeanAccessor, PropertyUtils, and the readSimpleProperty() method in CayennDataObject is even marked final). Because I know I will run into this again and again, given the existing large code base.
>
> Maik
>
>
>
>> Am 15.04.2017 um 23:18 schrieb Mark Wardle <ma...@wardle.org>:
>>
>> Can't try it as only have phone at the moment but have you tried adding "get" as a prefix to your method declaration?
>>
>> I still find it difficult to not name getters without the get.
>>
>> --
>> Dr. Mark Wardle
>> Consultant Neurologist, Cardiff, UK
>> (Sent from my mobile)
>>
>>
>>> On 13 Apr 2017, at 10:44, Musall, Maik <ma...@selbstdenker.ag> wrote:
>>>
>>> Hi John,
>>>
>>> can you elaborate that on this example?
>>>
>>> Previously, I did this to filter:
>>>
>>> result = ExpressionFactory.matchExp( filterPath, filterValue ).filterObjects( result );
>>>
>>> Now I tried:
>>>
>>> result = result.stream()
>>> .filter( obj -> PropertyUtils.getProperty( obj, filterPath ).equals( filterValue ) )
>>> .collect( Collectors.toList() );
>>>
>>> Both times, I get:
>>>
>>> java.lang.IllegalArgumentException: Property 'responsibleUser' is not readable
>>>
>>> where "result" is like a List<Foo> with Foo being a DataObject that has a method called "responsibleUser", returning another DataObject subclass.
>>>
>>> Maik
>>>
>>>
>>>> Am 12.04.2017 um 19:11 schrieb John Huss <jo...@gmail.com>:
>>>>
>>>> Ok, you can use property utils in conjunction to call a method using
>>>> reflection (with a string name)
>>>>> On Wed, Apr 12, 2017 at 6:07 PM Musall, Maik <ma...@selbstdenker.ag> wrote:
>>>>>
>>>>> Hi John,
>>>>>
>>>>> how do you mean that? Those filter paths come from the UI, passed on by
>>>>> the user assembling filter criteria. I wouldn't use string filter paths if
>>>>> the criteria would be constant.
>>>>>
>>>>> Maik
>>>>>
>>>>>> Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
>>>>>>
>>>>>> Just use a java 8 stream and lambda in addition or instead of.
>>>>>> On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag>
>>>>> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> when filtering a list of objects by expression.filterObjects( list ), is
>>>>>>> there a way for the expression to access regular methods instead of
>>>>> Cayenne
>>>>>>> db properties?
>>>>>>>
>>>>>>> Use Case: I have a class A that has several relationships to class B,
>>>>> and
>>>>>>> it depends on a number of factors which is relevant in this case. So
>>>>> there
>>>>>>> is a method that returns either this or that relation to class B. I
>>>>> would
>>>>>>> like to include the method name in the expression path. (This was
>>>>> possible
>>>>>>> in EOF, and I just found that it doesn't work in Cayenne.)
>>>>>>>
>>>>>>> Thanks
>>>>>>> Maik
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>
Re: in-memory filter by Expression accessing regular methods
Posted by "Musall, Maik" <ma...@selbstdenker.ag>.
Wow, Mark, good guess!
That's it. Added a get… method around each part of the path's accessed methods, and it works. Didn't occur to me at all, because those methods are not getters in the strict sense. But I could have discovered this before, by looking at the BeanAcccessor implementation. Dang.
I suppose there is no way in Cayenne to inject a different behaviour for this, through DI or something? It doesn't look like it from the code (BeanAccessor, PropertyUtils, and the readSimpleProperty() method in CayennDataObject is even marked final). Because I know I will run into this again and again, given the existing large code base.
Maik
> Am 15.04.2017 um 23:18 schrieb Mark Wardle <ma...@wardle.org>:
>
> Can't try it as only have phone at the moment but have you tried adding "get" as a prefix to your method declaration?
>
> I still find it difficult to not name getters without the get.
>
> --
> Dr. Mark Wardle
> Consultant Neurologist, Cardiff, UK
> (Sent from my mobile)
>
>
>> On 13 Apr 2017, at 10:44, Musall, Maik <ma...@selbstdenker.ag> wrote:
>>
>> Hi John,
>>
>> can you elaborate that on this example?
>>
>> Previously, I did this to filter:
>>
>> result = ExpressionFactory.matchExp( filterPath, filterValue ).filterObjects( result );
>>
>> Now I tried:
>>
>> result = result.stream()
>> .filter( obj -> PropertyUtils.getProperty( obj, filterPath ).equals( filterValue ) )
>> .collect( Collectors.toList() );
>>
>> Both times, I get:
>>
>> java.lang.IllegalArgumentException: Property 'responsibleUser' is not readable
>>
>> where "result" is like a List<Foo> with Foo being a DataObject that has a method called "responsibleUser", returning another DataObject subclass.
>>
>> Maik
>>
>>
>>> Am 12.04.2017 um 19:11 schrieb John Huss <jo...@gmail.com>:
>>>
>>> Ok, you can use property utils in conjunction to call a method using
>>> reflection (with a string name)
>>>> On Wed, Apr 12, 2017 at 6:07 PM Musall, Maik <ma...@selbstdenker.ag> wrote:
>>>>
>>>> Hi John,
>>>>
>>>> how do you mean that? Those filter paths come from the UI, passed on by
>>>> the user assembling filter criteria. I wouldn't use string filter paths if
>>>> the criteria would be constant.
>>>>
>>>> Maik
>>>>
>>>>> Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
>>>>>
>>>>> Just use a java 8 stream and lambda in addition or instead of.
>>>>> On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag>
>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> when filtering a list of objects by expression.filterObjects( list ), is
>>>>>> there a way for the expression to access regular methods instead of
>>>> Cayenne
>>>>>> db properties?
>>>>>>
>>>>>> Use Case: I have a class A that has several relationships to class B,
>>>> and
>>>>>> it depends on a number of factors which is relevant in this case. So
>>>> there
>>>>>> is a method that returns either this or that relation to class B. I
>>>> would
>>>>>> like to include the method name in the expression path. (This was
>>>> possible
>>>>>> in EOF, and I just found that it doesn't work in Cayenne.)
>>>>>>
>>>>>> Thanks
>>>>>> Maik
>>>>>>
>>>>>>
>>>>
>>>>
>>
Re: in-memory filter by Expression accessing regular methods
Posted by Mark Wardle <ma...@wardle.org>.
Can't try it as only have phone at the moment but have you tried adding "get" as a prefix to your method declaration?
I still find it difficult to not name getters without the get.
--
Dr. Mark Wardle
Consultant Neurologist, Cardiff, UK
(Sent from my mobile)
> On 13 Apr 2017, at 10:44, Musall, Maik <ma...@selbstdenker.ag> wrote:
>
> Hi John,
>
> can you elaborate that on this example?
>
> Previously, I did this to filter:
>
> result = ExpressionFactory.matchExp( filterPath, filterValue ).filterObjects( result );
>
> Now I tried:
>
> result = result.stream()
> .filter( obj -> PropertyUtils.getProperty( obj, filterPath ).equals( filterValue ) )
> .collect( Collectors.toList() );
>
> Both times, I get:
>
> java.lang.IllegalArgumentException: Property 'responsibleUser' is not readable
>
> where "result" is like a List<Foo> with Foo being a DataObject that has a method called "responsibleUser", returning another DataObject subclass.
>
> Maik
>
>
>> Am 12.04.2017 um 19:11 schrieb John Huss <jo...@gmail.com>:
>>
>> Ok, you can use property utils in conjunction to call a method using
>> reflection (with a string name)
>>> On Wed, Apr 12, 2017 at 6:07 PM Musall, Maik <ma...@selbstdenker.ag> wrote:
>>>
>>> Hi John,
>>>
>>> how do you mean that? Those filter paths come from the UI, passed on by
>>> the user assembling filter criteria. I wouldn't use string filter paths if
>>> the criteria would be constant.
>>>
>>> Maik
>>>
>>>> Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
>>>>
>>>> Just use a java 8 stream and lambda in addition or instead of.
>>>> On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag>
>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> when filtering a list of objects by expression.filterObjects( list ), is
>>>>> there a way for the expression to access regular methods instead of
>>> Cayenne
>>>>> db properties?
>>>>>
>>>>> Use Case: I have a class A that has several relationships to class B,
>>> and
>>>>> it depends on a number of factors which is relevant in this case. So
>>> there
>>>>> is a method that returns either this or that relation to class B. I
>>> would
>>>>> like to include the method name in the expression path. (This was
>>> possible
>>>>> in EOF, and I just found that it doesn't work in Cayenne.)
>>>>>
>>>>> Thanks
>>>>> Maik
>>>>>
>>>>>
>>>
>>>
>
Re: in-memory filter by Expression accessing regular methods
Posted by "Musall, Maik" <ma...@selbstdenker.ag>.
Hi John,
can you elaborate that on this example?
Previously, I did this to filter:
result = ExpressionFactory.matchExp( filterPath, filterValue ).filterObjects( result );
Now I tried:
result = result.stream()
.filter( obj -> PropertyUtils.getProperty( obj, filterPath ).equals( filterValue ) )
.collect( Collectors.toList() );
Both times, I get:
java.lang.IllegalArgumentException: Property 'responsibleUser' is not readable
where "result" is like a List<Foo> with Foo being a DataObject that has a method called "responsibleUser", returning another DataObject subclass.
Maik
> Am 12.04.2017 um 19:11 schrieb John Huss <jo...@gmail.com>:
>
> Ok, you can use property utils in conjunction to call a method using
> reflection (with a string name)
> On Wed, Apr 12, 2017 at 6:07 PM Musall, Maik <ma...@selbstdenker.ag> wrote:
>
>> Hi John,
>>
>> how do you mean that? Those filter paths come from the UI, passed on by
>> the user assembling filter criteria. I wouldn't use string filter paths if
>> the criteria would be constant.
>>
>> Maik
>>
>>> Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
>>>
>>> Just use a java 8 stream and lambda in addition or instead of.
>>> On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag>
>> wrote:
>>>
>>>> Hi,
>>>>
>>>> when filtering a list of objects by expression.filterObjects( list ), is
>>>> there a way for the expression to access regular methods instead of
>> Cayenne
>>>> db properties?
>>>>
>>>> Use Case: I have a class A that has several relationships to class B,
>> and
>>>> it depends on a number of factors which is relevant in this case. So
>> there
>>>> is a method that returns either this or that relation to class B. I
>> would
>>>> like to include the method name in the expression path. (This was
>> possible
>>>> in EOF, and I just found that it doesn't work in Cayenne.)
>>>>
>>>> Thanks
>>>> Maik
>>>>
>>>>
>>
>>
Re: in-memory filter by Expression accessing regular methods
Posted by John Huss <jo...@gmail.com>.
Ok, you can use property utils in conjunction to call a method using
reflection (with a string name)
On Wed, Apr 12, 2017 at 6:07 PM Musall, Maik <ma...@selbstdenker.ag> wrote:
> Hi John,
>
> how do you mean that? Those filter paths come from the UI, passed on by
> the user assembling filter criteria. I wouldn't use string filter paths if
> the criteria would be constant.
>
> Maik
>
> > Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
> >
> > Just use a java 8 stream and lambda in addition or instead of.
> > On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag>
> wrote:
> >
> >> Hi,
> >>
> >> when filtering a list of objects by expression.filterObjects( list ), is
> >> there a way for the expression to access regular methods instead of
> Cayenne
> >> db properties?
> >>
> >> Use Case: I have a class A that has several relationships to class B,
> and
> >> it depends on a number of factors which is relevant in this case. So
> there
> >> is a method that returns either this or that relation to class B. I
> would
> >> like to include the method name in the expression path. (This was
> possible
> >> in EOF, and I just found that it doesn't work in Cayenne.)
> >>
> >> Thanks
> >> Maik
> >>
> >>
>
>
Re: in-memory filter by Expression accessing regular methods
Posted by "Musall, Maik" <ma...@selbstdenker.ag>.
Hi John,
how do you mean that? Those filter paths come from the UI, passed on by the user assembling filter criteria. I wouldn't use string filter paths if the criteria would be constant.
Maik
> Am 12.04.2017 um 19:03 schrieb John Huss <jo...@gmail.com>:
>
> Just use a java 8 stream and lambda in addition or instead of.
> On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag> wrote:
>
>> Hi,
>>
>> when filtering a list of objects by expression.filterObjects( list ), is
>> there a way for the expression to access regular methods instead of Cayenne
>> db properties?
>>
>> Use Case: I have a class A that has several relationships to class B, and
>> it depends on a number of factors which is relevant in this case. So there
>> is a method that returns either this or that relation to class B. I would
>> like to include the method name in the expression path. (This was possible
>> in EOF, and I just found that it doesn't work in Cayenne.)
>>
>> Thanks
>> Maik
>>
>>
Re: in-memory filter by Expression accessing regular methods
Posted by John Huss <jo...@gmail.com>.
Just use a java 8 stream and lambda in addition or instead of.
On Wed, Apr 12, 2017 at 4:48 PM Musall, Maik <ma...@selbstdenker.ag> wrote:
> Hi,
>
> when filtering a list of objects by expression.filterObjects( list ), is
> there a way for the expression to access regular methods instead of Cayenne
> db properties?
>
> Use Case: I have a class A that has several relationships to class B, and
> it depends on a number of factors which is relevant in this case. So there
> is a method that returns either this or that relation to class B. I would
> like to include the method name in the expression path. (This was possible
> in EOF, and I just found that it doesn't work in Cayenne.)
>
> Thanks
> Maik
>
>