package com.mousetech.gourmetj.persistence.model; import java.io.Serializable; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.*; /** * The persistent class for the "recipe" database table. * Persisted by @see RecipeDAO */ @Entity @Table(name = "recipe") @NamedQueries({ @NamedQuery(name = "Recipe.findAll", query = "SELECT r FROM Recipe r"), @NamedQuery(name = "Recipe.findByTitle", query = "SELECT r FROM Recipe r WHERE r.title LIKE concat('%', :searchText,'%')") }) @NamedNativeQuery(name = "Recipe.findCusines", query = "SELECT DISTINCT cuisine from recipe" + " where cuisine is not null and cuisine <> ''" + " ORDER BY cuisine ASC") @NamedEntityGraph(name = "Recipe.findWorkingSet", attributeNodes = { @NamedAttributeNode(value = "categories"), @NamedAttributeNode(value = "ingredientHash", subgraph = "subgraph.shopcat"), @NamedAttributeNode(value = "ingredientHash", subgraph = "subgraph.pantry") }, subgraphs = { @NamedSubgraph(name = "subgraph.shopcat", attributeNodes = @NamedAttributeNode(value = "shopCat")), @NamedSubgraph(name = "subgraph.pantry", attributeNodes = @NamedAttributeNode(value = "pantry")) }) public class Recipe implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "cooktime") private Integer cooktime; @Column(name = "cuisine") private String cuisine; @Column(name = "deleted") private Integer deleted; @Column(name = "description") private String description; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "image") private byte[] image; // Actual Ingredient_hash field is VARCHAR(32) - UUID??? @OneToMany(fetch = FetchType.LAZY, mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true) private List ingredientHash = new ArrayList(); @Column(name = "instructions") private String instructions; @Column(name = "last_modified") private Integer lastModified; @Column(name = "link") private String link; @Column(name = "modifications") private String modifications; @Column(name = "preptime") private Integer preptime; @Column(name = "rating") private Integer rating; @Column(name = "recipe_hash") private String recipeHash; @Column(name = "servings") private Double servings; @Column(name = "source") private String source; @Column(name = "thumb") private byte[] thumb; @Column(name = "title") private String title; @Column(name = "yield_unit") private String yieldUnit; @Column(name = "yields") private Double yields; @OneToMany(fetch = FetchType.EAGER, mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true) private Set categories = new HashSet(); /** * @param categories the categories to set */ public void setCategories(Set categories) { this.categories = categories; } public Recipe() { } public Integer getCooktime() { return this.cooktime; } public void setCooktime(Integer cooktime) { this.cooktime = cooktime; } public String getCuisine() { return this.cuisine; } public void setCuisine(String cuisine) { this.cuisine = cuisine; } public Integer getDeleted() { return this.deleted; } public void setDeleted(Integer deleted) { this.deleted = deleted; } public String getDescription() { return this.description; } public void setDescription(String description) { this.description = description; } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public byte[] getImage() { return this.image; } public void setImage(byte[] image) { this.image = image; } public List getIngredientHash() { return this.ingredientHash; } public void setIngredientHash( List ingredientHash) { this.ingredientHash = ingredientHash; } public String getInstructions() { return this.instructions; } public void setInstructions(String instructions) { this.instructions = instructions; } public Integer getLastModified() { return this.lastModified; } public void setLastModified(Integer lastModified) { this.lastModified = lastModified; } public String getLink() { return this.link; } public void setLink(String link) { this.link = link; } public String getModifications() { return this.modifications; } public void setModifications(String modifications) { this.modifications = modifications; } public Integer getPreptime() { return this.preptime; } public void setPreptime(Integer preptime) { this.preptime = preptime; } public Integer getRating() { return this.rating; } public void setRating(Integer rating) { this.rating = rating; } public String getRecipeHash() { return this.recipeHash; } public void setRecipeHash(String recipeHash) { this.recipeHash = recipeHash; } public Double getServings() { return this.servings; } public void setServings(Double servings) { this.servings = servings; } public String getSource() { return this.source; } public void setSource(String source) { this.source = source; } public byte[] getThumb() { return this.thumb; } public void setThumb(byte[] thumb) { this.thumb = thumb; } public String getTitle() { return this.title; } public void setTitle(String title) { this.title = title; } public String getYieldUnit() { return this.yieldUnit; } public void String(String yieldUnit) { this.yieldUnit = yieldUnit; } public Double getYields() { return this.yields; } public void setYields(Double yields) { this.yields = yields; } @Override public String toString() { return "Recipe #" + this.getId() + " " + this.getTitle(); } public Set getCategories() { return this.categories; } }