Start Up Ordering Tutorial
This tutorial demonstrates ability to order the start up of various ManagedObjectSource instances. It will do so by ordering the Flyway migration to always occur before JPA validation of the schema.
Start Order Configuration
Flyway is configured as per the Flyway Tutorial.
The following demonstrates the object configuration in the officefloor/objects/ directory:
managed-object:
source: net.officefloor.jdbc.DataSourceManagedObjectSource
properties:
datasource.class: org.h2.jdbcx.JdbcDataSource
url: "jdbc:h2:mem:exampleDb;DB_CLOSE_DELAY=-1"
user: sa
managed-object:
source: net.officefloor.jpa.hibernate.HibernateJpaManagedObjectSource
properties:
persistence.unit.name: test
persistence.dependency: datasource
hibernate.hbm2ddl.auto: validate
start-after:
- net.officefloor.flyway.FlywayMigration
The start-after configuration in EntityManager.yml indicates for JPA to start after the Flyway migration has complete.
This ordering is even enforced if the start up is executed by another team, as per the tutorial's configuration:
# START SNIPPET: tutorial
source: net.officefloor.frame.impl.spi.team.ExecutorCachedTeamSource
type: javax.sql.DataSource
# END SNIPPET: tutorial
There is also start-before for flagging to starting before.
Note that without this configuration, the ManagedObjectSource instances are likely to start in parallel for improved start up performance. However, in the case of this tutorial, the JPA validation could then occur before the Flyway migration completed causing the JPA validation to fail. Hence, the start ordering is provided to avoid these issues.
Testing
The following test starts the application and retrieves the migrated data:
@RegisterExtension
public final MockWoofServerExtension server = new MockWoofServerExtension();
@Test
public void ensureSetup() {
MockWoofResponse response = this.server.send(MockWoofServer.mockRequest("/message"));
response.assertJson(200, new Message(1L, "SETUP"));
}
Next
The next tutorial covers caching constant values to avoid repeated computation or lookup.

