package com.ibtp.kontor.library.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by TPEETZ on 23.01.2015.
 */
@NamedQueries({
        @NamedQuery(name="Author.findAll", query="SELECT a from AuthorEntity as a"),
        @NamedQuery(name="Author.findById", query="SELECT a from AuthorEntity as a WHERE a.id = :id"),
        @NamedQuery(name="Author.findByName", query="SELECT a from AuthorEntity as a WHERE a.name = :name")
})
@Entity
@Table(name="AUTHOR")
public class AuthorEntity {

    private Long id;

    private String name;

    private Collection<BookEntity> books = new ArrayList<BookEntity>();

    private Collection<ArticleEntity> articles = new ArrayList<ArticleEntity>();

    public AuthorEntity() {}

    public AuthorEntity(String name) {
        setName(name);
    }

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    public Long getId() { return id; }

    @SuppressWarnings("unused")
    private void setId(Long id) { this.id = id; }

    @Column
    public String getName() { return name; }

    void setName(String name) { this.name = name; }

    @OneToMany(mappedBy="author", cascade=CascadeType.REMOVE)
    public Collection<BookEntity> getBooks() {
        return books;
    }

    public void setBooks(Collection<BookEntity> books) {
        this.books = books;
    }

    @OneToMany(mappedBy="author", cascade=CascadeType.REMOVE)
    public Collection<ArticleEntity> getArticles() {
        return articles;
    }

    public void setArticles(Collection<ArticleEntity> articles) {
        this.articles = articles;
    }
}
