Package javax.persistence

Examples of javax.persistence.NoResultException


     * @throws IllegalStateException if called for an EJB QL UPDATE or DELETE statement
     */
    public Object getSingleResult() {
        List<?> rows = getResultList();
        if (rows.size() == 0) {
            throw new NoResultException();
        }
        if (rows.size() > 1) {
            throw new NonUniqueResultException();
        }

View Full Code Here


            @Override
            public Page answer() throws Throwable {
                return (Page)EasyMock.getCurrentArguments()[0];
            }
        });
        expect(pageTemplateRepository.getDefaultPage(PageType.USER)).andThrow(new NoResultException("No Result Exception"));

        expect(pageRepository.getAllPages(user.getId(), PageType.USER)).andReturn(new ArrayList<Page>());
        replay(userService, pageLayoutRepository, pageRepository, pageTemplateRepository);

        Page newPage = pageService.addNewUserPage(PAGE_NAME, PAGE_LAYOUT_CODE);
View Full Code Here

     * @throws IllegalStateException if called for an EJB QL UPDATE or DELETE statement
     */
    public Object getSingleResult() {
        List rows = getResultList();
        if (rows.size() == 0) {
            throw new NoResultException();
        }
        if (rows.size() > 1) {
            throw new NonUniqueResultException();
        }

View Full Code Here

    public Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException {
        List result = list();

        if (result == null || result.size() == 0) {
            throw new NoResultException();
        }

        if (result.size() > 1) {
            throw new NonUniqueResultException();
        }
View Full Code Here

  @SuppressWarnings( { "ThrowableInstanceNeverThrown", "unchecked" })
  public Object getSingleResult() {
    try {
      List result = query.list();
      if ( result.size() == 0 ) {
        throwPersistenceException( new NoResultException( "No entity found for query" ) );
      }
      else if ( result.size() > 1 ) {
        Set uniqueResult = new HashSet( result );
        if ( uniqueResult.size() > 1 ) {
          throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements" ) );
View Full Code Here

      if ( mucked ) {
        query.setMaxResults( getSpecifiedMaxResults() );
      }

      if ( result.size() == 0 ) {
        NoResultException nre = new NoResultException( "No entity found for query" );
        getEntityManager().handlePersistenceException( nre );
        throw nre;
      }
      else if ( result.size() > 1 ) {
        Set<X> uniqueResult = new HashSet<X>(result);
View Full Code Here

  public X getSingleResult() {
    _em.assertNotCloseInvoked();
        setHint("openjpa.hint.OptimizeResultCount", 1); // for DB2 optimization
    List result = getResultList();
    if (result == null || result.isEmpty())
            throw new NoResultException(_loc.get("no-result", getQueryString())
                    .getMessage());
    if (result.size() > 1)
            throw new NonUniqueResultException(_loc.get("non-unique-result",
                    getQueryString(), result.size()).getMessage());
    try {
        return (X)result.get(0);
    } catch (Exception e) {
            throw new NoResultException(_loc.get("no-result", getQueryString())
                .getMessage());
    }
  }
View Full Code Here

        if (resultList instanceof LazyList<?>) {
            ((LazyList<?>) resultList).setMaxResultsPerToken(2);
        }
        Iterator<?> itr = resultList.iterator();
        if (!itr.hasNext()) {
            throw new NoResultException();
        }
        Object obj = itr.next();
        if (itr.hasNext()) {
            throw new NonUniqueResultException();
        }
View Full Code Here

        setHint(QueryHints.HINT_RESULT_COUNT, 1); // for DB2 optimization
    boolean queryFetchPlanUsed = pushQueryFetchPlan();
    try {
        List result = getResultList();
        if (result == null || result.isEmpty())
                throw new NoResultException(_loc.get("no-result", getQueryString())
                        .getMessage());
        if (result.size() > 1)
                throw new NonUniqueResultException(_loc.get("non-unique-result",
                        getQueryString(), result.size()).getMessage());
        try {
            return (X)result.get(0);
        } catch (Exception e) {
                throw new NoResultException(_loc.get("no-result", getQueryString())
                    .getMessage());
        }
    } finally {
      popQueryFetchPlan(queryFetchPlanUsed);
    }
View Full Code Here

    protected void setRollbackOnly() {
        entityManager.setRollbackOnly();
    }

    protected void throwNoResultException(String message) {
        throw new NoResultException(message);
    }
View Full Code Here

TOP

Related Classes of javax.persistence.NoResultException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.