27 lines
1.2 KiB
Java

package dev.dinauer.metrics.service;
import java.util.List;
import java.util.Optional;
import jakarta.enterprise.context.ApplicationScoped;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import io.quarkus.panache.common.Parameters;
import dev.dinauer.metrics.service.model.Bucket;
import dev.dinauer.metrics.service.model.BucketUnit;
@ApplicationScoped
public class Repo implements PanacheRepositoryBase<Bucket, String>
{
public Optional<Bucket> 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<Bucket> findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to)
{
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit AND unixTimestamp >= :from AND unixTimestamp <= :to ORDER BY unixTimestamp DESC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit).and("from", from).and("to", to));
}
}