Java Code Examples for org.hibernate.ScrollableResults#last()

The following examples show how to use org.hibernate.ScrollableResults#last() . 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: CollectionRepositoryImpl.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: MessageLoader.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public MessageLoader(ScrollableResults results, Session session) {
    this.results = results;
    this.session = session;
    results.last();
    numberOfRecords = results.getRowNumber() + 1;
    results.beforeFirst();
}
 
Example 3
Source File: AbstractHibernateDAO.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
protected int getTotalNumber(Criteria criteria) {
	ScrollableResults results = criteria.scroll();
	results.last();
	int total = results.getRowNumber() + 1;
	results.close();
	return total;
}
 
Example 4
Source File: HQLDataSet.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private int getResultNumberUsingScrollableResults(org.hibernate.Query hibernateQuery, Session session) {
	int resultNumber = 0;
	logger.debug("Scrolling query " + statement.getQueryString() + " ...");
	ScrollableResults scrollableResults = hibernateQuery.scroll();
	scrollableResults.last();
	logger.debug("Scrolled query " + statement.getQueryString());
	resultNumber = scrollableResults.getRowNumber() + 1; // Hibernate ScrollableResults row number starts with 0
	logger.debug("Number of fetched records: " + resultNumber + " for query " + statement.getQueryString());
	resultNumber = resultNumber < 0 ? 0 : resultNumber;
	return resultNumber;
}
 
Example 5
Source File: UserAccountRepositoryImpl.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: CollectionRepositoryImpl.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: IndexHelper.java    From document-management-system with GNU General Public License v2.0 4 votes vote down vote up
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;
}