Example usage for javax.persistence TypedQuery getResultList

List of usage examples for javax.persistence TypedQuery getResultList

Introduction

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

Prototype

List<X> getResultList();

Source Link

Document

Execute a SELECT query and return the query results as a typed List.

Usage

From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java

public List<TestMethodTypeDTO> getTestMethodTypeDTOList() {
    TypedQuery<TestMethodTypeDTO> query = createEntityManager().createQuery("SELECT t FROM TestMethodTypeDTO t",
            TestMethodTypeDTO.class);
    return query.getResultList();
}

From source file:eu.europa.ec.fisheries.uvms.exchange.dao.bean.ExchangeLogDaoBean.java

@Override
public List<ExchangeLog> getExchangeLogByRangeOfRefGuids(List<String> logGuids) {
    if (CollectionUtils.isEmpty(logGuids)) {
        return new ArrayList<>();
    }/*ww  w. j av  a  2 s  . c om*/
    TypedQuery<ExchangeLog> query = em.createNamedQuery(ExchangeConstants.LOG_BY_TYPE_RANGE_OF_REF_GUIDS,
            ExchangeLog.class);
    query.setParameter("refGuids", logGuids);
    return query.getResultList();
}

From source file:bq.jpa.demo.lock.service.LockService.java

/**
 * Statistic//from   w ww.  j  a v  a  2s  .  c om
 */
@Transactional
public void doReadWhileModify() {
    try {
        lock.lock();
        readCondition.await();

        TypedQuery<Employee> query = em.createQuery("SELECT e FROM jpa_lock_employee e", Employee.class);
        List<Employee> results = query.getResultList();
        System.out.println("[thread-reading] query employees");
        writeCondition.signal();
        readCondition.await();

        float totalSalary = 0f;
        for (Employee employee : results) {
            totalSalary += employee.getSalary();
        }

        System.out.println("[thread-reading] total salary is :" + totalSalary);
        writeCondition.signal();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        lock.unlock();
    }
}

From source file:bq.jpa.demo.lock.service.LockService.java

/**
 * modify employees salary/*from ww  w.  ja v  a 2s  .com*/
 */
@Transactional
public void doModify() {
    try {
        lock.lock();

        TypedQuery<Employee> query = em.createQuery("SELECT e FROM jpa_lock_employee e", Employee.class);
        List<Employee> results = query.getResultList();

        for (Employee employee : results) {
            em.lock(employee, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
            employee.setSalary(employee.getSalary() + 33);
        }
        System.out.println("[Thread-writing] lock employee");

        // let read thread continue
        readCondition.signal();
        writeCondition.await();

        System.out.println("[Thread-writing] modify employee salary!");
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        lock.unlock();
    }
}

From source file:net.groupbuy.dao.impl.ProductCategoryDaoImpl.java

public List<ProductCategory> findRoots(Integer count) {
    String jpql = "select productCategory from ProductCategory productCategory where productCategory.parent is null order by productCategory.order asc";
    TypedQuery<ProductCategory> query = entityManager.createQuery(jpql, ProductCategory.class)
            .setFlushMode(FlushModeType.COMMIT);
    if (count != null) {
        query.setMaxResults(count);// w ww  . ja  v a2s. co m
    }
    return query.getResultList();
}

From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.LexiconBuilderController.java

/**
 * Gets the unseen document with the next highest weight.
 * @param em the {@link EntityManager} to use.
 * @param builder the {@link LexiconBuilderDocumentStore} to use.
 * @return the {@link LexiconBuilderDocument} with the highest weight among unseen documents.
 *//*from w  w w.  j  a v  a2  s  . c  om*/
public LexiconBuilderDocument getNextDocument(EntityManager em, LexiconBuilderDocumentStore builder) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");
    Validate.notNull(builder, CannedMessages.NULL_ARGUMENT, "builder");

    TypedQuery<LexiconBuilderDocument> query = this.getDocumentsQuery(em, builder, false);
    query.setMaxResults(1);
    if (query.getResultList().size() != 1) {
        return null;
    }
    LexiconBuilderDocument document = query.getSingleResult();
    query = this.getDocumentsQuery(em, builder, null);
    document.setRank((long) query.getResultList().indexOf(document));
    return document;
}

From source file:org.openmeetings.app.data.calendar.daos.MeetingMemberDaoImpl.java

public List<MeetingMember> getMeetingMembers() {
    try {/*w  ww.  ja va 2  s  . c  o  m*/
        String hql = "select app from MeetingMember app";

        TypedQuery<MeetingMember> query = em.createQuery(hql, MeetingMember.class);

        List<MeetingMember> meetingMembers = query.getResultList();

        return meetingMembers;
    } catch (Exception ex2) {
        log.error("[getMeetingMembers]: ", ex2);
    }
    return null;
}

From source file:org.mitre.openid.connect.repository.impl.JpaPairwiseIdentifierRepository.java

@Override
public PairwiseIdentifier getBySectorIdentifier(String sub, String sectorIdentifierUri) {
    TypedQuery<PairwiseIdentifier> query = manager
            .createNamedQuery(PairwiseIdentifier.QUERY_BY_SECTOR_IDENTIFIER, PairwiseIdentifier.class);
    query.setParameter(PairwiseIdentifier.PARAM_SUB, sub);
    query.setParameter(PairwiseIdentifier.PARAM_SECTOR_IDENTIFIER, sectorIdentifierUri);

    return getSingleResult(query.getResultList());
}

From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java

public List<SoftwareLicenseDTO> getSoftwareLicenseDTOList() {
    TypedQuery<SoftwareLicenseDTO> query = createEntityManager()
            .createQuery("SELECT t FROM SoftwareLicenseDTO t", SoftwareLicenseDTO.class);
    return query.getResultList();
}

From source file:bq.jpa.demo.lock.service.LockService.java

/**
 * Statistic//from  w  w  w .j a  v  a  2  s.  c  o  m
 */
@Transactional
public void doStatisticSalary() {
    try {
        lock.lock();

        TypedQuery<Employee> query = em.createQuery("SELECT e FROM jpa_lock_employee e", Employee.class);
        List<Employee> results = query.getResultList();
        System.out.println("[thread-reading] query employees");

        for (Employee employee : results) {
            em.lock(employee, LockModeType.OPTIMISTIC);
            em.flush();
        }
        System.out.println("[thread-reading] lock employees");
        writeCondition.signal();
        readCondition.await();
        Thread.sleep(1000);

        float totalSalary = 0f;
        for (Employee employee : results) {
            totalSalary += employee.getSalary();
        }

        System.out.println("[thread-reading] total salary is :" + totalSalary);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        lock.unlock();
    }
}