Java Code Examples for org.hibernate.Query.setReadOnly()

The following are Jave code examples for showing how to use setReadOnly() of the org.hibernate.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dhus-core   File: HibernateDao.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
public List<T> executeHQLQuery(final String hql,
      final List<SQLVisitor.SQLVisitorParameter> parameters,
      final int skip, final int top)
{
   Session session = getSessionFactory().getCurrentSession();
   Query query = session.createQuery(hql);
   for (int i = 0; i < parameters.size(); i++)
   {
      SQLVisitor.SQLVisitorParameter param = parameters.get(i);
      query.setParameter(i, param.getValue(), param.getType());
   }

   if (skip > -1)
   {
      query.setFirstResult(skip);
   }
   if (top > -1)
   {
      query.setMaxResults(top);
   }
   query.setReadOnly(true);
   return (List<T>) query.list();
}
 
Example 2
Project: dhus-core   File: HibernateDao.java   View Source Code Vote up 6 votes
public int countHQLQuery(String hql,
      List<SQLVisitor.SQLVisitorParameter> parameters)
{
   String hqlQuery = "SELECT COUNT(*) " + hql;
   Session session = getSessionFactory().getCurrentSession();
   Query query = session.createQuery(hqlQuery);
   for (int i = 0; i < parameters.size(); i++)
   {
      SQLVisitor.SQLVisitorParameter param = parameters.get(i);
      query.setParameter(i, param.getValue(), param.getType());
   }
   query.setReadOnly(true);

   Object obj = query.uniqueResult();
   int result;
   if (obj instanceof Long)
   {
      result = ((Long) obj).intValue();
   }
   else
   {
      result = (int) obj;
   }
   return result;
}
 
Example 3
Project: lams   File: AbstractSessionImpl.java   View Source Code Vote up 5 votes
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() );
	}
}