HSAdmin Backend Domains, E-Mail, Datenbanken
Michael Hierweck
2017-09-20 1968b61fa9e1d1139b6af4c7e0dd15f9564638c9
Use module implementation to remove entities.
2 files modified
31 ■■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java 23 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java 8 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -12,6 +12,7 @@
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.GenericModuleImpl;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.hostsharing.BasePacType;
import de.hsadmin.mods.email.EMailAddress;
@@ -247,16 +248,24 @@
    @Override
    public void delete(AbstractEntity existingEntity) throws HSAdminException {
        EntityManager em = getTransaction().getEntityManager();
        needsWriteAccessOn(existingEntity, "delete");
        Domain dom = (Domain) existingEntity;
        EntityManager em = getTransaction().getEntityManager();
        Query query = em.createQuery("SELECT adr FROM " + EMailAddress.class.getAnnotation(javax.persistence.Entity.class).name()
                + " adr WHERE adr.domain.name='" + dom.getName() + "'");
        List<?> resultList = query.getResultList();
        for (Object obj : resultList) {
            EMailAddress eMailAddress = (EMailAddress) obj;
            em.remove(eMailAddress);
        GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
        String[] dependQueries = new String[] { "SELECT adr FROM EMailAdresses adr WHERE domain = :dom", };
        for (String queryString : dependQueries) {
            Query qEntities = em.createQuery(queryString);
            qEntities.setParameter("dom", dom.getName());
            List<?> entitiesList = qEntities.getResultList();
            for (Object o : entitiesList) {
                if (o instanceof AbstractEntity) {
                    helperModule.delete((AbstractEntity) o);
                }
            }
        }
        super.delete(existingEntity);
    }
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
@@ -214,10 +214,10 @@
            };
            for (String queryString : dependQueries) {
                Query qDoms = em.createQuery(queryString);
                qDoms.setParameter("pac", pacName);
                List<?> domsList = qDoms.getResultList();
                for (Object o : domsList) {
                Query qEntities = em.createQuery(queryString);
                qEntities.setParameter("pac", pacName);
                List<?> entitiesList = qEntities.getResultList();
                for (Object o : entitiesList) {
                    if (o instanceof AbstractEntity) {
                        helperModule.delete((AbstractEntity) o);
                    }