Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EMF/Teneo 1.0.4/EclipseLink Support

< EMF
Revision as of 02:22, 23 March 2009 by Unnamed Poltroon (Talk) (Accessing EMF Models in Databases using the EclipseLink Resource and URIs)

Teneo 1.0.4 provides support for EclipseLink. The following sections explain the principal features it includes and give advice how they can be used for building model-based applications on top of relational databases.

Creating EclipseLink/JPA Mappings for EMF models

Three possibilities:

  • Model-driven
  • Meet-in-the-middle
  • Schema-driven

Accessing EMF Models in Databases using the EclipseLink Resource and URIs

Teneo/EclipseLink provides a full implementation of EMF's Resource interface named EclipseLinkResourceImpl. It enables applications to load and save EMF models from or to relational databases and to manage their lifecycle directly through EMF's built-in persistence API, i.e. the ResourceSet interface. EclipseLinkResourceImpl represents an almost complete abstraction from JPA mappings and EclipseLink runtime APIs and makes accessing models in databases, from an EMF point of view, as natural as loading or saving models from files.

Along with EclipseLinkResourceImpl a dedicated eclipselink URI protocol and a underlying resource factory named EclipseLinkResourceFactoryImpl have been defined. EclipseLink URIs enable models in databases to be referenced and the EclipseLink resource factory makes sure that instances of EclipseLinkResourceImpl are used to load and save such models.

The EclipseLink URIs provide the information required for accessing models in databases. Compared to accessing models in files there are two major differences: 1/ Resource location: In addition to the path or URL of the resource some additional access parameters need to be specified. Most importantly these are JDBC driver, user name, password. 2/ Resource contents: Loading models from files is based on the implicit assumptions that the file's whole contents belongs to the model. In the case of databases this is rather unlikely, typically a smaller or bigger number of different models would be present in the same database. Therefore, the model that is to be accessed within a given database needs to be specified in some way.

eclipselink://sessionName?contentsQueryAlias

Persistence Unit Database access parameters (database URL, JDBC driver, user name, password) Contents query

A EclipseLink resource typically contains a certain subset of objects stored in the underlying database. It is identified by the URI passed to or created by its constructor. This URI must or will be a EclipseLink URI and indicates an optional database login, a database session declared in the EclipseLink sessions configuration (sessions.xml), and a query returning the objects which constitute the contents of the EclipseLink resource.


The EclipseLink URI protocol includes all parameters which are

=

 // create sample instance of library model
 Library library1 = LibraryFactory.eINSTANCE.createLibrary();
 library.setName("library1");
 // create EclipseLink URI for saving/loading library model in/from database
 String query = EclipseLinkResourceUtil.createContentsEqualQuery(LibraryPackage.eINSTANCE.getLibrary(),LibraryPackage.eINSTANCE.getLibrary_Name(), library1.getName());
 uri = EclipseLinkResourceUtil.createEclipseLinkURI("library", query);
 // save library model instance in database
 ResourceSet resourceSet1 = new ResourceSetImpl();
 resourceSet1.getLoadOptions().putAll(getTestPersistenceUnitProperties());
 resource1 = resourceSet1.createResource(uri);
 assertTrue(resource1 instanceof EclipseLinkResourceImpl);
 assertFalse(resource1.isLoaded());
 resource1.getContents().add(library1);
 assertTrue(resource1.isLoaded());
 resource1.save(null);

Building Model-based Rich Client Applications on top of Teneo and EclipseLink

--Stephaneberle9.gmail.com 05:16, 16 March 2009 (UTC)

Back to the top