Difference between revisions of "Teneo/Hibernate/GMF"
(→Initialization of Teneo)
|Line 63:||Line 63:|
Revision as of 05:10, 3 March 2010
This tutorial describes how the generated GMF editor can be adapted to operate on a relational database. Both the diagram data and the model data will be stored in the same relational database.
From the GMF website:
The Eclipse Graphical Modeling Framework (GMF) provides a generative component and runtime infrastructure for developing graphical editors based on EMF and GEF. The project aims to provide these components, in addition to exemplary tools for select domain models which illustrate its capabilities.
This tutorial shows you how to adapt the plugins from the GMF mindmap tutorial to operate on a relational database using hibernate. The chosen approach is to make very small changes to the generated code and is not necessarily focused on an elegant or optimal solution.
The result of this tutorial will be a displayed as a menu option in Eclipse which directly opens the editor on a relational database.
For additional information regarding GMF and Teneo (next to this tutorial), see the description provided in this bugzilla.
This tutorial assumes that you have a running Eclipse with EMF and Teneo installed. In addition the Teneo dependencies (incl. hsqldb and mysql drivers) should be installed. See the Download & Install page for more information.
The tutorial uses hsqldb but it can easily be changed to use mysql or another database. For other databases than hsqldb and mysql you need to take make sure that the jdbc driver is in the classpath of the org.eclipse.gmf.examples.edit project.
For mysql and other non-in-memory databases you have to create the database up-front (so not the tables inside the database but just the database itself). For this tutorial the database name should be: library.
Also GMF needs to be installed.
The GMF tutorial makes use of another set of example projects. These projects can be found in the gmf folder of the examples folder in cvs:
There are 3 projects:
Download all three projects into your workspace.
Adapting the generated mindmap plguins
This section describes how the generated mindmap code was adapted to facilitate the integration with Teneo. These changes have already been made in the projects you can download from cvs.
Setting dependendencies on Teneo and Hibernate =
Additional dependencies have to be set in the org.eclipse.gmf.examples.mindmap MANIFEST.MF file:
Note: the additional dependencies have been re-exported for convenience.
Initialization of Teneo
The Teneo layer has to be activated when the diagram editor starts. Note that this code assumes that database has been created. This example uses mysql/hsqldb, replace the relevant options for your specific database.
As a first step a new separate java package has been created in the org.eclipse.gmf.examples.mindmap.diagram plugin: org.eclipse.gmf.examples.mindmap.diagram.db. Three classes are present in this package (see the files in the ):
- StoreController: this class initializes and manages one Teneo datastore.
an annotations.xml file to map the GMF model to a relational store (download here). This file contains hints to Teneo on how to map the GMF model. It is required because the GMF model contains multiple-inheritance structures which can not be translated automatically to a relational store. See below for some more information.
- a specific EList property handler: this is to solve a minor technical detail with the GMF generated code and the GMF model, see here for more details.
- OpenbMindmapDBEditor: implements the menu choice to open a mindmap editor.
Then in the root of the src folder, 2 files are of importance:
- teneo.properties: contains hibernate and teneo properties. This file contains database connection information which probably has to be adapted to your specific case.
- annotations.xml: there are a number of GMF types (ShapeStyle, DiagramStyle and ConnectorStyle) which inherit from multiple other GMF types as well as the EMF EObject type. The EObject type is listed as the first supertype of these types. This means that Teneo will place these types in the EObject type hierarchy when mapping to a relational store. This will not work as for GMF these types are primarily subtypes of Style. The annotations.xml file in this tutorial ensures that the mentioned Style types are placed in the correct hierarchy (in the relational model).
Both the annotations.xml and teneo.properties file must be checked/flagged in the build.properties file so that they are copied to the build folder. To be sure check the contents of the build folder to ensure that these files are present.