use Duration for query timeout

This commit is contained in:
Athou
2024-08-15 09:05:56 +02:00
parent c18ed829aa
commit 47d39831d3
2 changed files with 5 additions and 4 deletions

View File

@@ -131,7 +131,7 @@ public interface CommaFeedConfiguration {
* 0 to disable. * 0 to disable.
*/ */
@WithDefault("0") @WithDefault("0")
int queryTimeout(); Duration queryTimeout();
Cleanup cleanup(); Cleanup cleanup();

View File

@@ -1,5 +1,6 @@
package com.commafeed.backend.dao; package com.commafeed.backend.dao;
import java.time.Duration;
import java.util.Collection; import java.util.Collection;
import org.hibernate.Session; import org.hibernate.Session;
@@ -57,9 +58,9 @@ public abstract class GenericDAO<T extends AbstractModel> {
return objects.size(); return objects.size();
} }
protected void setTimeout(JPAQuery<?> query, int timeoutMs) { protected void setTimeout(JPAQuery<?> query, Duration timeout) {
if (timeoutMs > 0) { if (!timeout.isZero()) {
query.setHint(SpecHints.HINT_SPEC_QUERY_TIMEOUT, timeoutMs); query.setHint(SpecHints.HINT_SPEC_QUERY_TIMEOUT, timeout.toMillis());
} }
} }