Java Code Examples for org.hibernate.Query#setCacheMode()

The following examples show how to use org.hibernate.Query#setCacheMode() . 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: ProfileDaoImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
	 * {@inheritDoc}
	 */
@Override
public List<UserProfile> getUserProfiles(final int start, final int count) {
	
	//get fields directly from the sakaiperson table and use Transformers.aliasToBean to transform into UserProfile pojo
	//the idea is we *dont* want a SakaiPerson object
	final HibernateCallback<List<UserProfile>> hcb = session -> {
           final Query q = session.getNamedQuery(QUERY_GET_SAKAI_PERSON);
           //see scalars in the hbm
           q.setFirstResult(start);
           q.setMaxResults(count);
           q.setResultTransformer(Transformers.aliasToBean(UserProfile.class));
           q.setCacheMode(CacheMode.GET);
           return q.list();
       };
  	
  	return getHibernateTemplate().execute(hcb);
}
 
Example 2
Source File: ProfileDaoImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
	 * {@inheritDoc}
	 */
@Override
public List<UserProfile> getUserProfiles(final int start, final int count) {
	
	//get fields directly from the sakaiperson table and use Transformers.aliasToBean to transform into UserProfile pojo
	//the idea is we *dont* want a SakaiPerson object
	final HibernateCallback<List<UserProfile>> hcb = session -> {
           final Query q = session.getNamedQuery(QUERY_GET_SAKAI_PERSON);
           //see scalars in the hbm
           q.setFirstResult(start);
           q.setMaxResults(count);
           q.setResultTransformer(Transformers.aliasToBean(UserProfile.class));
           q.setCacheMode(CacheMode.GET);
           return q.list();
       };
  	
  	return getHibernateTemplate().execute(hcb);
}
 
Example 3
Source File: AbstractSessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void initQuery(Query query, NamedQueryDefinition nqd) {
	query.setCacheable( nqd.isCacheable() );
	query.setCacheRegion( nqd.getCacheRegion() );
	if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
	if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
	if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() );
	query.setReadOnly( nqd.isReadOnly() );
	if ( nqd.getComment() != null ) query.setComment( nqd.getComment() );
}