/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package io.oasp.module.jpa.dataaccess.api;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import net.sf.mmm.util.entity.api.PersistenceEntity;

import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
import org.hibernate.envers.RevisionTimestamp;

/**
 * This is a custom {@link org.hibernate.envers.DefaultRevisionEntity revision entity} also containing the actual user.
 *
 * @see org.hibernate.envers.DefaultRevisionEntity If you are starting the development of your application from scratch
 *      , please use this class or else if you have an application developed and needs backward compatibility , please
 *      use the deprecated class {@link io.oasp.module.jpa.dataaccess.base.AdvancedRevisionEntity}
 */
@Entity
@RevisionEntity(AdvancedRevisionListener.class)
@Table(name = "RevInfo")
public class AdvancedRevisionEntity implements PersistenceEntity<Long> {

  /** UID for serialization. */
  private static final long serialVersionUID = 1L;

  /** @see #getId() */
  @Id
  @GeneratedValue
  @RevisionNumber
  private Long id;

  /** @see #getTimestamp() */
  @RevisionTimestamp
  private long timestamp;

  /** @see #getDate() */
  private transient Date date;

  /** @see #getUserLogin() */

  private String userLogin;

  /**
   * The constructor.
   */
  public AdvancedRevisionEntity() {

    super();
  }

  @Override
  public Long getId() {

    return this.id;
  }

  /**
   * @param id is the new value of {@link #getId()}.
   */
  public void setId(Long id) {

    this.id = id;
  }

  /**
   * @return the timestamp when this revision has been created.
   */
  public long getTimestamp() {

    return this.timestamp;
  }

  /**
   * @return the {@link #getTimestamp() timestamp} as {@link Date}.
   */
  public Date getDate() {

    if (this.date == null) {
      this.date = new Date(this.timestamp);
    }
    return this.date;
  }

  /**
   * @param timestamp is the new value of {@link #getTimestamp()}.
   */
  public void setTimestamp(long timestamp) {

    this.timestamp = timestamp;
  }

  /**
   * @return the login or id of the user that has created this revision.
   */

  public String getUserLogin() {

    return this.userLogin;
  }

  /**
   * @param userLogin is the new value of {@link #getUserLogin()}.
   */
  public void setUserLogin(String userLogin) {

    this.userLogin = userLogin;
  }

  @Override
  @GeneratedValue(strategy = GenerationType.TABLE)
  public int getModificationCounter() {

    return 0;
  }

  @Override
  public Number getRevision() {

    return null;
  }
}
@@ -186,24 +186,57 @@
 util.Date;%0A%0A
+import javax.persistence.Column;%0A
 import javax
@@ -1434,16 +1434,50 @@
 mestamp%0A
+  @Column(name = %22%5C%22timestamp%5C%22%22)%0A
   privat

enforce quotation of timestamp to make it also work with oracle