Example usage for org.springframework.orm.hibernate5 SessionHolder hasTimeout

List of usage examples for org.springframework.orm.hibernate5 SessionHolder hasTimeout

Introduction

In this page you can find the example usage for org.springframework.orm.hibernate5 SessionHolder hasTimeout.

Prototype

public boolean hasTimeout() 

Source Link

Document

Return whether this object has an associated timeout.

Usage

From source file:org.grails.orm.hibernate.GrailsHibernateTemplate.java

/**
 * Prepare the given Query object, applying cache settings and/or a
 * transaction timeout.//from w w  w . ja v a  2s . c om
 *
 * @param query the Query object to prepare
 */
protected void prepareQuery(Query query) {
    if (cacheQueries) {
        query.setCacheable(true);
    }
    if (shouldPassReadOnlyToHibernate()) {
        query.setReadOnly(true);
    }
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
    if (sessionHolder != null && sessionHolder.hasTimeout()) {
        query.setTimeout(sessionHolder.getTimeToLiveInSeconds());
    }
}

From source file:org.grails.orm.hibernate.GrailsHibernateTemplate.java

/**
 * Prepare the given Criteria object, applying cache settings and/or a
 * transaction timeout./* w w w. ja va  2  s .  c  o  m*/
 *
 * @param criteria the Criteria object to prepare
 */
protected void prepareCriteria(Criteria criteria) {
    if (cacheQueries) {
        criteria.setCacheable(true);
    }
    if (shouldPassReadOnlyToHibernate()) {
        criteria.setReadOnly(true);
    }
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
    if (sessionHolder != null && sessionHolder.hasTimeout()) {
        criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
    }
}

From source file:org.springframework.orm.hibernate5.HibernateTemplate.java

/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout./*from w ww  .  j a  v  a2  s. c  o m*/
 * @param criteria the Criteria object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 */
protected void prepareCriteria(Criteria criteria) {
    if (isCacheQueries()) {
        criteria.setCacheable(true);
        if (getQueryCacheRegion() != null) {
            criteria.setCacheRegion(getQueryCacheRegion());
        }
    }
    if (getFetchSize() > 0) {
        criteria.setFetchSize(getFetchSize());
    }
    if (getMaxResults() > 0) {
        criteria.setMaxResults(getMaxResults());
    }

    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .getResource(obtainSessionFactory());
    if (sessionHolder != null && sessionHolder.hasTimeout()) {
        criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
    }
}

From source file:org.springframework.orm.hibernate5.HibernateTemplate.java

/**
 * Prepare the given Query object, applying cache settings and/or
 * a transaction timeout./*  w ww  .j  a  va  2 s  .com*/
 * @param queryObject the Query object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 */
@Deprecated
@SuppressWarnings({ "rawtypes", "deprecation" })
protected void prepareQuery(org.hibernate.Query queryObject) {
    if (isCacheQueries()) {
        queryObject.setCacheable(true);
        if (getQueryCacheRegion() != null) {
            queryObject.setCacheRegion(getQueryCacheRegion());
        }
    }
    if (getFetchSize() > 0) {
        queryObject.setFetchSize(getFetchSize());
    }
    if (getMaxResults() > 0) {
        queryObject.setMaxResults(getMaxResults());
    }

    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .getResource(obtainSessionFactory());
    if (sessionHolder != null && sessionHolder.hasTimeout()) {
        queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
    }
}