You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Balázs Zsoldos <ba...@everit.biz> on 2012/05/16 14:32:21 UTC
JPA Container
Hi,
I spent a lot of time analyzing the code of the JPA Container. On the end I
decided to leave a part behind and only use the classes I can. I created an
own JPA Container based on the code of Aries where I simply bundle the
Aries JPA Container into my JAR.
My solution works in the following way:
- I wrote a RequisiteTracker and a MultiRequisiteTracker API
- Based on the requisite tracking solution I start EntityManagerFactorys
only when all necessary services are available:
- Nothing is started on a persistence bundle until a good
DataProvider service is available
- If the DataProvider is available the persistence units are started
separately if
- DataSourceFactory is available or
- jta-datasource service is available (osgi:service is defined in
jta-data-source) and/or
- non-jta-data-source service is available (osgi:service is
defined in non-jta-data-source)
- javax.transaction.TransactionManager OSGI service is available
(if we use JTA)
- if any of the services that a PersistenceUnit needs is unregistered
from the OSGI container the PersistenceUnit is stopped as well
- If normal JNDI is set for jta-data-source or non-jta-data-source
simple InitialContext.doLookup is used.
- I do not support AnnotationScanner yet as I think the jar-files in
persistence.xml should be scanned as well. Also annotation scanning is
against my religion :). It would not be hard to take it in but I simply was
not interested. If I see that others need it I will spend a night with it
(scanning the jars from persistence.xml and the bundle that contains the
PU).
- No EntityManagerFactoryBuilder service creation YET. It would be easy
to take it in but
For us it was very important to have a JPA container where in any test
system the ordering of the bundle start does not matter at all.
@Aries guys: Take my code back into Aries if you would like, Well, my
solution is based on the knowledge of yours and I use some of the functions
you wrote (e.g. ParsedPersistenceUnit, and finding out which
PersistenceProvider to use).
I have not written very precisely the multithreading part but I do not
think there will be an issue with it as ServiceTrackers are synchronous
calls. I used concurrentHashMap everywhere but if you find any exception
please send a stacktrace.
You can find information about the solution at
http://everit.org/osgi/jpa/org.everit.osgi.jpa.container/index.html
You can find a sample application that uses this solution at
http://everit.org/osgi/samples/hibernate/index.html
You can find a guide about the technologies behind the sample application
(and how to import them into eclipse to have a testing environment) at
http://everit.org/osgi/testing/step-by-step-guide.html
I hope this solution will help others as it did for us.
Regards,
Balazs Zsoldos
Software Architect
Mobile: +36-70/594-92-34
Everit Kft.
https://www.everit.biz