@Test void testGetSchemaVersion() throws SQLException { Connection connection = mock(Connection.class); when(dataSource.getConnection()).thenReturn(connection); Statement statement = mock(Statement.class); when(connection.createStatement()).thenReturn(statement); ResultSet resultSet = mock(ResultSet.class); when(statement.executeQuery("SELECT \"id\" FROM \"Version\"")).thenReturn(resultSet); when(resultSet.next()).thenReturn(true); when(resultSet.getInt("id")).thenReturn(30); assertEquals(30, molgenisVersionService.getSchemaVersion()); }
int getSchemaVersion() { int version; try (Connection connection = dataSource.getConnection()) { try (Statement statement = connection.createStatement()) { String selectVersionSql = "SELECT \"id\" FROM \"Version\""; try (ResultSet resultSet = statement.executeQuery(selectVersionSql)) { if (resultSet.next()) { version = resultSet.getInt("id"); } else { throw new SQLException("Expected non-empty result set"); } } } } catch (SQLException e) { throw new UncheckedSqlException(e); } return version; }
MolgenisVersionService { int getSchemaVersion() { int version; try (Connection connection = dataSource.getConnection()) { try (Statement statement = connection.createStatement()) { String selectVersionSql = "SELECT \"id\" FROM \"Version\""; try (ResultSet resultSet = statement.executeQuery(selectVersionSql)) { if (resultSet.next()) { version = resultSet.getInt("id"); } else { throw new SQLException("Expected non-empty result set"); } } } } catch (SQLException e) { throw new UncheckedSqlException(e); } return version; } }
MolgenisVersionService { int getSchemaVersion() { int version; try (Connection connection = dataSource.getConnection()) { try (Statement statement = connection.createStatement()) { String selectVersionSql = "SELECT \"id\" FROM \"Version\""; try (ResultSet resultSet = statement.executeQuery(selectVersionSql)) { if (resultSet.next()) { version = resultSet.getInt("id"); } else { throw new SQLException("Expected non-empty result set"); } } } } catch (SQLException e) { throw new UncheckedSqlException(e); } return version; } MolgenisVersionService(DataSource dataSource); }
MolgenisVersionService { int getSchemaVersion() { int version; try (Connection connection = dataSource.getConnection()) { try (Statement statement = connection.createStatement()) { String selectVersionSql = "SELECT \"id\" FROM \"Version\""; try (ResultSet resultSet = statement.executeQuery(selectVersionSql)) { if (resultSet.next()) { version = resultSet.getInt("id"); } else { throw new SQLException("Expected non-empty result set"); } } } } catch (SQLException e) { throw new UncheckedSqlException(e); } return version; } MolgenisVersionService(DataSource dataSource); @PostConstruct void init(); }
MolgenisVersionService { int getSchemaVersion() { int version; try (Connection connection = dataSource.getConnection()) { try (Statement statement = connection.createStatement()) { String selectVersionSql = "SELECT \"id\" FROM \"Version\""; try (ResultSet resultSet = statement.executeQuery(selectVersionSql)) { if (resultSet.next()) { version = resultSet.getInt("id"); } else { throw new SQLException("Expected non-empty result set"); } } } } catch (SQLException e) { throw new UncheckedSqlException(e); } return version; } MolgenisVersionService(DataSource dataSource); @PostConstruct void init();  }