Example usage for javax.persistence TypedQuery setHint

List of usage examples for javax.persistence TypedQuery setHint

Introduction

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

Prototype

TypedQuery<X> setHint(String hintName, Object value);

Source Link

Document

Set a query property or hint.

Usage

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 {/*  w  ww.j  a  v a2 s  . c  om*/
        return null;
    }
}

From source file:com.sonoport.service.account.jpa.UserServiceImpl.java

@Override
public List<User> listAll() {
    TypedQuery<User> query = entityManager.createQuery("select u from User u", User.class);
    // Force hard refresh, useful if running parallel instances
    query.setHint("javax.persistence.cache.storeMode", "REFRESH");
    return query.getResultList();
}

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

/**
 * /*from w w w  . j a  va 2  s. c o m*/
 * 
 * @param entCode
 * @param page
 * @param status
 * @return
 */
public int calPage(int page) {
    try {
        String jpql = LicenseTypeSQL(page);
        TypedQuery query = em().createQuery(jpql, LicenseTypeReturn.class);
        query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
        // query.setParameter("entCode", entCode);
        // Query query=em().createQuery(jpql);
        int sum = (query.getResultList().size() - 1) / PublicVariable.rows + 1;
        return sum;
    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("" + e.getMessage());
        return 1;
    }

}

From source file:com.sonoport.service.account.jpa.UserServiceImpl.java

@Override
public User loadByUserName(String username) {
    TypedQuery<User> query = entityManager
            .createQuery("select u from User u where u.username = :username", User.class)
            .setParameter("username", username);
    // Force hard refresh, useful if running parallel instances
    query.setHint("javax.persistence.cache.storeMode", "REFRESH");
    return query.getResultList().get(0);
}

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

public List<LicenseTypeReturn> LicenseTypeSpecList(String searchType, String keyword) {
    try {/*from w  ww .j ava 2 s.c o m*/
        // ??
        String jpql = LicenseTypeSpecSQL(searchType, keyword);
        TypedQuery<LicenseTypeReturn> query = em().createQuery(jpql, LicenseTypeReturn.class);
        query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
        List<LicenseTypeReturn> LicenseTypeSpecList = query.getResultList();
        System.out.println(" ??sql??");
        return LicenseTypeSpecList;

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println(" ??sql?" + e.getMessage());
        return null;
    }
}

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

public List<LicenseTypeReturn> getLicenseTypeList(int page) {
    try {/*  w w  w .  j a va 2s. c o  m*/
        String jpql = LicenseTypeSQL(page);
        TypedQuery<LicenseTypeReturn> query = em().createQuery(jpql, LicenseTypeReturn.class);
        query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
        int head = (page - 1) * 15;
        query.setFirstResult(head);
        query.setMaxResults(15);
        List<LicenseTypeReturn> LicenseTypeList = query.getResultList();
        System.out.println(" ??sql??");
        return LicenseTypeList;
    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("??sql?" + e.getMessage());
        return null;
    }
}

From source file:org.jasig.jpa.BaseJpaDao.java

/**
 * Common logic for creating and configuring JPA queries
 * // w ww .j  a  v  a  2s  . c o m
 * @param criteriaQuery The criteria to create the query from
 */
protected final <T> TypedQuery<T> createCachedQuery(CriteriaQuery<T> criteriaQuery) {
    final TypedQuery<T> query = this.entityManager.createQuery(criteriaQuery);
    final String cacheRegion = getCacheRegionName(criteriaQuery);
    query.setHint("org.hibernate.cacheable", true);
    query.setHint("org.hibernate.cacheRegion", cacheRegion);
    return query;
}

From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java

@Override
public List<T> findAll(Specification<T> spec, EntityGraphType type, String... attributeGraph) {
    final TypedQuery<T> typedQuery = getQuery(spec, (Sort) null);

    if (attributeGraph != null && attributeGraph.length > 0) {
        final EntityGraph<T> entityGraph = this.entityManager.createEntityGraph(getDomainClass());
        buildEntityGraph(entityGraph, attributeGraph);
        typedQuery.setHint(type.getType(), entityGraph);
    }//from   w w w . j  ava2s.c o  m
    return typedQuery.getResultList();
}

From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java

@Override
public Page<T> findAll(Specification<T> spec, Pageable pageable, EntityGraphType type,
        String... attributeGraph) {
    final TypedQuery<T> typedQuery = getQuery(spec, pageable);

    if (attributeGraph != null && attributeGraph.length > 0) {
        final EntityGraph<T> entityGraph = this.entityManager.createEntityGraph(getDomainClass());
        buildEntityGraph(entityGraph, attributeGraph);
        typedQuery.setHint(type.getType(), entityGraph);
    }/*  w w  w  .  ja  va  2s  .  co m*/

    return pageable == null ? new PageImpl<T>(typedQuery.getResultList())
            : readPage(typedQuery, pageable, spec);
}

From source file:org.cherchgk.services.SecurityService.java

/**
 *  ?? ? ?  ?? .//from  w  ww .j ava  2  s. c  o  m
 *
 * @return ? ? ?  ?? .
 */
public List<User> getAllUsers() {
    TypedQuery<User> usersQuery = entityManager
            .createQuery("select user " + "from User user " + "order by user.username", User.class);
    usersQuery.setHint("org.hibernate.cacheable", true);
    return usersQuery.getResultList();
}