How do I add no duplicates to cdo resource? [message #482268] |
Tue, 25 August 2009 22:35 |
Eclipse User |
|
|
|
Originally posted by: guen.my-lounge.net
Hi!
I just started with EMF and CDO :-), and I'am trying to read in a huge
external data set to the new EMF/CDO model. The external data set
contains some duplicate data and I have to read it in several time,
cause it is changing by time. Now I'am totally stuck on the problem to
avoid duplicates in the new model :-(
Example Code, duplicate/unique objects are defined by their name:
....
Foo foo1 = FooFactory.eINSTANCE.createFoo();
foo1.setName( "same" );
Foo foo2 = FooFactory.eINSTANCE.createFoo();
foo2.setName( "same" );
Resource resource = transaction.getResource( path ); // CDOTransaction
resource.getContents().add( foo1 );
resource.getContents().add( foo2 ); // should not add this obj!!!
I tried to check if it exist before with
resource.getContents().contains( foo2 ) but it's not possible to
override the equals method of Foo?! .. or do I have to query for
existing object? ... I couldn't find some examples for querying the
model :-(
Thanks and Greetz
guen
|
|
|
|
Re: How do I add no duplicates to cdo resource? [message #482290 is a reply to message #482268] |
Wed, 26 August 2009 06:16 |
|
Christian,
Have you tried EcoreUtil.equals(EObject, EObject)?
Is it appropriate?
Cheers
/Eike
----
http://thegordian.blogspot.com
Christian Guenther schrieb:
> Hi!
>
> I just started with EMF and CDO :-), and I'am trying to read in a huge
> external data set to the new EMF/CDO model. The external data set
> contains some duplicate data and I have to read it in several time,
> cause it is changing by time. Now I'am totally stuck on the problem to
> avoid duplicates in the new model :-(
>
> Example Code, duplicate/unique objects are defined by their name:
>
> ....
> Foo foo1 = FooFactory.eINSTANCE.createFoo();
> foo1.setName( "same" );
>
> Foo foo2 = FooFactory.eINSTANCE.createFoo();
> foo2.setName( "same" );
>
> Resource resource = transaction.getResource( path ); // CDOTransaction
> resource.getContents().add( foo1 );
> resource.getContents().add( foo2 ); // should not add this obj!!!
>
> I tried to check if it exist before with
> resource.getContents().contains( foo2 ) but it's not possible to
> override the equals method of Foo?! .. or do I have to query for
> existing object? ... I couldn't find some examples for querying the
> model :-(
>
>
> Thanks and Greetz
> guen
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: How do I add no duplicates to cdo resource? [message #482296 is a reply to message #482290] |
Wed, 26 August 2009 07:07 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Christian,
It seems to me that anyone can call setName after you've added the
object and still end up with two objects with the same name. Iterating
over the contents and looking for an object with a matching name, or
using EcoreUtil.equals if you want to do a deep structural comparison,
is the only way.
Eike Stepper wrote:
> Christian,
>
> Have you tried EcoreUtil.equals(EObject, EObject)?
> Is it appropriate?
>
> Cheers
> /Eike
>
> ----
> http://thegordian.blogspot.com
>
>
>
> Christian Guenther schrieb:
>> Hi!
>>
>> I just started with EMF and CDO :-), and I'am trying to read in a
>> huge external data set to the new EMF/CDO model. The external data
>> set contains some duplicate data and I have to read it in several
>> time, cause it is changing by time. Now I'am totally stuck on the
>> problem to avoid duplicates in the new model :-(
>>
>> Example Code, duplicate/unique objects are defined by their name:
>>
>> ....
>> Foo foo1 = FooFactory.eINSTANCE.createFoo();
>> foo1.setName( "same" );
>>
>> Foo foo2 = FooFactory.eINSTANCE.createFoo();
>> foo2.setName( "same" );
>>
>> Resource resource = transaction.getResource( path ); // CDOTransaction
>> resource.getContents().add( foo1 );
>> resource.getContents().add( foo2 ); // should not add this obj!!!
>>
>> I tried to check if it exist before with
>> resource.getContents().contains( foo2 ) but it's not possible to
>> override the equals method of Foo?! .. or do I have to query for
>> existing object? ... I couldn't find some examples for querying the
>> model :-(
>>
>>
>> Thanks and Greetz
>> guen
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04000 seconds