PkgAliasStore.java
/*
* Copyright © 2021-2026 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 org.ctan.site.domain.catalogue.Pkg;
import org.ctan.site.domain.catalogue.PkgAlias;
import org.hibernate.SessionFactory;
import io.dropwizard.hibernate.AbstractDAO;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Root;
/**
* The class <code>PkgAliasStore</code> contains the repository for package
* aliases.
*
* @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
*/
public class PkgAliasStore extends AbstractDAO<PkgAlias> {
/**
* This is the constructor for the <code>PkgAliasStore</code>.
*
* @param sessionFactory the session factory
*/
public PkgAliasStore(SessionFactory sessionFactory) {
super(sessionFactory);
}
/**
* The method <code>drop</code> deletes the given package from the database
* and the search index.
*
* @param pkg the package
*/
public void drop(Pkg pkg) {
currentSession().remove(pkg);
}
/**
* The method <code>getByKey</code> provides means to retrieve a package by
* its key.
*
* @param id the id
* @return the package or {@code null}
*/
public PkgAlias getByKey(String id) {
var query = criteriaQuery();
CriteriaBuilder cb = currentSession().getCriteriaBuilder();
Root<PkgAlias> p = query.from(PkgAlias.class);
query.where(cb.equal(p.get("key"), id));
return uniqueResult(query);
}
/**
* The method <code>insert</code> provides means to save a package.
*
* @param alias the package
* @return the package
*/
public PkgAlias save(PkgAlias alias) {
return persist(alias);
}
}