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:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java

License:Open Source License

public PluggableTaskDTO findByEntityType(Integer entityId, Integer typeId) {
    Query query = getSession().createQuery(findByEntityTypeSQL);
    query.setCacheable(true);
    query.setParameter("entity", entityId);
    query.setParameter("type", typeId);
    query.setComment("PluggableTaskDAS.findByEntityType");
    return (PluggableTaskDTO) query.uniqueResult();
}

From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java

License:Open Source License

public PluggableTaskDTO findByEntityCategoryOrder(Integer entityId, Integer categoryId,
        Integer processingOrder) {
    Query query = getSession().createQuery(findByEntityCategoryOrderSQL);
    query.setCacheable(true);
    query.setParameter("entity", entityId);
    query.setParameter("category", categoryId);
    query.setParameter("pr_order", processingOrder);
    query.setComment("PluggableTaskDAS.findByEntityTypeOrder");
    return (PluggableTaskDTO) query.uniqueResult();
}

From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java

License:Open Source License

public List<PluggableTaskDTO> findByEntityCategory(Integer entityId, Integer categoryId) {
    List<PluggableTaskDTO> ret = (List<PluggableTaskDTO>) cache
            .getFromCache("PluggableTaskDTO" + entityId + "+" + categoryId, cacheModel);
    if (ret == null) {
        Query query = getSession().createQuery(findByEntityCategorySQL);
        query.setCacheable(true);
        query.setParameter("entity", entityId);
        query.setParameter("category", categoryId);
        query.setComment("PluggableTaskDAS.findByEntityCategory");

        ret = query.list();/* w w w.jav a  2  s  .  c o m*/
        cache.putInCache("PluggableTaskDTO" + entityId + "+" + categoryId, cacheModel, ret);
    }
    return ret;
}

From source file:com.sapienter.jbilling.server.user.contact.db.ContactDAS.java

License:Open Source License

public ContactDTO findEntityContact(Integer entityId) {
    Query query = getSession().createQuery(FIND_SIMPLE_CONTACT_HQL);
    query.setParameter("id", entityId);
    query.setParameter("tableName", Constants.TABLE_ENTITY);
    query.setCacheable(true);
    return (ContactDTO) query.uniqueResult();
}

From source file:com.sapienter.jbilling.server.util.db.PreferenceDAS.java

License:Open Source License

public PreferenceDTO findByType_Row(Integer typeId, Integer foreignId, String tableName) {
    Query query = getSession().createQuery(findByType_Row);
    query.setParameter("typeId", typeId);
    query.setParameter("foreignId", foreignId);
    query.setParameter("tableName", tableName);
    query.setCacheable(true);
    return (PreferenceDTO) query.uniqueResult();
}

From source file:com.thoughtworks.go.server.dao.PluginSqlMapDao.java

License:Apache License

@Override
public List<Plugin> getAllPlugins() {
    return (List<Plugin>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
        Query query = sessionFactory.getCurrentSession().createQuery("FROM " + Plugin.class.getSimpleName());
        query.setCacheable(true);
        return query.list();
    });/*from  w  w  w. j  av a2s .  c om*/
}

From source file:com.thoughtworks.go.server.dao.UserSqlMapDao.java

License:Apache License

public Users allUsers() {
    return new Users((List<User>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
        Query query = sessionFactory.getCurrentSession().createQuery("FROM User");
        query.setCacheable(true);
        return query.list();
    }));/*from   ww w. jav  a  2 s  .  c  om*/
}

From source file:com.tracer.dao.persistence.impl.BaseDAOHibernate.java

License:Apache License

/**
 * Executes find using <code>org.springframework.orm.hibernate3.HibernateCallback</code>
  * with additional query info; with arguments and their types
 *
 * @param hql         Query to execute/*from ww  w  . j a v  a  2 s.c  o m*/
 * @param queryInfo   Object with additional information for query, currently offset and limit
 * @param args        Arguments to add to query. If <code>null</code>, nothing will be added.
 * @param types       Types of arguments. If <code>null</code>, Hibernate will determine types by itself.
 * @param cacheable   <code>true</code> if the query is cacheable
 * @param cacheRegion region of cache. E.g. one that used in configuration file of EHCahce (ehcache.xml)
 * @return List of found entities
 * @see org.springframework.orm.hibernate3.HibernateCallback
  * @see com.blandware.atleap.common.util.QueryInfo
 */
@SuppressWarnings("rawtypes")
protected List executeFind(final String hql, final QueryInfo queryInfo, final Object[] args, final Type[] types,
        final boolean cacheable, final String cacheRegion) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            Query query = session.createQuery(hql);
            query.setCacheable(cacheable);
            if (cacheRegion != null) {
                query.setCacheRegion(cacheRegion);
            }
            if (args != null) {
                for (int i = 0; i < args.length; i++) {
                    Object arg = args[i];
                    Type type = null;
                    if (types != null && i < types.length) {
                        type = types[i];
                    }
                    if (type == null) {
                        query.setParameter(i, arg);
                    } else {
                        query.setParameter(i, arg, type);
                    }
                }
            }
            if (queryInfo != null) {
                if (queryInfo.getLimit() != null) {
                    query.setMaxResults(queryInfo.getLimit().intValue());
                }
                if (queryInfo.getOffset() != null) {
                    query.setFirstResult(queryInfo.getOffset().intValue());
                }
            }
            return query.list();
        }
    });
}

From source file:com.tracer.dao.persistence.impl.BaseDAOHibernate.java

License:Apache License

/**
 * Returns unique result matching specified query using <code>org.springframework.orm.hibernate3.HibernateCallback</code>
  * with arguments and their types/*from  w w w .  j a v a 2 s.  co m*/
 *
 * @param hql         Query to execute
 * @param args        Arguments to set
 * @param types       Types of arguments
 * @param cacheable   <code>true</code> if the query is cacheable
 * @param cacheRegion region of cache. E.g. one that used in configuration file of EHCahce (ehcache.xml)
 * @return Unique result matching specified query
 */
public Object findUniqueResult(final String hql, final Object[] args, final Type[] types,
        final boolean cacheable, final String cacheRegion) {
    return getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            Query query = session.createQuery(hql);
            query.setCacheable(cacheable);
            if (cacheRegion != null) {
                query.setCacheRegion(cacheRegion);
            }
            if (args != null) {
                for (int i = 0; i < args.length; i++) {
                    Object arg = args[i];
                    Type type = null;
                    if (types != null && i < types.length) {
                        type = types[i];
                    }
                    if (type == null) {
                        query.setParameter(i, arg);
                    } else {
                        query.setParameter(i, arg, type);
                    }
                }
            }
            return query.uniqueResult();
        }
    });
}

From source file:com.trailmagic.image.hibernate.HibernateImageGroupRepository.java

License:Open Source License

public ImageGroup getRollByOwnerAndName(User owner, String rollName) {
    try {/*from   www .j a v  a 2  s .  c o  m*/
        Session session = SessionFactoryUtils.getSession(sessionFactory, false);
        Query qry = session.getNamedQuery(ROLL_BY_OWNER_AND_NAME_QRY);
        qry.setEntity("owner", owner);
        qry.setString("rollName", rollName);
        qry.setCacheable(true);
        return (ImageGroup) qry.uniqueResult();
    } catch (HibernateException e) {
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}