[CDO] - CDOResource [message #1780928] |
Tue, 30 January 2018 06:41 |
Nirmal Kanagasabai 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 76 times)
|
|
|
Re: [CDO] - CDOResource [message #1781068 is a reply to message #1780928] |
Thu, 01 February 2018 07:35 |
|
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?
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: [CDO] - CDOResource [message #1781135 is a reply to message #1781068] |
Thu, 01 February 2018 18:41 |
Nirmal Kanagasabai 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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03680 seconds