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:com.iselect.kernal.geo.dao.CountryDaoImpl.java

@Override
public List<CountryModel> getCountriesByName(String name) {
    Query query = em.createNamedQuery("country.findByName", CountryModelImpl.class);
    query.setParameter("countryName", name);
    return query.getResultList();
}

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

@Override
public List<Baggage> getAll() {
    try {/*from w  w w  .j a v a  2s  . com*/
        Query q = em.createQuery("FROM Plane");
        List<Baggage> planes = q.getResultList();

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

From source file:com.dhenton9000.birt.jpa.service.impl.EmployeesServiceImpl.java

@Override
public List<Employees> getEmployeesForOffice(String officeCode) {
    String qString = "select employees from " + "Offices o join o.employees employees "
            + "where o.officeCode = :id ";

    Query q = entityManager.createQuery(qString);
    q.setParameter("id", officeCode);

    List<Employees> officeEmployees = q.getResultList();

    //   http://www.objectdb.com/java/jpa/query/jpql/select

    return officeEmployees;
}

From source file:com.gerenciaProyecto.DaoImple.UsuarioDaoImpl.java

@Override
public List<Usuario> listarInactivos() {
    EntityManager em = getEntityManager();
    List<Usuario> lista = new ArrayList<Usuario>();
    Query q = em.createQuery("SELECT u FROM Usuario u where u.estado= :estado ");
    q.setParameter("estado", 'I');
    lista = q.getResultList();
    return lista;
}

From source file:com.nandhootoo.services.ProductServiceImpl.java

public List getProductsWithCriteria(String criteria) {
    try {//from  w w w .ja  va 2s.  c o m
        Query aQuery = entityManager.createQuery("select product from Product as product " + criteria);
        return aQuery.getResultList();
    } catch (Exception sqlex) {
        System.out.println("SQL Exception: " + sqlex.getMessage());
        return null;
    }
}

From source file:org.mifos.user.repository.StandardOfficeDao.java

@Override
@Transactional(readOnly = true)/*from w w  w. j av  a  2s  .c o  m*/
public Office getHeadOffice() {
    Query query = entityManager
            .createQuery("select office from Office office where office.parentOffice IS NULL");
    List<Office> result = query.getResultList();
    if (result.isEmpty()) {
        throw new MifosRuntimeException("Built in head office not found.");
    } else if (result.size() > 1) {
        throw new MifosRuntimeException("Multiple head offices found.");
    }
    return result.get(0);
}

From source file:com.apress.prospringintegration.springenterprise.stocks.dao.jpaandentitymanagers.JpaStockDao.java

@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*  w w  w  .  j a v a  2 s.  c  o  m*/
public List<Stock> findAvailableStockBySymbol(String symbol) {
    Query qu = entityManager.createQuery(" from Stock s where s.symbol = :stock ");
    qu.setParameter("stock", symbol);
    return (List<Stock>) qu.getResultList();
}

From source file:es.ucm.fdi.dalgs.mailbox.respository.MailBoxRepository.java

public MessageBox getMessageBox(String code) {

    Query query = null;

    query = em.createQuery("select m FROM MessageBox m where m.code=?1");
    query.setParameter(1, code);/*from ww  w .  ja va 2  s .  c o  m*/

    if (query.getResultList().isEmpty())
        return null;
    else
        return (MessageBox) query.getSingleResult();
}

From source file:com.exp.tracker.services.impl.JavaMailEmailService.java

/**
 * Sends the settlement email.//  w ww .  j  av a2 s .co  m
 */
@SuppressWarnings("unchecked")
@Async
public void sendSettlementEmail(Long sid, byte[] settlementReport, byte[] expenseReport) {
    // do not send email if sid is not valid
    if (sid != 0l) {
        Query queryGetSettlementForId = em.createNamedQuery("getSettlementForId");
        queryGetSettlementForId.setParameter("id", sid);
        SettlementEntity se = (SettlementEntity) queryGetSettlementForId.getSingleResult();
        SettlementBean sb = new SettlementBean(se);
        //
        Query querygetAllUsers = em.createNamedQuery("getAllUsers");
        List<UserEntity> uel = querygetAllUsers.getResultList();
        List<UserBean> ubl = new ArrayList<UserBean>();
        for (UserEntity ue : uel) {
            if (UserEntity.USER_ENABLED == ue.getEnabled() && null != ue.getEmailId()) {
                if (!("".equalsIgnoreCase(ue.getEmailId()))) {
                    ubl.add(new UserBean(ue));
                }
            }
        }
        // send email
        sendSettlementNotice(sb, ubl, settlementReport, expenseReport);
    }
}

From source file:de.hska.ld.content.persistence.repository.custom.impl.DocumentRepositoryImpl.java

@Override
@Transactional//from   w  ww.  ja v  a  2s .c  o  m
@SuppressWarnings("unchecked")
public Page<Document> searchDocumentByTitleOrDescription(String searchTerm, Pageable pageable) {

    FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);

    // create native Lucene query unsing the query DSL
    // alternatively you can write the Lucene query using the Lucene query parser
    // or the Lucene programmatic API. The Hibernate Search DSL is recommended though
    QueryBuilder searchQb = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
            .forEntity(Document.class).get();
    org.apache.lucene.search.Query luceneQuery = searchQb.phrase().onField("title").andField("description")
            //.onFields("title", "description")
            .sentence(searchTerm)
            //.matching(searchTerm)
            .createQuery();

    // wrap Lucene query in a javax.persistence.Query
    javax.persistence.Query jpaQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, Document.class);

    long total = jpaQuery.getResultList().size();

    jpaQuery.setMaxResults(pageable.getPageSize());
    jpaQuery.setFirstResult(pageable.getOffset());

    // execute search
    List result = jpaQuery.getResultList();

    return new PageImpl<Document>(result, pageable, total);
}