2025-11-15 11:16:35 +01:00

30 lines
1.6 KiB
Java

package dev.dinauer.metrics.service;
import java.util.List;
import java.util.Optional;
import dev.dinauer.metrics.service.model.BucketUnit;
import dev.dinauer.metrics.service.model.Collection;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import io.quarkus.panache.common.Parameters;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class Repo implements PanacheRepositoryBase<Collection, String>
{
public Optional<Collection> findByProperties(String resource, String name, String timestamp, BucketUnit bucketUnit)
{
return find("resource = :resource AND name = :name AND timestamp = :timestamp AND bucketUnit = :bucketUnit", Parameters.with("resource", resource).and("name", name).and("timestamp", timestamp).and("bucketUnit", bucketUnit)).firstResultOptional();
}
public List<Collection> findByResourceAndMetricAndTimeUnit(String resource, String name, BucketUnit bucketUnit)
{
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit));
}
public List<Collection> findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to)
{
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit AND (unix >= :from AND unix <= :to) ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit).and("from", from).and("to", to));
}
}