Example usage for javax.persistence TypedQuery getSingleResult

List of usage examples for javax.persistence TypedQuery getSingleResult

Introduction

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

Prototype

X getSingleResult();

Source Link

Document

Execute a SELECT query that returns a single result.

Usage

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllUnrankedLosesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedWinsForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllRankedMatchesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedMatchesForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:org.openmeetings.app.data.basic.ErrorManagement.java

public ErrorType getErrorType(Long errortype_id) {
    try {/*  w w  w  .j a va2s .  c o  m*/
        String hql = "select c from ErrorType as c "
                + "WHERE c.deleted <> :deleted AND c.errortype_id = :errortype_id";
        TypedQuery<ErrorType> query = em.createQuery(hql, ErrorType.class);
        query.setParameter("deleted", "true");
        query.setParameter("errortype_id", errortype_id);
        return query.getSingleResult();
    } catch (Exception ex2) {
        log.error("[getErrorType(" + errortype_id + ")]", ex2);
    }
    return null;
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllUnrankedMatchesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedMatchesForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:com.music.dao.PieceDao.java

public Piece getNewlyCreatedPiece(UserPreferences preferences) {
    String queryString = "SELECT piece FROM Piece piece WHERE piece.newlyCreated = true ORDER BY generationTime DESC";
    if (!preferences.isDefault()) {
        queryString = addPreferenceCriteria(preferences,
                "SELECT piece FROM Piece piece WHERE piece.newlyCreated = true AND ")
                + " ORDER BY generationTime DESC";
    }//from  w w  w  . j a va 2  s  . c  om
    TypedQuery<Piece> query = getEntityManager().createQuery(queryString, Piece.class);
    query.setMaxResults(1);

    try {
        return query.getSingleResult();
    } catch (NoResultException ex) {
        return null;
    }
}

From source file:com.agnie.useradmin.tools.dbinit.DBInitializer.java

@Transactional
private Role getRoleByNameAndApplication(String name, String appId) {

    TypedQuery<Role> qry = em.get().createNamedQuery("Role.getByApplicationAndName", Role.class);
    qry.setParameter("name", name);
    qry.setParameter("applicationId", appId);
    return qry.getSingleResult();
}

From source file:com.github.aynu.mosir.core.enterprise.persistence.StandardRepositoryImpl.java

/** {@inheritDoc} */
@Override//  www . j  a  v a  2 s .  co  m
public R findOne(final String name, final R object, final String... fields) throws PersistenceException {
    try {
        final TypedQuery<R> query = getManager().createNamedQuery(name, getEntityClass());
        for (final Entry<String, Object> entry : filter(object, fields).entrySet()) {
            query.setParameter(entry.getKey(), entry.getValue());
        }
        return query.getSingleResult();
    } catch (final IllegalArgumentException | IllegalStateException
            | javax.persistence.PersistenceException e) {
        LOG.warn(e.toString(), e);
        throw new PersistenceException(e);
    }
}

From source file:com.simplecrud.dao.UserInfoDao.java

/**
 *
 * @param username/*from   w  ww . j a v a  2  s.  c o  m*/
 * @return
 */
public Object getUserInfo(String username) {

    TypedQuery<NewMember> q = em.createQuery("SELECT n FROM NewMember n WHERE n.username = :username",
            NewMember.class);
    q.setParameter("username", username);
    return q.getSingleResult();
}

From source file:fr.univrouen.poste.web.SignUpController.java

@RequestMapping(value = "/initpassword", method = RequestMethod.POST)
public String initPassword(@Valid UserRegistrationForm userRegistration, BindingResult result, Model model,
        HttpServletRequest request) {// www  .j  a  v  a 2 s .c  om
    String textePremierePageAnonyme = AppliConfig.getCacheTextePremierePageAnonyme();
    model.addAttribute("textePremierePageAnonyme", textePremierePageAnonyme);
    TypedQuery<User> query = User.findUsersByActivationKeyAndEmailAddress(userRegistration.getActivationKey(),
            userRegistration.getEmailAddress(), null, null);
    User User = query.getSingleResult();
    if (null != User && userRegistration.getPassword().equals(userRegistration.getRepeatPassword())
            && !userRegistration.getPassword().isEmpty()) {
        if (User.getPassword() == null) {
            User.setActivationDate(new Date());
            User.setEnabled(true);
            User.setPassword(messageDigestPasswordEncoder.encodePassword(userRegistration.getPassword(), null));
            User.merge();
        }
        return "login";
    } else {
        return "signup/error";
    }

}

From source file:com.simplecrud.dao.UserInfoDao.java

/**
 *
 * @param username//from   w w w .j a va  2 s.  co  m
 * @return EMAIL
 */
public Object getUserEmail(String username) {

    TypedQuery<NewMember> q = em.createQuery("SELECT n.email FROM NewMember n WHERE n.username = :username",
            NewMember.class);
    q.setParameter("username", username);
    return q.getSingleResult();
}