org.hibernate.Query.setFetchSize()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(363)

本文整理了Java中org.hibernate.Query.setFetchSize方法的一些代码示例,展示了Query.setFetchSize的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setFetchSize方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setFetchSize

Query.setFetchSize介绍

[英]Set a fetch size for the underlying JDBC query.
[中]为基础JDBC查询设置获取大小。

代码示例

代码示例来源:origin: spring-projects/spring-batch

  1. /**
  2. * Get a cursor over all of the results, with the forward-only flag set.
  3. *
  4. * @param fetchSize the fetch size to use retrieving the results
  5. * @param parameterValues the parameter values to use (or null if none).
  6. *
  7. * @return a forward-only {@link ScrollableResults}
  8. */
  9. public ScrollableResults getForwardOnlyCursor(int fetchSize, Map<String, Object> parameterValues) {
  10. Query query = createQuery();
  11. if (parameterValues != null) {
  12. query.setProperties(parameterValues);
  13. }
  14. return query.setFetchSize(fetchSize).scroll(ScrollMode.FORWARD_ONLY);
  15. }

代码示例来源:origin: spring-projects/spring-batch

  1. /**
  2. * Read a page of data, clearing the existing session (if necessary) first,
  3. * and creating a new session before executing the query.
  4. *
  5. * @param page the page to read (starting at 0)
  6. * @param pageSize the size of the page or maximum number of items to read
  7. * @param fetchSize the fetch size to use
  8. * @param parameterValues the parameter values to use (if any, otherwise
  9. * null)
  10. * @return a collection of items
  11. */
  12. public Collection<? extends T> readPage(int page, int pageSize, int fetchSize, Map<String, Object> parameterValues) {
  13. clear();
  14. Query query = createQuery();
  15. if (parameterValues != null) {
  16. query.setProperties(parameterValues);
  17. }
  18. @SuppressWarnings("unchecked")
  19. List<T> result = query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list();
  20. return result;
  21. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Prepare the given Query object, applying cache settings and/or
  3. * a transaction timeout.
  4. * @param queryObject the Query object to prepare
  5. * @see #setCacheQueries
  6. * @see #setQueryCacheRegion
  7. */
  8. @SuppressWarnings({"rawtypes", "deprecation"})
  9. protected void prepareQuery(org.hibernate.Query queryObject) {
  10. if (isCacheQueries()) {
  11. queryObject.setCacheable(true);
  12. if (getQueryCacheRegion() != null) {
  13. queryObject.setCacheRegion(getQueryCacheRegion());
  14. }
  15. }
  16. if (getFetchSize() > 0) {
  17. queryObject.setFetchSize(getFetchSize());
  18. }
  19. if (getMaxResults() > 0) {
  20. queryObject.setMaxResults(getMaxResults());
  21. }
  22. ResourceHolderSupport sessionHolder =
  23. (ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
  24. if (sessionHolder != null && sessionHolder.hasTimeout()) {
  25. queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
  26. }
  27. }

代码示例来源:origin: org.springframework/spring-orm

  1. /**
  2. * Prepare the given Query object, applying cache settings and/or
  3. * a transaction timeout.
  4. * @param queryObject the Query object to prepare
  5. * @see #setCacheQueries
  6. * @see #setQueryCacheRegion
  7. */
  8. @SuppressWarnings({"rawtypes", "deprecation"})
  9. protected void prepareQuery(org.hibernate.Query queryObject) {
  10. if (isCacheQueries()) {
  11. queryObject.setCacheable(true);
  12. if (getQueryCacheRegion() != null) {
  13. queryObject.setCacheRegion(getQueryCacheRegion());
  14. }
  15. }
  16. if (getFetchSize() > 0) {
  17. queryObject.setFetchSize(getFetchSize());
  18. }
  19. if (getMaxResults() > 0) {
  20. queryObject.setMaxResults(getMaxResults());
  21. }
  22. ResourceHolderSupport sessionHolder =
  23. (ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
  24. if (sessionHolder != null && sessionHolder.hasTimeout()) {
  25. queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
  26. }
  27. }

代码示例来源:origin: stackoverflow.com

  1. Query query = session.createQuery(query);
  2. query.setReadOnly(true);
  3. // MIN_VALUE gives hint to JDBC driver to stream results
  4. query.setFetchSize(Integer.MIN_VALUE);
  5. ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
  6. // iterate over results
  7. while (results.next()) {
  8. Object row = results.get();
  9. // process row then release reference
  10. // you may need to evict() as well
  11. }
  12. results.close();

代码示例来源:origin: riotfamily/riot

  1. public TypedQuery<T> setFetchSize(int fetchSize) {
  2. query.setFetchSize(fetchSize);
  3. return this;
  4. }

代码示例来源:origin: com.github.cafdataprocessing/corepolicy-hibernate

  1. @Override
  2. public Query setFetchSize(int i) {
  3. return query.setFetchSize(i);
  4. }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

  1. @Override
  2. protected void applyFetchSize(int fetchSize) {
  3. query.setFetchSize( fetchSize );
  4. }

代码示例来源:origin: ezbz/projectx

  1. @Override
  2. public Query setFetchSize(final int fetchSize) {
  3. return query.setFetchSize(fetchSize);
  4. }

代码示例来源:origin: culturecommunication/ginco

  1. @Override
  2. public List<ThesaurusConcept> getConceptsWoNotes(String idThesaurus, int startIndex, int limit) {
  3. Query query = getCurrentSession().createSQLQuery("select c.* "
  4. + "from thesaurus_concept c "
  5. + "left join note n on c.identifier = n.conceptid "
  6. + "where c.thesaurusid=:pthesaurusid"
  7. + " and n.identifier is null").addEntity(ThesaurusConcept.class);
  8. query.setParameter("pthesaurusid", idThesaurus);
  9. query.setFirstResult(startIndex);
  10. query.setFetchSize(limit);
  11. query.setMaxResults(limit);
  12. return (List<ThesaurusConcept>) query.list();
  13. }

代码示例来源:origin: stackoverflow.com

  1. Query q = session.createCriteria(... no offset or limit ...);
  2. q.setCacheMode(CacheMode.IGNORE);
  3. q.setFetchSize(1000); // experiment with this to optimize performance vs. memory
  4. ScrollableResults iterator = query.scroll(ScrollMode.FORWARD_ONLY);
  5. while (iterator.next()) {
  6. Product p = (Product)iterator.get();
  7. ...
  8. // session.evict(p); // an alternative to setting the cache mode above
  9. }

代码示例来源:origin: stackoverflow.com

  1. Query query = session.createQuery(query);
  2. query.setReadOnly(true);
  3. // MIN_VALUE gives hint to JDBC driver to stream results
  4. query.setFetchSize(Integer.MIN_VALUE);
  5. ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
  6. // iterate over results
  7. while (results.next()) {
  8. Object row = results.get();
  9. // process row then release reference
  10. // you may need to evict() as well
  11. }
  12. results.close();

代码示例来源:origin: stackoverflow.com

  1. Query query = session.createQuery(query);
  2. query.setReadOnly(true);
  3. // MIN_VALUE gives hint to JDBC driver to stream results
  4. query.setFetchSize(Integer.MIN_VALUE);
  5. ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
  6. // iterate over results
  7. while (results.next()) {
  8. Object row = results.get();
  9. // process row then release reference
  10. // you may need to flush() as well
  11. }
  12. results.close();

代码示例来源:origin: stackoverflow.com

  1. Query query = session.createQuery(query);
  2. query.setReadOnly(true);
  3. query.setFetchSize(Integer.MIN_VALUE);
  4. ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
  5. // iterate over results
  6. while (results.next()) {
  7. Object row = results.get();
  8. // process row then release reference
  9. // you may need to evict() as well
  10. }
  11. results.close();

代码示例来源:origin: stackoverflow.com

  1. Query query = session.createQuery(query);
  2. query.setReadOnly(true);
  3. query.setFetchSize(50);
  4. ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
  5. // iterate over results
  6. while (results.next()) {
  7. Object row = results.get();
  8. // process row then release reference
  9. // you may need to flush() as well
  10. }
  11. results.close();

代码示例来源:origin: jboss.jboss-embeddable-ejb3/hibernate-all

  1. private void initQuery(Query query, NamedQueryDefinition nqd) {
  2. query.setCacheable( nqd.isCacheable() );
  3. query.setCacheRegion( nqd.getCacheRegion() );
  4. if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
  5. if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
  6. if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() );
  7. query.setReadOnly( nqd.isReadOnly() );
  8. if ( nqd.getComment() != null ) query.setComment( nqd.getComment() );
  9. }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate

  1. private void initQuery(Query query, NamedQueryDefinition nqd) {
  2. query.setCacheable( nqd.isCacheable() );
  3. query.setCacheRegion( nqd.getCacheRegion() );
  4. if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
  5. if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
  6. if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() );
  7. query.setReadOnly( nqd.isReadOnly() );
  8. if ( nqd.getComment() != null ) query.setComment( nqd.getComment() );
  9. }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

  1. private void initQuery(Query query, NamedQueryDefinition nqd) {
  2. query.setCacheable( nqd.isCacheable() );
  3. query.setCacheRegion( nqd.getCacheRegion() );
  4. if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
  5. if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
  6. if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() );
  7. query.setReadOnly( nqd.isReadOnly() );
  8. if ( nqd.getComment() != null ) query.setComment( nqd.getComment() );
  9. }

