Skip to content

muuki88/org.eclipse.gemini.ext.di

Repository files navigation

Build Status

Goal

Add the ability to inject EntityManagers for a certain persistence unit in Eclipse 4.

Getting Started

Target platform - Repositories

First of all you have to get the Gemini JPA and Gemini DBAccess bundles to make this work. A sample target platform for Juno is available here.

The p2 repositories

Inject it

You can directly inject an EntityManager via

@Inject
@GeminiPersistenceContext(unitName="puTest")
EntityManager em;

or you can inject an EntityManagerFactory if you want to have more control of your EntityManagers

@Inject
@GeminiPersistenceUnit(unitName="puTest")
EntityManager em;

Configuration

You can even configure your persistence units within the inject annotation.

@Inject
@GeminiPersistenceContext(unitName="puTest", properties = {
 @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, value="org.gjt.mm.mysql.Driver"),
 @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL, value="jdbc:mysql://127.0.0.1/test"),
 @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER, value="test"),
 @GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD, value="test"))
})
EntityManager em;

even with the Preference annotation. If you don't know them take a look here

@Inject
@GeminiPersistenceContext(unitName = "unconfigured2", properties = {
  @GeminiPersistenceProperty(name = PersistenceUnitProperties.JDBC_DRIVER, valuePref = @Preference("jdbc_driver")),
  @GeminiPersistenceProperty(name = PersistenceUnitProperties.JDBC_URL, valuePref = @Preference("jdbc_url")) })
private EntityManager em;

Sample application

A complete sample application can be found here. It contains examples for

  • Statically injected contexts
  • Dynamically injected contextes
  • Handling changing preferences with DAOs

Note

This repository contains the work done by Filipp A. and Nepomuk Seiler. See Gemini Forum Post for more information.

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages