You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2009/06/05 10:43:33 UTC

Problems with Expression.match()

I'm trying to figure out if a CayenneDataObject matches an
expression and I run into various and sundry problems.

This is the final solution I ended up with, but it's pretty ugly.


		List l=getDataContext().performQuery(new SelectQuery(Treatment.class,
				expression)));
		return l.contains(this);


1. I can't use expression.match() because it will fail when the
expression contains
an array in the path. I.e. matchExp(role.members.user, user) here "members"
will return a list, and this causes an exception for .match(), whereas it works
fine in a query.

2. In the above statement I don't know how to add a andExp() to only return
"this", so I get a bigger query result than I need + unecessary post processing.
I've run into this problem previously as well, without finding an
elegant solution.

-- 
Øyvind Harboe
Embedded software and hardware consulting services
http://consulting.zylin.com

Re: Problems with Expression.match()

Posted by Andrus Adamchik <an...@objectstyle.org>.
Here is one that I found:

https://issues.apache.org/jira/browse/CAY-419

The description in the Jira is a bit vague, but the idea seems to be  
the same.

Andrus

On Jun 10, 2009, at 6:40 PM, Andrey Razumovsky wrote:

> #1. I can have a look. Please find JIRA or create a new one
>
> #2. You should create table ID as ObjAttrbute and attach
> ExpressionFactory.noMatchExp("id", getId())
>
>
> 2009/6/10 Øyvind Harboe <oy...@zylin.com>
>
>> On Wed, Jun 10, 2009 at 5:26 PM, Andrus Adamchik<andrus@objectstyle.org 
>> >
>> wrote:
>>>
>>> On Jun 5, 2009, at 11:43 AM, Øyvind Harboe wrote:
>>>
>>>> 1. I can't use expression.match() because it will fail when the
>>>> expression contains
>>>> an array in the path. I.e. matchExp(role.members.user, user) here
>>>> "members"
>>>> will return a list, and this causes an exception for .match(),  
>>>> whereas
>> it
>>>> works
>>>> fine in a query.
>>>
>>> Yeah, this is a known limitation for in memory processing. We  
>>> probably
>> even
>>> have a Jira to fix it.
>>
>> If you find the JIRA # I'll see if we can't have a go at fixing it...
>>
>>>> 2. In the above statement I don't know how to add a andExp() to  
>>>> only
>>>> return
>>>> "this", so I get a bigger query result than I need + unecessary  
>>>> post
>>>> processing.
>>>> I've run into this problem previously as well, without finding an
>>>> elegant solution.
>>>
>>> Not sure I understand this.
>>
>> Since I can't use .match() I want to run expression against the  
>> database to
>> see if "this" matches the filter, but I don't want *lots* of returned
>> results where I need to check that "this" is in the list of objects.
>>
>> If I could create an expression that filtered out all objects that  
>> was not
>> "this", then I would know that the object matched the expression if
>> a single record was returned.
>>
>> --
>> Øyvind Harboe
>> Embedded software and hardware consulting services
>> http://consulting.zylin.com
>>


Re: Problems with Expression.match()

Posted by Andrey Razumovsky <ra...@gmail.com>.
#1. I can have a look. Please find JIRA or create a new one

#2. You should create table ID as ObjAttrbute and attach
ExpressionFactory.noMatchExp("id", getId())


2009/6/10 Øyvind Harboe <oy...@zylin.com>

> On Wed, Jun 10, 2009 at 5:26 PM, Andrus Adamchik<an...@objectstyle.org>
> wrote:
> >
> > On Jun 5, 2009, at 11:43 AM, Øyvind Harboe wrote:
> >
> >> 1. I can't use expression.match() because it will fail when the
> >> expression contains
> >> an array in the path. I.e. matchExp(role.members.user, user) here
> >> "members"
> >> will return a list, and this causes an exception for .match(), whereas
> it
> >> works
> >> fine in a query.
> >
> > Yeah, this is a known limitation for in memory processing. We probably
> even
> > have a Jira to fix it.
>
> If you find the JIRA # I'll see if we can't have a go at fixing it...
>
> >> 2. In the above statement I don't know how to add a andExp() to only
> >> return
> >> "this", so I get a bigger query result than I need + unecessary post
> >> processing.
> >> I've run into this problem previously as well, without finding an
> >> elegant solution.
> >
> > Not sure I understand this.
>
> Since I can't use .match() I want to run expression against the database to
> see if "this" matches the filter, but I don't want *lots* of returned
> results where I need to check that "this" is in the list of objects.
>
> If I could create an expression that filtered out all objects that was not
> "this", then I would know that the object matched the expression if
> a single record was returned.
>
> --
> Øyvind Harboe
> Embedded software and hardware consulting services
> http://consulting.zylin.com
>

Re: Problems with Expression.match()

Posted by Øyvind Harboe <oy...@zylin.com>.
On Wed, Jun 10, 2009 at 5:26 PM, Andrus Adamchik<an...@objectstyle.org> wrote:
>
> On Jun 5, 2009, at 11:43 AM, Øyvind Harboe wrote:
>
>> 1. I can't use expression.match() because it will fail when the
>> expression contains
>> an array in the path. I.e. matchExp(role.members.user, user) here
>> "members"
>> will return a list, and this causes an exception for .match(), whereas it
>> works
>> fine in a query.
>
> Yeah, this is a known limitation for in memory processing. We probably even
> have a Jira to fix it.

If you find the JIRA # I'll see if we can't have a go at fixing it...

>> 2. In the above statement I don't know how to add a andExp() to only
>> return
>> "this", so I get a bigger query result than I need + unecessary post
>> processing.
>> I've run into this problem previously as well, without finding an
>> elegant solution.
>
> Not sure I understand this.

Since I can't use .match() I want to run expression against the database to
see if "this" matches the filter, but I don't want *lots* of returned
results where I need to check that "this" is in the list of objects.

If I could create an expression that filtered out all objects that was not
"this", then I would know that the object matched the expression if
a single record was returned.

-- 
Øyvind Harboe
Embedded software and hardware consulting services
http://consulting.zylin.com

Re: Problems with Expression.match()

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jun 5, 2009, at 11:43 AM, Øyvind Harboe wrote:

> 1. I can't use expression.match() because it will fail when the
> expression contains
> an array in the path. I.e. matchExp(role.members.user, user) here  
> "members"
> will return a list, and this causes an exception for .match(),  
> whereas it works
> fine in a query.

Yeah, this is a known limitation for in memory processing. We probably  
even have a Jira to fix it.


> 2. In the above statement I don't know how to add a andExp() to only  
> return
> "this", so I get a bigger query result than I need + unecessary post  
> processing.
> I've run into this problem previously as well, without finding an
> elegant solution.

Not sure I understand this.

Andrus