@Test public void getQueryResult() throws Exception { AbstractResultQuery resultQuery = mock(AbstractResultQuery.class, Mockito.CALLS_REAL_METHODS); Whitebox.setInternalState(resultQuery, "fetchSize", 1); Query<QueryResultSet<?>> query = mock(Query.class); Whitebox.setInternalState(resultQuery, "queries", Collections.singletonList(query)); QueryResultSet resultSet = mock(QueryResultSet.class); when(query.getQueryResult()).thenReturn(resultSet); QueryResultSet mergeResultSet = mock(QueryResultSet.class); when(resultQuery.merge(Collections.singletonList(resultSet))).thenReturn(mergeResultSet).thenThrow(new RuntimeException()); assertThat(resultQuery.getQueryResult()).isEqualTo(mergeResultSet); try { resultQuery.getQueryResult(); fail(); } catch (Exception ignore) { } verify(resultSet).close(); }
@Override public T getQueryResult() throws SQLException { List<T> resultSets = new ArrayList<T>(queries.size()); try { for (Query<T> query : queries) { try { resultSets.add(query.getQueryResult()); } catch (SQLException e) { SwiftLoggers.getLogger().info("segment query error: {}", query, e); } } return merge(resultSets); } catch (Exception e) { IoUtil.close(resultSets); throw new SQLException(e); } }
AbstractResultQuery implements Query<T>, QueryResultSetMerger<T> { @Override public T getQueryResult() throws SQLException { List<T> resultSets = new ArrayList<T>(queries.size()); try { for (Query<T> query : queries) { try { resultSets.add(query.getQueryResult()); } catch (SQLException e) { SwiftLoggers.getLogger().info("segment query error: {}", query, e); } } return merge(resultSets); } catch (Exception e) { IoUtil.close(resultSets); throw new SQLException(e); } } }
AbstractResultQuery implements Query<T>, QueryResultSetMerger<T> { @Override public T getQueryResult() throws SQLException { List<T> resultSets = new ArrayList<T>(queries.size()); try { for (Query<T> query : queries) { try { resultSets.add(query.getQueryResult()); } catch (SQLException e) { SwiftLoggers.getLogger().info("segment query error: {}", query, e); } } return merge(resultSets); } catch (Exception e) { IoUtil.close(resultSets); throw new SQLException(e); } } protected  AbstractResultQuery(int fetchSize, List<Query<T>> queries); }
AbstractResultQuery implements Query<T>, QueryResultSetMerger<T> { @Override public T getQueryResult() throws SQLException { List<T> resultSets = new ArrayList<T>(queries.size()); try { for (Query<T> query : queries) { try { resultSets.add(query.getQueryResult()); } catch (SQLException e) { SwiftLoggers.getLogger().info("segment query error: {}", query, e); } } return merge(resultSets); } catch (Exception e) { IoUtil.close(resultSets); throw new SQLException(e); } } protected  AbstractResultQuery(int fetchSize, List<Query<T>> queries); @Override T getQueryResult(); }
AbstractResultQuery implements Query<T>, QueryResultSetMerger<T> { @Override public T getQueryResult() throws SQLException { List<T> resultSets = new ArrayList<T>(queries.size()); try { for (Query<T> query : queries) { try { resultSets.add(query.getQueryResult()); } catch (SQLException e) { SwiftLoggers.getLogger().info("segment query error: {}", query, e); } } return merge(resultSets); } catch (Exception e) { IoUtil.close(resultSets); throw new SQLException(e); } } protected  AbstractResultQuery(int fetchSize, List<Query<T>> queries); @Override T getQueryResult();  }