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

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

import javax.inject.Inject;

import de.ivu.elect.business.person.entity.Tag;
import de.ivu.elect.jee.entity.ExtendedDAO;

@javax.enterprise.context.RequestScoped
public class TagExtendedDAO extends AbstractTagDAO 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: MandantNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Tag o WHERE o.mandant = ?1<br>
* SQL: <br>
*/
@Override
public java.util.List<Tag> findByMandant( @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("Tag.findByMandant" ,  mandant  );

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

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

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

    return super.findByMandant( mandant  );
}
/**
* Name: NameNormalisiertMandantNoFlush<br>
* Beschreibung: <br>
* EJBQL: SELECT o FROM Tag o WHERE o.nameNormalisiert = ?1 AND o.mandant = ?2<br>
* SQL: <br>
*/
@Override
public Tag findByNameNormalisiertMandant( @javax.annotation.Nonnull String nameNormalisiert,  @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("Tag.findByNameNormalisiertMandant" ,  nameNormalisiert ,  mandant  );

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

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

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

    return super.findByNameNormalisiertMandant( nameNormalisiert ,  mandant  );
}

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

    super.clear();
  }
}
