All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fi.foyt.fni.persistence.dao.materials.CharacterSheetRollLabelDAO Maven / Gradle / Ivy

There is a newer version: 3.3.13
Show newest version
package fi.foyt.fni.persistence.dao.materials;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import fi.foyt.fni.persistence.dao.GenericDAO;
import fi.foyt.fni.persistence.model.materials.CharacterSheet;
import fi.foyt.fni.persistence.model.materials.CharacterSheetRollLabel;
import fi.foyt.fni.persistence.model.materials.CharacterSheetRollLabel_;

public class CharacterSheetRollLabelDAO extends GenericDAO {

	private static final long serialVersionUID = 1L;

	public CharacterSheetRollLabel create(CharacterSheet sheet, String label) {
    CharacterSheetRollLabel characterSheetData = new CharacterSheetRollLabel();

    characterSheetData.setLabel(label);
    characterSheetData.setSheet(sheet);

    return persist(characterSheetData);
  }
  
  public CharacterSheetRollLabel findBySheetAndLabel(CharacterSheet sheet, String label) {
    EntityManager entityManager = getEntityManager();

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery criteria = criteriaBuilder.createQuery(CharacterSheetRollLabel.class);
    Root root = criteria.from(CharacterSheetRollLabel.class);
    criteria.select(root);
    criteria.where(
      criteriaBuilder.and(
        criteriaBuilder.equal(root.get(CharacterSheetRollLabel_.sheet), sheet),
        criteriaBuilder.equal(root.get(CharacterSheetRollLabel_.label), label)
      )
    );
    
    return getSingleResult(entityManager.createQuery(criteria));
  }
	
  public List listBySheet(CharacterSheet sheet) {
    EntityManager entityManager = getEntityManager();

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery criteria = criteriaBuilder.createQuery(CharacterSheetRollLabel.class);
    Root root = criteria.from(CharacterSheetRollLabel.class);
    criteria.select(root);
    criteria.where(
      criteriaBuilder.and(
        criteriaBuilder.equal(root.get(CharacterSheetRollLabel_.sheet), sheet)
      )
    );
    
    return entityManager.createQuery(criteria).getResultList();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy