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 getCountAllMatchesForPlayerInLeague(Player p, League l) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllMatchesForPlayerInLeague", Long.class);
    query.setParameter("player", p);
    query.setParameter("league", l);
    return query.getSingleResult();
}

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

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

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

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

From source file:cn.newgxu.lab.core.repository.impl.AbstractCommonDaoImpl.java

/**
 * ??<b style="color: red;"> :xxx </b>?????
 * @param hql ?hql//from www.  j a  v  a2  s  . c  om
 * @param type 
 * @param objects ?map, ?
 * @return ?
 */
protected T executeQuery(String hql, Class<T> clazz, Map<String, Object> params) {
    TypedQuery<T> query = em.createQuery(hql, clazz);
    if (params != null) {
        for (String name : params.keySet()) {
            query.setParameter(name, params.get(name));
        }
    }
    return query.getSingleResult();
}

From source file:com.epam.ipodromproject.repository.jpa.JPABetRepository.java

@Override
public long getTotalArchivedBetsMadeByUser(String username) {
    TypedQuery<Long> query = entityManager.createNamedQuery("Bet.findBetsPagesArchivedByUser", Long.class);
    query.setParameter("username", username);
    query.setParameter("betResult", BetResult.NOT_CONSIDERED);
    long pages = 1;
    try {/*from  w  w  w .  ja v  a 2s  .c  o m*/
        pages = query.getSingleResult();
    } catch (Exception e) {
        pages = (long) 1;
    }
    return pages;
}

From source file:org.openmeetings.app.data.conference.PollManagement.java

public PollType getPollType(Long typeId) {
    TypedQuery<PollType> q = em.createQuery("SELECT pt FROM PollType pt WHERE pt.pollTypesId = :pollTypesId",
            PollType.class);
    q.setParameter("pollTypesId", typeId);
    return q.getSingleResult();
}

From source file:cn.newgxu.lab.core.repository.impl.AbstractCommonDaoImpl.java

/**
 * ??<b style="color: red;"> ? </b>????
 * @param hql hql/*w  w  w  .jav a 2  s . com*/
 * @param type 
 * @param objects ?, null?
 * @return ?
 */
protected T executeQuery(String hql, Class<T> clazz, Object... objects) {
    TypedQuery<T> query = em.createQuery(hql, clazz);
    if (objects != null) {
        for (int i = 0; i < objects.length; i++) {
            query.setParameter(i + 1, objects[i]);
        }
    }
    return query.getSingleResult();
}

From source file:com.epam.ipodromproject.repository.jpa.JPABetRepository.java

@Override
public long getTotalActiveBetsMadeByUser(String username) {
    TypedQuery<Long> query = entityManager.createNamedQuery("Bet.findNumberOfActiveBetsByUsername", Long.class);
    query.setParameter("betResult", BetResult.NOT_CONSIDERED);
    query.setParameter("username", username);
    long pages;/*  ww  w  .  jav a 2s.c o m*/
    try {
        pages = query.getSingleResult();
    } catch (Exception e) {
        pages = (long) 1;
    }
    return pages;
}

From source file:name.marcelomorales.siqisiqi.openjpa.impl.OrmFinderImpl.java

@Override
@TransactionAttribute//from w  w  w .  j  a  va  2s . c  o m
public long countByExample(final T example, final T example2) {
    OpenJPACriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> q = cb.createQuery(Long.class);
    Root<T> from = q.from(persistentClass);
    final Expression<Long> count = newCountExpression(cb, from);
    q.select(count);
    q.where(newQbePredicates(cb, from, example, example2));
    TypedQuery<Long> query = entityManager.createQuery(q);
    try {
        return query.getSingleResult();
    } catch (NoResultException e) {
        return 0;
    }
}

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

public FieldLanguage getFieldLanguageById(Long language_id) {
    try {//from   w ww. jav a  2  s. co  m
        String hql = "select c from FieldLanguage as c " + "WHERE c.deleted <> :deleted "
                + "AND c.language_id = :language_id";
        TypedQuery<FieldLanguage> query = em.createQuery(hql, FieldLanguage.class);
        query.setParameter("deleted", "true");
        query.setParameter("language_id", language_id);
        FieldLanguage fl = null;
        try {
            fl = query.getSingleResult();
        } catch (NoResultException ex) {
        }
        return fl;
    } catch (Exception ex2) {
        log.error("[getLanguageById]: ", ex2);
    }
    return null;
}