Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Comparing object ids with OCL query
[CDO] Comparing object ids with OCL query [message #987766] Wed, 28 November 2012 02:21 Go to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Hi,

How would I write an OCL query to compare CDO model objects to determine whether one is the same instance as the other. The same in this case would mean they have the same cdo id. I'm after a query something like this:

MyCompany.allInstances()->select(e:MyCompany|e.shippingInfo = infoObject)

Where MyCompany contains an uncontained reference to a model object of type ShippingInfo which is called "shippingInfo" and I want to fetch all the MyCompany objects that have a specific instance of the ShippingInfo object called "infoObject" that has been reused among multiple instances of MyCompany. Is there a way to do an object comparison to determine if they are the same model object? I've tried doing the above query but got an illegal parameter exception. I also tried passing the CDOID object for infoObject instead but got the same error. Any suggestions would be appreciated.

One added question: Will the ocl query handling accept parameter types other than string? So far I've been using string parameter values and not had any trouble. But it doesn't seem to like CDOID objects or Long parameters.

Thanks,
Warwick

[Updated on: Wed, 28 November 2012 02:29]

Report message to a moderator

Re: [CDO] Comparing object ids with OCL query [message #987771 is a reply to message #987766] Wed, 28 November 2012 04:15 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 28.11.2012 03:21, schrieb Warwick Burrows:
> Hi,
>
> How would I write an OCL query to compare CDO model objects to whether one is the same instance as the other. The same
> in this case would mean they have the same cdo id. I'm after a query something like this:
>
> MyCompany.allInstances()->select(e:MyCompany|e.shippingInfo = infoObject)
>
> Where MyCompany contains an uncontained reference to a model object of type ShippingInfo which is called
> "shippingInfo" and I want to fetch all the MyCompany objects that have a specific instance of the ShippingInfo object
> called "infoObject" that has been reused among multiple instances of MyCompany. Is there a way to do an object
> comparison to determine if they are the same model object? I've tried doing the above query but got an illegal
> parameter exception.
It's always good to share the stack traces of exceptions ;-)

> I also tried passing the CDOID object for infoObject instead but got the same error. Any suggestions would be
> appreciated.
It strikes me that this is really an OCL question rather than a CDO one. Or did I miss something?

Unfortunately I'm everything but an OCL expert. Perhaps Christian is (cc'ed ). If others can't help here I'd suggest to
ask OCL questions on the OCl forum.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Comparing object ids with OCL query [message #988326 is a reply to message #987766] Thu, 29 November 2012 12:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

OCL compares objects by object identity, which in practice means the
same lump of memory.

The 'same' object should have only one copy in each domain that host
that object, e.g each of
- your ResourceSet
- your local CDO repo
- a central CDO repo
- my local CDO repo
- my ResourceSet
and these domains should not be cross-connected since the object in your
ResourceSet will be a different lump of memory to the object in my
ResourceSet even if we share the same CPU.

The relevant loaders for the ResourceSets should ensure the uniqueness
of objects, so your question of 'are they the same' should not arise. If
it does, then there seems to be a bug in the loading. If you really
expect different lumps of memory you must do a deep compare and identify
what is permitted to be different.

Regards

Ed Willink



On 28/11/2012 02:21, Warwick Burrows wrote:
> Hi,
>
> How would I write an OCL query to compare CDO model objects to whether
> one is the same instance as the other. The same in this case would
> mean they have the same cdo id. I'm after a query something like this:
>
> MyCompany.allInstances()->select(e:MyCompany|e.shippingInfo = infoObject)
>
> Where MyCompany contains an uncontained reference to a model object of
> type ShippingInfo which is called "shippingInfo" and I want to fetch
> all the MyCompany objects that have a specific instance of the
> ShippingInfo object called "infoObject" that has been reused among
> multiple instances of MyCompany. Is there a way to do an object
> comparison to determine if they are the same model object? I've tried
> doing the above query but got an illegal parameter exception. I also
> tried passing the CDOID object for infoObject instead but got the same
> error. Any suggestions would be appreciated.
>
> Thanks,
> Warwick
>
Re: [CDO] Comparing object ids with OCL query [message #988380 is a reply to message #988326] Thu, 29 November 2012 16:41 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Hi Ed,

Thanks for your response. I do expect that the underlying implementation in CDO ensures entity uniqueness as you've noted and I don't want to deep compare the two objects just to know if this is the same object e.g. has the same CDOID. So what I was asking was how do I express an object identity comparison like this in OCL so that it will work with the underlying CDO implementation? e.g. is this the right OCL syntax to compare two CDO objects to see if they are the same object (but not do a deep compare).

MyCompany.allInstances()->select(e:MyCompany|e.shippingInfo = infoObject)

Thanks,
Warwick
Re: [CDO] Comparing object ids with OCL query [message #988540 is a reply to message #988380] Fri, 30 November 2012 12:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Never use allInstances if there is all alternative. By analogy, you seem
to be testing whether 2000 is the number 2000 by searching the domain of
numbers to see it 2000 is there. Of course it is. It was number before
you started. Your CDO object is an object, so of course it is equals to
itself.

You test equality in OCL using the "=" comparison operator.

Regards

Ed Willink


On 29/11/2012 16:41, Warwick Burrows wrote:
> Hi Ed,
>
> Thanks for your response. I do expect that the underlying
> implementation in CDO ensures entity uniqueness as you've noted and I
> don't want to deep compare the two objects just to know if this is the
> same object e.g. has the same CDOID. So what I was asking was how do I
> express an object identity comparison like this in OCL so that it will
> work with the underlying CDO implementation? e.g. is this the right
> OCL syntax to compare two CDO objects to see if they are the same
> object (but not do a deep compare).
>
> MyCompany.allInstances()->select(e:MyCompany|e.shippingInfo = infoObject)
>
> Thanks,
> Warwick
>
Re: [CDO] Comparing object ids with OCL query [message #988597 is a reply to message #988540] Fri, 30 November 2012 16:07 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
I think you misunderstand what I'm trying to query CDO for. To use your analogy: I was given 2000 as a parameter and I want a set of the model objects that contain 2000 in the shippingInfo field, not the object 2000 itself.

In any case if object equality is also tested with "=" then I'll try that again. I got an error when I first tried it but that may have been another issue. For example I found in another case that I also needed to exclude objects where the shippingInfo field was null otherwise I got an error that resulted in the "Legacy Model Not Enabled" exception that I mentioned in another thread. And I'll check whether I can avoid allInstances().

Thanks,
Warwick

Re: [CDO] Comparing object ids with OCL query [message #988609 is a reply to message #988597] Fri, 30 November 2012 17:05 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 30.11.2012 17:07, schrieb Warwick Burrows:
> [...] I got an error that resulted in the "Legacy Model Not Enabled" exception
At the client-side? Does that mean your model is not regenerated specifically for CDO?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Comparing object ids with OCL query [message #988614 is a reply to message #988609] Fri, 30 November 2012 17:21 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Hi Eike,

No the Legacy Mode exception was misleading. It's due to the same bug I noted in this thread:

http://www.eclipse.org/forums/index.php/mv/msg/377889/915628/#msg_915628

and have opened this bugzilla for:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=389826

Unfortunately it masks ocl syntax and other related errors as model errors which makes it really confusing to debug.

Thanks,
Warwick
Re: [CDO] Comparing object ids with OCL query [message #988619 is a reply to message #988614] Fri, 30 November 2012 17:36 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 30.11.2012 18:21, schrieb Warwick Burrows:
> Hi Eike,
>
> No the Legacy Mode exception was misleading. It's due to the same bug I noted in this thread:
>
> http://www.eclipse.org/forums/index.php/mv/msg/377889/915628/#msg_915628
Ah, that unfortunate thing ;-(

> and have opened this bugzilla for:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=389826
Unfortunately I can't imagine that I change CDO's generic query API to satisfy the OCL implementation (I think that was
Ed Willink's suggestion).

>
> Unfortunately it masks ocl syntax and other related errors as model errors which makes it really confusing to debug.
I see.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Comparing object ids with OCL query [message #988622 is a reply to message #988619] Fri, 30 November 2012 17:45 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Actually the problem is in OCLQueryHandler.executeQuery() so it should be ok to put OCL specific checks in there? Line 162 is where this code is:

      Object result = evaluate(query, object);
      if (result instanceof Collection<?>)
      {
        for (Object element : (Collection<?>)result)
        {
          if (!addResult(element, context, view))
          {
            break;
          }
        }
      }
      else
      {
        addResult(result, context, view);
      }


So its possible that you could check for the objects like OclInvalid here and not pass them on to AddResult unprocessed.

Warwick

Re: [CDO] Comparing object ids with OCL query [message #988628 is a reply to message #988622] Fri, 30 November 2012 18:04 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 30.11.2012 18:45, schrieb Warwick Burrows:
> Actually the problem is in OCLQueryHandler.executeQuery() so it should be ok to put OCL specific checks in there?
> Line 162 is where this code is:
>
>
> Object result = evaluate(query, object);
> if (result instanceof Collection<?>)
> {
> for (Object element : (Collection<?>)result)
> {
> if (!addResult(element, context, view))
> {
> break;
> }
> }
> }
> else
> {
> addResult(result, context, view);
> }
>
>
> So its possible that you could check for the objects like OclInvalid here and not pass them on to AddResult unprocessed.
I see. Is it possible that you provide a patch on that bug?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Comparing object ids with OCL query [message #988629 is a reply to message #988628] Fri, 30 November 2012 18:09 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
What's the right way to handle it? Throw an exception? Also is there a way to determine why OclInvalid was returned (Ed)?
Re: [CDO] Comparing object ids with OCL query [message #988630 is a reply to message #988629] Fri, 30 November 2012 18:13 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 30.11.2012 19:09, schrieb Warwick Burrows:
> What's the right way to handle it? Throw an exception?
I would start/try with this.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


> Also is there a way to determine why OclInvalid was returned (Ed)?


Re: [CDO] Comparing object ids with OCL query [message #988640 is a reply to message #988630] Fri, 30 November 2012 19:33 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member

> Also is there a way to determine why OclInvalid was returned (Ed)?

I should clarify that I meant is there a way to query the OCL layer for the reason for the error so it can be returned in the exception.

Re: [CDO] Comparing object ids with OCL query [message #988668 is a reply to message #988629] Fri, 30 November 2012 22:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

There is no way with the Ecore-based OCL to determine the exception
reason from the OclInvalid singleton returned by the Query facade.

Java exceptions are used, so if you dig into QueryImpl.evaluate you find
code such as

try {
result = ev.visitExpression(expression);
} catch (EvaluationHaltedException e) {
result = environment.getOCLStandardLibrary().getInvalid();
}

that converts a rich exception to the opaque singleton. You can catch
the exception yourself if you use

expression.accept(ev);

For the Ecore-based OCL, the exception usage is non-API so what you find
will be only accidentally useful.

For the experimental Pivot-based OCL, usage of parameterized
InvalidValueExceptions is envisaged to be
part of the API and is wrapped inside the returned non-singleton
OclInvalid instance.
---

The right way to communicate through the CDO protocols is outside my
knowledge.

If CDO has a good error reporting side-channel, use it.
If not, create an in-band CDO-wise, out-of-band application-wise, object
to carry the non-model information.

Regards

Ed Willink

On 30/11/2012 18:09, Warwick Burrows wrote:
> What's the right way to handle it? Throw an exception? Also is there
> a way to determine why OclInvalid was returned (Ed)?
Re: [CDO] Comparing object ids with OCL query [message #988669 is a reply to message #988668] Fri, 30 November 2012 23:16 Go to previous message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Ok thanks Ed
Previous Topic:[CDO] Problem with concurrent read and write threads
Next Topic:[EMF] Implementing Instance Model Inheritance
Goto Forum:
  


Current Time: Fri Mar 29 07:17:13 GMT 2024

Powered by FUDForum. Page generated in 0.05015 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top