TypedQueryImpl extends AbstractQuery implements TypedQuery<X> { @Override public X getSingleResult() { ensureOpen(); try { final List<X> res = getResultListImpl(); if (res.isEmpty()) { throw new NoResultException("No result found for query " + query); } if (res.size() > 1) { throw new NoUniqueResultException("Multiple results found for query " + query); } return res.get(0); } catch (OntoDriverException e) { markTransactionForRollback(); throw queryEvaluationException(e); } catch (RuntimeException e) { if (exceptionCausesRollback(e)) { markTransactionForRollback(); } throw e; } } TypedQueryImpl(final QueryHolder query, final Class<X> resultType,
                          final ConnectionWrapper connection, MetamodelProvider metamodelProvider); void setUnitOfWork(UnitOfWork uow); @Override List<X> getResultList(); @Override X getSingleResult(); @Override Stream<X> getResultStream(); @Override TypedQuery<X> setMaxResults(int maxResults); @Override TypedQuery<X> setFirstResult(int startPosition); @Override TypedQuery<X> setParameter(int position, Object value); @Override TypedQuery<X> setParameter(int position, String value, String language); @Override TypedQuery<X> setParameter(String name, Object value); @Override TypedQuery<X> setParameter(String name, String value, String language); @Override TypedQuery<X> setParameter(Parameter<T> parameter, T value); @Override TypedQuery<X> setParameter(Parameter<String> parameter, String value, String language); @Override TypedQuery<X> setUntypedParameter(int position, Object value); @Override TypedQuery<X> setUntypedParameter(String name, Object value); @Override TypedQuery<X> setUntypedParameter(Parameter<T> parameter, T value); @Override TypedQuery<X> setDescriptor(Descriptor descriptor);  }
@Test void getSingleResultWithEntityTypeReturnsCorrectResult() throws Exception { final TypedQuery<OWLClassA> query = create(SELECT_QUERY, OWLClassA.class); final List<String> uris = initDataForQuery(1); final OWLClassA res = query.getSingleResult(); assertNotNull(res); assertEquals(uris.get(0), res.getUri().toString()); }
@Test void askQueryReturnsSingleBoolean() throws Exception { final TypedQuery<Boolean> query = create(ASK_BOOLEAN_QUERY, Boolean.class); initAskQueryData(true); final Boolean result = query.getSingleResult(); assertNotNull(result); assertTrue(result); verify(uowMock, never()).readObject(eq(Boolean.class), any(), any(Descriptor.class)); }