package org.gmod.schema.mapped;

// Generated Aug 31, 2006 4:02:18 PM by Hibernate Tools 3.2.0.beta7

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.SequenceGenerator;
import javax.persistence.GeneratedValue;

import static javax.persistence.GenerationType.SEQUENCE; //Added explicit sequence generation behaviour 2.12.2015

/**
 * Phylotree generated by hbm2java
 */
@Entity
@Table(name = "phylotree", uniqueConstraints = {})
public class Phylotree implements java.io.Serializable {

    // Fields
	
	@SequenceGenerator(name = "generator", sequenceName = "phylotree_phylotree_id_seq",  allocationSize=1)
    @Id @GeneratedValue(strategy = SEQUENCE, generator = "generator")
    @Column(name = "phylotree_id", unique = true, nullable = false, insertable = true, updatable = true)
    private int phylotreeId;

    @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
    @JoinColumn(name = "type_id", unique = false, nullable = true, insertable = true, updatable = true)
    private CvTerm cvTerm;

    @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
    @JoinColumn(name = "dbxref_id", unique = false, nullable = false, insertable = true, updatable = true)
    private DbXRef dbXRef;

    @Column(name = "name", unique = false, nullable = true, insertable = true, updatable = true)
    private String name;

    @Column(name = "comment", unique = false, nullable = true, insertable = true, updatable = true)
    private String comment;

    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "phylotree")
    private Collection<Phylonode> phylonodes;

    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "phylotree")
    private Collection<PhylotreePub> phylotreePubs;


    // Constructors

    Phylotree() {
        // Deliberately empty default constructor
    }

    /** full constructor */
    public Phylotree(String name, CvTerm type, DbXRef dbXRef, String comment) {
        this.name = name;
        this.cvTerm = type;
        this.dbXRef = dbXRef;
        this.comment = comment;
    }


    // Property accessors

    public int getPhylotreeId() {
        return this.phylotreeId;
    }

    public CvTerm getType() {
        return this.cvTerm;
    }

    void setType(CvTerm type) {
        this.cvTerm = type;
    }

    public DbXRef getDbXRef() {
        return this.dbXRef;
    }

    void setDbXRef(DbXRef dbXRef) {
        this.dbXRef = dbXRef;
    }

    public String getName() {
        return this.name;
    }

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

    public String getComment() {
        return this.comment;
    }

    void setComment(String comment) {
        this.comment = comment;
    }

    public Collection<Phylonode> getPhylonodes() {
        return Collections.unmodifiableCollection(this.phylonodes);
    }

    public Collection<Pub> getPubs() {
        Collection<Pub> pubs = new HashSet<Pub>();
        for (PhylotreePub phylotreePub: this.phylotreePubs) {
            pubs.add(phylotreePub.getPub());
        }
        return Collections.unmodifiableCollection(pubs);
    }

    public void addPub(Pub pub) {
        this.phylotreePubs.add(new PhylotreePub(this, pub));
    }

}
