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

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

import javax.inject.Inject;

import de.ivu.elect.business.wahl.entity.Wahltermin;
import de.ivu.elect.jee.entity.ExtendedDAO;

@javax.enterprise.context.RequestScoped
public class WahlterminExtendedDAO extends AbstractWahlterminDAO 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 Wahltermin o WHERE o.mandant=?1<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahltermin> findByAll( @javax.annotation.Nonnull de.ivu.elect.business.mandant.entity.Mandant mandant) {

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

      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( mandant  ));
      } 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<Wahltermin>) cache.lookup(key));
    }

    return super.findByAll( mandant  );
}
/**
* Name: AllSystemweitNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahltermin o<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahltermin> findByAllSystemweit() {

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

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

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

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

    return super.findByAllSystemweit( );
}
/**
* Name: NameNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahltermin o WHERE o.mandant=?1 AND o.name = ?2<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahltermin> findByName( @javax.annotation.Nonnull de.ivu.elect.business.mandant.entity.Mandant mandant,  @javax.annotation.Nonnull String name) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Wahltermin.findByName" ,  mandant ,  name  );

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

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

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

    return super.findByName( mandant ,  name  );
}
/**
* Name: StatusNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahltermin o WHERE o.mandant=?1 AND o.status = ?2<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahltermin> findByStatus( @javax.annotation.Nonnull de.ivu.elect.business.mandant.entity.Mandant mandant,  @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.WahlterminStatus status) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Wahltermin.findByStatus" ,  mandant ,  status  );

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

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

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

    return super.findByStatus( mandant ,  status  );
}
/**
* Name: WahldatumAndNummerNoFlush<br>
* Beschreibung: Nummer wegen ELECTMUC-2011<br>
* EJBQL: SELECT o FROM Wahltermin o WHERE o.mandant=?1 AND o.wahldatum = ?2 AND o.nummer = ?3<br>
* SQL: <br>
*/
@Override
public Wahltermin findByWahldatumAndNummer( @javax.annotation.Nonnull de.ivu.elect.business.mandant.entity.Mandant mandant,  @javax.annotation.Nonnull java.util.Date wahldatum,  @javax.annotation.Nonnull java.lang.String 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("Wahltermin.findByWahldatumAndNummer" ,  mandant ,  wahldatum ,  nummer  );

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

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

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

    return super.findByWahldatumAndNummer( mandant ,  wahldatum ,  nummer  );
}

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

    super.clear();
  }
}
