/*
 * JPA DAO Template
 *
 *
 * Takatuka - Template fuer JPA DAO (Extended = ExtendedPersistenceContext ConversationScope (Group = EntityExtendedDAO.class)
 *
 */

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

import javax.inject.Inject;

import de.ivu.elect.business.mandant.entity.Mandant;
import de.ivu.elect.jee.entity.ExtendedDAO;

@javax.enterprise.context.RequestScoped
public class MandantExtendedDAO extends AbstractMandantDAO implements java.io.Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  transient ExtendedDAO extendedDAO;

  @Inject
  transient de.ivu.elect.presentation.system.ExtendedDAORequestCache cache;

  @Override
  protected javax.persistence.EntityManager getEntityManager() {
    return extendedDAO.getEntityManager();
  }

  @Override
  public void flush() {
    extendedDAO.flush();
  }

  public void flushNewTransaction() {
    extendedDAO.flushNewTransaction();
  }

/**
* Name: AllNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Mandant o<br>
* SQL: <br>
*/
@Override
public java.util.List<Mandant> findByAll() {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Mandant.findByAll"  );

      if (!cache.contains(key)) {
        if (de.ivu.elect.business.system.control.LogQueries.LOG_QUERIES) {
          System.out.println("Query: " + getClass().getName() + ".findByAll(): Miss");
        }

        cache.put(key, super.findByAll( ));
      } else if (de.ivu.elect.business.system.control.LogQueries.LOG_QUERIES) {
        System.out.println("Query: " + getClass().getName() + ".findByAll(): Hit");
      }

      return new java.util.ArrayList<>((java.util.List<Mandant>) cache.lookup(key));
    }

    return super.findByAll( );
}
/**
* Name: NummerNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Mandant o WHERE o.nummer=?1<br>
* SQL: <br>
*/
@Override
public Mandant findByNummer( @javax.annotation.Nonnull Long nummer) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Mandant.findByNummer" ,  nummer  );

      if (!cache.contains(key)) {
        if (de.ivu.elect.business.system.control.LogQueries.LOG_QUERIES) {
          System.out.println("Query: " + getClass().getName() + ".findByNummer(): Miss");
        }

        cache.put(key, super.findByNummer( nummer  ));
      } else if (de.ivu.elect.business.system.control.LogQueries.LOG_QUERIES) {
        System.out.println("Query: " + getClass().getName() + ".findByNummer(): Hit");
      }

      return (Mandant) cache.lookup(key);
    }

    return super.findByNummer( nummer  );
}

  @Override
  public void clear() {
    cache.clear();

    super.clear();
  }
}
