br.mdarte.exemplo.academico.cd.EstudanteAbstract.java Source code

Java tutorial

Introduction

Here is the source code for br.mdarte.exemplo.academico.cd.EstudanteAbstract.java

Source

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by: HibernateEntity.vsl in andromda-hibernate-cartridge.
// 
package br.mdarte.exemplo.academico.cd;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.FlushMode;
import br.mdarte.exemplo.academico.cd.AbstractDAO;
import br.mdarte.exemplo.academico.cd.AbstractEntity;
import br.mdarte.exemplo.academico.cd.DAOException;
import br.mdarte.exemplo.academico.to.EstudanteTO;
import br.mdarte.exemplo.academico.to.EstudanteTOImpl;
import br.mdarte.exemplo.academico.to.EstudanteTOExample;
import br.ufrj.coppetec.to.AbstractTO;
import br.ufrj.coppetec.to.AbstractTOExample;
import br.mdarte.exemplo.academico.util.PaginationStrategy;
import br.mdarte.exemplo.academico.cd.TOUtil;

/**
 * 
 */
public abstract class EstudanteAbstract extends br.mdarte.exemplo.academico.cd.AbstractEntity
        implements java.io.Serializable, br.mdarte.exemplo.academico.cd.Estudante {
    private final String ENTITY_KEY = "br.mdarte.exemplo.academico.cd.EstudanteAbstract";

    public Boolean needUpdate(AbstractTO abstractTO) {
        Boolean need = false;
        need = abstractTO.isUpdated();
        if (need)
            return true;
        if (((EstudanteTO) abstractTO).getExemploTO() == null)
            return false;
        EstudanteTO to = (EstudanteTO) abstractTO;
        if ((to.getExemploTO() != null && to.getExemploTO().getCurso() != null
                && !to.getExemploTO().getCurso().isEmpty()))
            need = need || TOUtil.isEntityChanged((AbstractTO) to.getCurso(), (AbstractEntity) this.getCurso());
        return need;
    }

    public static EstudanteAbstract getEntityFromTO(br.mdarte.exemplo.academico.to.EstudanteTO to)
            throws Exception {
        AbstractDAO.currentSession().setFlushMode(FlushMode.NEVER);
        EstudanteAbstract entity = (EstudanteAbstract) AbstractEntity.getEntityInstanceFromTO(to,
                new java.util.HashMap());
        AbstractDAO.currentSession().setFlushMode(FlushMode.AUTO);
        return entity;

    }

    protected br.mdarte.exemplo.academico.cd.AbstractEntity getEntityFromTO(AbstractTO to, java.util.HashMap map)
            throws Exception {
        if (map == null)
            map = new java.util.HashMap();
        EstudanteImpl bean = new EstudanteImpl();
        return getEntityFromTO((br.mdarte.exemplo.academico.to.EstudanteTO) to, bean, map);
    }

    protected EstudanteAbstract getEntityFromTO(br.mdarte.exemplo.academico.to.EstudanteTO to, Estudante bean,
            java.util.HashMap map) throws Exception {
        if (to == null)
            return null;
        map.put(to.getClass().toString() + to.hashCode(), bean);

        if (to != null) {
            if (to.getId() == null) {
                bean.setMatricula(to.getMatricula());
                bean.setNome(to.getNome());
                bean.setId(to.getId());

                if (to.getCurso() == null)
                    bean.setCurso(null);
                else {
                    br.mdarte.exemplo.academico.cd.Curso cdTemp = bean.getCurso();
                    if (map.get(to.getCurso().getClass().toString() + to.getCurso().hashCode()) == null) {
                        cdTemp = (br.mdarte.exemplo.academico.cd.Curso) AbstractEntity.getEntityInstanceFromTO(
                                (br.mdarte.exemplo.academico.to.CursoTO) to.getCurso(), map);
                    } else {
                        cdTemp = (br.mdarte.exemplo.academico.cd.Curso) map
                                .get(to.getCurso().getClass().toString() + to.getCurso().hashCode());
                    }

                    if (TOUtil.isEntityChanged(to, (AbstractEntity) bean.getCurso()))
                        bean.setCurso(cdTemp);
                }

            } else {
                EstudanteDAOImpl dao = new EstudanteDAOImpl();
                if (bean.getId() == null)
                    bean = (EstudanteImpl) dao.select(to.getId()).iterator().next();
                map.put(to.getClass().toString() + to.hashCode(), bean);
                if (bean.getHibernate_version() != to.getHibernate_version()) {
                    throw new Exception("hibernate.version.is.different");
                }
                if (to.isUpdated()) {
                    bean.setMatricula(to.getMatricula());
                    bean.setNome(to.getNome());
                    bean.setId(to.getId());
                }

                if (to.getExemploTO() != null && to.getExemploTO().getCurso() != null
                        && !to.getExemploTO().getCurso().isEmpty()) {
                    if (to.getCurso() == null)
                        bean.setCurso(null);
                    else {
                        br.mdarte.exemplo.academico.cd.Curso cdTemp = bean.getCurso();
                        if (map.get(to.getCurso().getClass().toString() + to.getCurso().hashCode()) == null) {
                            cdTemp = (br.mdarte.exemplo.academico.cd.Curso) AbstractEntity.getEntityInstanceFromTO(
                                    (br.mdarte.exemplo.academico.to.CursoTO) to.getCurso(), map);
                        } else {
                            cdTemp = (br.mdarte.exemplo.academico.cd.Curso) map
                                    .get(to.getCurso().getClass().toString() + to.getCurso().hashCode());
                        }

                        if (TOUtil.isEntityChanged(to, (AbstractEntity) bean.getCurso()))
                            bean.setCurso(cdTemp);
                    }
                }

            }
            return (EstudanteAbstract) bean;
        }
        return null;
    }

    public EstudanteTOImpl buildTO(EstudanteTOExample exemploTO) throws Exception {
        return (EstudanteTOImpl) this.buildTO(exemploTO, new java.util.HashMap());
    }

    public AbstractTO buildTO(AbstractTOExample exemploTO, java.util.HashMap map) throws Exception {
        if (map == null)
            map = new java.util.HashMap();
        EstudanteTOImpl to = new EstudanteTOImpl();
        to.beginInitialization();
        mapEntityAttributes2TO(to);
        mapEntityRelations2TO(to, TOUtil.getExample(exemploTO, this.getTOExample()), map);
        to.finishInitialization();
        if (to.getId() == null)
            to.setExemploTO(null);
        return to;
    }

    protected void mapEntityAttributes2TO(EstudanteTO to) {
        to.setMatricula(this.getMatricula());
        to.setNome(this.getNome());
        to.setId(this.getId());

        to.setHibernate_version(this.getHibernate_version());

    }

    protected void mapEntityRelations2TO(EstudanteTO to, AbstractTOExample abstractExemploTO, java.util.HashMap map)
            throws Exception {
        map.put(this.getEntityKey() + this.hashCode(), to);
        EstudanteTOExample exemploTO = (EstudanteTOExample) abstractExemploTO;
        if (abstractExemploTO != null) {
            to.setExemploTO(exemploTO);
            if (exemploTO.getCurso() != null && !exemploTO.getCurso().isEmpty() && this.getCurso() != null) {
                if (map.get(
                        ((AbstractEntity) this.getCurso()).getEntityKey() + this.getCurso().hashCode()) == null) {
                    br.mdarte.exemplo.academico.to.CursoTO toTemp = (br.mdarte.exemplo.academico.to.CursoTO) this.curso
                            .buildTO(TOUtil.getExample(exemploTO.getCurso(), this.curso.getTOExample()), map);
                    to.setCurso(toTemp);
                } else {
                    to.setCurso((br.mdarte.exemplo.academico.to.CursoTO) map
                            .get(((AbstractEntity) this.getCurso()).getEntityKey() + this.getCurso().hashCode()));
                }
            }
        }
    }

    /**
     * The serial version UID of this class. Needed for serialization.
     */
    private static final long serialVersionUID = -6608100513793347408L;

    /**
     * Version property managed by Hibernate.
     */
    private int hibernate_version;

    public int getHibernate_version() {
        return this.hibernate_version;
    }

    private void setHibernate_version(int hibernate_version) {
        this.hibernate_version = hibernate_version;
    }

    public EstudanteAbstract() {
    }

    private java.lang.String matricula;

    /**
     * 
     */
    public java.lang.String getMatricula() {
        return this.matricula;
    }

    public void setMatricula(java.lang.String matricula) {
        this.matricula = matricula;
    }

    private java.lang.String nome;

    /**
     * 
     */
    public java.lang.String getNome() {
        return this.nome;
    }

    public void setNome(java.lang.String nome) {
        this.nome = nome;
    }

    private java.lang.Long id;

    /**
     * 
     */
    public java.lang.Long getId() {
        return this.id;
    }

    public void setId(java.lang.Long id) {
        this.id = id;
    }

    private br.mdarte.exemplo.academico.cd.CursoAbstract curso;

    /**
     * 
     */
    public br.mdarte.exemplo.academico.cd.Curso getCurso() {
        return curso;
    }

    public void setCurso(br.mdarte.exemplo.academico.cd.Curso curso) {
        this.curso = (br.mdarte.exemplo.academico.cd.CursoAbstract) curso;
    }

    public void setCursoInverse(br.mdarte.exemplo.academico.cd.Curso curso) {
        Hibernate.initialize(curso);
        br.mdarte.exemplo.academico.cd.Curso temp = this.curso;
        this.curso = (br.mdarte.exemplo.academico.cd.CursoAbstract) curso;

        if (temp != null) {
            if (temp.getEstudantes() != null)
                temp.getEstudantes().remove(this);
        }

        if (curso != null) {
            Hibernate.initialize(curso.getEstudantes());

            if (!curso.getEstudantes().contains(this))
                curso.getEstudantes().add(this);
        }

    }

    /**
     * Returns <code>true</code> if the argument is an Estudante instance and all identifiers for this entity
     * equal the identifiers of the argument entity. Returns <code>false</code> otherwise.
     */
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (!(object instanceof Estudante)) {
            return false;
        }
        final Estudante that = (Estudante) object;
        if (this.getId() == null || that.getId() == null || !this.getId().equals(that.getId())) {
            return false;
        }
        return true;
    }

    /**
     * Returns a hash code based on this entity's identifiers.
     */
    public int hashCode() {
        int hashCode = super.hashCode();
        hashCode = 29 * hashCode + (id == null ? 0 : id.hashCode());

        return hashCode;
    }

    /**
     * Constructs new instances of {@link br.mdarte.exemplo.academico.cd.Estudante}.
     */
    public static final class Factory {
        /**
         * Constructs a new instance of {@link br.mdarte.exemplo.academico.cd.Estudante}.
         */
        public static final br.mdarte.exemplo.academico.cd.Estudante newInstance() {
            return new br.mdarte.exemplo.academico.cd.EstudanteImpl();
        }
    }

    public br.mdarte.exemplo.academico.cd.AbstractDAO getDaoImpl() {
        return new EstudanteDAOImpl();
    }

    @Deprecated
    public java.util.Collection THIS() {
        java.util.Collection col = new java.util.ArrayList();
        col.add(this);
        return col;
    }

    public Estudante inicializa() {
        Hibernate.initialize(this);
        return this;
    }

    public br.ufrj.coppetec.Entity getInstance() {
        return new EstudanteImpl();
    }

    public boolean instanceOf(Class<?> otherClass) {
        return otherClass.isAssignableFrom(getEstudanteClass());
    }

    public Class<?> getEstudanteClass() {
        return EstudanteImpl.class;
    }

    public AbstractTOExample getTOExample() {
        return EstudanteTOExample.newInstance();
    }

    public String getEntityKey() {
        return ENTITY_KEY;
    }

}