Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] - CDOResource(Questions on CDOResource Nodes (File Management) and using it across sessions)
[CDO] - CDOResource [message #1780928] Tue, 30 January 2018 06:41 Go to next message
Nirmal Kanagasabai is currently offline Nirmal KanagasabaiFriend
Messages: 8
Registered: January 2018
Junior Member
Hello Team,

1] The first question is about the CDO's Virtual File system (aka ResourceTree).

Right now, our client presents the users with a browser where we can create/load/save the model elements in XMI format. We would like to list down the contents of a CDO repository in the same way. The idea is to have our model elements organized into files and folders which facilitate an easy access. I would be glad if you can help me with a graceful way of creating and working with files and folders.

I read the documentation and the available online and created an unbaked version of CDOResourceFolder and added a CDO resource into it.

cdoTransaction = openTransaction();
CDOResourceFolder resourceFolder = cdoTransaction.createResourceFolder(folderName);
resourceFolder.addResource(resourceName);
CDOResource resource = cdoTransaction.createResource("/" + folderName + "/" +resourceName);
commitTransaction(cdoTransaction);


I am pretty sure I am missing something here or have interpreted the implementation wrongly. If I create an Online Transactional copy, I find the resourceFolder to be created and it contains the resource. However, I end up getting the Error (Please find attached Error.txt) printed in the console.

2] The second question is regarding the transactions. I happen to use one transaction to create the resource. I commit and close the transaction right after.

In order to work on the resource, I first open the transaction and get the resource, add the object to the resource content, commit and close the transaction. Please correct me if I am wrong. Right now, I am using:

CDOResource resource = transaction.getResource("/path/to/resource");
resource.getContents().add(UserDefinedbject);


However, I will have to find the resourcePath dynamically and not hard-code this. I can obtain the ResourceSet using the EditingDomain. I couldn't find any way to obtain the resourcePath. Is there anything that could be done about it?

  • Attachment: Error.txt
    (Size: 3.24KB, Downloaded 27 times)
Re: [CDO] - CDOResource [message #1781068 is a reply to message #1780928] Thu, 01 February 2018 07:35 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6402
Registered: July 2009
Senior Member
You can open and close transactions for each modification. You could also open just one transaction and apply several modifications. You can commit a transaction many times, whenever you want to.

You can get the resource set of the transaction by calling transaction.getResourceSet().

You can access the top-level nodes of the resource tree by calling transaction.getRootResource().getContents().

Regarding your error, the following two statements should do exactly the same:
1) transaction.createResourceFolder(folderName).addResource(resourceName);
2) transaction.createResource("/" + folderName + "/" +resourceName);

So, if you execute them both, the second one should indeed throw a "Duplicate resource node" exception.

Did that answer all your questions?
Re: [CDO] - CDOResource [message #1781135 is a reply to message #1781068] Thu, 01 February 2018 18:41 Go to previous messageGo to next message
Nirmal Kanagasabai is currently offline Nirmal KanagasabaiFriend
Messages: 8
Registered: January 2018
Junior Member
Hello Eike,

Thank you very much for the prompt reply. I can confirm that it did answer both of my questions.

I have another question regarding the objects that have been altered. Our application makes use of EMF Edit (EditingDomain, CommandStack).

As of now, I am trying to open a new transaction before and after this to capture the changes. However, to persist the changes, I will have to do something like,
CDOTransaction transaction = SessionManager.openTransaction();
CDOResource resource = transaction.getRootResource();
editingDomain.getCommandStack().execute(command);
resource.getContents().add(<Not sure what to add here>); 
transaction.commit();


One of the ways I tried to do this is to use:
command.getAffectedObjects()
This returns me a Collection<?> of objects.

I am not sure if that's the best way to tackle this issue. In short, I would like to know if there is a way to easily keep track of all the changes that the objects underwent and then persist them? I humbly request you to guide me on this.

Regards,
Nirmal

[Updated on: Thu, 01 February 2018 21:16]

Report message to a moderator

Re: [CDO] - CDOResource [message #1781153 is a reply to message #1781135] Fri, 02 February 2018 06:27 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6402
Registered: July 2009
Senior Member
CDO "sees" all model modifications, whether you apply them directly through the model's API or through EMF's Edit layer. In other words, if you execute one or more commands on the editing domain's command stack, the transaction automatically gets dirty and you just need to commit it at some point. There's no need to collect the commands' results and tell CDO explicitely about them.
Re: [CDO] - CDOResource [message #1781154 is a reply to message #1781153] Fri, 02 February 2018 06:32 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6402
Registered: July 2009
Senior Member
Of course, if you want to support Undo through the command stack, you should wrap all model modifications, including resource.getContents().add(xxx), in commands. For example org.eclipse.emf.edit.command.AddCommand.AddCommand(EditingDomain, EList<?>, Collection<?>).
Re: [CDO] - CDOResource [message #1781199 is a reply to message #1781154] Fri, 02 February 2018 13:50 Go to previous message
Nirmal Kanagasabai is currently offline Nirmal KanagasabaiFriend
Messages: 8
Registered: January 2018
Junior Member
Thank you very much Eike. That addresses my query. I will read more about the 'Undo' functionality and will get back to you if I have any doubts in the future.
Previous Topic:Link between 2 ecore?
Next Topic:XML Parsing fails due to special character
Goto Forum:
  


Current Time: Sun Oct 21 06:35:24 GMT 2018

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

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

Back to the top