org.hibernate.Query#setFetchSize ( )源码实例Demo

下面列出了org.hibernate.Query#setFetchSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: HibernateTemplate.java
/**
 * 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 项目: lams   文件: HibernateTemplate.java
/**
 * Prepare the given Query object, applying cache settings and/or
 * a transaction timeout.
 * @param queryObject the Query object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 * @see SessionFactoryUtils#applyTransactionTimeout
 */
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());
	}
	SessionFactoryUtils.applyTransactionTimeout(queryObject, getSessionFactory());
}
 
源代码3 项目: spring4-understanding   文件: HibernateTemplate.java
/**
 * Prepare the given Query object, applying cache settings and/or
 * a transaction timeout.
 * @param queryObject the Query object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 * @see SessionFactoryUtils#applyTransactionTimeout
 */
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());
	}
	SessionFactoryUtils.applyTransactionTimeout(queryObject, getSessionFactory());
}
 
源代码4 项目: spring4-understanding   文件: HibernateTemplate.java
/**
 * 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());
	}
}
 
源代码5 项目: spring4-understanding   文件: HibernateTemplate.java
/**
 * 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());
	}
}
 
源代码6 项目: cacheonix-core   文件: AbstractSessionImpl.java
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() );
}
 
源代码7 项目: unitime   文件: LookupTables.java
/**
   * Executes the query to retrieve instructors
   * @param request
   * @param clause
   * @throws Exception
   */
  private static void getInstructors(HttpServletRequest request, SessionContext context, StringBuffer clause) throws Exception {
      String instructorNameFormat = UserProperty.NameFormat.get(context.getUser());
      
      Long acadSessionId = context.getUser().getCurrentAcademicSessionId();

StringBuffer query = new StringBuffer();
query.append("select distinct i from DepartmentalInstructor i ");
query.append(" where i.department.session.uniqueId = :acadSessionId ");
query.append(clause);
      
      DepartmentalInstructorDAO idao = new DepartmentalInstructorDAO();
org.hibernate.Session hibSession = idao.getSession();

Query q = hibSession.createQuery(query.toString());
q.setFetchSize(5000);
q.setCacheable(true);
q.setLong("acadSessionId", acadSessionId);
      
List result = q.list();
      Vector v = new Vector(result.size());
      Vector h = new Vector(result.size());
      Collections.sort(result);
   for (Iterator i=result.iterator();i.hasNext();) {
          DepartmentalInstructor di = (DepartmentalInstructor)i.next();
          String name = di.getName(instructorNameFormat);
          v.addElement(new ComboBoxLookup(name, di.getUniqueId().toString()));
          if (di.hasPreferences())
              h.add(di.getUniqueId());
}
      
      request.setAttribute(DepartmentalInstructor.INSTR_LIST_ATTR_NAME, v);
      request.setAttribute(DepartmentalInstructor.INSTR_HAS_PREF_ATTR_NAME, h);
  }
 
源代码8 项目: fastdfs-zyc   文件: MonitorServiceImpl.java
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<Group> getAllGroups() throws IOException, MyException {
    List<Group> result = new ArrayList<Group>();
    Session session = getSession();
    String str = "from Group as g GROUP BY groupName order by g.created desc";
    Query query = session.createQuery(str);
    query.setFirstResult(0);
    query.setFetchSize(2);
    result = query.list();
    return result;
}
 
源代码9 项目: DataHubSystem   文件: HibernateDao.java
/**
 * <p>Returns a List of <b>T</b> entities, where HQL clauses can be
 * specified.</p>
 * 
 * Note: This method is useful in read only. It can be use to delete or 
 * create <b>T</b> entities, but caution with <code>top</code> and 
 * <code>skip</code> arguments.
 * 
 * @param clauses query clauses (WHERE, ORDER BY, GROUP BY), if null no
 * clauses are apply.
 * @param skip number of entities to skip.
 * @param n  number of entities max returned.
 * @return a list of <b>T</b> entities.
 */
