Example usage for org.hibernate Query setCacheable

List of usage examples for org.hibernate Query setCacheable

Introduction

In this page you can find the example usage for org.hibernate Query setCacheable.

Prototype

Query<R> setCacheable(boolean cacheable);

Source Link

Document

Enable/disable second level query (result) caching for this query.

Usage

From source file:kr.debop4j.data.hibernate.repository.impl.HibernateDao.java

License:Apache License

@Override
@Transactional(readOnly = true)// ww w .j  a v  a2  s  .  c o  m
public final <T> List<T> findAll(Class<T> clazz, Order... orders) {
    if (ArrayTool.isEmpty(orders)) {
        Query query = getSession().createQuery("from " + clazz.getName());
        return (List<T>) query.setCacheable(cacheable).list();
    } else {
        Criteria criteria = getSession().createCriteria(clazz);
        HibernateTool.addOrders(criteria, orders);
        return criteria.setCacheable(cacheable).list();
    }
}

From source file:kr.debop4j.data.hibernate.repository.impl.HibernateDao.java

License:Apache License

@Override
public final <T> List<T> findAll(Class<T> clazz, int firstResult, int maxResults, Order... orders) {
    if (ArrayTool.isEmpty(orders)) {
        Query query = getSession().createQuery("from " + clazz.getName());
        HibernateTool.setPaging(query, firstResult, maxResults);

        return (List<T>) query.setCacheable(cacheable).list();
    } else {/*from  w  w w  .ja  v  a  2s .c om*/
        Criteria criteria = getSession().createCriteria(clazz);
        HibernateTool.setPaging(criteria, firstResult, maxResults);
        if (!ArrayTool.isEmpty(orders))
            HibernateTool.addOrders(criteria, orders);

        return criteria.setCacheable(cacheable).list();
    }
}

From source file:kr.debop4j.data.hibernate.repository.impl.HibernateDao.java

License:Apache License

@Override
public <T> T findUnique(Class<T> clazz, Query query, HibernateParameter... parameters) {
    HibernateTool.setParameters(query, parameters);
    return (T) query.setCacheable(cacheable).uniqueResult();
}

From source file:kr.debop4j.data.hibernate.repository.impl.HibernateRepository.java

License:Apache License

@Override
public final <E> List<E> findAll(Order... orders) {
    if (ArrayTool.isEmpty(orders)) {
        Query query = getSession().createQuery("from " + entityClazz.getName());
        return (List<E>) query.setCacheable(cacheable).list();
    } else {//w w w .  j a v a  2s  . c o  m
        Criteria criteria = getSession().createCriteria(entityClazz);
        HibernateTool.addOrders(criteria, orders);
        return criteria.setCacheable(cacheable).list();
    }
}

From source file:kr.debop4j.data.hibernate.repository.impl.HibernateRepository.java

License:Apache License

@Override
public final <E> List<E> findAll(int firstResult, int maxResults, Order... orders) {
    if (ArrayTool.isEmpty(orders)) {
        Query query = getSession().createQuery("from " + entityClazz.getName());
        HibernateTool.setPaging(query, firstResult, maxResults);

        return (List<E>) query.setCacheable(cacheable).list();
    } else {/*  w  w  w  .ja v a  2  s . c  om*/
        Criteria criteria = getSession().createCriteria(entityClazz);
        HibernateTool.setPaging(criteria, firstResult, maxResults);
        if (!ArrayTool.isEmpty(orders))
            HibernateTool.addOrders(criteria, orders);

        return criteria.setCacheable(cacheable).list();
    }
}

From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateRestaurantRepositoryImpl.java

License:Apache License

public List findAvailableRestaurantsInline(Address deliveryAddress, Date deliveryTime) {
    final String[] paramNames = { "zipCode", "dayOfWeek", "hour", "minute" };
    final Object[] paramValues = makeParameterValues(deliveryAddress, deliveryTime);
    return getHibernateTemplate().executeFind(new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.getNamedQuery("findAvailableRestaurants");
            query.setCacheable(true);
            for (int i = 0; i < paramValues.length; i++) {
                Object value = paramValues[i];
                String name = paramNames[i];
                query.setParameter(name, value);
            }/*from   ww w  .  j ava2 s. c om*/
            if (true)
                return query.list();
            else {
                Iterator it = query.iterate();
                List result = new ArrayList();
                while (it.hasNext()) {
                    Restaurant restaurant = (Restaurant) it.next();
                    result.add(restaurant);
                }
                return result;
            }
        }
    });
}

From source file:net.chrisrichardson.foodToGo.util.hibernate.HibernateNamedQueryExecutorCallback.java

License:Apache License

public Object doInHibernate(Session session) throws HibernateException {
    Query query = session.getNamedQuery(queryParams.getQueryName());
    query.setCacheable(true);
    for (Iterator it = queryParams.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        String name = (String) entry.getKey();
        Object value = entry.getValue();
        query.setParameter(name, value);
    }//from  w ww.j av a2s . com
    if (queryParams.getLockAlias() != null) {
        query.setLockMode(queryParams.getLockAlias(), queryParams.getLockMode());
    }
    if (queryParams.isJustOne())
        query.setMaxResults(1);
    return query.list();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static List tradeListForJsp(String claimName) {
    Claim claim = getClaimByName(claimName);
    Session session = currentSession();//from w ww  .ja  v a 2  s . co  m
    Query mQ = session.createQuery("select t from Trade t " + "join t.pos p "
            + "where t.pos = p.id and p.claim = :cl " + "order by t.time");
    mQ.setEntity("cl", claim);
    mQ.setCacheable(true);
    return mQ.list();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static List maxTradeTime(String claimName) {
    Claim claim = getClaimByName(claimName);
    Session session = currentSession();/*from www  .  j a  va2  s . c  om*/
    Query mQ = session.createQuery(
            "select max(t.time) from Trade t " + "join t.pos p " + "where t.pos = p.id and p.claim = :cl ");
    mQ.setEntity("cl", claim);
    mQ.setCacheable(true);
    return mQ.list();
}

From source file:net.commerce.zocalo.hibernate.HibernateUtil.java

License:Open Source License

public static Market getMarketByName(String name) {
    Session session = currentSession();/*from w  w  w .  ja  v  a 2s .  c o  m*/
    Query mQ = session.createQuery(
            "select m from Market m " + "join m.claim c " + "where m.claim = c.id and c.name = :name");
    mQ.setString("name", name);
    mQ.setCacheable(true);
    return (Market) mQ.uniqueResult();
}