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:org.simbasecurity.core.domain.repository.RoleDatabaseRepository.java

@SuppressWarnings("unchecked")
@Override/*from   ww  w .  j a v a2 s  .co m*/
public Collection<Role> findNotLinked(Policy policy) {
    Query query = entityManager
            .createQuery(
                    "SELECT r FROM RoleEntity r WHERE :policy not in " + "elements(r.policies) order by r.name")
            .setParameter("policy", policy);

    return query.getResultList();
}

From source file:ru.anr.base.dao.BaseRepositoryImpl.java

/**
 * {@inheritDoc}// ww  w.  jav  a2 s. c om
 */
@SuppressWarnings("unchecked")
@Override
public <S extends BaseEntity> List<S> query(String queryStr, Object... params) {

    Query q = entityManager.createQuery(queryStr);
    if (params != null) {
        for (int i = 0; i < params.length; i++) {
            q.setParameter(i + 1, params[i]);
        }
    }
    return q.getResultList();
}

From source file:com.linksinnovation.elearning.repository.CourseDTORepository.java

public List<CourseDTO> findByCategory(Map<String, Long> map) {
    List<Object[]> result;
    if (null != map.get("category")) {
        String queryString = query + " WHERE category_id=:cat";
        if (null != map.get("subcategory")) {
            queryString = queryString + " AND sub_category_id=:subcat";
        }//from w  w  w. j  ava 2 s  . co m
        Query q = em.createNativeQuery(queryString);
        q.setParameter("cat", map.get("category"));
        if (null != map.get("subcategory")) {
            q.setParameter("subcat", map.get("subcategory"));
        }
        result = q.getResultList();
    } else {
        result = Collections.EMPTY_LIST;
    }
    return mapObject(result);
}

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

@Override
public Plane find(Long id) {
    if (id == null) {
        throw new IllegalArgumentException("ID is null");
    }/*from www  .  j ava  2 s.c o m*/

    Query query = em.createQuery("SELECT p FROM Plane p WHERE p.archived = :archived AND p.id = :id");
    query.setParameter("archived", false);
    query.setParameter("id", id);

    List resultList = query.getResultList();

    return resultList.isEmpty() ? null : (Plane) resultList.get(0);
}

From source file:com.jd.survey.dao.security.UserDAOImpl.java

@SuppressWarnings("unchecked")
@Transactional/*  w  ww  . j a  v a2 s  .c o  m*/
public Set<User> findAll(int startResult, int maxRows) throws DataAccessException {
    Query query = createNamedQuery("User.findAll", startResult, maxRows);
    return new LinkedHashSet<User>(query.getResultList());
}

From source file:com.appdynamicspilot.persistence.CartPersistence.java

/**
 * Get the cart based on user// ww  w  . j  a v a2s  .  c  om
 *
 * @param userId
 * @return cart object
 */
public Cart getCartByUser(Long userId) {
    Query q = getEntityManager().createQuery("SELECT c FROM Cart c where c.user.id = :userid");
    q.setParameter("userid", userId);
    List<Cart> carts = q.getResultList();
    if ((carts == null) || (carts.size() == 0)) {
        return null;
    }
    return carts.get(0);
}

From source file:com.tsystems.javaschool.logiweb.dao.jpa.TruckDaoJpa.java

/**
 * {@inheritDoc}//from  w  w w. ja  va  2 s. c  o m
 */
@Override
public Truck findByLicensePlate(String licensePlate) throws DaoException {
    try {
        EntityManager em = getEntityManager();
        Class<Truck> truckEntityClass = getEntityClass();
        String classSimpleName = truckEntityClass.getSimpleName();

        Query query = em.createQuery("SELECT t FROM " + classSimpleName + " t WHERE licencePlate = :plate",
                truckEntityClass);
        query.setParameter("plate", licensePlate);

        List<Truck> resultList = query.getResultList();
        if (resultList.isEmpty()) {
            return null;
        } else {
            return resultList.get(0);
        }
    } catch (Exception e) {
        LOG.warn(e);
        throw new DaoException(e);
    }
}

From source file:fi.vm.sade.organisaatio.dao.impl.OrganisaatioNimiDAOImpl.java

/**
 * Haetaan organisaatiot, joiden nimi eroaa nimihistorian current nimest
 * -----------------------------------------------------------------------
 * SELECT org.*//ww  w  .j  av a2 s . com
 * FROM organisaatio org
 * WHERE org.nimi_mkt !=
 * (
 * SELECT org_nimi.nimi_mkt
 * FROM organisaatio_nimi org_nimi
 * WHERE org_nimi.alkupvm =
 * (
 * SELECT max(org_nimi2.alkupvm)
 * FROM organisaatio_nimi org_nimi2
 * WHERE org_nimi.organisaatio_id = org_nimi2.organisaatio_id
 * AND org_nimi2.alkupvm <= '2014-09-01'
 * )
 * AND org.id = org_nimi.organisaatio_id
 * )
 *
 * Ylloleva SQL lauseke on alla kirjoitettu HQL muotoon.
 *
 * @return
 **/
@Override
public List<Organisaatio> findNimiNotCurrentOrganisaatiot() {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    String s = "SELECT org FROM Organisaatio org " + "WHERE org.nimi != " + "( "
            + "SELECT org_nimi.nimi FROM OrganisaatioNimi org_nimi " + "WHERE org_nimi.alkuPvm = " + "( "
            + "SELECT MAX (org_nimi2.alkuPvm) FROM OrganisaatioNimi org_nimi2 "
            + "WHERE org_nimi.organisaatio = org_nimi2.organisaatio " + "AND org_nimi2.alkuPvm <= '"
            + df.format(new Date()) + "' " + ") " + "AND org = org_nimi.organisaatio " + ")";

    Query q = getEntityManager().createQuery(s);

    List<Organisaatio> organisaatiot = (List<Organisaatio>) q.getResultList();

    return organisaatiot;
}

From source file:com.ovalsearch.dao.impl.ApplicationsDaoImpl.java

@SuppressWarnings("unchecked")
@Override/*ww  w.  j a  va  2  s .com*/
@Transactional
public Applications getApplicationByApkId(String apkId) {
    Query query = entityDao.getEntityManager()
            .createQuery("Select applications from Applications applications where apkId =:apkId");
    query.setParameter("apkId", apkId);
    List<Applications> applications = (List<Applications>) query.getResultList();
    if (applications != null && applications.size() > 0) {
        return applications.get(0);
    } else {
        return null;
    }
}

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

@Override
public List<SeatReservation> getBySeat(Long seat) {
    try {/*  w ww. j  a  va  2s  .  c o m*/
        Query q = em.createQuery("FROM SeatReservation WHERE seat_id=:seat");
        q.setParameter("seat", seat);
        List<SeatReservation> planes = q.getResultList();

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