QueryImpl extends AbstractQuery implements Query { @Override public List getResultList() { ensureOpen(); try { if (getMaxResults() == 0) { return Collections.emptyList(); } return getResultListImpl(); } catch (OntoDriverException e) { markTransactionForRollback(); throw queryEvaluationException(e); } catch (RuntimeException e) { markTransactionForRollback(); throw e; } } QueryImpl(final QueryHolder query, final ConnectionWrapper connection); @Override List getResultList(); @Override Object getSingleResult(); @Override Stream getResultStream(); @Override Query setMaxResults(int maxResults); @Override Query setFirstResult(int startPosition);  }
@Test void queryResultRowIsArrayOfObjectsWhenMultipleColumnsExist() throws Exception { final Query q = createQuery(SELECT_QUERY); when(resultRow.getColumnCount()).thenReturn(2); when(resultSetIterator.hasNext()).thenReturn(true).thenReturn(false); final String res = "str"; when(resultRow.isBound(anyInt())).thenReturn(true); when(resultRow.getObject(anyInt())).thenReturn(res); final List result = q.getResultList(); for (Object row : result) { assertTrue(row instanceof Object[]); final Object[] rowArr = (Object[]) row; for (Object o : rowArr) { assertEquals(res, o); } } }
@Test void queryResultRowObjectWhenSingleColumnExists() throws Exception { final Query q = createQuery(SELECT_QUERY); when(resultRow.getColumnCount()).thenReturn(1); when(resultSetIterator.hasNext()).thenReturn(true).thenReturn(false); final String res = "str"; when(resultRow.getObject(anyInt())).thenReturn(res); final List result = q.getResultList(); for (Object o : result) { assertEquals(res, o); } }
@Test void getResultListSetsValuesOfUnboundVariablesToNullInResultArrays() throws Exception { final Query q = createQuery(SELECT_QUERY); when(resultRow.getColumnCount()).thenReturn(2); when(resultSetIterator.hasNext()).thenReturn(true).thenReturn(false); when(resultRow.isBound(0)).thenReturn(true); when(resultRow.isBound(1)).thenReturn(false); when(resultRow.getObject(0)).thenReturn("str"); final List result = q.getResultList(); assertEquals(1, result.size()); assertEquals("str", ((Object[]) result.get(0))[0]); assertNull(((Object[]) result.get(0))[1]); verify(resultRow).isBound(0); verify(resultRow).isBound(1); verify(resultRow, never()).getObject(1); }