Fork me on GitHub

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.

Tutorial Source

Start Order Configuration

Flyway is configured as per the Flyway Tutorial.

The following demonstrates the object configuration:

	<managed-object source="net.officefloor.jpa.hibernate.HibernateJpaManagedObjectSource" type="javax.persistence.EntityManager">
		<property name="persistence.unit.name" value="test" />
		<property name="persistence.dependency" value="datasource" />
		<property name="hibernate.hbm2ddl.auto" value="validate" />
		<start-after type="net.officefloor.flyway.FlywayMigration" />
	</managed-object>

	<managed-object source="net.officefloor.jdbc.DataSourceManagedObjectSource">
		<property-file path="datasource.properties" />
	</managed-object>

The start-after configuration 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:

	<team source="net.officefloor.frame.impl.spi.team.ExecutorCachedTeamSource" type="javax.sql.DataSource" />

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(1, "SETUP"));
	}

Next

The next tutorial covers using ExecutiveSource for thread affinity.