Contents

Introduction

This tutorial will help you to get started with CDO. Therefore we will set up a small project to show the CDO basics. This tutorial was build on Eclipse 3.4

Maybe, hopefully not, you will experience some trouble through the tutorial. At the end of this tutorial you will find a Trouble-Shooting which might help you to handle the problems. If not, please contact the EMFT-Newsgroup.

Set up Eclipse

To ensure that everyone starts from the same point and to avoid conflicts with the tutorial we first will download a fresh Eclipse installation. You are free to use your still existing application through the tutorial. You also can start with you own and return to this point if something described in the tutorial does not meet your settings.

We will use the Classic version because this will give you a good overview which additional Plugins are needed. So if you are running another distribution you can add the missing Plugins, if needed.
Unpack the archive and copy the “eclipse” folder to a directory of your choice. This tutorial will use “C:/eclipse”.
So far with the installation. Now start the IDE.

Set Up the Environment

The IDE will start with a fresh workspace
Now we need to configure the environment with the CDO Plug-ins. You can either download the CDO Plugins from the CDO Downloadpage or follow the next steps to get a feeling for the needed Plugins.

To install the packages open the Update Manager (Help->Software Updates…) and select the "Available Software" tab.

Now we need the Derby core feature to work with a derby database through the example. Just search for “derby” in the “Available Software” tab and select “Apache Derby Core Feature”

In the next step we need the net4j Platform which is the communication base of CDO.

Finally to work the the example in the latter part of the tutorial we need some EMF.

Get the server started

Before you can start the server it needs to be configured. CDO makes use of a configuration file. Copy the following file to a “config” folder und the root of your Eclipse folder (C:/eclipse/config) and name it cdo-server.xml.

Now let us start the server. This can be achieved by creating a new run configuration. Open the Run dialog by selection Run->Run Configurations. Right click the "Eclipse Application" entry and create a new configuration. Just name it "CDO_Server". Select the "org.eclipse.emf.cdo.server.product" as new product on the "Program to Run" field.

Note: On the arguments tab you can configure where your configuration file is stored. Therefore you need to add the following entry to the VM Arguments:

-Dnet4j.config=${resource_loc:<path>}

By default the "config" folder under the distribution root will be used.

On the configuration tab select "Generate a config.ini file with default content"

Now hit the "Run" button. Your CDO Server will start.

Now the server hast started and additionally a derby database. If you have not changed the default settings there will be a new folder "C:\temp\cdodb1" which holds the data for the derby db.

Prepare the Client

To prepare the client we will use the very basic EMF-library example. If you are not familiar with EMF or this famous tutorial at all, please refer to this instruction
Create a new Java-Project and name it "CDO_Client" (or any other name). Create a folder called “model”. We will us the *.mdl file from the tutorial. If you have still executed the tutorial you will not need this steps.
Create a new EMF-Model and name your generation model "library.genmodel".

This will create the generation model and the ecore for your. Now we need to convert the generation model to meet the need of CDO. Right click the genmodel and select CDO->Migrate EMF Model. This will change the model.
Now you can open it and generate the code by invoking "generate all" an the model root.

Connect the clients

Now it is time to play with CDO. Start on client by right clicking the editor plugin and selecting “Run as…->Eclipse Application”.

To start another client open the run configuration in the host eclipse. “Duplicate” the “Eclipse Application” and give the “Location” on the main tab a new folder.

Now run the second client, too.
To Play with CDO we will use the CDO session view. This can be opened under "Windows->show View->Others…CDO session View"

To open a new Session just click the green plus symbol. Add the location of the server. Remember the config.xml. Here we configured the port. We will use tcp as protocol by setting the acceptor to "tcp".

That’s why we will now connect to this protocol. You might also remember the repository settings:

<repository name="repo1">…</repository>

Here we specified the name of the repository which we will now connect to.

Now open a transaction on the newly created Session.

To work with the library we need to create a new session. This can be done on the transaction itself. Name it "/res1".

This will open an editor for you. In this editor create a new Library by rightclicking the editor pane and choosing “New Root->library.ecore->Library”. After saving the editor the local data will be published to the repository.

By now we have connected to the repository and created a new resource in it. Automatically a new editor has opened. Right-click the empty editor pane and add a library object as new root. You can also add a book and/or a writer.

To connect the second client repeat the previous steps in the other instance. Open the CDO view, add a session and open a transaction. But now do not create but open a resource. Again enter "/res1" as resource name.

You will see the data you added to the repository on the other client. Remember that we have an opened session on both clients. Add another book on one client and watch the other. The book will appear on the other site. Because the transaction is opened on both clients you can produce a conflict and wee what happens. Change the name of a book on one client and try to commit the data on both. The second committer will not be able to publish the book and will receive an error message.

Congratulation! You managed your first CDO tutorial.

Trouble Shooting

[ERROR] Unknown DB adapter: derby-embedded

If this error occurs while starting the server, please make sure that the correct entry is set in the config.xml. Make also sure that you have download a plugin which contains the specific database driver for your choosen database system.