package org.devocative.metis.entity;

import org.devocative.demeter.entity.ICreationDate;
import org.devocative.demeter.entity.IModificationDate;
import org.devocative.demeter.entity.User;
import org.devocative.metis.entity.connection.DBConnection;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "t_mts_usr_prf")
public class MetisUserProfile implements ICreationDate, IModificationDate {
	private static final long serialVersionUID = 4805397319500384541L;

	@Id
	private Long id;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id", nullable = false, insertable = false, updatable = false,
		foreignKey = @ForeignKey(name = "mtsusrprf2user"))
	private User user;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "f_dflt_conn", nullable = false, foreignKey = @ForeignKey(name = "mtsusrprf2dbconn"))
	private DBConnection defaultConnection;

	@Column(name = "f_dflt_conn", nullable = false, insertable = false, updatable = false)
	private Long defaultConnectionId;

	// ------------------------------ CREATE / MODIFY

	@Column(name = "d_creation", nullable = false, columnDefinition = "date")
	private Date creationDate;

	@Column(name = "d_modification", columnDefinition = "date")
	private Date modificationDate;

	@Version
	@Column(name = "n_version", nullable = false)
	private Integer version = 0;

	// ------------------------------ CONSTRUCTORS

	public MetisUserProfile() {
	}

	public MetisUserProfile(Long id) {
		this.id = id;
	}

	// ------------------------------ ACCESSORS

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public User getUser() {
		return user;
	}

	public DBConnection getDefaultConnection() {
		return defaultConnection;
	}

	public void setDefaultConnection(DBConnection defaultConnection) {
		this.defaultConnection = defaultConnection;
	}

	public Long getDefaultConnectionId() {
		return defaultConnectionId;
	}

	@Override
	public Date getCreationDate() {
		return creationDate;
	}

	@Override
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	@Override
	public Date getModificationDate() {
		return modificationDate;
	}

	@Override
	public void setModificationDate(Date modificationDate) {
		this.modificationDate = modificationDate;
	}

	@Override
	public Integer getVersion() {
		return version;
	}

	@Override
	public void setVersion(Integer version) {
		this.version = version;
	}
}

@@ -766,34 +766,16 @@
 t_conn%22,
- nullable = false,
  foreign
@@ -892,34 +892,16 @@
 t_conn%22,
- nullable = false,
  inserta
@@ -2408,11 +2408,387 @@
 sion;%0A%09%7D
+%0A%0A%09// ---------------%0A%0A%09@Override%0A%09public boolean equals(Object o) %7B%0A%09%09if (this == o) return true;%0A%09%09if (!(o instanceof MetisUserProfile)) return false;%0A%0A%09%09MetisUserProfile that = (MetisUserProfile) o;%0A%0A%09%09return getId() != null ? getId().equals(that.getId()) : that.getId() == null;%0A%09%7D%0A%0A%09@Override%0A%09public int hashCode() %7B%0A%09%09return getId() != null ? getId().hashCode() : 0;%0A%09%7D
 %0A%7D%0A

make "defaultConnection" nullable