Java Code Examples for org.hibernate.Criteria#setTimeout()

The following examples show how to use org.hibernate.Criteria#setTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateTemplate.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @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());
	}

	ResourceHolderSupport sessionHolder =
			(ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
	if (sessionHolder != null && sessionHolder.hasTimeout()) {
		criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
	}
}
 
Example 2
Source File: HibernateTemplate.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @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());
	}

	ResourceHolderSupport sessionHolder =
			(ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
	if (sessionHolder != null && sessionHolder.hasTimeout()) {
		criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
	}
}
 
Example 3
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @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(getSessionFactory());
	if (sessionHolder != null && sessionHolder.hasTimeout()) {
		criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
	}
}
 
Example 4
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @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(getSessionFactory());
	if (sessionHolder != null && sessionHolder.hasTimeout()) {
		criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
	}
}
 
Example 5
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @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(getSessionFactory());
	if (sessionHolder != null && sessionHolder.hasTimeout()) {
		criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
	}
}
 
Example 6
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @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(getSessionFactory());
	if (sessionHolder != null && sessionHolder.hasTimeout()) {
		criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
	}
}
 
Example 7
Source File: SessionFactoryUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply the current transaction timeout, if any, to the given
 * Hibernate Criteria object.
 * @param criteria the Hibernate Criteria object
 * @param sessionFactory Hibernate SessionFactory that the Criteria was created for
 * @see org.hibernate.Criteria#setTimeout
 */
public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory) {
	Assert.notNull(criteria, "No Criteria object specified");
	if (sessionFactory != null) {
		SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
		if (sessionHolder != null && sessionHolder.hasTimeout()) {
			criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
		}
	}
}
 
Example 8
Source File: SessionFactoryUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Apply the current transaction timeout, if any, to the given
 * Hibernate Criteria object.
 * @param criteria the Hibernate Criteria object
 * @param sessionFactory Hibernate SessionFactory that the Criteria was created for
 * @see org.hibernate.Criteria#setTimeout
 */
public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory) {
	Assert.notNull(criteria, "No Criteria object specified");
	if (sessionFactory != null) {
		SessionHolder sessionHolder =
			(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
		if (sessionHolder != null && sessionHolder.hasTimeout()) {
			criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
		}
	}
}