All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.topia.it.mapping.test3.GeneratedA33TopiaDao Maven / Gradle / Ivy

There is a newer version: 4.0
Show newest version
package org.nuiton.topia.it.mapping.test3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import org.hibernate.Session;
import org.nuiton.topia.it.mapping.AbstractTopiaItMappingTopiaDao;
import org.nuiton.topia.it.mapping.TopiaItMappingEntityEnum;
import org.nuiton.topia.persistence.TopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaException;
import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep;
import org.nuiton.topia.persistence.internal.support.HibernateTopiaJpaSupport;
import org.nuiton.topia.persistence.support.TopiaHibernateSupport;

@Generated(value = "org.nuiton.topia.templates.EntityDaoTransformer", date = "Thu Oct 13 17:59:14 CEST 2016")
public abstract class GeneratedA33TopiaDao extends AbstractTopiaItMappingTopiaDao {

    @Override
    public Class getEntityClass() {
        return (Class) A33.class;
    }

    @Override
    public TopiaItMappingEntityEnum getTopiaEntityEnum() {
        return TopiaItMappingEntityEnum.A33;
    }

    @Override
    public void delete(E entity) {
        if ( ! entity.isPersisted()) {
            throw new IllegalArgumentException("entity " + entity  + " is not persisted, you can't delete it");
        }

        TopiaHibernateSupport hibernateSupport = ((HibernateTopiaJpaSupport) topiaJpaSupport).getHibernateSupport();
        Session hibernateSession = hibernateSupport.getHibernateSession();

        {
            String sql = "SELECT main.* " +
                    " FROM b33 main, rolea33_roleb33 secondary " +
                    " WHERE main.topiaId=secondary.roleB33 " +
                    " AND secondary.roleA33='" + entity.getTopiaId() + "'";
            List list = hibernateSession
                    .createSQLQuery(sql)
                    .addEntity("main", TopiaItMappingEntityEnum.B33.getImplementation())
                    .list();

            for (B33 item : list) {
                item.removeRoleA33(entity);
            }
        }

        super.delete(entity);
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forRoleB33Contains(B33 v) {
        return forContains(A33.PROPERTY_ROLE_B33, v);
    }

    @Deprecated
    public E findContainsRoleB33(B33 v) {
        return forRoleB33Contains(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllContainsRoleB33(B33 v) {
        return forRoleB33Contains(v).findAll();
    }

    @Override
    public  List findUsages(Class type, E entity) {
        List result = new LinkedList();
        List tmp;

        if (type == B33.class) {
            B33TopiaDao dao =
                topiaDaoSupplier.getDao(B33.class, B33TopiaDao.class);
            tmp = dao.forRoleA33Contains(entity).findAll();
            result.addAll(tmp);
        }

        return (List) result;
    }

    @Override
    public Map, List> findAllUsages(E entity) {
        Map,List> result;
        result = new HashMap, List>(1);

        List list;

        list = findUsages(B33.class, entity);
        if (!list.isEmpty()) {
            result.put(B33.class, list);
        }

        return result;
    }

    @Override
    public List getAggregate(E entity) throws TopiaException {
        List tmp = new ArrayList();

        // pour tous les attributs rechecher les composites et les class d'asso
        // on les ajoute dans tmp

        // on refait un tour sur chaque entity de tmp pour recuperer leur
        // composite
        List result = new ArrayList();
        for (TopiaEntity e : tmp) {
            result.add(e);
            TopiaDao dao = (TopiaDao) topiaDaoSupplier.getDao(e.getClass());
            result.addAll(dao.getAggregate(e));
        }
        return result;
    }

    @Override
    public List getComposite(E entity) throws TopiaException {
        List tmp = new ArrayList();

        // pour tous les attributs rechecher les composites et les class d'asso
        // on les ajoute dans tmp

        // on refait un tour sur chaque entity de tmp pour recuperer leur
        // composite
        List result = new ArrayList();
        for (TopiaEntity e : tmp) {
            if (e != null) {
                result.add(e);
                TopiaDao dao = (TopiaDao) topiaDaoSupplier.getDao(e.getClass());
                result.addAll(dao.getComposite(e));
            }
        }
        return result;
    }

} //GeneratedA33TopiaDao