32 lines
1.5 KiB
Java
32 lines
1.5 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> 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<Bucket> 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));
|
|
}
|
|
}
|