Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Cross references and xmi serialization
[CDO] Cross references and xmi serialization [message #551904] Tue, 10 August 2010 06:18 Go to next message
Nils Israel is currently offline Nils IsraelFriend
Messages: 72
Registered: May 2010
Member
Hi,

I have several resources and object with a unique feature named nr (ID
is set to true), say:

/parts/partTypeA/
- Part1
- Part2
/parts/partTypeB/
- Part3
- Part4
/products/cat1/
- Product1
-> Part1 (non containing reference)
-> Part3 (non containing reference)
/products/cat2/
- Product2
-> Part2 (non containing reference)

I am trying to export the objects into several xml files, one for each
resource. I am using the code from the CDO Explorer Export-command. This is:

CDOResource res = ...
List<EObject> sourceContents = res.getContents();
// Target Resource
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
String path = res.getPath().replace('/', '_').substring(1) + ".xml";
URI sourceURI = URI.createFileURI(mDirname + "/" + path);
Resource resource = resourceSet.createResource(sourceURI);
Collection<EObject> copiedRoots = EcoreUtil.copyAll(sourceContents);
resource.getContents().addAll(copiedRoots);
resource.save(null);

The problem is: the parts are referenced by their CDO id an not by my nr-id:

<Product nr="15">
<Part href="cdo://mydb/parts/partTypeA#-1/6"/>
</Product>

If I try to import the xmi-Resources into an empty database I get a
DanglingReferenceException: The part is not contained n a resource.

I would like to change my model, so I am trying to export the objects,
migrate the data in the xml files manually an reimport them into an
empty cdo store.
Is there a way to keep the cross references after an export/import
operation?

One possible solution could be:
Create a class 'Folder' in my model and use this class to organize the
data in a _single_ resource. But that doesn't feel right...

Best regards,
Nils
Re: [CDO] Cross references and xmi serialization [message #551915 is a reply to message #551904] Tue, 10 August 2010 07:10 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010400020803080805010407
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi Nils,

Performance-wise there 's not much of a difference between one huge CDOResource (in a repository) or multiple smaller ones. Of course sometimes it makes sense for organizational reasons to have multiple well-known entry points into the persistent object graph.

I think the trick with cross references is always to copy all objects in one huge copy operation. Maybe Ed knows some tricks on how to do this with multiple source and target resources. Maybe use EcoreUtil.Copier directly, like:

Copier copier = new Copier();
Collection<T> result1 = copier.copyAll(res1.getContents());
Collection<T> result2 = copier.copyAll(res2.getContents());
Collection<T> result3 = copier.copyAll(res3.getContents());
copier.copyReferences();

Cheers
/Eike

Contact: http://www.esc-net.de Blogger <http://thegordian.blogspot.com>Twitter <http://twitter.com/eikestepper>Linkedin <http://de.linkedin.com/in/eikestepper>Xing <http://www.xing.com/profile/Eike_Stepper>
Article: What exactly is inside that p2 repository? < http://thegordian.blogspot.com/2010/05/what-exactly-is-insid e-that-p2.html>

I'm going to Eclipse Summit Europe 2010 <http://www.eclipsesummit.org/>



Am 10.08.2010 08:18, schrieb Nils Israel:
> Hi,
>
> I have several resources and object with a unique feature named nr (ID is set to true), say:
>
> /parts/partTypeA/
> - Part1
> - Part2
> /parts/partTypeB/
> - Part3
> - Part4
> /products/cat1/
> - Product1
> -> Part1 (non containing reference)
> -> Part3 (non containing reference)
> /products/cat2/
> - Product2
> -> Part2 (non containing reference)
>
> I am trying to export the objects into several xml files, one for each resource. I am using the code from the CDO Explorer Export-command. This is:
>
> CDOResource res = ...
> List<EObject> sourceContents = res.getContents();
> // Target Resource
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
> String path = res.getPath().replace('/', '_').substring(1) + ".xml";
> URI sourceURI = URI.createFileURI(mDirname + "/" + path);
> Resource resource = resourceSet.createResource(sourceURI);
> Collection<EObject> copiedRoots = EcoreUtil.copyAll(sourceContents);
> resource.getContents().addAll(copiedRoots);
> resource.save(null);
>
> The problem is: the parts are referenced by their CDO id an not by my nr-id:
>
> <Product nr="15">
> <Part href="cdo://mydb/parts/partTypeA#-1/6"/>
> </Product>
>
> If I try to import the xmi-Resources into an empty database I get a DanglingReferenceException: The part is not contained n a resource.
>
> I would like to change my model, so I am trying to export the objects, migrate the data in the xml files manually an reimport them into an empty cdo store.
> Is there a way to keep the cross references after an export/import operation?
>
> One possible solution could be:
> Create a class 'Folder' in my model and use this class to organize the data in a _single_ resource. But that doesn't feel right...
>
> Best regards,
> Nils
>

--------------010400020803080805010407
Content-Type: multipart/related;
boundary="------------080906050200040706070709"


--------------080906050200040706070709
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Nils,<br>
<br>
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
Performance-wise there
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
<meta content="text/html; charset=ISO-8859-15"
http-equiv="Content-Type">
's not much of a difference between one huge CDOResource (in a
repository) or multiple smaller ones. Of course sometimes it makes
sense for organizational reasons to have multiple well-known entry
points into the persistent object graph.<br>
<br>
I think the trick with cross references is always to copy all
objects in one huge copy operation. Maybe Ed knows some tricks on
how to do this with multiple source and target resources. Maybe use
EcoreUtil.Copier directly, like:<br>
<br>


Re: [CDO] Cross references and xmi serialization [message #551916 is a reply to message #551904] Tue, 10 August 2010 07:24 Go to previous messageGo to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 307
Registered: July 2009
Location: Germany
Senior Member
Hi,

comments below.


Am 10.08.2010 08:18, schrieb Nils Israel:
> Hi,
>
> I have several resources and object with a unique feature named nr (ID
> is set to true), say:
>
> /parts/partTypeA/
> - Part1
> - Part2
> /parts/partTypeB/
> - Part3
> - Part4
> /products/cat1/
> - Product1
> -> Part1 (non containing reference)
> -> Part3 (non containing reference)
> /products/cat2/
> - Product2
> -> Part2 (non containing reference)
>
> I am trying to export the objects into several xml files, one for each
> resource. I am using the code from the CDO Explorer Export-command.
> This is:
>
> CDOResource res = ...
> List<EObject> sourceContents = res.getContents();
> // Target Resource
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
>
> new XMIResourceFactoryImpl());
> String path = res.getPath().replace('/', '_').substring(1) + ".xml";
> URI sourceURI = URI.createFileURI(mDirname + "/" + path);
> Resource resource = resourceSet.createResource(sourceURI);
> Collection<EObject> copiedRoots = EcoreUtil.copyAll(sourceContents);
> resource.getContents().addAll(copiedRoots);
> resource.save(null);
>
> The problem is: the parts are referenced by their CDO id an not by my
> nr-id:
>
> <Product nr="15">
> <Part href="cdo://mydb/parts/partTypeA#-1/6"/>
> </Product>
Yes, if you think about it, this is exactly what you do. You copy a
resource but the targets are still in the database -- you do not *move*
the targets, only make a copy of them. I don't know if such a logic
exists, but what you might want to do is to traverse your XMI-model(s)
before saving and readjust the cross references. Maybe this can be done
by using the EMF Copier util or a subclass of it. But in general, I
think, you have to adjust the cross-references manually (i.e., by custom
code).

> If I try to import the xmi-Resources into an empty database I get a
> DanglingReferenceException: The part is not contained n a resource.
I guess the import should work in the same way -> you have to adjust the
cross-references again to the CDO-backend.

Cheers,
Stefan
Re: [CDO] Cross references and xmi serialization [message #552440 is a reply to message #551915] Thu, 12 August 2010 09:08 Go to previous message
Nils Israel is currently offline Nils IsraelFriend
Messages: 72
Registered: May 2010
Member
Hi Eike and Stefan,

thanks for your hints. I am now using a single resource and the export
and import is working well.

Best regards,
Nils

Am 10.08.2010 09:10, schrieb Eike Stepper:
> Hi Nils,
>
> Performance-wise there 's not much of a difference between one huge
> CDOResource (in a repository) or multiple smaller ones. Of course
> sometimes it makes sense for organizational reasons to have multiple
> well-known entry points into the persistent object graph.
>
> I think the trick with cross references is always to copy all objects in
> one huge copy operation. Maybe Ed knows some tricks on how to do this
> with multiple source and target resources. Maybe use EcoreUtil.Copier
> directly, like:
>
> Copier copier = new Copier();
> Collection<T> result1 = copier.copyAll(res1.getContents());
> Collection<T> result2 = copier.copyAll(res2.getContents());
> Collection<T> result3 = copier.copyAll(res3.getContents());
> copier.copyReferences();
>
> Cheers
> /Eike
>
> Contact: http://www.esc-net.de Blogger
> <http://thegordian.blogspot.com>Twitter
> <http://twitter.com/eikestepper>Linkedin
> <http://de.linkedin.com/in/eikestepper>Xing
> <http://www.xing.com/profile/Eike_Stepper>
> Article: What exactly is inside that p2 repository?
> < http://thegordian.blogspot.com/2010/05/what-exactly-is-insid e-that-p2.html>
>
> I'm going to Eclipse Summit Europe 2010 <http://www.eclipsesummit.org/>
>
>
>
> Am 10.08.2010 08:18, schrieb Nils Israel:
>> Hi,
>>
>> I have several resources and object with a unique feature named nr (ID
>> is set to true), say:
>>
>> /parts/partTypeA/
>> - Part1
>> - Part2
>> /parts/partTypeB/
>> - Part3
>> - Part4
>> /products/cat1/
>> - Product1
>> -> Part1 (non containing reference)
>> -> Part3 (non containing reference)
>> /products/cat2/
>> - Product2
>> -> Part2 (non containing reference)
>>
>> I am trying to export the objects into several xml files, one for each
>> resource. I am using the code from the CDO Explorer Export-command.
>> This is:
>>
>> CDOResource res = ...
>> List<EObject> sourceContents = res.getContents();
>> // Target Resource
>> ResourceSet resourceSet = new ResourceSetImpl();
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
>>
>> new XMIResourceFactoryImpl());
>> String path = res.getPath().replace('/', '_').substring(1) + ".xml";
>> URI sourceURI = URI.createFileURI(mDirname + "/" + path);
>> Resource resource = resourceSet.createResource(sourceURI);
>> Collection<EObject> copiedRoots = EcoreUtil.copyAll(sourceContents);
>> resource.getContents().addAll(copiedRoots);
>> resource.save(null);
>>
>> The problem is: the parts are referenced by their CDO id an not by my
>> nr-id:
>>
>> <Product nr="15">
>> <Part href="cdo://mydb/parts/partTypeA#-1/6"/>
>> </Product>
>>
>> If I try to import the xmi-Resources into an empty database I get a
>> DanglingReferenceException: The part is not contained n a resource.
>>
>> I would like to change my model, so I am trying to export the objects,
>> migrate the data in the xml files manually an reimport them into an
>> empty cdo store.
>> Is there a way to keep the cross references after an export/import
>> operation?
>>
>> One possible solution could be:
>> Create a class 'Folder' in my model and use this class to organize the
>> data in a _single_ resource. But that doesn't feel right...
>>
>> Best regards,
>> Nils
>>
Previous Topic:Generate model only once for different domains
Next Topic:Do bounds (lower and upper) of EReference have any effect?
Goto Forum:
  


Current Time: Fri Apr 26 17:27:07 GMT 2024

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

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

Back to the top