Example usage for javax.persistence NoResultException NoResultException

List of usage examples for javax.persistence NoResultException NoResultException

Introduction

In this page you can find the example usage for javax.persistence NoResultException NoResultException.

Prototype

public NoResultException(String message) 

Source Link

Document

Constructs a new NoResultException exception with the specified detail message.

Usage

From source file:edu.berkeley.compbio.ncbitaxonomy.jpadao.NcbiTaxonomyNodeDaoImpl.java

/**
 * {@inheritDoc}/*  ww w  .  j  a  v  a 2s. c  o  m*/
 */
@NotNull
//@Transactional
public NcbiTaxonomyNode findById(Integer id) {
    NcbiTaxonomyNode node = entityManager.find(NcbiTaxonomyNode.class, id);
    if (node == null) {
        throw new NoResultException("Could not find taxon: " + id);
    }
    // eagerly load the path
    //node.getAncestorPath();
    return node;
}

From source file:com.eu.evaluation.server.service.impl.EvaluateTemplateServiceImpl.java

public EvaluateItem createOrReplaceEvaluateItem(EvaluateTypeEnum type, String objectDictionaryID,
        String fieldDictionaryID, Map<String, Object> otherMap) {

    ObjectDictionary od = objectDictionaryDAO.get(objectDictionaryID);
    if (od == null) {
        throw new NoResultException("ID " + objectDictionaryID + " ?-");
    }//from   w w  w.  j a  v a  2 s .  c  om

    FieldDictionary fd = fieldDictionaryDAO.get(fieldDictionaryID);
    if (fd == null) {
        throw new NoResultException("ID " + fieldDictionaryID + " ?-");
    }

    EvaluateItemTemplate template = evaluateItemTemplateDAO.findTheMatching(type, od, fd);//??

    EvaluateItemBuilder builder = EvaluateItemBuilderFactory.getBuilder(template.getEvaluateItemBuilder());//?

    EvaluateItem item = builder.findTheMatching(od, fd, otherMap);//

    if (item == null) {
        try {
            item = (EvaluateItem) type.getEvaClass().newInstance();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex.getMessage(), ex);
        }
    }

    //?
    item.setEvaluateClass(template.getEvaluateClass());
    item.setFieldDictionary(fd);
    item.setObjectDictionary(od);
    item.setDescribetion(template.getDescribetion());
    item.setEvaluateTypeEnum(template.getEvaluateTypeEnum());

    builder.buildEvaluateItem(item, template, otherMap);//?

    item = evaluateItemDAO.save(item);
    return item;
}

From source file:edu.berkeley.compbio.ncbitaxonomy.jpadao.NcbiTaxonomyNameDaoImpl.java

/**
 * {@inheritDoc}//from  w w  w. j  ava2s .com
 */
@NotNull
public NcbiTaxonomyName findById(Integer id) {
    NcbiTaxonomyName result = entityManager.find(NcbiTaxonomyName.class, id);
    if (result == null) {
        throw new NoResultException("Could not find taxon: " + id);
        //throw new NoSuchElementException();
    }
    return result;
}

From source file:com.lzs.core.support.ShiroDbRealm.java

/**
 * ?,./*from   w w w .ja v  a 2 s.c o m*/
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    try {
        UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
        String userName = token.getUsername();
        String plainPassword = String.valueOf(token.getPassword());
        if (userName != null && !"".equals(userName)) {
            User user = userService.findUniqueBy("username", token.getUsername());
            if (user == null || user.getDeleted() == 1) {
                throw new NoResultException("??");
            }
            PasswordService passwordService = new DefaultPasswordService();
            if (passwordService.passwordsMatch(plainPassword, user.getPassword())) {
                return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getUsername()),
                        plainPassword, getName());
            }
        }
    } catch (NoResultException e) {
        RuntimeException re = new RuntimeException("??", e);
        logger.error(re.getMessage(), re);
        throw re;
    } catch (NonUniqueResultException e) {
        RuntimeException re = new RuntimeException("????", e);
        logger.error(re.getMessage(), re);
        throw re;
    } catch (Exception e) {
        logger.error("", e);
    }

    throw new RuntimeException("??");
}

