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

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

import javax.inject.Inject;

import de.ivu.elect.business.wertelisten.entity.Wertelisten;
import de.ivu.elect.jee.entity.ExtendedDAO;

@javax.enterprise.context.RequestScoped
public class WertelistenExtendedDAO extends AbstractWertelistenDAO 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: CountWahlAndWertelistenArtNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT COUNT(obj) FROM Wertelisten obj WHERE obj.wahl = ?1 AND obj.wertelistenArt IN(?2)<br>
* SQL: <br>
*/
@Override
public java.lang.Long findByCountWahlAndWertelistenArt( @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.Wahl wahl,  @javax.annotation.Nonnull java.util.Collection<de.ivu.elect.business.wertelisten.entity.WertelistenArt> wertelistenArt) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Wertelisten.findByCountWahlAndWertelistenArt" ,  wahl ,  wertelistenArt  );

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

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

      return (java.lang.Long) cache.lookup(key);
    }

    return super.findByCountWahlAndWertelistenArt( wahl ,  wertelistenArt  );
}
/**
* Name: WahlAndWertelistenArtNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT obj FROM Wertelisten obj WHERE obj.wahl = ?1 AND obj.wertelistenArt IN (?2)<br>
* SQL: <br>
*/
@Override
public java.util.List<Wertelisten> findByWahlAndWertelistenArt( @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.Wahl wahl,  @javax.annotation.Nonnull java.util.Collection<de.ivu.elect.business.wertelisten.entity.WertelistenArt> wertelistenArt) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Wertelisten.findByWahlAndWertelistenArt" ,  wahl ,  wertelistenArt  );

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

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

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

    return super.findByWahlAndWertelistenArt( wahl ,  wertelistenArt  );
}

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

    super.clear();
  }
}
