@Test public void transformDataSource() throws Throwable { CompileOfficeFloor compiler = new CompileOfficeFloor(); compiler.office((context) -> { OfficeManagedObjectSource mos = context.getOfficeArchitect().addOfficeManagedObjectSource("mo", H2DataSourceManagedObjectSource.class.getName()); mos.addProperty("url", "jdbc:h2:mem:test"); mos.addProperty("user", "sa"); mos.addOfficeManagedObject("mo", ManagedObjectScope.THREAD); context.addSection("SECTION", MockDataSourceSection.class); }); try (OfficeFloor officeFloor = compiler.compileAndOpenOfficeFloor()) { MockDataSourceSection.dataSource = null; MockDataSourceSection.connection = null; CompileOfficeFloor.invokeProcess(officeFloor, "SECTION.service", null); assertNotNull(MockDataSourceSection.dataSource, "Should have DataSource"); assertTrue(MockDataSourceSection.dataSource instanceof HikariDataSource, "Should transform to Hikari pooling"); try (Connection connection = MockDataSourceSection.dataSource.getConnection()) { ResultSet results = connection.createStatement().executeQuery("SELECT CONTENT FROM TEST"); assertTrue(results.next(), "Should have entry"); assertEquals("AVAILABLE", results.getString("CONTENT"), "Incorrect data"); } } }
@Override public DataSource transformDataSource(DataSourceTransformerContext context) throws Exception { HikariDataSource hikari = new HikariDataSource(); hikari.setDataSource(context.getDataSource()); DefaultDataSourceFactory.loadProperties(hikari, context.getSourceContext()); return hikari; }
HikariDataSourceTransformer implements DataSourceTransformer, DataSourceTransformerServiceFactory { @Override public DataSource transformDataSource(DataSourceTransformerContext context) throws Exception { HikariDataSource hikari = new HikariDataSource(); hikari.setDataSource(context.getDataSource()); DefaultDataSourceFactory.loadProperties(hikari, context.getSourceContext()); return hikari; } }
HikariDataSourceTransformer implements DataSourceTransformer, DataSourceTransformerServiceFactory { @Override public DataSource transformDataSource(DataSourceTransformerContext context) throws Exception { HikariDataSource hikari = new HikariDataSource(); hikari.setDataSource(context.getDataSource()); DefaultDataSourceFactory.loadProperties(hikari, context.getSourceContext()); return hikari; }  }
HikariDataSourceTransformer implements DataSourceTransformer, DataSourceTransformerServiceFactory { @Override public DataSource transformDataSource(DataSourceTransformerContext context) throws Exception { HikariDataSource hikari = new HikariDataSource(); hikari.setDataSource(context.getDataSource()); DefaultDataSourceFactory.loadProperties(hikari, context.getSourceContext()); return hikari; }  @Override DataSourceTransformer createService(ServiceContext context); @Override DataSource transformDataSource(DataSourceTransformerContext context); }
HikariDataSourceTransformer implements DataSourceTransformer, DataSourceTransformerServiceFactory { @Override public DataSource transformDataSource(DataSourceTransformerContext context) throws Exception { HikariDataSource hikari = new HikariDataSource(); hikari.setDataSource(context.getDataSource()); DefaultDataSourceFactory.loadProperties(hikari, context.getSourceContext()); return hikari; }  @Override DataSourceTransformer createService(ServiceContext context); @Override DataSource transformDataSource(DataSourceTransformerContext context);  }