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

org.nuiton.topia.it.legacy.topiatest.GeneratedCompanyTopiaDao Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import org.nuiton.topia.it.legacy.AbstractTopiaItLegacyDao;
import org.nuiton.topia.it.legacy.TopiaItLegacyEntityEnum;
import org.nuiton.topia.persistence.TopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaException;
import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep;

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

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

    @Override
    public TopiaItLegacyEntityEnum getTopiaEntityEnum() {
        return TopiaItLegacyEntityEnum.Company;
    }

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

        {
            DepartmentTopiaDao dao = topiaDaoSupplier
                    .getDao(Department.class, DepartmentTopiaDao.class);
            List list = dao
                    .forProperties(Department.PROPERTY_COMPANY, entity)
                    .findAll();
            for (Department item : list) {

                // sletellier : Set null only if target is concerned by deletion
                if (entity.equals(item.getCompany())) {
                    item.setCompany(null);
                }
            
            }
        }

        super.delete(entity);
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forNameIn(Collection v) {
        TopiaQueryBuilderAddCriteriaOrRunQueryStep result = forIn(Company.PROPERTY_NAME, (Collection) v);
        return result;
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forNameEquals(String v) {
        TopiaQueryBuilderAddCriteriaOrRunQueryStep result = forEquals(Company.PROPERTY_NAME, v);
        return result;
    }

    @Deprecated
    public E findByName(String v) {
        return forNameEquals(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllByName(String v) {
        return forNameEquals(v).findAll();
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forSiretIn(Collection v) {
        TopiaQueryBuilderAddCriteriaOrRunQueryStep result = forIn(Company.PROPERTY_SIRET, (Collection) v);
        return result;
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forSiretEquals(int v) {
        TopiaQueryBuilderAddCriteriaOrRunQueryStep result = forEquals(Company.PROPERTY_SIRET, v);
        return result;
    }

    @Deprecated
    public E findBySiret(int v) {
        return forSiretEquals(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllBySiret(int v) {
        return forSiretEquals(v).findAll();
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forEmployeContains(Employe v) {
        return forContains(Company.PROPERTY_EMPLOYE, v);
    }

    @Deprecated
    public E findContainsEmploye(Employe v) {
        return forEmployeContains(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllContainsEmploye(Employe v) {
        return forEmployeContains(v).findAll();
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forDepartmentContains(Department v) {
        return forContains(Company.PROPERTY_DEPARTMENT, v);
    }

    @Deprecated
    public E findContainsDepartment(Department v) {
        return forDepartmentContains(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllContainsDepartment(Department v) {
        return forDepartmentContains(v).findAll();
    }

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

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

        {
            BillTopiaDao dao = topiaDaoSupplier
                    .getDao(Bill.class, BillTopiaDao.class);
            List findAllByProperties = dao.forProperties("company", entity).findAll();
            if (findAllByProperties != null) {
                tmp.addAll(findAllByProperties);
            }
        }
        if (entity.getDepartment() != null) {
              tmp.addAll(entity.getDepartment());
           }

        // 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;
    }

} //GeneratedCompanyTopiaDao