package de.ivu.elect.business.person.control;

import javax.inject.Inject;

import de.ivu.elect.business.anschrift.boundary.AnschriftDAO;
import de.ivu.elect.business.anschrift.entity.Anschrift;
import de.ivu.elect.business.person.boundary.KontoverbindungDAO;
import de.ivu.elect.business.person.boundary.PersonendatenDAO;
import de.ivu.elect.business.person.entity.Personendaten;
import de.ivu.elect.jee.entity.SimpleDAO;

public class PersonendatenWildfly11HackPersist {

  @Inject
  private transient SimpleDAO simpleDAO;

  @Inject
  private transient AnschriftDAO anschriftDAO;

  @Inject
  private transient PersonendatenDAO personendatenDAO;

  @Inject
  private transient KontoverbindungDAO kontoverbindungDAO;

  /**
   * ELECT-8342 WFLY11-Hack wg. Foreign-Key-Constraint-Violation
   */
  public void persist(Personendaten entity) {
    persist(entity.getAnschrift());
    kontoverbindungDAO.persist(entity.getKontoverbindung());
    flush();

    personendatenDAO.persist(entity);
  }

  /**
   * ELECT-8342 WFLY11-Hack wg. Foreign-Key-Constraint-Violation
   */
  public void persist(Anschrift entity) {
    anschriftDAO.persist(entity);
  }

  /**
   * ELECT-8342 WFLY11-Hack wg. Foreign-Key-Constraint-Violation
   */
  public void flush() {
    // ELECT-8342 simpleDAO.getEntityManager().flush();
  }
}
