Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How do I add no duplicates to cdo resource?
How do I add no duplicates to cdo resource? [message #482268] Tue, 25 August 2009 22:35 Go to next message
Eclipse UserFriend
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 #482277 is a reply to message #482268] Wed, 26 August 2009 01:52 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Hello Christian.

As for querying the model ...
What backend do you use for CDO?
If you use the HibernateStore you can query the backend with HQL.
If you use the DBStore you can query the backend with SQL.
For DBStore see http://wiki.eclipse.org/Query_DB_Store_by_using_SQL
HQL works similar.

Regards,
Kai

Christian Guenther wrote:
> 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 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
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


Re: How do I add no duplicates to cdo resource? [message #482296 is a reply to message #482290] Wed, 26 August 2009 07:07 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:ExtendedMetaData and <!DOCTYPE
Next Topic:Databinding with DateTime
Goto Forum:
  


Current Time: Fri Apr 26 11:28:47 GMT 2024

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

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

Back to the top