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.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * Get all child processes regardless of state
 * //from  w w w . j a  v  a 2s .co m
 * @return
 * @throws PersistenceException
 * @throws HibernateException
 */
@Transient
public List<ZebraProcessInstance> getAllChildProcesses() {
    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();

    String querySQL = "select api from ZebraProcessInstance api where api.parentProcessInstance.processInstanceId =:guid";

    Session s = RegistryHelper.getInstance().getSession();
    Query q = s.createQuery(querySQL);
    q.setCacheable(true);

    // Recursive Process children
    recursivelyQueryChildProcesses(results, q);
    return results;
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

@SuppressWarnings({ "unchecked", "cast" })
private void cacheVariablesNoBatch(Session session, List<Long> contextInstanceIds,
        Map<Long, TokenVariableMap> variablesCache) {
    Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheInstanceVariables");
    query.setParameterList("ids", contextInstanceIds);
    query.setCacheMode(CacheMode.PUT);//  w  w  w.ja va2s  .c om
    query.setFlushMode(FlushMode.MANUAL);
    query.setCacheable(true);

    List<TokenVariableMap> results = (List<TokenVariableMap>) query.list();
    for (TokenVariableMap tokenVariableMap : results) {
        variablesCache.put(tokenVariableMap.getContextInstance().getId(), tokenVariableMap);
    }
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

@SuppressWarnings({ "unchecked", "cast" })
private void cacheTasksNoBatch(Session session, List<Long> taskInstanceIds, Map<Long, TaskInstance> returnMap) {
    Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheTaskInstanceProperties");
    query.setParameterList("ids", taskInstanceIds);
    query.setCacheMode(CacheMode.PUT);//from   w  ww  . j a v  a  2 s  .  c om
    query.setFlushMode(FlushMode.MANUAL);
    query.setCacheable(true);

    List<TaskInstance> results = (List<TaskInstance>) query.list();
    for (TaskInstance taskInstance : results) {
        returnMap.put(taskInstance.getId(), taskInstance);
    }
}

From source file:com.ejushang.steward.common.genericdao.search.hibernate.HibernateSearchProcessor.java

License:Apache License

/**
 * ??// ww  w .  j a  v a  2  s.c o m
 * @param query
 * @param search
 */
private void setQueryCache(Query query, ISearch search) {
    if (search.isCacheable()) {
        query.setCacheable(true);
    }
    if (search.getCacheMode() != null) {
        query.setCacheMode(search.getCacheMode());
    }

}

From source file:com.enonic.cms.store.dao.ContentEntityDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ContentKey> findBySpecification(ContentSpecification specification, String orderBy, int count) {

    Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession()
            .createQuery(getContentKeysHQL(specification, orderBy, false));

    compiled.setCacheable(true);
    compiled.setMaxResults(count);/* www .j  a va2 s .co  m*/

    @SuppressWarnings({ "unchecked" })
    List<ContentKey> list = compiled.list();

    List<ContentKey> contentKeys = new ArrayList<ContentKey>();
    for (ContentKey row : list) {
        contentKeys.add(row);
    }

    return contentKeys;
}

From source file:com.enonic.cms.store.dao.ContentEntityDao.java

License:Open Source License

private int doGetNumberOfRelatedParentsByKey(List<ContentKey> contentKeys) {
    String hql = getNumberOfRelatedParentsByKeyHQL(contentKeys);

    Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hql);
    compiled.setCacheable(true);

    @SuppressWarnings({ "unchecked" })
    int count = ((Number) compiled.uniqueResult()).intValue();

    return count;
}

From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java

License:Open Source License

public List<Object[]> findIndexValues(final String query) {
    return executeListResult(Object[].class, new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query compiled = session.createQuery(query);
            compiled.setCacheable(true);
            return compiled.list();
        }/*from ww  w . j  av a  2  s.  c  o m*/
    });
}

From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java

License:Open Source License

public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters,
        final boolean cacheable) {
    return executeListResult(ContentKey.class, new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query compiled = session.createQuery(hqlQuery);
            compiled.setCacheable(cacheable);

            for (String key : parameters.keySet()) {
                Object value = parameters.get(key);
                if (value instanceof Date) {
                    compiled.setTimestamp(key, (Date) value);
                } else if (value instanceof String) {
                    compiled.setString(key, (String) value);
                } else if (value instanceof Boolean) {
                    compiled.setBoolean(key, (Boolean) value);
                } else if (value instanceof Long) {
                    compiled.setLong(key, (Long) value);
                } else if (value instanceof Integer) {
                    compiled.setInteger(key, (Integer) value);
                } else if (value instanceof Byte) {
                    compiled.setByte(key, (Byte) value);
                } else if (value instanceof byte[]) {
                    compiled.setBinary(key, (byte[]) value);
                } else if (value instanceof Float) {
                    compiled.setFloat(key, (Float) value);
                } else if (value instanceof Double) {
                    compiled.setDouble(key, (Double) value);
                } else if (value instanceof BigDecimal) {
                    compiled.setBigDecimal(key, (BigDecimal) value);
                } else if (value instanceof Short) {
                    compiled.setShort(key, (Short) value);
                } else if (value instanceof BigInteger) {
                    compiled.setBigInteger(key, (BigInteger) value);
                } else if (value instanceof Character) {
                    compiled.setCharacter(key, (Character) value);
                } else {
                    compiled.setParameter(key, value);
                }//from w  w w . ja v  a 2s  .c o  m
            }

            final List result = compiled.list();

            LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size());

            for (Object value : result) {
                if (value instanceof ContentKey) {
                    distinctContentKeySet.add((ContentKey) value);
                } else {
                    Object[] valueList = (Object[]) value;
                    distinctContentKeySet.add(((ContentKey) valueList[0]));
                }
            }

            List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size());
            distinctContentKeyList.addAll(distinctContentKeySet);
            return distinctContentKeyList;
        }
    });
}

From source file:com.enonic.cms.store.dao.ContentVersionEntityDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ContentVersionKey> findBySpecification(ContentVersionSpecification specification, String orderBy,
        int count) {
    Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession()
            .createQuery(getContentVersionKeysHQL(specification, orderBy, false));
    compiled.setCacheable(true);
    compiled.setMaxResults(count);/* w  w w.  j  ava 2  s  . c  o m*/

    @SuppressWarnings({ "unchecked" })
    List<ContentVersionKey> list = compiled.list();

    List<ContentVersionKey> versionKeys = new ArrayList<ContentVersionKey>();
    for (ContentVersionKey row : list) {
        versionKeys.add(row);
    }

    return versionKeys;
}

From source file:com.enonic.cms.store.dao.FindCategoryByKeysQuerier.java

License:Open Source License

List<CategoryEntity> queryCategories(final Collection<CategoryKey> categoryKeys) {
    final SelectBuilder hqlQuery = new SelectBuilder(0);
    hqlQuery.addSelect("c");
    hqlQuery.addFromTable(CategoryEntity.class.getName(), "c", SelectBuilder.NO_JOIN, null);
    hqlQuery.addFilter("AND", new InClauseBuilder<CategoryKey>("c.key", categoryKeys) {
        public void appendValue(StringBuffer sql, CategoryKey value) {
            sql.append(value.toString());
        }//www  .j  a  v  a  2  s.  co  m
    }.toString());

    Query compiled = hibernateSession.createQuery(hqlQuery.toString());
    compiled.setReadOnly(true);
    compiled.setCacheable(false);
    //noinspection unchecked
    return compiled.list();
}