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.PositionDaoBase.java

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

From source file:com.algoTrader.entity.security.SecurityDaoBase.java

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

From source file:com.algoTrader.entity.security.SecurityDaoBase.java

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

From source file:com.algoTrader.entity.security.SecurityDaoBase.java

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

From source file:com.algoTrader.entity.security.SecurityDaoBase.java

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

From source file:com.algoTrader.entity.security.SecurityDaoBase.java

/**
 * {@inheritDoc}//from   w ww .  ja va 2 s  . c o m
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findSecuritiesInPortfolio(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.security.SecurityDaoBase.java

/**
 * {@inheritDoc}//w  ww.j a va  2 s  .co  m
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findSecuritiesOnWatchlist(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.security.SecurityDaoBase.java

/**
 * {@inheritDoc}/*www  . j  a v  a 2  s . com*/
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findSecuritiesOnActiveWatchlist(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.security.SecurityFamilyDaoBase.java

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

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

/**
 * {@inheritDoc}//from   ww  w . jav a  2  s  .c om
 */
@Override
@SuppressWarnings("unchecked")
public Object findByName(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);
    }
}