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

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

The newest version!
package org.nuiton.topia.it.mapping.test3;

/*-
 * #%L
 * ToPIA :: IT
 * %%
 * Copyright (C) 2004 - 2024 Code Lutin
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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;

public abstract class GeneratedA32TopiaDao extends AbstractTopiaItMappingTopiaDao {

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

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

    @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();

        {
            String sql = "SELECT main.topiaId " +
                    " FROM b32 main, a32_b32 secondary " +
                    " WHERE main.topiaId=secondary.b32 " +
                    " AND secondary.a32='" + entity.getTopiaId() + "'";
            List listIds = hibernateSupport.getHibernateSession()
                    .createNativeQuery(sql, String.class)
                    .list();

            TopiaDao dao = topiaDaoSupplier.getDao(org.nuiton.topia.it.mapping.test3.B32.class);
            List list = dao.forTopiaIdIn(listIds).findAll();

            for (B32 item : list) {
                item.removeA32(entity);
            }
        }

        super.delete(entity);
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forB32Contains(B32 v) {
        return forContains(A32.PROPERTY_B32, v);
    }

    @Deprecated
    public E findContainsB32(B32 v) {
        return forB32Contains(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllContainsB32(B32 v) {
        return forB32Contains(v).findAll();
    }

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

        if (type == B32.class) {
            B32TopiaDao dao =
                topiaDaoSupplier.getDao(B32.class, B32TopiaDao.class);
            tmp = dao.forA32Contains(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(B32.class, entity);
        if (!list.isEmpty()) {
            result.put(B32.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;
    }

} //GeneratedA32TopiaDao