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:com.github.peholmst.springsecuritydemo.services.impl.CategoryServiceImpl.java

@Override
@Transactional(readOnly = true)/*from   w  ww .j  av a2s.co m*/
public List<Category> getRootCategories() {
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieving root categories");
    }
    TypedQuery<Category> query = getEntityManager()
            .createQuery("SELECT c FROM Category c WHERE c.parent IS NULL ORDER BY c.name", Category.class);
    List<Category> result = query.getResultList();
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + result.size() + " root categories");
    }
    return Collections.unmodifiableList(result);
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.CheckDocumentRepositoryImplementation.java

@Override
public List<CheckDocument> findAllForEmployer(Employer employer) {
    EntityManager em = entityManagerFactory.createEntityManager();
    List<CheckDocument> list = new LinkedList<>();
    try {/*from  w  w  w . jav  a  2 s  .c  o m*/
        em.getTransaction().begin();

        TypedQuery<CheckDocument> query = em.createNamedQuery("CheckDocument.findAllForEmployer",
                CheckDocument.class);
        query.setParameter("employer", employer);
        list = query.getResultList();

        em.getTransaction().commit();
    } catch (RuntimeException e) {
        Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }

    return list;
}

From source file:org.broadleafcommerce.menu.dao.MenuDaoImpl.java

@Override
public Menu readMenuByName(String menuName) {
    TypedQuery<Menu> query = em.createNamedQuery("BC_READ_MENU_BY_NAME", Menu.class);
    query.setParameter("menuName", menuName);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Cms");

    List<Menu> results = query.getResultList();
    if (!results.isEmpty()) {
        return results.get(0);
    } else {/*from   w ww. ja  va  2  s  .  c o  m*/
        return null;
    }
}

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

@Override
public List<StorageFile> getStorageFilesOfContentType(User user, FileContentType contentType) {

    TypedQuery<StorageFile> query = getEntityManager()
            .createQuery("FROM StorageFile s WHERE s.contentType = :contentType AND s.user = :user",
                    StorageFile.class)
            .setParameter("contentType", contentType).setParameter("user", user);

    return query.getResultList();
}

From source file:eu.domibus.ebms3.common.dao.PModeDao.java

@Override
public List<String> getMpcList() {
    final TypedQuery<String> query = entityManager.createNamedQuery("Mpc.getAllNames", String.class);
    return query.getResultList();
}

From source file:bzzAgent.BiteSizedBzzDaoJpa.java

@Override
public boolean memberHasBSBActivities(String username) {
    Validate.notBlank(username, "username was missing");
    Instant cutoff = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant();

    final StringBuilder sql = new StringBuilder("from BsbAgentActivityEntity bsbaae ")
            .append(" left join fetch bsbaae.incentives incentive ")
            .append(" where bsbaae.username = :username ").append(" and bsbaae.campaignInviteStatus in (1,2)") //'New', 'Viewed'
            .append(" and bsbaae.startDate < '" + cutoff + "' and bsbaae.endDate > '" + cutoff + "'");

    final TypedQuery<BsbAgentActivityEntity> query2 = em
            .createQuery(sql.toString(), BsbAgentActivityEntity.class).setParameter("username", username);

    return BzzUtil.isNotEmpty(query2.getResultList());
}

From source file:example.springdata.jpa.showcase.before.CustomerServiceImpl.java

@Override
public List<Customer> findByLastname(String lastname, int page, int pageSize) {

    TypedQuery<Customer> query = em.createQuery("select c from Customer c where c.lastname = ?1",
            Customer.class);

    query.setParameter(1, lastname);/*from  w ww.jav  a 2s.  co  m*/
    query.setFirstResult(page * pageSize);
    query.setMaxResults(pageSize);

    return query.getResultList();
}

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

public List<ArticleCategory> findRoots(Integer count) {
    String jpql = "select articleCategory from ArticleCategory articleCategory where articleCategory.parent is null order by articleCategory.order asc";
    TypedQuery<ArticleCategory> query = entityManager.createQuery(jpql, ArticleCategory.class)
            .setFlushMode(FlushModeType.COMMIT);
    if (count != null) {
        query.setMaxResults(count);/*w w  w. j ava 2s  .  co m*/
    }
    return query.getResultList();
}

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

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

From source file:com.pingdu.dao.licenseDao.LicenseDao.java

public Integer sumOfSearch(String searchType, Object keyWord) {
    String jpql = new String();
    ////w  w  w  .ja  v a  2  s  . co m
    //      if (searchType.equals("???")) {
    if (searchType.equals("???")) {
        jpql = "select lic from License lic where lic.licTypeCode =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("")) {
        jpql = "select lic from License lic where lic.uploadDate =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("")) {
        jpql = "select lic from License lic where lic.expireDate =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("?")) {
        jpql = "select lic from License lic where lic.isExpire =:keyWord order by lic.licenseCode";
    }
    TypedQuery<License> query = em().createQuery(jpql, License.class);
    //query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
    query.setParameter("keyWord", keyWord);
    int sum = ((query.getResultList().size()) - 1) / PublicVariable.rows + 1;
    return sum;
}