本文整理匯總了Java中org.hibernate.Query.setTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.setTimeout方法的具體用法?Java Query.setTimeout怎麽用?Java Query.setTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.Query
的用法示例。
在下文中一共展示了Query.setTimeout方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prepareQuery
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* Prepare the given Query object, applying cache settings and/or
* a transaction timeout.
* @param queryObject the Query object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
*/
protected void prepareQuery(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(getSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) {
queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
}
}
示例2: applyTransactionTimeout
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* Apply the current transaction timeout, if any, to the given
* Hibernate Query object.
* @param query the Hibernate Query object
* @param sessionFactory Hibernate SessionFactory that the Query was created for
* (may be {@code null})
* @see org.hibernate.Query#setTimeout
*/
public static void applyTransactionTimeout(Query query, SessionFactory sessionFactory) {
Assert.notNull(query, "No Query object specified");
if (sessionFactory != null) {
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
if (sessionHolder != null && sessionHolder.hasTimeout()) {
query.setTimeout(sessionHolder.getTimeToLiveInSeconds());
}
}
}
示例3: initQuery
import org.hibernate.Query; //導入方法依賴的package包/類
private void initQuery(Query query, NamedQueryDefinition nqd) {
// todo : cacheable and readonly should be Boolean rather than boolean...
query.setCacheable( nqd.isCacheable() );
query.setCacheRegion( nqd.getCacheRegion() );
query.setReadOnly( nqd.isReadOnly() );
if ( nqd.getTimeout() != null ) {
query.setTimeout( nqd.getTimeout() );
}
if ( nqd.getFetchSize() != null ) {
query.setFetchSize( nqd.getFetchSize() );
}
if ( nqd.getCacheMode() != null ) {
query.setCacheMode( nqd.getCacheMode() );
}
if ( nqd.getComment() != null ) {
query.setComment( nqd.getComment() );
}
if ( nqd.getFirstResult() != null ) {
query.setFirstResult( nqd.getFirstResult() );
}
if ( nqd.getMaxResults() != null ) {
query.setMaxResults( nqd.getMaxResults() );
}
if ( nqd.getFlushMode() != null ) {
query.setFlushMode( nqd.getFlushMode() );
}
}