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.log.LogWriter;
import open.dolphin.queries.DolphinQuery;
import org.hibernate.lob.BlobImpl;

/**
 * 保険 MEMO:マッピング  d_health_insurance
 * HealthInsuranceModel generated by hbm2java
 */
public class HealthInsuranceModel extends InfoModel {

    private long id;//MEMO:Refrection
    private PatientModel patient;//MEMO:Refrection
    private Blob beanBlob;//MEMO:Refrection
    private byte[] beanBytes;//MEMO:Refrection

    /**
     *
     */
    public HealthInsuranceModel() {
    }

    /**
     * 検索 MEMO:何もしない
     * @param query
     * @return false
     */
    @Override
    public boolean search(DolphinQuery query) {
        return false;
    }

    /**
     * idのGetter
     * MEMO:Refrection
     * @return
     */
    public long getId() {
        return this.id;
    }

    /**
     * idのSetter
     * MEMO:Refrection
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * beanBytesのGetter
     * MEMO:Refrection
     * @return
     */
    public byte[] getBeanBytes() {
        return this.beanBytes;
    }

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

    /**
     * beanBlobのGetter
     * MEMO:Refrection
     * @return
     */
    public Blob getBeanBlob() {
        return this.beanBlob;
    }

    /**
     * beanBlobのSetter
     * MEMO:Refrection
     * @param beanBlob
     * @throws SQLException
     */
    public void setBeanBlob(Blob beanBlob) throws SQLException {
        if (beanBlob != null) {
            this.beanBlob = beanBlob;
            this.beanBytes = beanBlob.getBytes(1, (int) beanBlob.length());
        }
    }

    /**
     * xmlのGetter
     * @return xml
     */
    public String getXml() {
        if (beanBytes != null) {
            try {
                return new String(beanBytes, "UTF-8");
            } catch (UnsupportedEncodingException ex) {
                  LogWriter.error(getClass(), ex);
            }
        }
        return "";
    }

    /**
     * xmlのSetter
     * @param xml
     */
    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) {
                  LogWriter.error(getClass(), ex);
            }
        }
    }

    /**
     * patientのGetter
     * @return patient
     */
    public PatientModel getPatient() {
        return patient;
    }

    /**
     * patientのSetter
     * @param patient
     */
    public void setPatient(PatientModel patient) {
        this.patient = patient;
    }

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

    /**
     *
     * @param obj
     * @return true false
     */
    @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()));
    }
}
