0
votes

in my current project I have integrated JPA into OSGi standalone application. For integration I have taken following OSGi specification Implementations:

  • OSGi R7 Platform (Equinox 3.13.0)
  • JPA 2.2 (Eclipselink 2.7.1)
  • JPA Container
    • Apache Aries JPA Container 2.7.0
    • Apache Aries JPA Eclipselink adapter 2.7.0
  • JDBC Service (PAX JDBC MariaDB 1.3.0)

This integration works perfect.

The next step to go - Flyway integration. The DB Migration Scripts should be packed directly into Persistence Bundle. Now I would like to trigger the migration exactly when DataSource is created, immediately before EntityManagerFactory and EntityManagerFactoryBuilder Services will be Registerd. At this moment I should have access to Persistence Bundle class loader and i should have an initialized Datasource. The only solution, that I have found, is to refactor Apache Areas JPA Container and put a Flyway migration call into AriesEntityManagerFactoryBuilder.dataSourceReady. The Flyway trigger is stored as locations in JPA properties like this:

    <property name="org.flywaydb.Locations" value="classpath:com/hrrm/budget/domain/account/migrations"/>

This solution is correct placed at a perfect time to call. But it is not confirm with OSGi JPA Service Specification 1.1 and was implemented as a hook into Apache Aries JPA Container.

Is there another more perfect and specification-confirm solution to integrate Flyway into my project?

1

1 Answers

0
votes

To hook into the DataSource creation you can use a PreHook service like described in the pax-jdbc docs.

You can find an example here.

@Component(property="name=persondb")
public class Migrator implements PreHook {
    public void prepare(DataSource ds) throws SQLException {
        // Put your migration calls here
    }
}