From source file:edu.zipcloud.cloudstreetmarket.core.services.StockProductServiceImpl.java

@Override
public Page<StockProduct> get(String indexId, String exchangeId, MarketId marketId, String startWith,
        Specification<StockProduct> spec, Pageable pageable, boolean validResults) {
    if (!StringUtils.isEmpty(indexId)) {
        Index index = indexRepository.findOne(indexId);
        if (index == null) {
            throw new NoResultException("No result found for the index ID " + indexId + " !");
        }//from   w  w w.j a va2  s.  c  o  m
        return stockProductRepository.findByIndices(index, pageable);
    }

    if (!StringUtils.isEmpty(startWith)) {
        spec = Specifications.where(spec)
                .and(new ProductSpecifications<StockProduct>().nameStartsWith(startWith));
    }

    if (marketId != null) {
        Market market = marketRepository.findOne(marketId);
        if (market == null) {
            throw new NoResultException("No result found for the market ID " + marketId + " !");
        }
        spec = Specifications.where(spec)
                .and(new ProductSpecifications<StockProduct>().marketIdEquals(marketId));
    }

    if (!StringUtils.isEmpty(exchangeId)) {
        spec = Specifications.where(spec)
                .and(new ProductSpecifications<StockProduct>().exchangeIdEquals(exchangeId));
    }

    spec = Specifications.where(spec).and(new ProductSpecifications<StockProduct>().nameNotNull())
            .and(new ProductSpecifications<StockProduct>().exchangeNotNull());

    if (validResults) {
        spec = Specifications.where(spec).and(new ProductSpecifications<StockProduct>().currencyNotNull())
                .and(new ProductSpecifications<StockProduct>().hasAPrice());
    }

    return stockProductRepository.findAll(spec, pageable);
}

From source file:org.eurekastreams.server.persistence.mappers.db.GetFieldFromTableByUniqueField.java

/**
 * Get the field by the unique field./* w  ww .j  a v a2  s . co m*/
 *
 * @param param
 *            the unique value to search on
 * @return the field found from the unique value
 */
@SuppressWarnings("unchecked")
public ResultFieldType execute(final UniqueFieldType param) {
    List<ResultFieldType> results = getEntityManager().createQuery(queryString)
            .setParameter("uniqueValue", param).getResultList();

    if (results.size() != 1) {
        throw new NoResultException("Expected 1 record from " + entityName + " with " + resultFieldName + ":"
                + uniqueFieldName + ", but found " + results.size());
    }
    return results.get(0);
}

From source file:com.hiperium.bo.manager.exception.ExceptionManager.java

/**
 * {@inheritDoc}/* w  ww  .j ava 2 s.  co m*/
 */
