@Override public CacheQuery<E> timeout(long timeout, TimeUnit timeUnit) { hSearchQuery.getTimeoutManager().setTimeout(timeout, timeUnit); return this; }
@Override public boolean hasPartialResults() { return hSearchQuery.getTimeoutManager().hasPartialResults(); }
@Override public FullTextQueryImpl limitExecutionTimeTo(long timeout, TimeUnit timeUnit) { hSearchQuery.getTimeoutManager().setTimeout( timeout, timeUnit ); hSearchQuery.getTimeoutManager().limitFetchingOnTimeout(); return this; }
@Override public FullTextQueryImpl setTimeout(long timeout, TimeUnit timeUnit) { super.setTimeout( (int) timeUnit.toSeconds( timeout ) ); hSearchQuery.getTimeoutManager().setTimeout( timeout, timeUnit ); hSearchQuery.getTimeoutManager().raiseExceptionOnTimeout(); return this; }
@Override public CacheQuery<E> timeout(long timeout, TimeUnit timeUnit) { queryDefinition.getHsQuery().getTimeoutManager().setTimeout(timeout, timeUnit); return this; } }
/** * 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; }
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; }
@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() ); }
@Override public List<E> list() throws SearchException { hSearchQuery.getTimeoutManager().start(); final List<EntityInfo> entityInfos = hSearchQuery.queryEntityInfos(); return (List<E>) getResultLoader().load(entityInfos); }
private Loader getProjectionLoader(ObjectLoaderBuilder loaderBuilder) { ProjectionLoader loader = new ProjectionLoader(); loader.init( session, hSearchQuery.getExtendedSearchIntegrator(), resultTransformer, loaderBuilder, hSearchQuery.getProjectedFields(), hSearchQuery.getTimeoutManager(), hSearchQuery.hasThisProjection() ); return loader; }
@Override public List<E> list() throws SearchException { partitionHandlingSupport.checkCacheAvailable(); HSQuery hSearchQuery = queryDefinition.getHsQuery(); hSearchQuery.getTimeoutManager().start(); List<EntityInfo> entityInfos = hSearchQuery.queryEntityInfos(); return (List<E>) getResultLoader(hSearchQuery).load(entityInfos); }
@Override public ResultIterator<E> iterator(FetchOptions fetchOptions) throws SearchException { if (fetchOptions.getFetchMode() == FetchOptions.FetchMode.EAGER) { hSearchQuery.getTimeoutManager().start(); List<EntityInfo> entityInfos = hSearchQuery.queryEntityInfos(); return filterNulls(new EagerIterator<>(entityInfos, getResultLoader(), fetchOptions.getFetchSize())); } else if (fetchOptions.getFetchMode() == FetchOptions.FetchMode.LAZY) { DocumentExtractor extractor = hSearchQuery.queryDocumentExtractor(); //triggers actual Lucene search return filterNulls(new LazyIterator<>(extractor, getResultLoader(), fetchOptions.getFetchSize())); } else { throw new IllegalArgumentException("Unknown FetchMode " + fetchOptions.getFetchMode()); } }
@Override public ResultIterator<E> iterator(FetchOptions fetchOptions) throws SearchException { partitionHandlingSupport.checkCacheAvailable(); HSQuery hSearchQuery = queryDefinition.getHsQuery(); if (fetchOptions.getFetchMode() == FetchOptions.FetchMode.EAGER) { hSearchQuery.getTimeoutManager().start(); List<EntityInfo> entityInfos = hSearchQuery.queryEntityInfos(); return filterNulls(new EagerIterator<>(entityInfos, getResultLoader(hSearchQuery), fetchOptions.getFetchSize())); } else if (fetchOptions.getFetchMode() == FetchOptions.FetchMode.LAZY) { DocumentExtractor extractor = hSearchQuery.queryDocumentExtractor(); //triggers actual Lucene search return filterNulls(new LazyIterator<>(extractor, getResultLoader(hSearchQuery), fetchOptions.getFetchSize())); } else { throw new IllegalArgumentException("Unknown FetchMode " + fetchOptions.getFetchMode()); } }
/** * Decide which object loader to use depending on the targeted entities. If there is only a single entity targeted * a <code>QueryLoader</code> can be used which will only execute a single query to load the entities. If more than * one entity is targeted a <code>MultiClassesQueryLoader</code> must be used. We also have to consider whether * projections or <code>Criteria</code> are used. * * @return The loader instance to use to load the results of the query. */ private Loader getLoader() { ObjectLoaderBuilder loaderBuilder = new ObjectLoaderBuilder() .criteria( criteria ) .targetedEntities( hSearchQuery.getTargetedEntities() ) .indexedTargetedEntities( hSearchQuery.getIndexedTargetedEntities().toPojosSet() ) .session( session ) .searchFactory( hSearchQuery.getExtendedSearchIntegrator() ) .timeoutManager( hSearchQuery.getTimeoutManager() ) .lookupMethod( objectLookupMethod ) .retrievalMethod( databaseRetrievalMethod ); if ( hSearchQuery.getProjectedFields() != null ) { return getProjectionLoader( loaderBuilder ); } else { return loaderBuilder.buildLoader(); } }