Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Question about locking
[CDO] Question about locking [message #1372049] Wed, 21 May 2014 13:03 Go to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 147
Registered: September 2011
Senior Member
Hi all,

I have an application which displays two different Graphiti diagrams in their respective editors. These diagrams are stored in seperate resources in CDO.
And a same element is displayed in both diagrams.
So, when I acquire lock to edit the element in one diagram, it is then locked and non-editable in the other diagram because each Graphiti editor uses its own CDO transaction.

In my use case, locking the element makes sense to prevent conflicts with other users running other instances of my application.
But, it should not "apply" between editors inside a same application when one owns the lock.

Locking at session level would solve my problem but - unless i'm wrong - is not possible.

Any idea on how to handle this situation ? Is there any CDO option / feature, I'm not yet aware of, that could be used ?

kind regards,

Laurent
Re: [CDO] Question about locking [message #1372339 is a reply to message #1372049] Wed, 21 May 2014 15:56 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 147
Registered: September 2011
Senior Member
Well... Actually, the problem is probably even more complicated if we consider that any element modification (e.g. its name) should be immediately reflected in the other diagram...
Re: [CDO] Question about locking [message #1372462 is a reply to message #1372339] Wed, 21 May 2014 17:06 Go to previous messageGo to next message
Leonid Ripeynih is currently offline Leonid Ripeynih
Messages: 93
Registered: February 2012
Member
I would suggest sharing a transaction between editors in this case.
Re: [CDO] Question about locking [message #1374567 is a reply to message #1372462] Thu, 22 May 2014 13:59 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 147
Registered: September 2011
Senior Member
Hi Leonid,

Thanks for your answer. A shared transaction seems indeed to be the best solution for now.
But there's one drawback. Saving an editor then causes the others opened and dirty ones to be saved as well...

It would be nice to be able to save only the selected one. But this would imply to commit only part of the shared transaction.

In other words, the editor content (mainly the Graphiti diagram) is stored in a dedicated CDO resource. Saving the editor leads to a resource.save.
And, after looking at CDOResourceImpl code, the save method actually gets a reference to the resource transaction (the shared one) and calls commit.

So my question is now : Is it possible to override the save method and may be create a temporary "inner" transaction to commit only the resource content ?
But this, I guess, will lead me back to lock issues between the shared transaction and the inner one...

Regards,

Laurent
Re: [CDO] Question about locking [message #1376314 is a reply to message #1374567] Fri, 23 May 2014 06:59 Go to previous messageGo to next message
Leonid Ripeynih is currently offline Leonid Ripeynih
Messages: 93
Registered: February 2012
Member
Laurent,

there is a method CDOTransaction.setCommittables, after this call transaction will only commit changes in a given set of objects. Even more, it will validate that you commit is not dependent on an out-of-commit-scope objects, and will fail otherwise.

[Updated on: Fri, 23 May 2014 07:00]

Report message to a moderator

Re: [CDO] Question about locking [message #1383387 is a reply to message #1376314] Mon, 26 May 2014 06:41 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 147
Registered: September 2011
Senior Member
Hi Leonid,

Thanks for the tip ! I try to use setCommittables but then, saving my diagram (resource) fails with the following error message :
!ENTRY org.eclipse.graphiti.ui 0 0 2014-05-26 12:22:57.807
!MESSAGE The following resources could not be saved:
URI: cdo://EntrepriseArchitectureRepository/Application_app1_1400270224492, cause: 
org.eclipse.net4j.util.transaction.TransactionException: org.eclipse.emf.cdo.util.CommitException: org.eclipse.net4j.util.transaction.TransactionException: org.eclipse.emf.cdo.util.CommitIntegrityException: The resource of new object CommitInfo@oid1[NEW] needs to be included in the commit but isn't
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.save(CDOResourceImpl.java:1236)


I create a CommitInfo element before the saving to store additionnal information (user Id, time stamp and an associated comment).

This element is added to the resource to be saved :
TransactionalEditingDomain ted = editor.getEditingDomain();
CDOResource r = editor.getDiagramTypeProvider().getDiagram().cdoResource();
ted.getCommandStack().execute(new AddCommand(ted, r.getContents(), commitInfo));


Then, for the saving, I make copy of the whole resource content (including the new element) :
TreeIterator<EObject> resourceWholeContent = diagramBehavior.getDiagramTypeProvider().getDiagram().cdoResource().getAllContents();
HashSet<EObject> commitables = new HashSet<EObject>();
while (resourceWholeContent.hasNext())
	commitables.add(resourceWholeContent.next());

transaction.setCommittables(commitables);
Set<Resource> res = super.save(editingDomain, saveOptions, monitor);


Any idea why the 'NEW' object is apparently not considered in the same resource as the rest ?

Regards,

Laurent
Re: [CDO] Question about locking [message #1383484 is a reply to message #1383387] Mon, 26 May 2014 07:39 Go to previous messageGo to next message
Leonid Ripeynih is currently offline Leonid Ripeynih
Messages: 93
Registered: February 2012
Member
It looks like you forgot to include resource itself in commitables list.

I.e. you should add all the objects you want to save + their corresponding resources, as CDOResource is EObject itself.

Hope this helps!
Re: [CDO] Question about locking [message #1383623 is a reply to message #1383484] Mon, 26 May 2014 09:01 Go to previous message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 147
Registered: September 2011
Senior Member
Oups ! I should have found this one by myself...
It now works great.
Many thanks for your help !
Previous Topic:EMF - How to restrict values of non-containment references?
Next Topic:[Xcore] Xcore for Xtext 2.6?
Goto Forum:
  


Current Time: Sat Aug 23 05:47:22 EDT 2014

Powered by FUDForum. Page generated in 0.01814 seconds