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

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

import javax.inject.Inject;

import de.ivu.elect.business.wahlvorschlag.entity.ReferendumOption;
import de.ivu.elect.jee.entity.ExtendedDAO;

@javax.enterprise.context.RequestScoped
public class ReferendumOptionExtendedDAO extends AbstractReferendumOptionDAO 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: ReferendumVorlageImGebietAndPositionNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT obj FROM ReferendumOption obj WHERE obj.gruppeImGebiet = ?1 AND obj.position = ?2<br>
* SQL: <br>
*/
@Override
public java.util.List<ReferendumOption> findByReferendumVorlageImGebietAndPosition( @javax.annotation.Nonnull de.ivu.elect.business.gruppeimgebiet.entity.GruppeImGebiet referendumVorlageImGebiet,  @javax.annotation.Nonnull java.lang.Long position) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("ReferendumOption.findByReferendumVorlageImGebietAndPosition" ,  referendumVorlageImGebiet ,  position  );

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

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

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

    return super.findByReferendumVorlageImGebietAndPosition( referendumVorlageImGebiet ,  position  );
}
/**
* Name: WahlNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM ReferendumOption o WHERE o.gruppeImGebiet.gruppe.wahl = ?1<br>
* SQL: <br>
*/
@Override
public java.util.List<ReferendumOption> findByWahl( @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.Wahl wahl) {

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

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

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

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

    return super.findByWahl( wahl  );
}

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

    super.clear();
  }
}
