문제

So I'm involved in a project using Apache Karaf as a web services framework. We are developing bundles using OSGi to provide services.

I'm just trying to understand the high level architecture for DB access by these bundles, and I'm not able to find any solid information on this via Google search -- everything seems scattered.

Basically we're using JPA, Persistence Units (persistence.xml?), and DataSource. All of these are very confusing to me. If I have a "Hello World" bundle that needs to write stuff to a database, what's the general workflow here and how are each of the aforementioned components utilized? What's the overall "diagram" for this architecture? What's a bundle, and what isn't?

I'm very new to JAVA and there's just a lot to keep track of right now, so hoping for some help here! Thanks in advance!

도움이 되었습니까?

해결책

The first thing to solve is the abstraction from the db driver. The default Java approach of using DriverManager.getConnection does not work well in OSGi because of the classloading. It can be solved by offering and consuming the DataSource as an OSGI service.

Then the next thing is the setting up JPA. This is supported by Aries JNDI which allows to refer to the DataSource OSGi service using jndi inside your peristence.xml.

The last part of the puzzle is container managed persistence which is supported by aries JPA.

Below you can find a tutorial that shows all these concepts. The demo project examplejpa shows how it all works together.

http://liquid-reality.de/display/liquid/2012/01/13/Apache+Karaf+Tutorial+Part+6+-+Database+Access

https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejpa

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top