Eclipse EMF: a CRUD at no-cost

Eclipse EMF: a CRUD at no-cost

This tutorial follows the one dedicated to modeling with EMF ( Eclipse EMF: Designing the Model )
In this article we will see how, through EMF automatic code generation tools, it’s possible to generate a CRUD, an application that is able to perform typical operations for manipulating the contents of the model: Create (= insert), Read (= Select), Update and Delete.

This management requires some form of persistence, however a “channel” storage of these information. In fact, in most cases it should be possible, for example:

  • reload the data stored during a previous run
  • share data with other instances of the same or other applications

The default persistence mechanism of EMF provides storing of information on file system, through XMI file format (XML Metadata Interchange, an OMG standard for exchanging data via XML).

To obtain an application that can manage our data in this format, the following steps are sufficient.
Referring to the previous tutorial (mentioned above), reopen the file Library.genmodel, select the root of the structure, we display the Properties view and modify the property Runtime Platform by setting the value “RCP” (instead of “IDE”), then save (File -> Save).

Select the root element again, right-click on “Generate Code Edit” and then “Generate Code Editor“.

We get two new plugins:

  • it.rcpvision.rcptutorial.model.edit
  • it.rcpvision.rcptutorial.model.editor

In particular, the last one (it.rcpvision.rcptutorial.model.editor) can be run as an RCP application by selecting it and right-clicking Run As -> Eclipse Application.

The result should be the following

If you now select File -> New -> Library Model
we will have to set values ÔÇïÔÇïin the following dialog

Nel primo campo andiamo ad impostare il path completo del file XMI che conterrà i nostri dati (notate che l’estensione del file .library è legata al nome iniziale che abbiamo attribuito al nostro ecore).
Il secondo campo indica invece di che tipo (EClass) EMF sarà l’elemento root all’interno di tale file XMI. Per come abbiamo progettato il Modello, tutte le entità sono contenute all’interno della classe Library, pertanto selezioniamo questa come Model Object. Premiamo quindi Finish.

In the first field we are going to set the full path of the XMI file that will contain our data (note that the extension .library is linked to the name we gave to our initial ecore).
The second field indicates what type (EClass) EMF will be the root element in the XMI file. By the way we designed the model, all entities are contained within the class Library, so we select this as a Model Object. Then press Finish.

Now we have a CRUD very basic but effective:

  • add a new Author

  • set attribute values

  • create a new Book

  • set a title and authors

and so on, populating our library of Book and Author objects tied together according to the relations specified in the EMF Model. Everything (for now) in a XMI file stored on the file system, that you can reopen the next time you restart the application, finding the data previously set and of course with the option of being able to once again manage (add, delete and modify) and save

In the next tutorial we’ll see how this CRUD, with some modifications to generated code (note that we haven’t put hand in that code yet!) can allow us to change the mode of persistence from XMI file to a Relational Database.

Back to index

2012-06-08T11:52:29+00:00By |

Leave A Comment