Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO]Identify the author of a CDOCommit
[CDO]Identify the author of a CDOCommit [message #1840397] Wed, 14 April 2021 07:43 Go to next message
Xavier GISTAU is currently offline Xavier GISTAUFriend
Messages: 6
Registered: February 2019
Junior Member
Hello everyone, I hope you are all doing great !

Some months ago, I started to work with CDO, and asked for some insights about interacting with CDO programmatically. I have since then been able to achieve a lot using CDO, and I am glad for the help I was given and thankful to the CDO team for their work.

I am now facing new issues, as my work with CDO gets bigger and bigger!
Working with a CDO repo and an EMF client, I have been able to implement functionalities in order to add EMF model elements to my CDO repo programmatically.
My goal is now to have two clients using the same repo, and when one client pushes modifications to the CDO base these modifications are replicated into the other client. I currently have the various mechanisms that I need but my question is the following : is it possible to identify which client has committed a CDOCommit ?
At this time, I have a single session for each of my client, each client has a transaction monitoring the latest state of the repo, and it catches a CDOViewAdaptersNotifiedEvent from which I get the changes and replicate them in the local model.
The problem is because I am reacting on changes to the latest state of the repo, this can happen :

- Client 1 creates an element A into its local model, and push it to the repo
- Client 1 monitoring transaction notices a change in the repo
- Client 1 replicates the change that happens in the repo, into the Client 1
- Client 1 now has two elements A

To avoid that, I thought maybe checking which SessionID produced the change would help me, since a client could just ignore commit that its session created. Is it the way to go or am I completely off track here ? Is it possible to get this kind of information based on a CDOViewAdaptersNotifiedEvent ?

As always, thanks for your time and your help, if you need any further details, I will be happy to tell you.

Best regards,
Xavier
Re: [CDO]Identify the author of a CDOCommit [message #1840423 is a reply to message #1840397] Thu, 15 April 2021 04:49 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Xavier,

What do you mean by "Client 1 replicates the change that happens in the repo, into the Client 1"? Have you written own code to patch your client 1 local model objects? If so, why? As you must have noticed, CDO is already doing that for you, and it's clear that you end up with duplicate elements if you "replicate" them again.

Regarding the availability of the user name, you can set up your client session like so:

    ITCPConnector connector = TCPUtil.getConnector(IPluginContainer.INSTANCE, "localhost:2036");

    CDONet4jSessionConfiguration configuration = CDONet4jUtil.createNet4jSessionConfiguration();
    configuration.setConnector(connector);
    configuration.setRepositoryName("repo1");

    if (serverIsAuthenticating)
    {
      configuration.setCredentialsProvider(new PasswordCredentialsProvider("Eike", "12345"));
    }
    else
    {
      configuration.setUserID("Eike");
    }

    CDOSession session = configuration.openNet4jSession();


You'll see in the commit history that the commits (i.e., the CDOCommitInfos) carry the proper userID.

Cheers
Eike


Re: [CDO]Identify the author of a CDOCommit [message #1840434 is a reply to message #1840423] Thu, 15 April 2021 08:09 Go to previous messageGo to next message
Xavier GISTAU is currently offline Xavier GISTAUFriend
Messages: 6
Registered: February 2019
Junior Member
Hello Eike,

Thanks again for the speed of your answer, that is really amazing !
"CDO is already doing that for you" I think I might be missing something then, so far when I was adding elements to my repo through the CDOExplorer, none of them was replicated into my local model. This is why I wrote my own code to achieve that.
That is the code I use to connect to the repo :
		Net4jUtil.prepareContainer(IPluginContainer.INSTANCE);
		IConnector connector = (IConnector) IPluginContainer.INSTANCE.getElement(connectorPackage, protocol, url);
		CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration();
		config.setConnector(connector);
		config.setRepositoryName(repo);
		session = config.openNet4jSession();
		session.options().setGeneratedPackageEmulationEnabled(true);
		return session.openTransaction();


Is there a specific configuration in which you can set CDO to do the replication for you ?

Regarding the userID, I am going to try it right now ! But it sounds like a perfect solution and exactly what I am looking for ! :)

Have a great day,
Xavier
Re: [CDO]Identify the author of a CDOCommit [message #1840474 is a reply to message #1840434] Fri, 16 April 2021 04:07 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Xavier GISTAU wrote

none of them was replicated into my local model


You still haven't explained what you mean by "my local model" and I have no clue. Are you aware that the CDOTransaction that you are returning from your "connection method" provides you with a local model? You can enter and access it through different ways:

  ResourceSet rset = tx.getResourceSet();


Or:

  Resource res = tx.getResource("/my-folder/my-model");


Or:

  EObject obj = tx.getObject(cdoid);


Xavier GISTAU wrote

  Net4jUtil.prepareContainer(IPluginContainer.INSTANCE);



You don't need any of the XyzUtil.prepareContainer() calls if you're running inside Eclipse, i.e., with the extension registry enabled.


Re: [CDO]Identify the author of a CDOCommit [message #1840640 is a reply to message #1840474] Wed, 21 April 2021 08:34 Go to previous messageGo to next message
Xavier GISTAU is currently offline Xavier GISTAUFriend
Messages: 6
Registered: February 2019
Junior Member
Hello Eike, sorry for the late reply !

What I mean by "local model" is the local file that is stored under the extension "myFile.myModel". My goal is to keep updated this file with the changes done in the repo. Sorry for not explaining that earlier !

Also, the userID seems to be the kind of mechanism I was looking for to help me discard the changes already done in my client. So far, everything is good on my side so thank you. I hope you are doing well and wish you a good day.

Xavier
Re: [CDO]Identify the author of a CDOCommit [message #1840648 is a reply to message #1840640] Wed, 21 April 2021 10:36 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
I'm glad that it's working well for you. Thanks ;-)

Previous Topic:Automatic generation of random ecore model instances
Next Topic:[CDO] Can't get repositories to checkout properly
Goto Forum:
  


Current Time: Sat Apr 20 00:50:07 GMT 2024

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

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

Back to the top