PostgresDataStorage implements DataStorage<R> { void createTables(Connection connection) { try (Statement stmt = connection.createStatement()) { stmt.execute(CharStreams.toString(new InputStreamReader(getClass().getResourceAsStream("createConfigurationtables.sql"), StandardCharsets.UTF_8))); } catch (SQLException | IOException e) { throw new RuntimeException(e); } } PostgresDataStorage(DataSource dataSource, R initialDataParam, MigrationManager<R> migrationManager, SimpleObjectMapper objectMapper); @Override R getHistoryData(String id); @Override Collection<StoredDataMetadata> getHistoryDataList(); @Override DataAndId<R> getCurrentData(); @Override void updateCurrentData(DataUpdate<R> update, UpdateSummary changeSummary); @Override void patchAll(DataStoragePatcher consumer); @Override void patchCurrentData(DataStoragePatcher consumer); @Override Collection<ScheduledUpdateMetadata> getFutureDataList(); @Override void deleteFutureData(String id); R getFutureData(String id); @Override void addFutureData(ScheduledUpdate<R> futureFactory);  }
@Test public void test_init_no_existing_factory_but_schema() throws SQLException { PostgresDataStorage<ExampleFactoryA> postgresFactoryStorage = new PostgresDataStorage<>(postgresDatasource, createInitialExampleFactoryA(), createDataMigrationManager(),ObjectMapperBuilder.build()); try (Connection con = postgresDatasource.getConnection()) { postgresFactoryStorage.createTables(con); con.commit(); } try (Connection con = postgresDatasource.getConnection()) { for (String sql : Arrays.asList("select * from currentconfiguration" ,"select * from configurationmetadata" ,"select * from configuration")) { PreparedStatement pstmt = con.prepareStatement(sql); try (ResultSet rs = pstmt.executeQuery()) { Assertions.assertFalse(rs.next(),sql); } } } }