package mil.army.usace.p2.entity; import mil.army.usace.p2.constants.LogLevel; import mil.army.usace.p2.constants.RecordSource; import mil.army.usace.p2.util.ExtendedEqualsBuilder; import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import java.io.Serializable; import java.sql.Timestamp; import java.util.Date; /** * @version $Revision: 1270 $ * @author $Author: u4iesabm $ * Last Modified: $Date: 2011-07-28 08:55:14 -0500 (Thu, 28 Jul 2011) $ */ @Entity @Table(name="PROCESS_RUN_LOG", schema="CILSTAGE") @SequenceGenerator(name="PROCESS_RUN_LOG_GEN", sequenceName="LOG_ENTRY_ID_SEQ", allocationSize=1) public class ProcessRunLog implements Serializable, Comparable { private static final long serialVersionUID = 1L; @Id @Column(name = "LOG_ENTRY_ID") @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="PROCESS_RUN_LOG_GEN") private Long id; @Column(name = "TABLE_NAME") @Enumerated(EnumType.STRING) private RecordSource recordSource; @Column(name = "FK_ID1") private Long fkId1; @Column(name = "FK_ID2") private Long fkId2; @Column(name = "LOG_LEVEL_TYPE_ID") @Enumerated(EnumType.ORDINAL) private LogLevel level; @Column(name = "LOG_NOTE") private String note; @Temporal(TemporalType.TIMESTAMP) @Column(name = "LOG_TIME") private Date time; @Column(name="PROCESS_RUN_ID") private Long processRunId; // bi-directional many-to-one association to ProcessRun @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="PROCESS_RUN_ID", insertable=false, updatable=false) private ProcessRun processRun; public ProcessRunLog() { super(); } public ProcessRunLog(LogLevel aLogLevel, ProcessRun aProcessRun, String note) { this(); this.level = aLogLevel; this.note = note; this.time = new Timestamp(System.currentTimeMillis()); // current timestamp this.setProcessRun(aProcessRun); } public ProcessRunLog(LogLevel aLogLevel, ProcessRun aProcessRun, RecordSource aRecordSource, Long fkId1, Long fkId2, String note) { this(aLogLevel, aProcessRun, note); this.recordSource = aRecordSource; this.fkId1 = fkId1; this.fkId2 = fkId2; } @Override public boolean equals(Object obj) { ExtendedEqualsBuilder anExtendedEqualsBuilder = new ExtendedEqualsBuilder(this, obj); if (! anExtendedEqualsBuilder.isEquals()) return false; ProcessRunLog aProcessRunLog = (ProcessRunLog) obj; return anExtendedEqualsBuilder .append(this.time, aProcessRunLog.time) .append(this.processRunId, aProcessRunLog.processRunId) .isEquals(); } @Override public int hashCode() { return new HashCodeBuilder() .append(this.time) .append(this.processRunId) .toHashCode(); } public int compareTo(ProcessRunLog aProcessRunLog) { return new CompareToBuilder() .append(this.time, aProcessRunLog.time) .append(this.processRunId, aProcessRunLog.processRunId) .toComparison(); } @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) .append("id", this.id) .append("time", this.time) .append("level", this.level) .append("processRunId", this.processRunId) .append("recordSource", this.recordSource) .append("fkId1", this.fkId1) .append("fkId2", this.fkId2) .append("note", this.note) .toString(); } public Long getId() { return this.id; } public void setId(Long recordId) { this.id = recordId; } public RecordSource getRecordSource() { return this.recordSource; } public void setRecordSource(RecordSource recordSource) { this.recordSource = recordSource; } public Long getFkId1() { return this.fkId1; } public void setFkId1(Long fkId1) { this.fkId1 = fkId1; } public Long getFkId2() { return this.fkId2; } public void setFkId2(Long fkId2) { this.fkId2 = fkId2; } public LogLevel getLevel() { return this.level; } public void setLevel(LogLevel logLevel) { this.level = logLevel; } public String getNote() { return this.note; } public void setNote(String note) { this.note = note; } public Date getTime() { return this.time; } public void setTime(Date time) { this.time = time; } public Long getProcessRunId() { return this.processRunId; } public void setProcessRunId(Long processRunId) { this.processRunId = processRunId; } public ProcessRun getProcessRun() { return this.processRun; } public void setProcessRun(ProcessRun processRun) { if (processRun != null) { this.processRun = processRun; this.processRunId = processRun.getId(); this.processRun.add(this); } } }