public InformationException createMessageException(@NotNull Exception ex, @NotNull Locale locale)
        throws InformationException {
    this.log.debug("createMessageException - START");
    if (ex instanceof InformationException || ex.getCause() instanceof InformationException) {
        return (InformationException) ex;
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    InformationException informacionExcepcion = null;
    try {
        informacionExcepcion = this.findErrorCode(ex, locale);
        if (informacionExcepcion == null) {
            return InformationException.generate(EnumI18N.COMMON, EnumInformationException.SYSTEM_EXCEPTION,
                    locale);
        } else if (informacionExcepcion.getErrorCode() == null) {
            return informacionExcepcion;
        }
        ErrorLanguagePK languagePK = new ErrorLanguagePK(informacionExcepcion.getErrorCode().toString(),
                locale.getLanguage());
        ErrorLanguage errorLenguaje = this.errorLanguageDAO.findById(languagePK, false, true);
        if (errorLenguaje == null) {
            throw new NoResultException(informacionExcepcion.getMessage());
        } else {
            informacionExcepcion = new InformationException(errorLenguaje.getText());
        }
        informacionExcepcion = this.createMessageParameters(informacionExcepcion, locale);
    } catch (NoResultException e) {
        this.log.error("ERROR - MESSAGE NOT FOUND IN DATA BASE: " + e.getMessage());
    }
    this.log.debug("createMessageException - END");
    return informacionExcepcion;
}

From source file:com.hiperium.bo.manager.exception.ExceptionManager.java

/**
 * This method finds the name of the entity table required for error message
 * generation in the case of Foreign Keys.
 * /*from  w w w  .j a va  2 s .  c  o m*/
 * @param infoExcepcion
 *            Exception information detail
 * @param locale
 *            user logged locale
 * @return the detail of the referenced table
 * @throws EntidadNoEncontradaException
 *             if the method not found the referenced entity table detail
 */
private String findEntityTableName(InformationException infoExcepcion, Locale locale)
        throws NoResultException, InformationException {
    this.log.debug("findEntityTableName - START");
    String message = infoExcepcion.getMessage();
    String[] messageSplit = message.split("fk_");
    String key = null;
    if (messageSplit.length > 0) {
        key = "fk_" + messageSplit[1].split("\"")[0];
    }
    Integrity integrity = this.integrityDAO.findByConstraintName(key);
    if (integrity == null) {
        throw new NoResultException(key);
    }
    String tableCode = integrity.getReferencedTableName();
    EntityLanguagePK languagePK = new EntityLanguagePK(tableCode, locale.getLanguage());
    EntityLanguage entityLanguage = this.entityLanguageDAO.findById(languagePK, false, true);
    String entityName = null;
    if (entityLanguage == null) {
        EntityTable entityTable = this.entityTableDAO.findById(tableCode, false, true);
        if (entityTable == null) {
            throw new NoResultException(tableCode);
        }
    } else {
        entityName = entityLanguage.getText();
    }
    this.log.debug("findEntityTableName - END");
    return entityName;
}

From source file:org.querybyexample.jpa.GenericRepository.java

@Transactional(readOnly = true)
public E findUnique(E entity, SearchParameters sp) {
    E result = findUniqueOrNone(entity, sp);
    if (result != null) {
        return result;
    }//from  w  w  w.jav  a2 s . co m
    throw new NoResultException("Developper: You expected 1 result but found none !");
}

From source file:org.sparkcommerce.openadmin.server.service.AdminEntityServiceImpl.java

@Override
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata,
        Entity containingEntity, Property collectionProperty, String collectionItemId,
        List<SectionCrumb> sectionCrumbs) throws ServiceException {
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(),
            sectionCrumbs);/*from ww  w. j a va 2  s  . c  o m*/

    FieldMetadata md = collectionProperty.getMetadata();
    String containingEntityId = getContextSpecificRelationshipId(containingClassMetadata, containingEntity,
            collectionProperty.getName());
    ppr.setSectionEntityField(collectionProperty.getName());

    PersistenceResponse response;

    if (md instanceof AdornedTargetCollectionMetadata) {
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);

        fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName() + "Target");
        fasc.setFilterValue(collectionItemId);
        ppr.addFilterAndSortCriteria(fasc);

        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        Assert.isTrue(entities != null && entities.length == 1, "Entity not found");
    } else if (md instanceof MapMetadata) {
        MapMetadata mmd = (MapMetadata) md;
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);

        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        for (Entity e : entities) {
            String idProperty = getIdProperty(containingClassMetadata);
            if (mmd.isSimpleValue()) {
                idProperty = "key";
            }
            Property p = e.getPMap().get(idProperty);
            if (p.getValue().equals(collectionItemId)) {
                response.setEntity(e);
                break;
            }
        }
    } else {
        throw new IllegalArgumentException(String.format(
                "The specified field [%s] for class [%s] was not an " + "advanced collection field.",
                collectionProperty.getName(), containingClassMetadata.getCeilingType()));
    }

    if (response == null) {
        throw new NoResultException(String.format(
                "Could not find record for class [%s], field [%s], main entity id "
                        + "[%s], collection entity id [%s]",
                containingClassMetadata.getCeilingType(), collectionProperty.getName(), containingEntityId,
                collectionItemId));
    }

    return response;
}