Skip to content

Commit

Permalink
HSEARCH-3787 Pass timeout as hint query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Aug 18, 2020
1 parent 2f8eabe commit 8aa74d5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Expand Up @@ -53,10 +53,4 @@ default List<E> loadBlocking(List<EntityReference> references, Long timeout) {
void loadBlocking(List<EntityReference> references, Map<? super EntityReference, ? super E> entitiesByReference,
Long timeout);

static Integer getTimeoutInSeconds(Long timeout) {
long result = ( timeout / 1000 );
long longResult = ( timeout % 1000 == 0 ) ? result : result + 1;
return Math.toIntExact( longResult );
}

}
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jpa.QueryHints;
import org.hibernate.metamodel.spi.MetamodelImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.Query;
Expand Down Expand Up @@ -150,7 +151,7 @@ private Query<?> createQuery(int fetchSize, Long timeout) {

query.setFetchSize( fetchSize );
if ( timeout != null ) {
query.setTimeout( HibernateOrmComposableEntityLoader.getTimeoutInSeconds( timeout ) );
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, Math.toIntExact( timeout ) );
}

EntityGraphHint<?> entityGraphHint = loadingOptions.entityGraphHintOrNullForType( entityPersister );
Expand Down
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.AssertionFailure;
import org.hibernate.Hibernate;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jpa.QueryHints;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.Query;
import org.hibernate.search.mapper.orm.common.EntityReference;
Expand Down Expand Up @@ -122,7 +123,7 @@ private Query<? extends E> createQuery(int fetchSize, Long timeout) {

query.setFetchSize( fetchSize );
if ( timeout != null ) {
query.setTimeout( HibernateOrmComposableEntityLoader.getTimeoutInSeconds( timeout ) );
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, Math.toIntExact( timeout ) );
}

EntityGraphHint<?> entityGraphHint = loadingOptions.entityGraphHintOrNullForType( entityPersister );
Expand Down

0 comments on commit 8aa74d5

Please sign in to comment.