List of usage examples for org.hibernate ScrollMode FORWARD_ONLY
ScrollMode FORWARD_ONLY
To view the source code for org.hibernate ScrollMode FORWARD_ONLY.
Click Source Link
From source file:org.squashtest.tm.service.internal.advancedsearch.IndexationServiceImpl.java
License:Open Source License
private ScrollableResults getScrollableResults(FullTextSession ftSession, Class<?> entity, Collection<Long> ids) { Criteria query = ftSession.createCriteria(entity); query.add(Restrictions.in("id", ids)); return query.scroll(ScrollMode.FORWARD_ONLY); }
From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateMilestoneDao.java
License:Open Source License
private ScrollableResults scrollableResults(Query query) throws HibernateException { return query.setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY); }
From source file:org.wallride.service.SystemService.java
License:Apache License
@Async @Transactional(propagation = Propagation.SUPPORTS) public void reIndex() throws Exception { logger.info("Re-Index started"); FullTextSession fullTextSession = Search.getFullTextSession((entityManager.unwrap(Session.class))); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); for (Class persistentClass : fullTextSession.getSearchFactory().getIndexedTypes()) { Transaction transaction = fullTextSession.beginTransaction(); // Scrollable results will avoid loading too many objects in memory ScrollableResults results = fullTextSession.createCriteria(persistentClass).setFetchSize(BATCH_SIZE) .scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++;//from w w w.j a v a2 s. com fullTextSession.index(results.get(0)); //index each element if (index % BATCH_SIZE == 0) { fullTextSession.flushToIndexes(); //apply changes to indexes fullTextSession.clear(); //free memory since the queue is processed } } transaction.commit(); } logger.info("Re-Index finished"); }
From source file:org.yes.cart.dao.impl.GenericDAOHibernateImpl.java
License:Apache License
/** * {@inheritDoc}//www . j a va 2 s . c om */ public ResultsIterator<Object> findByQueryIterator(final String hsqlQuery, final Object... parameters) { Query query = sessionFactory.getCurrentSession().createQuery(hsqlQuery); if (parameters != null) { setQueryParameters(query, parameters); } return new ResultsIteratorImpl<Object>(query.scroll(ScrollMode.FORWARD_ONLY)); }
From source file:org.yes.cart.dao.impl.GenericDAOHibernateImpl.java
License:Apache License
/** * {@inheritDoc}//from ww w . j a va2 s. co m */ @SuppressWarnings("unchecked") public ResultsIterator<T> findByNamedQueryIterator(final String namedQueryName, final Object... parameters) { Query query = sessionFactory.getCurrentSession().getNamedQuery(namedQueryName); if (parameters != null) { setQueryParameters(query, parameters); } return new ResultsIteratorImpl<T>(query.scroll(ScrollMode.FORWARD_ONLY)); }
From source file:org.yes.cart.dao.impl.GenericDAOHibernateImpl.java
License:Apache License
/** * {@inheritDoc}//from w ww .j av a 2 s .com */ @SuppressWarnings("unchecked") public ResultsIterator<Object> findQueryObjectByNamedQueryIterator(final String namedQueryName, final Object... parameters) { Query query = sessionFactory.getCurrentSession().getNamedQuery(namedQueryName); setQueryParameters(query, parameters); final ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY); return new ResultsIteratorImpl<Object>(results); }
From source file:org.yes.cart.dao.impl.GenericDAOHibernateImpl.java
License:Apache License
/** * {@inheritDoc}//w ww. j a va 2 s .c om */ public ResultsIterator<T> findAllIterator() { final Criteria crit = sessionFactory.getCurrentSession().createCriteria(getPersistentClass()); final ScrollableResults results = crit.scroll(ScrollMode.FORWARD_ONLY); return new ResultsIteratorImpl<T>(results); }
From source file:org.yes.cart.dao.impl.GenericDAOHibernateImpl.java
License:Apache License
private Runnable createIndexingRunnable(final boolean async, final int batchSize, final IndexFilter<T> filter) { return new Runnable() { @Override// w w w .j a v a 2 s . co m public void run() { int index = 0; final Logger log = LOGFTQ; try { if (persistentClassIndexble) { currentIndexingCount.set(0); if (log.isInfoEnabled()) { log.info("Full reindex for {} class", persistentClass); } FullTextSession fullTextSession = Search.getFullTextSession( async ? sessionFactory.openSession() : sessionFactory.getCurrentSession()); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); if (filter == null) { // only purge global full reindex because this clears all entries fullTextSession.purgeAll(getPersistentClass()); } ScrollableResults results = fullTextSession.createCriteria(persistentClass) .setFetchSize(batchSize).scroll(ScrollMode.FORWARD_ONLY); try { while (results.next()) { final T entity = (T) HibernateHelper.unproxy(results.get(0)); if (filter != null && filter.skipIndexing(entity)) { continue; // skip this object } if (entityIndexingInterceptor != null) { if (IndexingOverride.APPLY_DEFAULT == entityIndexingInterceptor .onUpdate(entity)) { fullTextSession.index(entity); } } else { fullTextSession.index(entity); } index++; if (index % batchSize == 0) { fullTextSession.flushToIndexes(); //apply changes to indexes fullTextSession.clear(); //clear since the queue is processed if (log.isInfoEnabled()) { log.info("Indexed {} items of {} class", index, persistentClass); } } currentIndexingCount.compareAndSet(index - 1, index); } } finally { results.close(); } fullTextSession.flushToIndexes(); //apply changes to indexes fullTextSession.clear(); //clear since the queue is processed if (log.isInfoEnabled()) { log.info("Indexed {} items of {} class", index, persistentClass); } fullTextSession.getSearchFactory().optimize(getPersistentClass()); } } catch (Exception exp) { LOGFTQ.error("Error during indexing", exp); } finally { asyncRunningState.set(COMPLETED); if (async) { try { if (persistentClassIndexble) { sessionFactory.getCurrentSession().close(); } } catch (Exception exp) { } } if (log.isInfoEnabled()) { log.info("Full reindex for {} class ... COMPLETED", persistentClass); } } } }; }
From source file:org.zanata.dao.HTextFlowTargetStreamingDAO.java
License:Open Source License
/** * * @return scrollable result set of HTextFlowTarget which has all * fields(locale, textflow, document, document locale, project * iteration and project) eagerly fetched. *//*ww w. j a v a 2 s .co m*/ public ScrollableResults getAllTargetsWithAllFieldsEagerlyFetched() { Query query = getSession().createQuery("from HTextFlowTarget tft " + "join fetch tft.locale " + "join fetch tft.textFlow " + "join fetch tft.textFlow.document " + "join fetch tft.textFlow.document.locale " + "join fetch tft.textFlow.document.projectIteration " + "join fetch tft.textFlow.document.projectIteration.project"); query.setFetchSize(Integer.MIN_VALUE); return query.scroll(ScrollMode.FORWARD_ONLY); }
From source file:org.zanata.dao.HTextFlowTargetStreamingDAO.java
License:Open Source License
/** * * @return scrollable result set of HTextFlowTarget under a project, with * all of its fields(locale, textflow, document, document locale, * project iteration and project) eagerly fetched. *///from ww w . j a v a2s. co m public ScrollableResults getTargetsWithAllFieldsEagerlyFetchedForProject(HProject project) { Query query = getSession().createQuery("from HTextFlowTarget tft " + "join fetch tft.locale " + "join fetch tft.textFlow " + "join fetch tft.textFlow.document " + "join fetch tft.textFlow.document.locale " + "join fetch tft.textFlow.document.projectIteration " + "join fetch tft.textFlow.document.projectIteration.project p where p = :project"); return query.setFetchSize(Integer.MIN_VALUE).setParameter("project", project) .scroll(ScrollMode.FORWARD_ONLY); }