
package de.ivu.elect.business.geodata.boundary;

import javax.inject.Inject;

import de.ivu.elect.business.geodata.entity.GeodataOrt;

// abgeleitete Klasse mit "@javax.ejb.Stateless" annotieren!
public abstract class AbstractGeodataOrtEdit {

  @Inject
  protected GeodataOrtDAO dao;

  @Inject
  protected GeodataOrtExtendedDAO extendedDao;

  public void delete(GeodataOrt entity) {
    dao.remove(getAttachedEntity(entity));
  }

  public void save(GeodataOrt entity) {
    validate(entity);

    flushToSave();
  }

  protected void validate(GeodataOrt entity) {
    // Do nothing by default.
  }

  protected void flushToSave() {
    if(usesMixedTransactionalContexts()) {
        extendedDao.flushNewTransaction();
    } else {
        extendedDao.flush();
    }
  }

  // ELECT-945
  protected boolean usesMixedTransactionalContexts() {
    return false;
  }

  protected GeodataOrt getAttachedEntity(GeodataOrt entity) {
    return dao.findByPrimaryKey(entity.getPk());
  }

  // Cf. ELECT-3187 (Änderungen an Entität werden nicht gespeichert)
  protected GeodataOrt getAttachedAndRefreshedEntity(GeodataOrt entity) {
    return dao.refresh(entity);
  }
}
