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:pdsanchez.mywebtools.model.dao.jpa.ToolDAOJPAImpl.java

@Override
public List<Tool> findAll(Category category) {
    Query q = getEntityManager()
            .createQuery("select o from Tool o where lower(o.category.categoryName) = :name and o.isvalid = 1");
    q.setParameter("name", category.getCategoryName().toLowerCase());
    return q.getResultList();
}

From source file:com.thingtrack.konekti.dao.impl.internal.ProductDaoImpl.java

@Override
@SuppressWarnings("unchecked")
public List<Product> getAll(User user) throws Exception {
    StringBuffer queryString = new StringBuffer("SELECT p FROM " + getEntityName() + " p");

    if (user.getActiveArea() != null)
        queryString.append(" WHERE :area MEMBER OF p.areas");

    Query query = (Query) getEntityManager().createQuery(queryString.toString());

    if (user.getActiveArea() != null)
        query.setParameter("area", user.getActiveArea());

    return query.getResultList();

}

From source file:com.epam.training.taranovski.spring.repository.oracle.AdminRepositoryOracle.java

/**
 *
 * @return/*from w w  w.  j  a va2s  . c  om*/
 */
@Override
public List<Admin> getAll() {
    Query q = emf.createEntityManager().createNamedQuery("Admin.findAll", Admin.class);
    return q.getResultList();
}

From source file:com.luna.common.repository.UserRepository2Impl.java

public BaseInfo findBaseInfoByUserId(Long userId) {
    String ql = "select bi from BaseInfo bi where bi.user.id=?1";
    Query query = entityManager.createQuery(ql);
    query.setParameter(1, userId);//  w  w  w  .  j a va 2  s.  c o  m
    query.setMaxResults(1);
    List<BaseInfo> baseInfoList = query.getResultList();
    if (baseInfoList.size() > 0) {
        return baseInfoList.get(0);
    }
    return null;
}

From source file:com.mothsoft.alexis.dao.DataSetTypeDaoImpl.java

@Override
public DataSetType findSystemDataSetType(String name) {
    final Query query = this.em.createQuery("FROM DataSetType WHERE name = :name AND system = TRUE");
    query.setParameter("name", name);

    @SuppressWarnings("unchecked")
    final List<DataSetType> types = query.getResultList();

    if (types.size() > 0) {
        return types.get(0);
    }//from  w w w  .  j  a v  a2 s.  c  om

    return null;
}

From source file:nc.noumea.mairie.appock.dao.impl.SousFamilleDaoImpl.java

@Override
public List<SousFamille> findAllOrderByLibelle(Catalogue catalogue) {

    if (catalogue == null) {
        return null;
    }/*from   w  w  w .  ja v a 2  s .c om*/

    // @formatter:off
    String jpaQuery = "   SELECT sousFamille FROM SousFamille sousFamille "
            + "         left join sousFamille.famille famille "
            + "         left join famille.catalogue catalogue " + "       WHERE catalogue = :catalogue"
            + "       ORDER BY sousFamille.libelle";
    // @formatter:on

    Query query = persistentManager.getEntityManager().createQuery(jpaQuery);

    AppockUtil.setParameter(query, "catalogue", catalogue);

    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:DAO.MessagesDAOImpl.java

/**
 *
 * @param destinataireId/*from w  w w  .ja v a 2 s. com*/
 * @return
 */
@Transactional(readOnly = true)
@Override
public List<MessagesEntity> findByDestinataire(int destinataireId) {
    Query q = em.createQuery("SELECT m FROM MessagesEntity m where m.destinataire.id <> ?");
    q.setParameter(1, destinataireId);
    return q.getResultList();
}

From source file:com.brienwheeler.lib.db.dao.PersistentAttributeDaoBase.java

@SuppressWarnings("unchecked")
@Override//from w ww  .  j a va 2  s  .  c o  m
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<AttrClass> findByOwner(long ownerId) {
    Query query = entityManager
            .createQuery("from " + getEntityClass().getSimpleName() + " where owner_id = :ownerId");
    query.setParameter("ownerId", ownerId);
    return (List<AttrClass>) query.getResultList();
}

From source file:org.businessmanager.dao.ContactDaoImpl.java

@SuppressWarnings("unchecked")
@Override/*from w  w  w  .j av a  2s.c  o  m*/
public List<Contact> fullTextSearchContact(String searchString) {
    EntityManager em = getEntityManager();
    FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);

    QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Contact.class)
            .get();
    org.apache.lucene.search.Query query = qb.keyword()
            .onFields("firstname", "lastname", "company", "contactItems.value").matching(searchString)
            .createQuery();

    // wrap Lucene query in a javax.persistence.Query
    javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Contact.class);

    // execute search
    List<?> result = persistenceQuery.getResultList();

    // avoid ClassCastException
    if (result == null) {
        return null;
    }

    return (List<Contact>) result;
}

From source file:com.expressui.sample.dao.StateDao.java

public List<State> findByCountry(Country country) {
    Query query = getEntityManager()
            .createQuery("SELECT s FROM State s WHERE s.country = :country ORDER BY s.name");
    query.setParameter("country", country);
    setReadOnly(query);/* w ww .  j  a va 2  s.  c om*/

    return query.getResultList();
}