Example usage for javax.persistence Query getResultList

List of usage examples for javax.persistence Query getResultList

Introduction

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

Prototype

List getResultList();

Source Link

Document

Execute a SELECT query and return the query results as an untyped List.

Usage

From source file:cz.fi.muni.pa036.airticketbooking.dao.impl.SeatDaoImpl.java

@Override
public List<Seat> getByPlane(Long plane) {
    try {/*from  w w  w  .  j a  va2  s  .  c o  m*/
        Query q = em.createQuery("FROM Seat WHERE plane_id=:plane");
        q.setParameter("plane", plane);
        List<Seat> planes = q.getResultList();

        return Collections.unmodifiableList(planes);
    } catch (PersistenceException | IllegalArgumentException ex) {
        throw new DataAccessException(ex.getMessage(), ex) {
        };
    }
}

From source file:at.irian.demo.jsfatwork.repository.jpa.JpaPollRepository.java

public List<Poll> loadOpenPolls(User user) {
    Query openPolls = this.entityManager.createNamedQuery(FIND_OPEN_POLLS);
    openPolls.setParameter(PARAMETER_CURRENT_DATE, new Date(), TemporalType.DATE);
    openPolls.setParameter(PARAMETER_USER, user);

    return openPolls.getResultList();
}

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

public boolean checkUsername(User user) {
    Query query = em.createQuery("select user from User user where user.username = :username");

    query.setParameter("username", user.getUsername());
    if (query.getResultList().isEmpty()) {
        return false;
    } else {//from w w  w.j  a v  a 2s  . c  o m
        return true;
    }
}

From source file:cz.muni.fi.pa165.airport.dao.dao.PlaneDAO.java

@Override
public List<Plane> getAll() {
    Query query = em.createQuery("SELECT f FROM Plane f WHERE f.archived = :archived  ORDER BY f.name ASC");
    query.setParameter("archived", false);
    return (List<Plane>) query.getResultList();
}

From source file:com.accounting.smsbundle.SmsInfoSessionBean.java

public List<SmsInfo> findAll(Date fromDate, Date todate, SmsInfoStatus status, long sentToId, int orgid) {
    StringBuilder qSql = new StringBuilder();
    qSql.append("Select  s from SmsInfo s where s.orgId=");
    qSql.append(orgid);//w ww.  ja  v  a  2  s  .com
    if (fromDate != null && todate != null) {
        qSql.append(" and date(s.createdDate) BETWEEN '").append(HelperUtil.formatDateYYYMMDD(fromDate))
                .append("' and '").append(HelperUtil.formatDateYYYMMDD(todate)).append("'");
    }
    if (sentToId != 0) {
        //sentToId is customer id, or member id of any other table etc.
        qSql.append(" and d.sentToId=").append(sentToId);
    }
    if (status != null) {
        //sentToId is customer id, or member id of any other table etc.
        qSql.append(" and d.sentStatus=").append(status);
    }
    if (sentToId != 0) {
        //sentToId is customer id, or member id of any other table etc.
        qSql.append(" and d.sentToId=").append(sentToId);
    }
    //        System.out.println("final sql " + qSql.toString());
    Query q = em.createQuery(qSql.toString(), SmsInfo.class);
    return q.getResultList();
}

From source file:com.cimpoint.mes.server.repositories.PartRepository.java

@SuppressWarnings("unchecked")
public Set<String> findAllPartNameWithRevisions() throws Exception {
    try {/*from   ww  w.ja  v a  2s . c  om*/
        Set<String> strSet = new HashSet<String>();

        Query qry = entityManager.createQuery("SELECT e FROM EPart e");
        List<EPart> parts = (List<EPart>) qry.getResultList();
        if (parts != null && parts.size() > 0) {
            for (EPart e : parts) {
                strSet.add(e.getName() + MESConstants.REV_FOR_TEXT + e.getRevision());
            }
        }
        return strSet;
    } catch (NoResultException ex) {
        return new HashSet<String>();
    } catch (Exception ex) {
        ex.printStackTrace();
        return new HashSet<String>();
    }
}

From source file:de.inetsource.jsfforum.db.PostFacade.java

public List<Post> findRange(Thread thread, int[] rangeArray) {
    Query query = getEntityManager().createNamedQuery("Post.findByThreadId");
    query.setParameter("id", thread.getId());
    query.setFirstResult(rangeArray[0]);
    query.setMaxResults(rangeArray[1]);/*from w w  w . ja va  2 s  . c  o m*/
    return query.getResultList();
}

From source file:org.simbasecurity.core.domain.repository.PolicyDatabaseRepository.java

@SuppressWarnings("unchecked")
public Policy findByName(String policyName) {
    Query query = entityManager.createQuery("SELECT p FROM PolicyEntity p WHERE p.name = :policyName")
            .setParameter("policyName", policyName);
    List<Policy> resultList = query.getResultList();

    if (resultList.size() == 0) {
        return null;
    } else if (resultList.size() == 1) {
        return resultList.get(0);
    }//from   w  w w  .  j  a v a2  s . com

    throw new IllegalStateException("Multiple policies found for policyname: '" + policyName + "'");
}

From source file:org.simbasecurity.core.domain.repository.RoleDatabaseRepository.java

@SuppressWarnings("unchecked")
@Override//  w ww.j  av a  2  s .  c  om
public Collection<Role> findNotLinked(User user) {
    Query query = entityManager
            .createQuery("SELECT r FROM RoleEntity r WHERE :user not in " + "elements(r.users) order by r.name")
            .setParameter("user", user);

    return query.getResultList();
}

From source file:de.zib.gndms.GORFX.context.service.globus.resource.ExtTaskResourceHome.java

private void resumeTasks() throws Exception {

    logger.debug("Checking for aborted tasks.");
    EntityManager em = null;/*  w w  w  . ja v  a2s  .c o  m*/
    List<String> rs = null;
    try {
        em = system.getEntityManagerFactory().createEntityManager();
        Query q = em.createNamedQuery("unfinishedTaskIds");
        rs = q.getResultList();
        if (rs.size() == 0) {
            logger.debug("No tasks found :-)");
            return;
        }
    } finally {
        if (em != null && em.isOpen())
            em.close();
    }

    logger.debug("Try to resume " + rs.size() + " tasks");
    for (String id : rs) {
        logger.debug("Resuming " + id);
        Resource k = find(getKeyForId(id));
    }
}