Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Basic use of CDO programmatically(Trying to create session and connect to a CDO server programmatically)
[CDO] Basic use of CDO programmatically [message #1837976] Thu, 11 February 2021 15:35 Go to next message
Xavier GISTAU is currently offline Xavier GISTAUFriend
Messages: 4
Registered: February 2019
Junior Member
Hello everyone,

I am fairly new to CDO, and I am trying to get familiar with it. I have followed a tutorial on how to install all the plugins and packages to use CDO with my first EMF model and everything went great !
The tutorial : https://wiki.eclipse.org/Getting_started_with_CDO

I have been able to create sessions and transactions using the various CDO views.

What I would like to achieve now is to do the exact same thing, but now using only Java code.

So far, I am just trying out stuff and yet it seems that I am getting stuck on basic stuff.


		IConnector connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, "tcp://localhost:2036");

		CDONet4jSessionConfiguration sessionConfiguration = CDONet4jUtil.createNet4jSessionConfiguration();
		sessionConfiguration.setConnector(connector);
		sessionConfiguration.setRepositoryName("repo1");
		CDONet4jSession session = sessionConfiguration.openNet4jSession();

		CDOTransaction transaction = session.openTransaction();
                CDOResource resource = transaction.getOrCreateResource("/path/to/my/resource");


I have several questions regarding this little block of code :

- First, I can't find my self to understand what should I put instead of the "/path/to/my/resource" string : is it supposed to be the address of the Database where my model is ? Is it the path
- Then, is there a way for me to check if the session opened successfully ? I thought I could access for example the list of resources that were existing in the repo, but when inspecting the "session" variable in the debugger interface, it seems that most stuff related to resources are "null".

If you need any further details, and I am almost certain you will, I will be happy to tell you.

Thanks for your time and your help.

Best regards,

Xavier
Re: [CDO] Basic use of CDO programmatically [message #1837988 is a reply to message #1837976] Fri, 12 February 2021 07:59 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6556
Registered: July 2009
Senior Member
Hi Xavier,

You're almost perfectly on track. Here's a short explanation of the most basic CDO concepts:

  • IConnector represents your end of the physical network connection. It can multiplex different IChannels with a separate application protocol (such as CDO) each.
  • CDOSession opens and maintains one such IChannel (with the CDO protocol) through the IConnector in order to connect you to a specific IRepository on the server. With the session you can already access the meta models (EPackages), the CDOBranches and CDOTags, and a low-level representation of the versioned model objects (CDORevisions). You can't access the model graph (EObjects) through the CDOSession, but you can open/manage multiple CDOViews and CDOTransactions through it.
  • CDOView provides you with a consistent model object graph (Folders, Resources and EObjects) in a specified branch and at a specified time (including the floating HEAD of a branch). The model graph of/in a CDOView is read-only and thread-safe (and thus usable in multiple Eclipse views).
  • CDOTransaction is a CDOView but without the read-only restriction. It can only "look" at the floating HEAD of the specified branch and has the commit() and rollback() API.

Regarding your questions:

  1. The aforementioned model graph (in any branch and at any time) comprises a so called "root resource", nestable folders, and leaf resources. The leafs can be text resources, binary resources, or model resources. The model resources finally contain the normal EObjects. You can only access the model graph through a CDOView or CDOTransaction (because it's only consistent at a specified branch and time, a so called CDOBranchPoint). The most common way to "enter" the graph is view.getResource(path), where "path" is the resorce path from the root resource "/" down to the wanted model resource. You can really think of it as a versioned file system within the repository.
  2. If the openNet4jSession() call did not throw an exception you can assume that the session was successfully opened. IConnectors, CDOSessions, CDOViews (including CDOTransactions) allocate system resources that must be freed with close() when not needed anymore. They can all be closed at any time "from remote", for example when the server or the network go away. You can actively check that with isClosed(), or be notified by calling addListener(new LifecycleEventAdapter() { ... }).

I hope that helps. Don't hesistate to ask, if not ;-)


Re: [CDO] Basic use of CDO programmatically [message #1837991 is a reply to message #1837988] Fri, 12 February 2021 09:05 Go to previous messageGo to next message
Xavier GISTAU is currently offline Xavier GISTAUFriend
Messages: 4
Registered: February 2019
Junior Member
Hi Eike,

First thank you for taking the time to answer my questions ! I would say that you have cleared most of my doubts so far and I have been able to add elements to my model, root elements, child elements...
Your explanation was perfect and I hope I will be able to continue on my own for a bit now.

Again, thanks a lot for your help, have a great day.

Best regards,

Xavier
Re: [CDO] Basic use of CDO programmatically [message #1837992 is a reply to message #1837991] Fri, 12 February 2021 10:24 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6556
Registered: July 2009
Senior Member
You're welcome. Have fun with CDO ;-)

Previous Topic:[Compare] How to resolve proxies
Next Topic:Unable to Edit Dynamic Ecore Model Instance
Goto Forum:
  


Current Time: Sat Apr 17 20:57:16 GMT 2021

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

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

Back to the top