@SuppressWarnings ("unchecked")
public List<T> scroll (final String clauses, final int skip, final int n)
{
   StringBuilder hql = new StringBuilder ();
   hql.append ("FROM ").append (entityClass.getName ());
   if (clauses != null)
      hql.append (" ").append (clauses);

   Session session;
   boolean newSession = false;
   try
   {
      session = getSessionFactory ().getCurrentSession ();
   }
   catch (HibernateException e)
   {
      session = getSessionFactory ().openSession ();
      newSession = true;
   }

   Query query = session.createQuery (hql.toString ());
   if (skip > 0) query.setFirstResult (skip);
   if (n > 0) 
   {
      query.setMaxResults (n);
      query.setFetchSize (n);
   }
   
   logger.info("Execution of HQL: " + hql.toString ());
   long start = System.currentTimeMillis ();

   List<T> result = (List<T>) query.list ();
   logger.info("HQL executed in " + 
      (System.currentTimeMillis() -start) + "ms.");

   if (newSession)
   {
      session.disconnect ();
   }

   return result;
}
 
源代码10 项目: unitime   文件: InstructionalOffering.java
/**
 * Search for instructional offerings
 * @param acadSessionId Academic Session
 * @param subjectAreaId Subject Area
 * @param courseNbr Course Number
 * @return TreeSet of results
 */
public static TreeSet<InstructionalOffering> search(
        Long acadSessionId,
        Long subjectAreaId,
        String courseNbr,
        boolean fetchStructure,
        boolean fetchCredits,
        boolean fetchInstructors,
        boolean fetchPreferences,
        boolean fetchAssignments,
        boolean fetchReservations) {

	org.hibernate.Session hibSession = (new InstructionalOfferingDAO()).getSession();

	StringBuffer query = new StringBuffer();
	query.append("select distinct io ");
	query.append(" from InstructionalOffering as io inner join io.courseOfferings as co ");

	if (fetchStructure) {
		query.append("left join fetch io.courseOfferings as cox ");
		query.append("left join fetch io.instrOfferingConfigs as ioc ");
		query.append("left join fetch ioc.schedulingSubparts as ss ");
		query.append("left join fetch ss.classes as c ");
		query.append("left join fetch ss.childSubparts as css ");
		query.append("left join fetch c.childClasses as cc ");
	}

	if (fetchCredits)
		query.append("left join fetch ss.creditConfigs as ssc ");

	if (fetchPreferences || fetchInstructors) {
		query.append("left join fetch c.classInstructors as ci ");
		query.append("left join fetch ci.instructor as di ");
	}

	if (fetchAssignments) {
		query.append("left join fetch c.assignments as ca ");
		query.append("left join fetch ca.rooms as car ");
	}

	if (fetchPreferences) {
		query.append("left join fetch c.preferences as cp ");
		query.append("left join fetch ss.preferences as ssp ");
		query.append("left join fetch di.preferences as dip ");
	}

	if (fetchReservations) {
		query.append("left join fetch ioc.individualReservations as ir ");
		query.append("left join fetch ioc.studentGroupReservations as sgr ");
		query.append("left join fetch ioc.acadAreaReservations as aar ");
		query.append("left join fetch ioc.posReservations as pr ");
	}

	query.append(" where io.session.uniqueId=:sessionId ");

	if (courseNbr != null && courseNbr.length() > 0){
		if (courseNbr.indexOf('*') >= 0) {
			query.append(" and co.courseNbr like :courseNbr ");
		} else {
			query.append(" and co.courseNbr = :courseNbr ");
		}
	}

	query.append(" and co.subjectArea.uniqueId = :subjectAreaId ");

	Query q = hibSession.createQuery(query.toString());
	q.setFetchSize(1000);
	q.setLong("subjectAreaId", subjectAreaId);
	q.setLong("sessionId", acadSessionId.longValue());
	if (courseNbr != null && courseNbr.length() > 0) {
		if (ApplicationProperty.CourseOfferingNumberUpperCase.isTrue())
           	courseNbr = courseNbr.toUpperCase();
		q.setString("courseNbr", courseNbr.replace('*', '%'));
	}
	q.setCacheable(true);


       TreeSet<InstructionalOffering> ts = new TreeSet<InstructionalOffering>(new InstructionalOfferingComparator(Long.valueOf(subjectAreaId)));

       long sTime = new java.util.Date().getTime();
	ts.addAll(q.list());
	long eTime = new java.util.Date().getTime();
       Debug.debug("fetch time = " + (eTime - sTime));

       return ts;
}