InstallDataStore.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */
package org.ctan.site.stores;

import java.util.List;

import org.ctan.site.domain.catalogue.InstallData;
import org.hibernate.SessionFactory;

import io.dropwizard.hibernate.AbstractDAO;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Root;

/**
 * The class <code>InstallDataStore</code> contains the repository for install
 * data. The underlying table is filled from an external program. Thus the site
 * will only read the data.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
public class InstallDataStore extends AbstractDAO<InstallData> {

    /**
     * This is the constructor for the <code>InstallDataStore</code>.
     *
     * @param sessionFactory the session factory
     */
    public InstallDataStore(SessionFactory sessionFactory) {

        super(sessionFactory);
    }

    /**
     * The method <code>findAllByPkg</code> provides means to find all install
     * entries for a pkg.
     *
     * @param pkg the package key
     * @return the list of entries in ascending order
     */
    public List<InstallData> findAllByPkg(String pkg) {

        var query = criteriaQuery();
        CriteriaBuilder cb = currentSession().getCriteriaBuilder();
        Root<InstallData> data = query.from(InstallData.class);
        query.where(cb.equal(data.get("pkg"), pkg))
            .orderBy(cb.asc(data.get("installationDate")));
        return list(query);
    }
}