/*******************************************************************************
 * Copyright 2Fi Business Solutions Ltd.
 *
 * This code is copyrighted. Under no circumstances should any party, people,
 * or organization should redistribute any portions of this code in any form,
 * either verbatim or through electronic media, to any third parties, unless
 * under explicit written permission by 2Fi Business Solutions Ltd.
 ******************************************************************************/
package com.ffii.core;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@MappedSuperclass
public abstract class BaseEntity<PK extends Serializable> implements Serializable, Cloneable {

	private static final long serialVersionUID = -7211267047474252631L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private PK id;

	@Column(columnDefinition = "int(11)")
	private Integer sysGroupId;

	@Version
	@Column(columnDefinition = "mediumint unsigned", nullable = false)
	private int versionId; // hibernate optimistic lock version id

	@Column(columnDefinition = "boolean", nullable = false)
	private boolean deleted; // defaults to false

	@Column(updatable = false)
	private Integer createdBy; // User ID that created this record

	@Column
	private Integer modifiedBy; // User ID that last modified this record

	@Column(updatable = false, nullable = false)
	private Date created; // date created

	@Column(nullable = false)
	private Date modified; // last modified date

	/** Default constructor */
	public BaseEntity() {

	}

	/*
	 * implements Cloneable
	 */
	@Override
	protected Object clone() throws CloneNotSupportedException {
		BaseEntity<?> clone = (BaseEntity<?>) super.clone();
		clone.id = null;
		return clone;
	}

	/*
	 * getters and setters
	 */
	public PK getId() {
		return id;
	}

	@SuppressWarnings("unchecked")
	public void setId(Serializable id) {
		this.id = (PK) id;
	}

	public int getVersionId() {
		return versionId;
	}

	public void setVersionId(int versionId) {
		this.versionId = versionId;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public Integer getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(Integer createdBy) {
		this.createdBy = createdBy;
	}

	public Integer getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(Integer modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getModified() {
		return modified;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}

	public Integer getSysGroupId() {
		return sysGroupId;
	}

	public void setSysGroupId(Integer sysGroupId) {
		this.sysGroupId = sysGroupId;
	}

}
