dana-i2cat/opennaas — pull request #734 by isartcanyameres (2013-11-19 14:43:29+00:00)
Title: Use injected EntityManagerFactory.

This patch changes the way GenericOSGiJpaRepository and SecurityRepository get an EntityManager.
Instead of looking up in the service registry for an EntityManagerFactory, this object is now injected at instantiation time.

Injection is specified in blueprint configuration files, by first resolving a reference to the EntityManagerFactory service,
and second injecting it as a property when instantiating each ResourceDescriptorReposiroty bean. The same is true for the SecurityRepository.

All bundles resolving a reference to the EntityManagerFactory must import javax.persistence package.
If the reference is in blueprint files, this import must be explicitely set in maven-bundle-plugin instructions in the bundle pom.xml, because the plugin does not inspect blueprint files.
All required poms have been updated with the new required import.

This patch also fixes a duplication of persistence related beans in org.opennaaas.core.security (same beans were instantiated in blueprint and spring-context.xml)
Persistence related beans and services are now instantiated and published by blueprint.
The spring-context.xml file resolves references to required persistence services using the osgi registry.

EntityManagerFactory creation and injection works as follows:
- A data source is specified in a persistence file.
- The data source is published as an OSGi service using javax.sql.DataSource interface and with osgi.jndi.service.name property set to the jdbc identifier of the DB.
- Apache Aries JPA (that listens to data sources being published as explained above) creates the EntityManagerFactory and publishes it as an OSGi service, with following properties:
osgi.unit.name - this is the name of the persistence unit
osgi.unit.provider - this is the class name of the JPA PersistenceProvider that was used to create the EntityManagerFactory
org.apache.aries.jpa.container.managed - this property will be set to true, indicating this is a managed EntityManagerFactory.
- A reference to the EntityManagerFactory is obtained from the OSgi service registry using javax.persistence.EntityManagerFactory interface and properties above.
- The reference is injected in desired bean by blueprint.
More information at https://aries.apache.org/modules/jpaproject.html