package open.dolphin.infomodel;
// Generated 2010/06/30 10:57:59 by Hibernate Tools 3.2.1.GA

import java.io.UnsupportedEncodingException;
import java.sql.Blob;
import java.sql.SQLException;
import open.dolphin.queries.DolphinQuery;
import org.hibernate.lob.BlobImpl;

/**
 * HealthInsuranceModel generated by hbm2java
 */
public class HealthInsuranceModel extends InfoModel {

    private long id;
    private PatientModel patient;
    private Blob beanBlob;
    private byte[] beanBytes;

    public HealthInsuranceModel() {
    }

    @Override
    public boolean search(DolphinQuery query) {
        return false;
    }

    /**
     *
     * @return
     */
    public long getId() {
        return this.id;
    }
    
    public void setId(long id) {
        this.id = id;
    }

    public byte[] getBeanBytes() {
        return this.beanBytes;
    }

    /**
     *
     * @param beanBytes
     */
    public void setBeanBytes(byte[] beanBytes) {
        this.beanBytes = beanBytes;
        if (beanBytes == null) {
            this.beanBlob = null;
        }
        else {
            this.beanBlob = new BlobImpl(beanBytes);
        }
    }

    public Blob getBeanBlob() {
        return this.beanBlob;
    }
    
    public void setBeanBlob(Blob beanBlob) throws SQLException {
        if (beanBlob != null) {
            this.beanBlob = beanBlob;
            this.beanBytes = beanBlob.getBytes(1, (int)beanBlob.length());
        }
    }

    public String getXml() {
        if (beanBytes != null) {
            try {
                return new String(beanBytes, "UTF-8");
            } catch (UnsupportedEncodingException ex) {
            }
        }
        return "";
    }

    public void setXml(String xml) {
        if (xml != null) {
            try {
                beanBytes = xml.getBytes("UTF-8");
                if (beanBytes == null) {
                    beanBlob = null;
                }
                else {
                    beanBlob = new BlobImpl(beanBytes);
                }
            } catch (UnsupportedEncodingException ex) {
            }
        }
    }

    public PatientModel getPatient() {
        return patient;
    }

    public void setPatient(PatientModel patient) {
        this.patient = patient;
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + (int) (id ^ (id >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final HealthInsuranceModel other = (HealthInsuranceModel) obj;
        if (getId() != other.getId()) {
            return false;
        }
        if (getBeanBytes() != other.getBeanBytes()) {
            return false;
        }
        return true;
    }

    /**
     *
     * @return
     */
    public PVTHealthInsuranceModel toInfoModel() {
        return ((PVTHealthInsuranceModel) BeanUtils.xmlDecode(getBeanBytes()));
    }
}
