當前位置: 首頁>>代碼示例>>Java>>正文


Java ScrollableResults.last方法代碼示例

本文整理匯總了Java中org.hibernate.ScrollableResults.last方法的典型用法代碼示例。如果您正苦於以下問題:Java ScrollableResults.last方法的具體用法?Java ScrollableResults.last怎麽用?Java ScrollableResults.last使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.ScrollableResults的用法示例。


在下文中一共展示了ScrollableResults.last方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNthElement

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
/**
 * @param query
 *            The query.
 * @param n
 *            The n'th element.
 * @param logPerformance
 *            True, if the performance should be logged.
 * @param class1
 * @param <T>
 *            Return type of this method.
 * @return The n'th element or null.
 */
private <T> T getNthElement(org.hibernate.Query query, int n, boolean logPerformance) {
    StopWatch stopWatch = new StopWatch();
    if (logPerformance) {
        stopWatch.start();
    }
    query.setMaxResults(n);
    ScrollableResults scrollableResults = query.scroll(ScrollMode.SCROLL_INSENSITIVE);

    stopStopWatches(logPerformance, stopWatch, "QueryHelper#query.scroll");
    resetAndStartStopWatch(logPerformance, stopWatch);
    if (scrollableResults.last()) {
        stopStopWatches(logPerformance, stopWatch, "QueryHelper#scrollableResults.setRowNumber"
                + n);
        resetAndStartStopWatch(logPerformance, stopWatch);
        return (T) scrollableResults.get(0);
    }
    return null;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:31,代碼來源:QueryHelperDaoImpl.java

示例2: getStoppedCollectionsCount

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
@Override
public Long getStoppedCollectionsCount(String terms) {
	Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
	criteria.setProjection(Projections.projectionList()
			.add(Projections.property("id"), "id"));
	
	LogicalExpression or = Restrictions.or(
			Restrictions.eq("status", CollectionStatus.STOPPED),
			Restrictions.eq("status", CollectionStatus.NOT_RUNNING)
			);
	
	LogicalExpression orAll = Restrictions.or(
			or,
			Restrictions.eq("status", CollectionStatus.FATAL_ERROR)
			);
	
	criteria.add(orAll);
	addCollectionSearchCriteria(terms, criteria);

	ScrollableResults scroll = criteria.scroll();
	int i = scroll.last() ? scroll.getRowNumber() + 1 : 0;
	return Long.valueOf(i);
}
 
開發者ID:qcri-social,項目名稱:AIDR,代碼行數:24,代碼來源:CollectionRepositoryImpl.java

示例3: getGroupedCount

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
protected int getGroupedCount(Query countQuery) {
  int nRows = -1;
  ScrollableResults scrollableResults = countQuery.scroll();
  if (scrollableResults.last()) {
    nRows = scrollableResults.getRowNumber();
  }
  scrollableResults.close();
  return nRows + 1;
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:10,代碼來源:HQLDataSourceService.java

示例4: getRowCountOfDCRst

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
public Integer getRowCountOfDCRst(DetachedCriteria dc) {
	Session session = (Session) this.em.getDelegate();
	boolean needClose = false;
	if (!session.isOpen()) {
		session = session.getSessionFactory().openSession();
		needClose = true;
	}

	ScrollableResults sc = null;
	try {
		Criteria c = dc.getExecutableCriteria(session);
		sc = c.scroll(ScrollMode.FORWARD_ONLY);
		sc.last();
		int count = sc.getRowNumber() + 1;

		return count;
	} finally {
		if (sc != null) {
			sc.close();
			sc = null;
		}

		if (needClose) {
			session.close();
			session = null;
		}

	}
}
 
開發者ID:dynamo2,項目名稱:tianma,代碼行數:30,代碼來源:AbstractBaseDAO.java

示例5: getUsersCount

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
@Override
   public Long getUsersCount(String query) {
	Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(UserAccount.class);
       criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

       if (StringUtils.hasText(query)){
           String wildcard ='%'+ URLDecoder.decode(query.trim())+'%';
           criteria.add(Restrictions.ilike("userName", wildcard));
       }

       ScrollableResults scroll = criteria.scroll();
       int i = scroll.last() ? scroll.getRowNumber() + 1 : 0;
       return Long.valueOf(i);
}
 
開發者ID:qcri-social,項目名稱:AIDR,代碼行數:15,代碼來源:UserAccountRepositoryImpl.java

示例6: getRunningCollectionsCount

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
@Override
public Long getRunningCollectionsCount(String terms) {
	Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
	criteria.setProjection(Projections.projectionList()
			.add(Projections.property("id"), "id"));

	LogicalExpression or = Restrictions.or(
			Restrictions.eq("status", CollectionStatus.RUNNING),
			Restrictions.eq("status", CollectionStatus.RUNNING_WARNING)
			);

	LogicalExpression or2 = Restrictions.or(
			or,
			Restrictions.eq("status", CollectionStatus.INITIALIZING)
			);
	
	LogicalExpression orAll = Restrictions.or(
			or2,
			Restrictions.eq("status", CollectionStatus.WARNING)
			);

	LogicalExpression andAll = Restrictions.and(
			orAll,
			Restrictions.ne("status", CollectionStatus.TRASHED)
			);

	criteria.add(andAll);
	addCollectionSearchCriteria(terms, criteria);

	ScrollableResults scroll = criteria.scroll();
	int i = scroll.last() ? scroll.getRowNumber() + 1 : 0;
	return Long.valueOf(i);
}
 
開發者ID:qcri-social,項目名稱:AIDR,代碼行數:34,代碼來源:CollectionRepositoryImpl.java

示例7: QueryDataModel

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public QueryDataModel(String jpql) {
    this.jpql = jpql;

    QueryImpl<T> query = (QueryImpl<T>) JPAUtil.getEntityManager().createQuery(jpql);
    ScrollableResults scroll = query.getHibernateQuery().scroll();
    scroll.last();
    int count = scroll.getRowNumber();
    setRowCount(count);
}
 
開發者ID:joedayz,項目名稱:javaee7-samples,代碼行數:11,代碼來源:QueryDataModel.java

示例8: withSession

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
public final int withSession(Session session)
{
	final String idFinderHql = buildIdFinderHql();
	final String dmlHql = buildDmlHql();

	int total = 0;

	long startId = -1;
	long endId = -1;
	while( true )
	{
		// Find the next start and end ID
		startId = endId + 1;

		Query idFinder = session.createQuery(idFinderHql);
		idFinder.setMaxResults(MAX_BATCH_SIZE);
		idFinder.setParameter("startId", startId);
		setWhereParams(idFinder);
		ScrollableResults sr = idFinder.scroll();
		try
		{
			if( sr.last() )
			{
				endId = sr.getLong(0);
			}
			else
			{
				// Nothing more to process
				return total;
			}
		}
		finally
		{
			sr.close();
		}

		// Process rows in our ID range
		Query dml = session.createQuery(dmlHql);
		dml.setParameter("startId", startId);
		dml.setParameter("endId", endId);
		setWhereParams(dml);
		setDmlParams(dml);

		total += dml.executeUpdate();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:47,代碼來源:DMLPartitioner.java

示例9: withSession

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private final int withSession(Session session) {
	log.debug("inside withSession() method");
	final String idFinderHql = buildIdFinderHql();
	final String dmlHql = buildDeleteAuditLogDmlHql();

	int total = 0;

	long startId = -1;
	long endId = -1;
	while( true )
	{
		// Find the next start and end ID
		startId = endId + 1;
		Query idFinder = session.createQuery(idFinderHql);
		idFinder.setMaxResults(MAX_BATCH_SIZE);
		idFinder.setParameter("startId", startId);		
		idFinder.setParameter("date", daysBeforeRemoval);
		idFinder.setParameter("institution", institution);
		ScrollableResults sr = idFinder.scroll();
		try
		{
			if( sr.last() )
			{				
				endId = sr.getLong(0);
			}
			else
			{
				// Nothing more to process
				log.debug("Total Audit Log Deleted Records :: "+total);
				return total;
			}
		}
		finally
		{
			sr.close();
		}
		
		Query dml = session.createQuery(dmlHql);
		dml.setParameter("startId", startId);
		dml.setParameter("endId", endId);
		dml.setParameter("date", daysBeforeRemoval);
		dml.setParameter("institution", institution);			
		total += dml.executeUpdate();
		log.debug("Start Id:: "+startId+" End Id:: "+endId+" Total Deleted Records ::"+total);
	}		
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:47,代碼來源:AuditLogDMLPartitioner.java

示例10: doRebuildIndex

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
protected int doRebuildIndex() throws Exception {
	FullTextSession fullTextSession = (FullTextSession) entityManager.getDelegate();
	fullTextSession.setFlushMode(org.hibernate.FlushMode.MANUAL);
	fullTextSession.setCacheMode(org.hibernate.CacheMode.IGNORE);
	fullTextSession.purgeAll(NodeDocumentVersion.class);
	fullTextSession.getSearchFactory().optimize(NodeDocumentVersion.class);

	String query = "select ndv from NodeDocumentVersion ndv";
	ScrollableResults cursor = fullTextSession.createQuery(query).scroll();
	cursor.last();
	int count = cursor.getRowNumber() + 1;
	log.warn("Re-building Wine index for " + count + " objects.");

	if (count > 0) {
		int batchSize = 300;
		cursor.first(); // Reset to first result row
		int i = 0;

		while (true) {
			fullTextSession.index(cursor.get(0));

			if (++i % batchSize == 0) {
				fullTextSession.flushToIndexes();
				fullTextSession.clear(); // Clear persistence context for each batch
				log.info("Flushed index update " + i + " from Thread "
						+ Thread.currentThread().getName());
			}

			if (cursor.isLast()) {
				break;
			}

			cursor.next();
		}
	}

	cursor.close();
	fullTextSession.flushToIndexes();
	fullTextSession.clear(); // Clear persistence context for each batch
	fullTextSession.getSearchFactory().optimize(NodeDocumentVersion.class);

	return count;
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:44,代碼來源:IndexHelper.java

示例11: getQueryResults

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
public List<GlycanSequence> getQueryResults()
{
    Criteria query = createCriteria();

    log.info( "Performing query: " + query.toString() );
    setMessage(query.toString());
        
    ScrollableResults scroll = null;
    try 
    {
    
        scroll = query.scroll();
        
        scroll.last();
        setTotalResults(scroll.getRowNumber()+1);
        
        int count = getTotalResults();

        int first = getOffset();
        int max = getMaxResults();
        
        
        if ( first > 0 ) 
        {
            query.setFirstResult(first);
        }

        if ( max > 0 ) 
        {
            query.setMaxResults(max);
        }
        
        
        
        List<GlycanSequence> ret = (List<GlycanSequence>) query.list();

        log.debug( "query executed ok, results count=" + ret.size() );
        return ret;     
    }
    catch ( HibernateException e ) 
    {
        log.warn( "Caught " 
              + e.getClass().getName() 
              + " performing query:", e 
              );
                
        return Collections.emptyList();            
    }
    finally
    {
        if ( scroll != null )
            scroll.close();
    }
}
 
開發者ID:glycoinfo,項目名稱:eurocarbdb,代碼行數:55,代碼來源:SearchGlycanSequence.java


注:本文中的org.hibernate.ScrollableResults.last方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。