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

@javax.enterprise.context.RequestScoped
public class WahlartExtendedDAO extends AbstractWahlartDAO 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: AllOrderByNameNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahlart o WHERE o.mandant=?1 ORDER BY o.name<br>
* SQL: <br>
*/
@Override
public java.util.List<Wahlart> findByAllOrderByName( @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("Wahlart.findByAllOrderByName" ,  mandant  );

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

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

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

    return super.findByAllOrderByName( mandant  );
}
/**
* Name: NameNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Wahlart o WHERE o.mandant=?1 AND o.name=?2<br>
* SQL: <br>
*/
@Override
public Wahlart 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("Wahlart.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 (Wahlart) cache.lookup(key);
    }

    return super.findByName( mandant ,  name  );
}

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

    super.clear();
  }
}
