[CDO] Basic use of CDO programmatically [message #1837976] |
Thu, 11 February 2021 15:35  |
Xavier GISTAU Messages: 6 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   |
|
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:
- 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.
- 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 ;-)
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01926 seconds