Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Teneo/Hibernate/Editor Tutorial"

(New page: This tutorial describes how the Hibernate EMF resource can be used in the Library editor. This tutorial assumes that you have a basic knowledge of EMF and EMF generated editors. For inform...)
 
Line 14: Line 14:
  
 
[[Image:org.eclipse.emf.teneo.generate.all.png|center|800px]]
 
[[Image:org.eclipse.emf.teneo.generate.all.png|center|800px]]
 +
 +
 +
== Adapting the generated editor code ==
 +
The generated editor code needs to be adapted so that it start the Teneo persistence layer when the editor starts.
 +
 +
The following code needs to be added to the static inner class ''Implementation'' in the ''ExtlibraryEditorPlugin'' class:
 +
<source lang="java">
 +
public void start(BundleContext context) throws Exception
 +
{
 +
// Set the database information, Environment is org.hibernate.cfg.Environment
 +
final Properties props = new Properties();
 +
props.setProperty(Environment.DRIVER, "org.hsqldb.jdbcDriver");
 +
props.setProperty(Environment.USER, "sa");
 +
props.setProperty(Environment.URL, "jdbc:hsqldb:file:/tmp/hsqldb");
 +
props.setProperty(Environment.PASS, "");
 +
props.setProperty(Environment.DIALECT, org.hibernate.dialect.HSQLDialect.class.getName());
 +
// props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
 +
// props.setProperty(Environment.USER, "root");
 +
// props.setProperty(Environment.URL, "jdbc:mysql://127.0.0.1:3306/library");
 +
// props.setProperty(Environment.PASS, "root");
 +
// props.setProperty(Environment.DIALECT, org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
 +
 +
// Initialize create the HbDataStore
 +
HbDataStore hbds = HbHelper.INSTANCE.createRegisterDataStore("library");
 +
hbds.setEPackages(new EPackage[]{ExtlibraryPackage.eINSTANCE});
 +
hbds.setProperties(props);
 +
hbds.initialize();
 +
 +
super.start(context);
 +
}
 +
</source>

Revision as of 04:44, 3 March 2010

This tutorial describes how the Hibernate EMF resource can be used in the Library editor. This tutorial assumes that you have a basic knowledge of EMF and EMF generated editors. For information on EMF see http://eclipse.org/modeling/emf/docs this page].

Initial Setup

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.emf.teneo.hibernate.examples 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.

Generating the editor code

After downloading the example project the first step is to generate the EMF editor code. Open the genmodel file in the model folder and right click and select 'Generate All'. This will generate three new development projects (see screenshot).


Org.eclipse.emf.teneo.generate.all.png


Adapting the generated editor code

The generated editor code needs to be adapted so that it start the Teneo persistence layer when the editor starts.

The following code needs to be added to the static inner class Implementation in the ExtlibraryEditorPlugin class:

		public void start(BundleContext context) throws Exception 
		{
			// Set the database information, Environment is org.hibernate.cfg.Environment
			final Properties props = new Properties();
			props.setProperty(Environment.DRIVER, "org.hsqldb.jdbcDriver");
			props.setProperty(Environment.USER, "sa");
			props.setProperty(Environment.URL, "jdbc:hsqldb:file:/tmp/hsqldb");
			props.setProperty(Environment.PASS, "");
			props.setProperty(Environment.DIALECT, org.hibernate.dialect.HSQLDialect.class.getName());
//			props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
//			props.setProperty(Environment.USER, "root");
//			props.setProperty(Environment.URL, "jdbc:mysql://127.0.0.1:3306/library");
//			props.setProperty(Environment.PASS, "root");
//			props.setProperty(Environment.DIALECT, org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
 
			// Initialize create the HbDataStore
			HbDataStore hbds = HbHelper.INSTANCE.createRegisterDataStore("library");
			hbds.setEPackages(new EPackage[]{ExtlibraryPackage.eINSTANCE});
			hbds.setProperties(props);
			hbds.initialize();
 
			super.start(context);
		}

Back to the top