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

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.deltaspike.core.api.scope.ConversationGroup;

import de.ivu.elect.business.statistik.entity.StatistikKennzeichen;

@RequestScoped
@Named(StatistikKennzeichenConversationSelect.COMPONENT_NAME)
public class StatistikKennzeichenConversationSelect implements java.io.Serializable {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "statistikKennzeichenConversationSelect";

  @Inject
  protected transient StatistikKennzeichenExtendedDAO entityDAO;

  @Inject
  @ConversationGroup(StatistikKennzeichenConversationStore.class)
  protected transient StatistikKennzeichenConversationStore conversationStore;

  public StatistikKennzeichenConversationSelect() {
    super();
  }

  public boolean isSelected() {
    return getEntityPK() != null;
  }

  public StatistikKennzeichen getEntity() {
    return getEntityInternal();
  }

  private StatistikKennzeichen getEntityInternal() {
    if (getEntityPK() == null) {
      return null;
    }

    return attach(getEntityPK());
  }

  public void setEntity(StatistikKennzeichen entity) {
    setEntityAttached(attach(entity));
  }

  public void setEntity( de.ivu.elect.business.statistik.entity.StatistikKennzeichenPK  pk) {
    setEntityAttached(attach(pk));
  }

  protected void setEntityAttached(StatistikKennzeichen entity) {
    if(entity == null) {
      setEntityPK(null);
    } else {
      setEntityPK(entity.getPk());
    }
  }

  public
    de.ivu.elect.business.statistik.entity.StatistikKennzeichenPK
   getEntityPK() {
    return conversationStore.getEntityPK();
  }

  public void setEntityPK(
    de.ivu.elect.business.statistik.entity.StatistikKennzeichenPK
   entityPK) {
    conversationStore.setEntityPK(entityPK);
  }

  protected StatistikKennzeichen attach(StatistikKennzeichen entity) {
    if (entity == null){
      return null;
    }

    return attach(entity.getPk());
  }

  protected StatistikKennzeichen attach( de.ivu.elect.business.statistik.entity.StatistikKennzeichenPK  pk) {
    if (pk == null) {
      return null;
    }

    return entityDAO.findByPrimaryKey(pk);
  }

  public void clearEntity() {
    setEntityPK(null);

    conversationStore.close();
  }
}
