Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Saving resources in transaction
[CDO] Saving resources in transaction [message #1060834] Tue, 28 May 2013 14:54 Go to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Hello,

I have this issue: I want to upload my existing file-based resources to CDO server. These resources are contained in ResourceSet and have cross-document references. The URIs in the ResourceSet are file-based since the ResourceSet is loaded from my local hard drive. However, on the CDO server I need to have those URIs little bit differently structured. For exmaple instead of having

/project/content.xmi

I would like to have something like

/allprojects/project/content

Is there any simple way to achieve this?

Regards

Martin
Re: [CDO] Saving resources in transaction [message #1060839 is a reply to message #1060834] Tue, 28 May 2013 15:17 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6441
Registered: July 2009
Senior Member
Am 28.05.2013 16:54, schrieb Martin odloucký:
> Hello,
> I have this issue: I want to upload my existing file-based resources to CDO server. These resources are contained in
> ResourceSet and have cross-document references. The URIs in the ResourceSet are file-based since the ResourceSet is
> loaded from my local hard drive. However, on the CDO server I need to have those URIs little bit differently
> structured. For exmaple instead of having
>
> /project/content.xmi
>
> I would like to have something like
>
> /allprojects/project/content
>
> Is there any simple way to achieve this?
The new "Resource Transfer Framework" is made for this purpose. With this framework the generic CDO UI supports drag and
drop of multiple files/folders between workspace, file system and repositories.

Cheers
/Eike

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


Re: [CDO] Saving resources in transaction [message #1060867 is a reply to message #1060834] Tue, 28 May 2013 18:29 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Oh, that's very nice. Is there some bit of documentation or a little code snippet to show how these classes can be used?
Re: [CDO] Saving resources in transaction [message #1060869 is a reply to message #1060867] Tue, 28 May 2013 18:43 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6441
Registered: July 2009
Senior Member
Am 28.05.2013 20:29, schrieb Martin odloucký:
> Oh, that's very nice. Is there some bit of documentation or a little code snippet to show how these classes can be used?
No, it's very new. The core framework is in http://git.eclipse.org/c/cdo/cdo.git/tree/plugins/org.eclipse.emf.cdo.transfer

The UI is currently the best usage example. For example
http://git.eclipse.org/c/cdo/cdo.git/tree/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDialog.java

Cheers
/Eike

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


Re: [CDO] Saving resources in transaction [message #1061014 is a reply to message #1060869] Wed, 29 May 2013 14:02 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Hi Eike,

thank you very much for the link. I donwloaded the plugin from Git and studied the code. I have also looked at some documentation I have found. Unfortunately, I could not grasp the basic idea. I learned that you somehow create a source and target systems (such as FileSystemTransferSystem or RespositoryTransferSystem) and then create a CDOTransform object to perform the task. I have succesfully defined a source element of a file on my disk but I have no idea how to map it to another file or to a repository location. Sadly the FileSystemUIProvider class in the transfer plugins says TODO in convertTransferTarget method in which I hoped I would have found a hint.

If you could provide just a few lines of simple code of how to do a very basic mapping you would make me happy for an entire week.

Regards

Martin
Re: [CDO] Saving resources in transaction [message #1061249 is a reply to message #1061014] Thu, 30 May 2013 18:41 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6441
Registered: July 2009
Senior Member
Am 29.05.2013 16:02, schrieb Martin odloucký:
> Hi Eike,
> thank you very much for the link. I donwloaded the plugin from Git and studied the code. I have also looked at some
> documentation I have found. Unfortunately, I could not grasp the basic idea. I learned that you somehow create a
> source and target systems (such as FileSystemTransferSystem or RespositoryTransferSystem) and then create a
> CDOTransform object to perform the task.
So you could grasp the basic idea :P

> I have succesfully defined a source element of a file on my disk but I have no idea how to map it to another file or
> to a repository location.
Try these methods:

org.eclipse.emf.cdo.transfer.CDOTransfer.map(IPath, IProgressMonitor)
org.eclipse.emf.cdo.transfer.CDOTransfer.map(String, IProgressMonitor)
org.eclipse.emf.cdo.transfer.CDOTransfer.map(CDOTransferElement, IProgressMonitor)

> Sadly the FileSystemUIProvider class in the transfer plugins says TODO in convertTransferTarget method in which I
> hoped I would have found a hint.
Yeah, due to time constraints some methods are not implemented, yet. They're not needed for basic functionality.

>
> If you could provide just a few lines of simple code of how to do a very basic mapping you would make me happy for an
> entire week.
You're almost there. Try the methods above, call CDOTransfer.perform() and you're done.

Cheers
/Eike

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


Re: [CDO] Saving resources in transaction [message #1061342 is a reply to message #1061249] Fri, 31 May 2013 09:57 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Ok Eike,

seems you won't give me anything for free, will you? Smile Well, I still believe that if you had written me five lines of code we would have saved each other a lot of time. But it seems you want to play the game. Alright then Smile

This is what I have came up with so far

CDOTransferElement source = FileSystemTransferSystem.INSTANCE.getElement(new Path("/some/file.xmi"));
CDOSession cdoSession = connector.openSession("demo", "127.0.0.1", "2036");
CDOTransaction transaction = cdoSession.openTransaction();
CDOTransferSystem target = new RepositoryTransferSystem(transaction);
CDOTransfer transfer = new CDOTransfer(source.getSystem(), target);
CDOTransferMapping mapping = transfer.map("/some/file.xmi", new NullProgressMonitor());
mapping.setRelativePath("/foo");
transfer.perform();
transaction.commit();
transaction.close();


After executing this block there is no resource 'foo' in the repo event though there was no expception thrown or semothing. Can you tell me what I am doing wrong?

Also I would like to ask if it is possible to transform resources already loaded in memory. Sometime the user creates the model and wants to upload it on the server without having it saved on hard drive before.

Thanks in advance
Re: [CDO] Saving resources in transaction [message #1061362 is a reply to message #1061342] Fri, 31 May 2013 10:33 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6441
Registered: July 2009
Senior Member
Am 31.05.2013 11:57, schrieb Martin odloucký:
> Ok Eike,
> seems you won't give me anything for free, will you? :) Well, I still believe that if you had written me five lines of
> code we would have saved each other a lot of time. But it seems you want to play the game. Alright then :)
No games. I'm just busy with the Kepler release preparations and way behind my schedule. I wish there was more
documentation available.

>
> This is what I have came up with so far
>
>
> CDOTransferElement source = FileSystemTransferSystem.INSTANCE.getElement(new Path("/some/file.xmi"));
> CDOSession cdoSession = connector.openSession("demo", "127.0.0.1", "2036");
> CDOTransaction transaction = cdoSession.openTransaction();
> CDOTransferSystem target = new RepositoryTransferSystem(transaction);
> CDOTransfer transfer = new CDOTransfer(source.getSystem(), target);
> CDOTransferMapping mapping = transfer.map("/some/file.xmi", new NullProgressMonitor());
> mapping.setRelativePath("/foo");
> transfer.perform();
> transaction.commit();
> transaction.close();
>
>
> After executing this block there is no resource 'foo' in the repo event though there was no expception thrown or
> semothing. Can you tell me what I am doing wrong?
I don't see anything that immediately pops into my eyes. What happens if you omit the setRelativePath() call? If that
doesn't help and there are no exceptions I recommend to set a breakpoint and step into the perform() call.

>
> Also I would like to ask if it is possible to transform resources already loaded in memory. Sometime the user creates
> the model and wants to upload it on the server without having it saved on hard drive before.
That's currently not supported by the resource transfer framework. If you submit a bugzilla we can discuss the new
feature there.

Cheers
/Eike

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


Re: [CDO] Saving resources in transaction [message #1061374 is a reply to message #1061362] Fri, 31 May 2013 11:18 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Thanks Eike,

I understand you are very busy and I appreciate your answers very much. I started debugging your code and I am now confident I can get it work. I have two points:

* I think that direct transfer of ResourceSets can be done by implementing something like ResourceSetTransferSystem similar to FileSystemTransferSystem. I am going to do it right now since I need it for my project.
* Your ResourceFactoryRegistryWithoutDefaults does not work correctly. I don't know what is the purpouse of this class but it corrupts ResourceSet loading capabilities. For example, ResourceSet with this factory cannot load files with pure xmi extension. I am not sure how to fix it, since do resource loading mechanism in EMF is quite complex to me.

I wish a pleasant day

Martin
Re: [CDO] Saving resources in transaction [message #1061381 is a reply to message #1061374] Fri, 31 May 2013 11:53 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6441
Registered: July 2009
Senior Member
Am 31.05.2013 13:18, schrieb Martin odloucký:
> Thanks Eike,
> I understand you are very busy and I appreciate your answers very much. I started debugging your code and I am now
> confident I can get it work. I have two points:
>
> * I think that direct transfer of ResourceSets can be done by implementing something like ResourceSetTransferSystem
> similar to FileSystemTransferSystem. I am going to do it right now since I need it for my project.
That was my idea, too ;-)

> * Your ResourceFactoryRegistryWithoutDefaults does not work correctly. I don't know what is the purpouse
How can you judge then whether it works correctly? :P

> of this class but it corrupts ResourceSet loading capabilities. For example, ResourceSet with this factory cannot load
> files with pure xmi extension. I am not sure how to fix it, since do resource loading mechanism in EMF is quite
> complex to me.
The resource transfer framework tries to figure out whether a transfer element (e.g. a file) is a model resource or a
"normal" file (see JavaDoc of ResourceFactoryRegistryWithoutDefaults) by attempting to load the file into a resourceset.
That would always succeed with the default extension / content type being registered.

You just need to register the resource factories for the files you want to be recognized (but not under the default
extension!).

Cheers
/Eike

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


Re: [CDO] Saving resources in transaction [message #1061383 is a reply to message #1061381] Fri, 31 May 2013 12:12 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
> How can you judge then whether it works correctly? Razz

Good point Smile

However, it WORKS!!!! Arrrrrgghhhhhh! Now I can easily transfer my resources in ResourceSet to my CDO server. Thank you very much Eike.
Re: [CDO] Saving resources in transaction [message #1158930 is a reply to message #1061383] Mon, 28 October 2013 07:25 Go to previous message
wang songbai is currently offline wang songbaiFriend
Messages: 27
Registered: October 2013
Junior Member
hi Martin odloucký
Can look at your code? thank you!!
Previous Topic:[CDO] parse XMI Exception?????
Next Topic:[CDO]Load an XMIResource Exception!!!
Goto Forum:
  


Current Time: Thu Aug 22 07:08:25 GMT 2019

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

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

Back to the top