/*
 * 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.Wahl;
import de.ivu.elect.jee.entity.ExtendedDAO;

@javax.enterprise.context.RequestScoped
public class WahlExtendedDAO extends AbstractWahlDAO 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 Wahl o WHERE o.wahltermin.mandant=?1<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahl> 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("Wahl.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<Wahl>) cache.lookup(key));
    }

    return super.findByAll( mandant  );
}
/**
* Name: BerichtetAnAndMandantNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahl o WHERE o.berichtetAn=?1 AND o.wahltermin.mandant = ?2<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahl> findByBerichtetAnAndMandant( @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.Wahl wahl,  @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("Wahl.findByBerichtetAnAndMandant" ,  wahl ,  mandant  );

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

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

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

    return super.findByBerichtetAnAndMandant( wahl ,  mandant  );
}
/**
* Name: BerichtetAnNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahl o WHERE o.berichtetAn=?1<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahl> findByBerichtetAn( @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("Wahl.findByBerichtetAn" ,  wahl  );

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

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

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

    return super.findByBerichtetAn( wahl  );
}
/**
* Name: CountWahlartNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT COUNT(o) FROM Wahl o WHERE o.wahlart=?1<br>
* SQL: <br>
*/
@Override
public java.lang.Long findByCountWahlart( @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.Wahlart wahlart) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Wahl.findByCountWahlart" ,  wahlart  );

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

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

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

    return super.findByCountWahlart( wahlart  );
}
/**
* Name: StatusNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT w FROM Wahl w WHERE w.wahltermin.mandant=?1 AND w.status = ?2<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahl> findByStatus( @javax.annotation.Nonnull de.ivu.elect.business.mandant.entity.Mandant mandant,  @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.WahlStatus 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("Wahl.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<Wahl>) cache.lookup(key));
    }

    return super.findByStatus( mandant ,  status  );
}
/**
* Name: UnterstuetzerErfassbarNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahl o WHERE o.wahltermin.mandant=?1 AND o.unterstuetzerErfassbar = TRUE<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahl> findByUnterstuetzerErfassbar( @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("Wahl.findByUnterstuetzerErfassbar" ,  mandant  );

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

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

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

    return super.findByUnterstuetzerErfassbar( mandant  );
}
/**
* Name: WahlterminNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahl o WHERE o.wahltermin=?1<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahl> findByWahltermin( @javax.annotation.Nonnull de.ivu.elect.business.wahl.entity.Wahltermin wahltermin) {

    if (de.ivu.elect.business.system.control.CacheQueries.CACHE_QUERIES) {
      de.ivu.elect.presentation.system.FinderKey key = new de.ivu.elect.presentation.system.FinderKey("Wahl.findByWahltermin" ,  wahltermin  );

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

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

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

    return super.findByWahltermin( wahltermin  );
}

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

    super.clear();
  }
}
