
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.StatistikLauf;

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

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "statistikLaufConversationSelect";

  @Inject
  protected transient StatistikLaufExtendedDAO entityDAO;

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

  public StatistikLaufConversationSelect() {
    super();
  }

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

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

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

    return attach(getEntityPK());
  }

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

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

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

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

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

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

    return attach(entity.getPk());
  }

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

    return entityDAO.findByPrimaryKey(pk);
  }

  public void clearEntity() {
    setEntityPK(null);

    conversationStore.close();
  }
}
