Example usage for javax.persistence Query getSingleResult

List of usage examples for javax.persistence Query getSingleResult

Introduction

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

Prototype

Object getSingleResult();

Source Link

Document

Execute a SELECT query that returns a single untyped result.

Usage

From source file:br.org.indt.ndg.server.language.LanguageManagerBean.java

@Override
public String getLanguagePath(String locale) {
    Query q = manager.createNamedQuery("languages.getPath");
    q.setParameter("locale", locale + "%");

    Language language = (Language) q.getSingleResult();

    return language.getPath();
}

From source file:br.org.indt.ndg.server.language.LanguageManagerBean.java

@Override
public String getFontPath(String locale) {
    Query q = manager.createNamedQuery("languages.getPath");
    q.setParameter("locale", locale + "%");

    Language language = (Language) q.getSingleResult();

    return language.getFontPath();
}

From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java

public int count() {
    javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
    javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
    cq.select(em.getCriteriaBuilder().count(rt));
    javax.persistence.Query q = em.createQuery(cq);
    return ((Long) q.getSingleResult()).intValue();
}

From source file:dao.LocalisationDAOImpl.java

@Override
public LocalisationEntity findForExperience(Long experienceId) {
    Query q = this.em.createQuery("SELECT l FROM LocalisationEntity l WHERE l.experience.id = ?");
    q.setParameter(1, experienceId);//from w ww  . ja v a  2s. co m
    return (LocalisationEntity) q.getSingleResult();
}

From source file:ca.travelagency.persistence.DaoSupportImpl.java

@Override
public Long count(DaoCriteria daoCriteria) {
    Query query = QuerySQL.count(daoCriteria.getCriteria(), entityManager).makeQuery();
    Number count = (Number) query.getSingleResult();
    return count.longValue();
}

From source file:de.berlios.jhelpdesk.dao.jpa.ArticleCategoryDAOJpa.java

@Transactional(readOnly = false)
public void moveUp(final Long categoryId) {
    this.jpaTemplate.execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query q = em.createNativeQuery("SELECT category_move_up(?1)");
            q.setParameter(1, categoryId);
            q.getSingleResult();
            return null;
        }/* ww  w.  j  a  v  a2  s. c o  m*/
    });
}

From source file:com.expressui.core.dao.security.RoleDao.java

/**
 * Finds Role by a given name./*from  w w w  . j  a  va2 s . c  o m*/
 *
 * @param name name to query
 * @return found Role
 */
public Role findByName(String name) {
    Query query = getEntityManager().createQuery("SELECT r FROM Role r WHERE r.name = :name");

    query.setParameter("name", name);

    return (Role) query.getSingleResult();
}

From source file:de.berlios.jhelpdesk.dao.jpa.ArticleCategoryDAOJpa.java

@Transactional(readOnly = false)
public void moveDown(final Long categoryId) {
    this.jpaTemplate.execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query q = em.createNativeQuery("SELECT category_move_down(?1)");
            q.setParameter(1, categoryId);
            q.getSingleResult();
            return null;
        }//w ww . j a v a2  s  .  c  o m
    });
}

From source file:Professor.java

  public Professor findProfessorNoCacheNamed(int empId) {
  Query q = em.createNamedQuery("findProfessorNoCache");
  q.setParameter(1, empId);/*from  ww  w. j  a va 2 s . c  o m*/
  try {
    return (Professor) q.getSingleResult();
  } catch (NoResultException e) {
    return null;
  }
}

From source file:bc8.movies.dao.UserDaoImpl.java

public boolean isFavorite(User user, Movie movie) {
    int favorite = Constants.DB_MOVIE_FAVORITE;
    boolean toReturn = false;

    StringBuilder sb = new StringBuilder();
    sb.append("select * from ").append(Constants.DB_TABLE_USER_MOVIE).append(" where userId=")
            .append(user.getId()).append(" and movieId=").append(movie.getId());

    Query query = em.createNativeQuery(sb.toString());

    try {//from   www  . ja va 2  s  . co m
        Object[] myArr = ((Object[]) query.getSingleResult());
        String value = myArr[4].toString();
        if (value.equals("1")) {
            toReturn = true;
        }
    } catch (NoResultException e) {
    }
    return toReturn;
}