/** * Return an iterator on the results. * Retrieve the object one by one (initialize it during the next() operation) */ @Override public Iterator iterate() { //implement an iterator which keep the id/class for each hit and get the object on demand //cause I can't keep the searcher and hence the hit opened. I don't have any hook to know when the //user stops using it //scrollable is better in this area hSearchQuery.getTimeoutManager().start(); final List<EntityInfo> entityInfos = hSearchQuery.queryEntityInfos(); //stop timeout manager, the iterator pace is in the user's hands hSearchQuery.getTimeoutManager().stop(); //TODO is this no-loader optimization really needed? final Iterator<Object> iterator; if ( entityInfos.size() == 0 ) { iterator = new IteratorImpl( entityInfos, noLoader ); return iterator; } else { Loader loader = getLoader(); iterator = new IteratorImpl( entityInfos, loader ); } hSearchQuery.getTimeoutManager().stop(); return iterator; }
@Override public ScrollableResultsImpl scroll() { //keep the searcher open until the resultset is closed hSearchQuery.getTimeoutManager().start(); final DocumentExtractor documentExtractor = hSearchQuery.queryDocumentExtractor(); //stop timeout manager, the iterator pace is in the user's hands hSearchQuery.getTimeoutManager().stop(); Loader loader = getLoader(); return new ScrollableResultsImpl( fetchSize, documentExtractor, loader, this.session, hSearchQuery.hasThisProjection() ); }
protected List doHibernateSearchList() { hSearchQuery.getTimeoutManager().start(); final List<EntityInfo> entityInfos = hSearchQuery.queryEntityInfos(); Loader loader = getLoader(); List list = loader.load( entityInfos ); //no need to timeoutManager.isTimedOut from this point, we don't do anything intensive if ( resultTransformer == null || loader instanceof ProjectionLoader ) { //stay consistent with transformTuple which can only be executed during a projection //nothing to do } else { list = resultTransformer.transformList( list ); } hSearchQuery.getTimeoutManager().stop(); return list; }