package com.peetz.library.entity;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@NamedQueries({
	@NamedQuery(name="Bookshelf.findAll", query="SELECT b from BookshelfEntity as b"),
	@NamedQuery(name="Bookshelf.findById", query="SELECT b from BookshelfEntity as b WHERE b.id = :id"),
	@NamedQuery(name="Bookshelf.findByTitle", query="SELECT b from BookshelfEntity as b WHERE b.title = :title")
})

@Entity
@Table(name="BOOKSHELF")
public class BookshelfEntity {

	private Long id;
	
	private String title;
	
	private Collection<ShelfboardEntity> shelfBoards = new ArrayList<ShelfboardEntity>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() { return id; }
	
	@SuppressWarnings("unused")
	private void setId(Long id) { this.id = id; }

	@Column
	public String getTitle() { return title; }

	public void setTitle(String title) { this.title = title; }

	@OneToMany(mappedBy="bookshelf", cascade=CascadeType.REMOVE)
	public Collection<ShelfboardEntity> getShelfBoards() {
		return shelfBoards;
	}

	public void setShelfBoards(Collection<ShelfboardEntity> shelfBoards) {
		this.shelfBoards = shelfBoards;
	}
}
