/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cosmodas.EntCosmos;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * @author obper
 */
@Entity
@Table(name = "tablas")
@XmlRootElement
@NamedQueries({
        @NamedQuery(name = "Tablas.findAll", query = "SELECT t FROM Tablas t"),
        @NamedQuery(name = "Tablas.findByTablaCodigo", query = "SELECT t FROM Tablas t WHERE t.tablaCodigo = :tablaCodigo"),
        @NamedQuery(name = "Tablas.findByTablaNombre", query = "SELECT t FROM Tablas t WHERE t.tablaNombre = :tablaNombre")})
public class Tablas implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 2)
    @Column(name = "tabla_codigo")
    private String tablaCodigo;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "tabla_nombre")
    private String tablaNombre;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "tablaCodigo")
    private Collection<Documentos> documentosCollection;

    public Tablas() {
    }

    public Tablas(String tablaCodigo) {
        this.tablaCodigo = tablaCodigo;
    }

    public Tablas(String tablaCodigo, String tablaNombre) {
        this.tablaCodigo = tablaCodigo;
        this.tablaNombre = tablaNombre;
    }

    public String getTablaCodigo() {
        return tablaCodigo;
    }

    public void setTablaCodigo(String tablaCodigo) {
        this.tablaCodigo = tablaCodigo;
    }

    public String getTablaNombre() {
        return tablaNombre;
    }

    public void setTablaNombre(String tablaNombre) {
        this.tablaNombre = tablaNombre;
    }

    @XmlTransient
    public Collection<Documentos> getDocumentosCollection() {
        return documentosCollection;
    }

    public void setDocumentosCollection(Collection<Documentos> documentosCollection) {
        this.documentosCollection = documentosCollection;
    }

//    @Override
//    public int hashCode() {
//        int hash = 0;
//        hash += (tablaCodigo != null ? tablaCodigo.hashCode() : 0);
//        return hash;
//    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Tablas)) {
            return false;
        }
        Tablas other = (Tablas) object;
        if ((this.tablaCodigo == null && other.tablaCodigo != null) || (this.tablaCodigo != null && !this.tablaCodigo.equals(other.tablaCodigo))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "dbcon.Tablas[ tablaCodigo=" + tablaCodigo + " ]";
    }

}
