package de.ivu.elect.business.system.entity;

import static java.util.Arrays.asList;

public class HibernateEntityStatistik {

  private final String name;

  public HibernateEntityStatistik(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public long getInsertCount() {
    return 0;
  }

  public long getUpdateCount() {
    return 0;
  }

  public long getDeleteCount() {
    return 0;
  }

  /**
   * "the fetch counter only gets incremented when the entity is retrieved from the datasource (as opposed to any
   * caches)"
   * <p/>
   * http://stackoverflow.com/questions/609351/in-hibernate-statistics-whats-the-difference-between-load-and-fetch
   */
  public long getFetchCount() {
    return 0;
  }

  /**
   * "The load counter gets incremented any time the entity gets loaded, whether from the datasource or the caches."
   * <p/>
   * http://stackoverflow.com/questions/609351/in-hibernate-statistics-whats-the-difference-between-load-and-fetch
   */
  public long getLoadCount() {
    return 0;
  }

  public long getOptimisticFailureCount() {
    return 0;
  }

  public boolean isWertVorhanden() {
    return getInsertCount() > 0 || getUpdateCount() > 0 || getDeleteCount() > 0 || getFetchCount() > 0 || getLoadCount() > 0 || getOptimisticFailureCount() > 0;
  }

  @Override
  public String toString() {
    return "|" + String.join("|", asList(getName(), Long.toString(getInsertCount()), Long.toString(getUpdateCount()), Long.toString(getDeleteCount()),
            Long.toString(getFetchCount()), Long.toString(getLoadCount()), Long.toString(getOptimisticFailureCount()))) + "|";
  }

  public static String toStringHeader() {
    return "||" + String.join("||",
            asList("Name", "Inserts", "Updates", "Deletes", "Fetches", "Loads", "Optimistic Failures")) + "||";
  }

}
