Example usage for org.hibernate Query setTimeout

List of usage examples for org.hibernate Query setTimeout

Introduction

In this page you can find the example usage for org.hibernate Query setTimeout.

Prototype

Query<R> setTimeout(int timeout);

Source Link

Document

Set the query timeout in seconds.

Usage

From source file:org.rhq.server.metrics.migrator.workers.AggregateDataMigrator.java

License:Open Source License

private long getRowCount(String countQuery) {
    StatelessSession session = getSQLSession(config);

    org.hibernate.Query query = session.createSQLQuery(countQuery);
    query.setReadOnly(true);/*from ww  w.ja v a2  s . c om*/
    query.setTimeout(DataMigrator.SQL_TIMEOUT);
    long count = Long.parseLong(query.uniqueResult().toString());

    closeSQLSession(session);

    return count;
}

From source file:org.rhq.server.metrics.migrator.workers.RawDataMigrator.java

License:Open Source License

private long getRowCount(String countQuery) {
    StatelessSession session = getSQLSession(config);

    org.hibernate.Query query = session.createSQLQuery(countQuery);
    query.setReadOnly(true);/*ww  w .  ja va  2s.c o  m*/
    query.setTimeout(DataMigrator.SQL_TIMEOUT);

    long count = Long.parseLong(query.uniqueResult().toString());

    closeSQLSession(session);

    return count;
}

From source file:org.springframework.orm.hibernate3.SessionFactoryUtils.java

License:Apache License

/**
 * Apply the current transaction timeout, if any, to the given
 * Hibernate Query object.//from   w  w w .  ja v a 2  s.c  om
 * @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());
        }
    }
}

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

License:Apache License

/**
 * Prepare the given Query object, applying cache settings and/or
 * a transaction timeout./*from w ww.j  ava  2 s .c om*/
 * @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());
    }
}