代码示例来源:origin: org.jboss.seam/jboss-seam

  1. protected org.hibernate.Query createQuery()
  2. {
  3. parseEjbql();
  4. evaluateAllParameters();
  5. org.hibernate.Query query = getSession().createQuery( getRenderedEjbql() );
  6. setParameters( query, getQueryParameterValues(), 0 );
  7. setParameters( query, getRestrictionParameterValues(), getQueryParameterValues().size() );
  8. if ( getFirstResult()!=null) query.setFirstResult( getFirstResult() );
  9. if ( getMaxResults()!=null) query.setMaxResults( getMaxResults()+1 ); //add one, so we can tell if there is another page
  10. if ( getCacheable()!=null ) query.setCacheable( getCacheable() );
  11. if ( getCacheRegion()!=null ) query.setCacheRegion( getCacheRegion() );
  12. if ( getFetchSize()!=null ) query.setFetchSize( getFetchSize() );
  13. return query;
  14. }

代码示例来源:origin: OpenNMS/opennms

  1. private void prepareQuery(Query queryObject) {
  2. if(getHibernateTemplate().isCacheQueries()) {
  3. queryObject.setCacheable(true);
  4. if(getHibernateTemplate().getQueryCacheRegion() != null) {
  5. queryObject.setCacheRegion(getHibernateTemplate().getQueryCacheRegion());
  6. }
  7. }
  8. if(getHibernateTemplate().getFetchSize() > 0) {
  9. queryObject.setFetchSize(getHibernateTemplate().getFetchSize());
  10. }
  11. if(getHibernateTemplate().getMaxResults() > 0) {
  12. queryObject.setMaxResults(getHibernateTemplate().getMaxResults());
  13. }
  14. }

相关文章