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

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ivu.elect.business.system.entity.AfterCacheResetEvent;
import de.ivu.elect.jee.entity.ExtendedDAO;


import static de.ivu.elect.business.system.boundary.CacheResetSession.reset;

/**
 *  on 04.12.2015.
 */
@RequestScoped
public class CacheResetExtended implements Serializable {

  private static final Logger LOG = LoggerFactory.getLogger(CacheResetExtended.class);

  private static final long serialVersionUID = 1L;

  @Inject
  transient ExtendedDAO extendedDAO;

  @Inject
  transient CacheResetSession cacheResetSession;

  @Inject
  transient AfterCacheResetEvent afterCacheResetEvent;

  @javax.persistence.PersistenceContext
  private javax.persistence.EntityManager entityManager;

  public void resetCache() {
    LOG.info("Setze EntityManager zurück");
    cacheResetSession.resetCache();
    LOG.info("Setze Extended EntityManager zurück");
    reset(extendedDAO.getEntityManager());
    LOG.info("Caches invalidiert");
    afterCacheResetEvent.sendEvent();
  }


}
