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:eu.europa.ec.fisheries.uvms.exchange.dao.bean.ExchangeLogDaoBean.java

@Override
public ExchangeLog getExchangeLogByGuid(String logGuid, TypeRefType typeRefType) throws ExchangeDaoException {
    try {/* ww w.j  a  v a 2 s  . c  o m*/
        TypedQuery<ExchangeLog> query = em.createNamedQuery(ExchangeConstants.LOG_BY_GUID, ExchangeLog.class);
        query.setParameter("typeRefType", typeRefType);
        query.setParameter("guid", logGuid);
        return query.getSingleResult();
    } catch (NoResultException e) {
        LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
        throw new NoEntityFoundException("[ Error when getting entity by ID. ]");
    } catch (Exception e) {
        LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting entity by ID. ] ");
    }
}

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

@Override
public User getById(String id) {
    try {/*from w  w  w  . j  a  v  a2  s . co m*/
        UserEntity userEntity = userDao.getById(id);
        User user = userConverter.toScim(userEntity);
        return getUserWithoutPassword(user);
    } catch (NoResultException nre) {
        LOGGER.log(Level.INFO, nre.getMessage(), nre);

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

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

From source file:eu.europa.ec.fisheries.uvms.exchange.dao.bean.ExchangeLogDaoBean.java

@Override
public List<ExchangeLog> getExchangeLogByTypesRefAndGuid(String typeRefGuid, List<TypeRefType> types)
        throws ExchangeDaoException {
    try {/*  w ww .ja  va2 s  .c om*/
        org.hibernate.Query namedQuery = getEm().unwrap(Session.class)
                .getNamedQuery(ExchangeConstants.LOG_BY_TYPE_REF_AND_GUID);
        namedQuery.setParameter("typeRefGuid", typeRefGuid);
        namedQuery.setParameterList("typeRefTypes", types);
        return namedQuery.list();
    } catch (NoResultException e) {
        LOG.error("[ Error when getting entity by type ref ID. ] {}", e.getMessage());
        throw new NoEntityFoundException("[ Error when getting entity by type ref ID. ]");
    } catch (Exception e) {
        LOG.error("[ Error when getting entity by type ref ID. ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting entity by type ref ID. ] ");
    }
}

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

/**
 * It get the tier instance which have the concrete network.
 * @param name: the network name//  w  w w.j a  v  a 2 s.c  om
 * @param vdc: the vdc
 * @param region: the region
 * @return
 * @throws EntityNotFoundException
 */
public List<TierInstance> findTierInstanceUsedByNetwork(String name, String vdc, String region)
        throws EntityNotFoundException {
    Query query = getEntityManager()
            .createQuery("select tier from TierInstance tier join tier.networkInstances net where "
                    + "net.name = :name and net.vdc = :vdc and net.region = :region");
    query.setParameter("name", name);
    query.setParameter("vdc", vdc);
    query.setParameter("region", region);
    List<TierInstance> tierInstanceList = null;
    try {
        tierInstanceList = (List<TierInstance>) query.getResultList();
    } catch (NoResultException e) {
        String message = " No TierInstance found in the database with network Instance: " + name + " vdc " + vdc
                + " region " + region + " Exception: " + e.getMessage();
        log.debug(message);
        throw new EntityNotFoundException(NetworkInstance.class, "name", name);
    }
    return tierInstanceList;
}

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

private NetworkInstance findByNetworkInstanceName(String name, String vdc, String region)
        throws EntityNotFoundException {
    Query query = getEntityManager().createQuery("select p from NetworkInstance p left join "
            + "fetch p.subNets where p.name = :name and p.vdc = :vdc and p.region = :region");
    query.setParameter("name", name);
    query.setParameter("vdc", vdc);
    query.setParameter("region", region);
    NetworkInstance networkInstance = null;
    try {/* w w  w . j  av a  2s . c o  m*/
        networkInstance = (NetworkInstance) query.getSingleResult();
    } catch (NoResultException e) {
        String message = " No NetworkInstance found in the database with id: " + name + " vdc " + vdc
                + " region " + region + " Exception: "

                + e.getMessage();
        log.debug(message);
        throw new EntityNotFoundException(NetworkInstance.class, "name", name);
    }
    return networkInstance;
}

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

/**
 * {@inheritDoc}//from  w  w w.ja  va2 s  . c o 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.telefonica.euro_iaas.paasmanager.dao.impl.ApplicationInstanceDaoJpaImpl.java

/**
 * Get an application instance given its name and vdc.
 * @param name//from  w  w w .j  a  va 2s.  c o  m
 * @param vdc
 * @return
 * @throws EntityNotFoundException
 */
public ApplicationInstance load(String name, String vdc) throws EntityNotFoundException {
    Query query = getEntityManager()
            .createQuery("select p from ApplicationInstance p where p.name = :name and p.vdc = :vdc");
    query.setParameter("name", name);

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

        query.setParameter("vdc", "");
    } else {
        query.setParameter("vdc", vdc);
    }
    ApplicationInstance app = null;
    try {
        app = (ApplicationInstance) query.getSingleResult();
    } catch (NoResultException e) {
        String message = " No app found in the database with id: " + name + " and vdc " + vdc + " Exception: "
                + e.getMessage();

        throw new EntityNotFoundException(Network.class, "name", name);
    }
    return app;
}

From source file:de.egore911.opengate.services.GameserverService.java

@GET
@Path("/remove")
@Produces("application/json")
@Documentation("This method removes a gameserver from the list. It is recommend to call this "
        + "method on shutdown of the gameserver. The remote IP will be obtained from the packet "
        + "sent to the server so server behind a NAT will not work. The method will answer using "
        + "a JSON object like {status: 'ok', detail: '...'}.")
public Response removeGameserver(@Context HttpServletRequest req) {
    String remoteAddr = req.getRemoteAddr();
    EntityManager em = EntityManagerFilter.getEntityManager();
    Gameserver gameserver;//w w w  . jav  a 2s.  c o  m
    try {
        JSONObject retval = new JSONObject();
        StatusHelper.ok(retval);
        try {
            gameserver = (Gameserver) em
                    .createQuery("select gameserver from Gameserver gameserver where address = :address")
                    .setParameter("address", remoteAddr).getSingleResult();
            em.remove(gameserver);
            retval.put("detail", "Successfully removed");
        } catch (NoResultException e) {
            // Nothing to do
            retval.put("detail", "Already removed");
        }
        return Response.ok(retval.toString()).build();
    } catch (JSONException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:de.egore911.opengate.services.GameserverService.java

@GET
@Path("/add")
@Produces("application/json")
@Documentation("Add or update a gameserver to the list of available game servers. "
        + "The remote IP will be obtained from the packet sent to the server so server "
        + "behind a NAT will not work. The method will answer using a JSON object like "
        + "{status: 'ok', detail: '...'}.")
public Response addGameserver(@Context HttpServletRequest req) {
    String remoteAddr = req.getRemoteAddr();
    EntityManager em = EntityManagerFilter.getEntityManager();
    Gameserver gameserver;//from w  w w  .  j a  va2 s .co m
    try {
        JSONObject retval = new JSONObject();
        StatusHelper.ok(retval);
        try {
            gameserver = (Gameserver) em
                    .createQuery("select gameserver from Gameserver gameserver where address = :address")
                    .setParameter("address", remoteAddr).getSingleResult();
            retval.put("detail", "Gameserver updated");
        } catch (NoResultException e) {
            gameserver = new Gameserver();
            gameserver.setAddress(remoteAddr);
            retval.put("detail", "Gameserver added");
        }
        gameserver.setLastSeen(new Date());
        em.persist(gameserver);
        return Response.ok(retval.toString()).build();
    } catch (JSONException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:com.exp.tracker.services.impl.JpaUserService.java

@Transactional
public UserBean addUser(UserBean ub, RequestContext ctx) {
    UserBean newUb = null;//from  w ww  .j  a  v a2  s .c o  m
    boolean userExists = true;
    // first find match
    Query queryFindMatch = em.createNamedQuery("findUserMatch");
    queryFindMatch.setParameter("username", ub.getUsername());
    // queryFindMatch.setParameter("emailId", ub.getEmailId());
    @SuppressWarnings("unused")
    UserEntity ue = null;
    try {
        ue = (UserEntity) queryFindMatch.getSingleResult();
    } catch (NoResultException nre) {
        if (logger.isDebugEnabled()) {
            logger.debug("User Id does not exist, thus can be added - " + ub.getUsername() + nre.getMessage());
        }
        userExists = false;
    }

    if (!userExists) {
        UserEntity ue1 = ub.getUserEntity();
        Calendar calendar = Calendar.getInstance();
        String newPassword = ub.getPassword();
        if (null == newPassword) {
            newPassword = RandomStringUtils.random(8, true, true);
        }
        // save hashed with salt
        ue1.setPassword(passwordEncoder.getHash(ub.getUsername(), newPassword));
        ue1.setCreatedDate(calendar.getTime());
        ue1.setPasswordChangeNeeded(1);
        em.persist(ue1);
        // we will add a "ROLE_USER" by default
        List<AuthEntity> ael = new ArrayList<AuthEntity>();
        AuthEntity ae = new AuthEntity();
        ae.setAuthority(RoleEntity.ROLE_USER);
        ae.setUsername(ub.getUsername());
        ae.setUser_id(ue1.getId());
        ael.add(ae);
        ue1.setAuthSet(ael);
        // now merge
        em.merge(ue1);
        // default role merged
        newUb = new UserBean(ue1);
        // we set this clear text just this once so that it can be emailed
        // to user
        newUb.setPassword(newPassword);
        // Add message to be displayed on UI
        ctx.getMessageContext()
                .addMessage(new MessageBuilder().info().defaultText("User added successfuly.").build());
    } else {
        // Add message to be displayed on UI
        ctx.getMessageContext().addMessage(new MessageBuilder().error()
                .defaultText("Username has been taken already. Choose another.").build());
    }
    return newUb;
}