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.algoTrader.entity.StrategyDaoBase.java

/**
 * {@inheritDoc}/*  www.j  a va2  s.  co m*/
 */
@Override
@SuppressWarnings("unchecked")
public Object findByNameFetched(final int transform, final String queryString, final String name) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        queryObject.setParameter("name", name);
        Set results = new LinkedHashSet(queryObject.list());
        Object result = null;
        if (results.size() > 1) {
            throw new InvalidDataAccessResourceUsageException(
                    "More than one instance of 'com.algoTrader.entity.Strategy"
                            + "' was found when executing query --> '" + queryString + "'");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (transform != TRANSFORM_NONE) {
            result = transformEntity(transform, (Strategy) result);
        }
        return result;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.algoTrader.entity.StrategyDaoBase.java

/**
 * {@inheritDoc}/*from   www . j a v a 2 s . co  m*/
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findAutoActivateStrategies(final int transform, final String queryString, int pageNumber,
        int pageSize) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        if (pageNumber > 0 && pageSize > 0) {
            queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize));
            queryObject.setMaxResults(pageSize);
        }
        List results = queryObject.list();
        transformEntities(transform, results);
        return results;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.algoTrader.entity.TransactionDaoBase.java

/**
 * {@inheritDoc}/* w w w.  j ava 2 s  .  com*/
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findAllTrades(final int transform, final String queryString, int pageNumber, int pageSize) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        if (pageNumber > 0 && pageSize > 0) {
            queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize));
            queryObject.setMaxResults(pageSize);
        }
        List results = queryObject.list();
        transformEntities(transform, results);
        return results;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.algoTrader.entity.TransactionDaoBase.java

/**
 * {@inheritDoc}//  w w w.j  av  a2s.  com
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findAllCashflows(final int transform, final String queryString, int pageNumber, int pageSize) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        if (pageNumber > 0 && pageSize > 0) {
            queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize));
            queryObject.setMaxResults(pageSize);
        }
        List results = queryObject.list();
        transformEntities(transform, results);
        return results;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.algoTrader.entity.WatchListItemDaoBase.java

/**
 * {@inheritDoc}/*from   w  w w  .j  a  v a 2 s.  c  o  m*/
 */
@Override
@SuppressWarnings("unchecked")
public Object findByStrategyAndSecurity(final int transform, final String queryString,
        final String strategyName, final int securityId) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        queryObject.setParameter("strategyName", strategyName);
        queryObject.setParameter("securityId", new Integer(securityId));
        Set results = new LinkedHashSet(queryObject.list());
        Object result = null;
        if (results.size() > 1) {
            throw new InvalidDataAccessResourceUsageException(
                    "More than one instance of 'com.algoTrader.entity.WatchListItem"
                            + "' was found when executing query --> '" + queryString + "'");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (transform != TRANSFORM_NONE) {
            result = transformEntity(transform, (WatchListItem) result);
        }
        return result;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.all.client.model.LocalModelDao.java

License:Apache License

@SuppressWarnings("unchecked")
public Object findAll(final String hql, final Map<String, Object> values, final boolean includeAllResults) {
    Object result = hibernateTemplate.execute(new HibernateCallback() {
        @Override/*from w  w w  . ja v a  2 s .  c o  m*/
        public Object doInHibernate(Session session) throws SQLException {
            Query q = session.createQuery(hql);
            q.setCacheable(true);
            if (values != null) {
                for (String param : values.keySet()) {
                    q.setParameter(param, values.get(param));
                }
            }
            if (includeAllResults) {
                return q.list();
            } else {
                return q.uniqueResult();
            }
        }
    });

    return result;
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * returns a recursive list of processes that are children of this process
 * //from   w ww.j a  v  a  2s  .co  m
 * @return list of processes that are children of this process
 * @throws PersistenceException
 *             persistence exception
 * @throws HibernateException
 *             hibernate exception
 */
@Transient
public List<ZebraProcessInstance> getRunningChildProcesses() {

    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();

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

    Session s = RegistryHelper.getInstance().getSession();
    Query q = s.createQuery(querySQL);
    q.setCacheable(true);
    q.setLong("state", IProcessInstance.STATE_RUNNING);

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

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

@SuppressWarnings("unchecked")
@Transient/*from  w w  w  .  jav  a  2 s .  co m*/
public List<ZebraProcessInstance> getRunningRelatedProcesses() {
    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();

    if (this.getRelatedKey() != null) {

        String querySQL = "select api from ZebraProcessInstance api where api.relatedClass =:relatedClass";
        querySQL += " and api.relatedKey = :relatedKey";
        querySQL += " and api.state=:state";

        Session s = RegistryHelper.getInstance().getSession();
        Query q = s.createQuery(querySQL);
        q.setCacheable(true);
        q.setParameter("relatedClass", this.getRelatedClass());
        q.setLong("relatedKey", this.getRelatedKey().longValue());
        q.setLong("state", IProcessInstance.STATE_RUNNING);
        results = q.list();
    }
    return results;
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * Returns a list of all related processes that are complete
 * // w ww . java  2s .c  om
 * @return list of processes that are children of this process
 * @throws PersistenceException
 *             persistence exception
 * @throws HibernateException
 *             hibernate exception
 */
@SuppressWarnings("unchecked")
@Transient
public List<ZebraProcessInstance> getCompleteRelatedProcesses() {
    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();
    if (this.getRelatedKey() != null) {

        String querySQL = "select api from ZebraProcessInstance api where api.relatedClass =:relatedClass";
        querySQL += " and api.relatedKey = :relatedKey";
        querySQL += " and api.state=:state";

        Session s = RegistryHelper.getInstance().getSession();
        Query q = s.createQuery(querySQL);
        q.setCacheable(true);
        q.setParameter("relatedClass", this.getRelatedClass());
        q.setParameter("relatedKey", this.getRelatedKey());
        q.setLong("state", IProcessInstance.STATE_COMPLETE);

        results = q.list();
    }
    return results;
}

From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java

License:Apache License

/**
 * Get all child processes not running (e.g. complete and killed)
 * //  w w w .j a  v  a  2 s.c  o m
 * @return
 * @throws PersistenceException
 * @throws HibernateException
 */
@Transient
public List<ZebraProcessInstance> getNotRunningChildProcesses() throws HibernateException {
    List<ZebraProcessInstance> results = new ArrayList<ZebraProcessInstance>();

    String querySQL = "select api from ZebraProcessInstance api where api.parentProcessInstance.processInstanceId =:guid";
    querySQL += " and api.state!=:state";

    Session s = RegistryHelper.getInstance().getSession();
    Query q = s.createQuery(querySQL);
    q.setLong("state", IProcessInstance.STATE_RUNNING);
    q.setCacheable(true);

    recursivelyQueryChildProcesses(results, q);
    return results;
}