>>>>> Jean-Baptiste Onofré <[email protected]>:
> It's pretty close to Karaf JPA and JDBC examples right ?
Not sure. The JDBC example gets a DataSource and I'm unable to see
where the DataSource comes from?
https://github.com/apache/karaf/blob/master/examples/karaf-jdbc-example/karaf-jdbc-example-provider/src/main/java/org/apache/karaf/examples/jdbc/provider/BookingServiceJdbcImpl.java#L74
Hm... it loads pax-jdbc-derby, but that would only give it a
DataSourceFactory...?
https://github.com/apache/karaf/blob/master/examples/karaf-jdbc-example/karaf-jdbc-example-features/src/main/feature/feature.xml#L49
Something needs to take that DataSourceFactory and create a DataSource
for an actual database. And I can't find that something in
https://github.com/apache/karaf/tree/master/examples/karaf-jdbc-example
Hm... the first <config> element seems to contain the config necessary
to create a DataSource of an in-memory derby so it is possibly
karaf-jdbc-example-provider that creates the DataSource...? But I'm
unable to see what it is in there that does the actual work?
So OK the differences:
1. Going from DataSourceFactory to DataSource
a. The JDBC example uses some magic I don't know about to get from a
DataSourceFactory to a DataSource (something that I should know
about perhaps, but don't), based on config in the feature
b. The method of my blogpost introduces a DS component that listens for
DataSourceFactory and provides a DataSource
2. Schema setup
a. The JDBC example has derby-specific table setup in the
BookingServiceImpl class
https://github.com/apache/karaf/blob/master/examples/karaf-jdbc-example/karaf-jdbc-example-provider/src/main/java/org/apache/karaf/examples/jdbc/provider/BookingServiceJdbcImpl.java#L46
b. the DS component of the blog post uses liquibase to set up the
schema in a database-independent manner
3. Switching databases
a. To swap a database the config magic in the feature will have to be changed
b. The method in the blog post allows switching between databases by
swapping the DS component for a different component
The core point of the blogpost is that the JDBC connection and setup is
lifted out of the business logic and into a pluggable component. And
then I swap that component if I want to use PostgreSQL instead of derby.
The JPA example expects a JpaTemplate example
https://github.com/apache/karaf/blob/master/examples/karaf-jpa-example/karaf-jpa-example-provider/karaf-jpa-example-provider-ds/karaf-jpa-example-provider-ds-eclipselink/src/main/java/org/apache/karaf/examples/jpa/provider/ds/eclipselink/BookingServiceImpl.java#L34
and doesn't use any JDBC stuff directly...? (I couldn't find the string
"jdbc" in the example)
Hi
I think you should take a look on pax-jdbc-config.
It can simplify a lot your stuff.
Regards
JB
Le 26 oct. 2019 19:46, Steinar Bang <[email protected]> a écrit :
- Pluggable databases in apache karaf Steinar Bang
- Re: Pluggable databases in apache karaf jb
- Re: Pluggable databases in apache karaf Steinar Bang
- Re: Pluggable databases in apache karaf Jean-Baptiste Onofré
- Re: Pluggable databases in apache k... Steinar Bang
- Re: Pluggable databases in apa... jb
- Re: Pluggable databases in... Steinar Bang
- Re: Pluggable database... Steinar Bang
- Re: Pluggable database... Jean-Baptiste Onofré
- Re: Pluggable database... Steinar Bang
- Using pax-jdbc-config ... Steinar Bang
- Re: Pluggable databases in apache karaf Christian Schneider
- Re: Pluggable databases in apache k... Jean-Baptiste Onofré
- Re: Pluggable databases in apache k... Steinar Bang
- Re: Pluggable databases in apa... Steinar Bang
- Re: Pluggable databases in... Steinar Bang
