Java tutorial
package com.webbfontaine.valuewebb.model; import org.apache.commons.lang3.time.DateUtils; import org.hibernate.validator.Length; import org.hibernate.validator.NotNull; import javax.persistence.*; import java.util.Date; /** * Copyrights 2002-2010 Webb Fontaine * This software is the proprietary information of Webb Fontaine. * Its use is subject to License terms. * User: nigiyan * Date: Nov 18, 2010 */ @Entity @Table(name = "TT_LOG") @org.hibernate.annotations.Entity(dynamicUpdate = true, selectBeforeUpdate = false) public class TtLog { private Long id; private Date date; private String actorLogin; private String action; private String msg; private String msgType; private Integer msgHashCode; private TtGen ttGen; public TtLog() { } public TtLog(Date date, String actorLogin, String action, String msg, String msgType, TtGen ttGen) { this.date = date; this.actorLogin = actorLogin; this.action = action; this.msg = msg; this.msgType = msgType; this.ttGen = ttGen; } @Id @GeneratedValue @Column(name = "LOG_ID") public Long getId() { return id; } public void setId(Long id) { this.id = id; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "TT_ID", updatable = false) @NotNull public TtGen getTtGen() { return ttGen; } public void setTtGen(TtGen ttGen) { this.ttGen = ttGen; } @Column(name = "LOG_DAT") @Temporal(TemporalType.TIMESTAMP) public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } @Length(max = 30) public String getActorLogin() { return actorLogin; } public void setActorLogin(String actorLogin) { this.actorLogin = actorLogin; } @Length(max = 30) public String getAction() { return action; } public void setAction(String action) { this.action = action; } @Length(max = 1000) public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } @Column(name = "MSG_TYP") @Length(max = 20) public String getMsgType() { return msgType; } public void setMsgType(String msgType) { this.msgType = msgType; } @Column(name = "HSH_MSG") public Integer getMsgHashCode() { return msgHashCode; } public void setMsgHashCode(Integer msgHashCode) { this.msgHashCode = msgHashCode; } public Boolean dateTitleRequired() { Date today = new Date(); int i = ttGen.getLogs().indexOf(this); //list is ordered by Date (ascending) return (i == 0 && !DateUtils.isSameDay(date, today)) || (i > 0 && !DateUtils.isSameDay(ttGen.getLogs().get(i - 1).getDate(), date)); } public Boolean addLogin() { int i = ttGen.getLogs().indexOf(this); //list is ordered by Date (ascending) return i == 0 || dateTitleRequired() || (i > 0 && !ttGen.getLogs().get(i - 1).getActorLogin().equals(actorLogin)); } @Override public String toString() { return "TtLog{" + "id=" + id + ", date=" + date + ", actorLogin='" + actorLogin + '\'' + ", action='" + action + '\'' + ", msg='" + msg + '\'' + '}'; } }