HI Devs,
These days I am looking into this new feature that we need implement to
comply the Java EE 6 Spec.
This feature requires the ability to "plug-in" a vendor JPA Provider to the
Java EE server, and the JPA app can "pick-up" the vendor provider and get
the corresponding EntityManagerFactory. That is, let's take a use case for
example, the steps are:
a. User put a Oracle topLink.jar into the server's lib folder.
b. In the JPA app's persistence.xml, specify the provider as following:
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
Then the entity manager factory should be created from the toplink's
EntityManagerFactoryProvider by our server.
Currently, we don't have such ability because of the following obstacles:
1. We are running server on OSGi framework. There is not way to just put-in
a jar file and make it work for other Bundles' classloader.
2. We are tight coupling the JPA20 builder to Openjpa. In the
PersistenceUnitBuilder, we set the defaultEnvironment with:
<dependencies>
<dependency>
<groupId>org.apache.geronimo.configs</groupId>
<artifactId>openjpa2</artifactId>
<version>${version}</version>
<type>car</type>
</dependency>
</dependencies>
This will add all the export-packages from openjpa to the JPA app bundle
when deploy, but it is actually useless for the ones specified other vendor
providers.
For #1, I think we should add the ability to convert a normal jar to OSGi
bundle. I looked into the maven-bundle-plugin, and the aQute bndlib should
be a good tool to do this. We can just provide the basic function that wrap
a jar and:
Export-Package: *
Import-Package: <packages inside the target jar>
to make it as bundle. And in the long term, we can provide a portlet in
admin console for user to customizing his bundle.
For #2, User need input the dependency in the jpa app's deployment plan and
specify to the bundle generated by geronimo in #1, such as:
<dependencies>
<dependency>
<groupId>geronimo.generated.bundles</groupId>
<artifactId>topLink</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
</dependencies>
Then all the topLink export-packages will be imported by the jpa app bundle
of user. We won't need merge the defaultEnviroment(i.e. openjpa) in the
PersistenceUnitBuilder if use specify a vendor provider in persistence.xml.
Another approach is we can add the
imports "oracle.toplink.essentials.ejb.cmp3;" when analyzing the
persistence.xml in PersistenceUnitBuilder so that user won't need manually
add a deployment plan and input the dependency.
Any comments?
--
Lei Wang (Rex)
rwonly AT apache.org