Example usage for javax.persistence NoResultException getMessage

List of usage examples for javax.persistence NoResultException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.seedstack.i18n.internal.infrastructure.jpa.LocaleJpaRepository.java

@Override
public Locale getDefaultLocale() {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Locale> q = cb.createQuery(Locale.class);
    Root<Locale> l = q.from(Locale.class);
    q.where(cb.equal(l.get("defaultLocale"), true));
    try {// w w  w. ja v a2 s  .co m
        return entityManager.createQuery(q.select(l)).getSingleResult();
    } catch (NoResultException e) {
        LOGGER.warn(e.getMessage(), e);
        return null;
    }
}

From source file:org.apache.ranger.db.XXGroupUserDao.java

public List<XXGroupUser> findByUserId(Long userId) {
    if (userId != null) {
        try {//from  w  w  w .  j  a va 2 s.  com
            return getEntityManager().createNamedQuery("XXGroupUser.findByUserId", XXGroupUser.class)
                    .setParameter("userId", userId).getResultList();
        } catch (NoResultException e) {
            logger.debug(e.getMessage());
        }
    } else {
        logger.debug("ResourceId not provided.");
        return new ArrayList<XXGroupUser>();
    }
    return null;
}

From source file:org.apache.ranger.db.XXGroupUserDao.java

public XXGroupUser findByGroupNameAndUserId(String groupName, Long userId) {
    if (StringUtils.isNotBlank(groupName) && userId != null) {
        try {//  w  w  w  . j ava2 s.  c om
            return getEntityManager()
                    .createNamedQuery("XXGroupUser.findByGroupNameAndUserId", XXGroupUser.class)
                    .setParameter("userId", userId).setParameter("groupName", groupName).getSingleResult();
        } catch (NoResultException e) {
            logger.debug(e.getMessage());
        }
    } else {
        logger.debug("userId and/or groupId not provided.");
        return new XXGroupUser();
    }
    return null;
}

From source file:org.apache.ranger.db.XXGroupUserDao.java

/**
 * @param xUserId//from   w  w w.  j a v  a  2  s . co m
 *            -- Id of X_USER table
 * @return
 */
@SuppressWarnings("unchecked")
public List<Long> findGroupIdListByUserId(Long xUserId) {
    if (xUserId != null) {
        try {
            return getEntityManager().createNamedQuery("XXGroupUser.findGroupIdListByUserId")
                    .setParameter("xUserId", xUserId).getResultList();
        } catch (NoResultException e) {
            logger.debug(e.getMessage());
        }
    } else {
        logger.debug("UserId not provided.");
        return new ArrayList<Long>();
    }
    return null;
}

From source file:org.apache.ranger.db.XXGroupUserDao.java

public Set<String> findGroupNamesByUserName(String userName) {
    List<String> groupList = null;

    if (userName != null) {
        try {/*from w  w w  .  j a v  a 2s  .  c  o  m*/
            groupList = getEntityManager()
                    .createNamedQuery("XXGroupUser.findGroupNamesByUserName", String.class)
                    .setParameter("userName", userName).getResultList();
        } catch (NoResultException e) {
            logger.debug(e.getMessage());
        }
    } else {
        logger.debug("UserId not provided.");
    }

    if (groupList != null) {
        return new HashSet<String>(groupList);
    }

    return new HashSet<String>();
}

From source file:org.meveo.service.communication.impl.MeveoInstanceService.java

public MeveoInstance findByCode(String meveoInstanceCode) {
    QueryBuilder qb = new QueryBuilder(MeveoInstance.class, "c");
    qb.addCriterion("code", "=", meveoInstanceCode, true);

    try {/*from   www .  ja  v  a 2 s  . c o m*/
        return (MeveoInstance) qb.getQuery(getEntityManager()).getSingleResult();
    } catch (NoResultException e) {
        log.warn("failed to find MeveoInstance", e.getMessage());
        return null;
    }
}

From source file:org.osiam.resources.provisioning.SCIMGroupProvisioning.java

@Override
public Group getById(String id) {
    try {// w  w  w .j  a va 2s  .c  om
        return groupConverter.toScim(groupDao.getById(id));
    } catch (NoResultException nre) {
        LOGGER.log(Level.INFO, nre.getMessage(), nre);

        throw new ResourceNotFoundException(String.format("Group with id '%s' not found", id), nre);
    } catch (PersistenceException pe) {
        LOGGER.log(Level.WARNING, pe.getMessage(), pe);

        throw new ResourceNotFoundException(String.format("Group with id '%s' not found", id), pe);
    }
}

From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.SubNetworkInstanceDaoJpaImpl.java

private SubNetworkInstance findByNetworkInstanceName(String name, String vdc, String region)
        throws EntityNotFoundException {
    Query query = getEntityManager().createQuery(
            "select p from SubNetworkInstance p where p.name = :name and p.vdc = :vdc and p.region = :region");
    query.setParameter("name", name);
    query.setParameter("vdc", vdc);
    query.setParameter("region", region);
    SubNetworkInstance subNetworkInstance = null;
    try {//from  w ww  . j  a v a2 s  .c om
        subNetworkInstance = (SubNetworkInstance) query.getSingleResult();
    } catch (NoResultException e) {
        String message = " No subNetworkInstance found in the database with id: " + name + " Exception: "
                + e.getMessage();
        throw new EntityNotFoundException(NetworkInstance.class, "name", name);
    }
    return subNetworkInstance;
}

From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.SubNetworkDaoJpaImpl.java

private SubNetwork findByNetworkName(String name, String vdc, String region) throws EntityNotFoundException {
    Query query = getEntityManager().createQuery(
            "select p from SubNetwork p where p.name = :name and p.vdc = :vdc and p.region = :region");
    query.setParameter("name", name);
    query.setParameter("vdc", vdc);
    query.setParameter("region", region);
    SubNetwork subNetwork = null;/*from   w  w w.  j a v a 2s  .  c  o m*/
    try {
        subNetwork = (SubNetwork) query.getSingleResult();
    } catch (NoResultException e) {
        String message = " No subNetwork found in the database with id: " + name + " vdc " + vdc + " region "
                + region + " Exception: " + e.getMessage();
        throw new EntityNotFoundException(SubNetwork.class, "name", name);
    }
    return subNetwork;
}

From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.NetworkDaoJpaImpl.java

private Network findNetworkWithSubNet(String name, String vdc, String region) throws EntityNotFoundException {
    Query query = getEntityManager().createQuery("select p from Network p left join "
            + " fetch p.subNets where p.name = :name and p.vdc = :vdc and p.region =:region");
    query.setParameter("name", name);

    query.setParameter("region", region);
    if (vdc == null) {

        query.setParameter("vdc", "");
    } else {/*from ww  w.  ja  v  a 2s. c o m*/
        query.setParameter("vdc", vdc);
    }
    Network network = null;
    try {
        network = (Network) query.getSingleResult();
    } catch (NoResultException e) {
        String message = " No network found in the database with id: " + name + " and vdc " + vdc + " region "
                + region + " Exception: " + e.getMessage();
        throw new EntityNotFoundException(Network.class, "name", name);
    }
    return network;
}