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.zkbase.dao.BasicDao.java

/**
 * Retrieves a non-paged query. Use with care, this method could potentially
 * instantiate large amounts of data./*from w  w w .j  a v  a2  s . c om*/
 */
@SuppressWarnings("unchecked")
public <T> List<T> find(String queryString, Object... params) {
    //queryString += " order by firstName desc";
    Query query = entityManager.createQuery(queryString);
    setParameters(query, params);
    return query.getResultList();
}

From source file:nz.co.senanque.database.DatabaseLoadDAOImpl.java

@Override
@Transactional(readOnly = true)/*w  ww .j  a v  a2  s  . co m*/
public List<Long> query() {
    List<Long> ret = new ArrayList<Long>();
    Query query = m_workflow.createQuery("select x from nz.co.senanque.workflow.instances.ProcessInstance x");
    int size = 0;
    for (Object pi : query.getResultList()) {
        log.info("ProcessInstance id={}", ((ProcessInstance) pi).getId());
        ret.add(((ProcessInstance) pi).getId());
        size++;
    }
    log.info("found {} records", size);
    return ret;
}

From source file:org.kuali.mobility.push.dao.PushDeviceTupleDaoImpl.java

@SuppressWarnings("unchecked")
public List<PushDeviceTuple> findTuplesForPush(Push push) {
    Query query = entityManager.createNamedQuery("PushDeviceTuple.findTuplesForPush");
    query.setParameter("pushId", push.getPushId());
    return query.getResultList();
}

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

@SuppressWarnings("unchecked")
Collection<ResourceRule> getResourceRulesViaGroups(String username, String resource) {
    Query query = entityManager.createQuery(QUERY_RESOURCE_RULES_FOR_GROUPUSER);

    query.setParameter(USERNAME, username).setParameter(RESOURCE, resource.toLowerCase());

    return query.getResultList();
}

From source file:org.syncope.core.persistence.dao.impl.TaskDAOImpl.java

@Override
public List<PropagationTask> findAll(final SyncopeUser user) {
    StringBuilder queryString = buildfindAllQuery(PropagationTask.class);
    queryString.append("WHERE e.syncopeUser=:user");
    final Query query = entityManager.createQuery(queryString.toString());
    query.setParameter("user", user);

    return query.getResultList();
}

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

@Override
public List<Plane> getByAirline(Long airline) {
    try {//www  .  j  av a 2s  . c  om
        Query q = em.createQuery("FROM Plane WHERE airline_id=:airline");
        q.setParameter("airline", airline);
        List<Plane> planes = q.getResultList();

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

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

@SuppressWarnings("unchecked")
@Override/*  www.java 2 s. c o  m*/
public Collection<Policy> findPolicies(Condition condition) {
    Query query = entityManager.createQuery(
            "SELECT policy FROM PolicyEntity policy WHERE :condition in elements(policy.conditions) ");
    query.setParameter("condition", condition);
    return new ArrayList<Policy>(query.getResultList());
}

From source file:org.syncope.core.persistence.dao.impl.SchemaDAOImpl.java

@Override
public <T extends AbstractAttr> List<T> getAttributes(final AbstractSchema schema, final Class<T> reference) {

    Query query = entityManager
            .createQuery("SELECT e FROM " + reference.getSimpleName() + " e" + " WHERE e.schema=:schema");
    query.setParameter("schema", schema);

    return query.getResultList();
}

From source file:facades.PersonFacadeDB.java

@Override
public String getPersons() {

    String result = "";
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceFileName);
    EntityManager em = emf.createEntityManager();
    EntityTransaction transaction = em.getTransaction();
    transaction.begin();/*from w  w w  .j  av a2 s  .  c  om*/

    try {
        Query query = em.createNamedQuery("Person.findAll");
        List<Person> people = query.getResultList();

        try {
            result = om.writeValueAsString(people);
        } catch (JsonProcessingException ex) {
            Logger.getLogger(PersonFacadeDB.class.getName()).log(Level.SEVERE, null, ex);
        }

    } finally {
        em.close();
    }
    return result;
}

From source file:com.emc.plants.service.impl.SuppliersBean.java

/**
 * @return suppliers/*from   w  w  w  . j a  v  a 2  s. com*/
 */
@SuppressWarnings("unchecked")
public Collection<SupplierInfo> findSuppliers() {
    Vector suppliers = new Vector();
    /*
     try {
     Util.debug("BackOrderStockBean.findSuppliers() - Entered");
     Collection supplierItems = getSupplierLocalHome().findAll();
     Iterator i = supplierItems.iterator();
     while (i.hasNext()) {
     SupplierLocal supplier = (SupplierLocal) i.next();
     suppliers.add(new SupplierInfo(supplier));
     }
     } catch (Exception e) {
     Util.debug("BackOrderStockBean.findSupplierItems() - Exception: " + e);
     }
     */
    Query q = em.createNamedQuery("findAllSuppliers");
    List l = q.getResultList();
    if (l != null) {
        Iterator i = l.iterator();
        while (i.hasNext()) {
            Supplier supplier = (Supplier) i.next();
            suppliers.add(new SupplierInfo(supplier));
        }
    }

    return suppliers;
}