?? historyentry.java
字號:
package net.jeffrey.hibernate.history;import java.io.Serializable;import java.text.DateFormat;import java.util.Date;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.Enumerated;import javax.persistence.NamedQueries;import javax.persistence.NamedQuery;import javax.persistence.Temporal;import javax.persistence.TemporalType;import net.jeffrey.hibernate.AbstractEntity;/** * 操作日志的條目 * @author jeffrey */@Entity@NamedQueries({ // 命名查詢,根據實體查詢與其關聯的審計日志記錄,注意這里審計日志和被審計實體并沒有物理關聯(數據庫約束),即使實體被刪除,仍然可以根據實體id訪問審計日志。 @NamedQuery(name = "HistoryEntry.findByEntity", query = "select h from HistoryEntry h where entity = :entity and entityId = :entityId order by timestamp asc")})public class HistoryEntry extends AbstractEntity implements Serializable { private static final long serialVersionUID = 9025279546306024660L; /* 操作的時間 */ @Temporal(TemporalType.TIMESTAMP) @Column(name = "hs_timestamp") private Date timestamp; /* 操作的類型(枚舉型:新建、更新、刪除) */ @Enumerated(javax.persistence.EnumType.STRING) private OperationType operationType; /* 被操作的實體類型 */ private Class entity; /* 被操作實體的主鍵id */ @Column(name = "entity_id") private Integer entityId; /* 操作描述 */ private String description; /* 被操作的屬性 */ private String property; /* 操作前的值 */ private String previousValue; /* 更新值 */ private String newValue; public HistoryEntry() { } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Class getEntity() { return entity; } public void setEntity(Class entity) { this.entity = entity; } public Integer getEntityId() { return entityId; } public void setEntityId(Integer entityId) { this.entityId = entityId; } public String getNewValue() { return newValue; } public void setNewValue(String newValue) { this.newValue = newValue; } public OperationType getOperationType() { return operationType; } public void setOperationType(OperationType operationType) { this.operationType = operationType; } public String getPreviousValue() { return previousValue; } public void setPreviousValue(String previousValue) { this.previousValue = previousValue; } public String getProperty() { return property; } public void setProperty(String property) { this.property = property; } public Date getTimestamp() { return timestamp; } public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } public void setHistorizableEntity(Historizable entity) { this.setEntity(entity.getClass()); this.setEntityId(entity.getId()); this.setDescription(entity.toString()); } @Override public String toString() { return "History[" + DateFormat.getDateTimeInstance().format(timestamp) + ", " + operationType + ", " + entity.getSimpleName() + "," + id + " " + property + "]"; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final HistoryEntry other = (HistoryEntry) obj; return this.getId().equals(other.getId()); } @Override public int hashCode() { int hash = 5; hash = 47 * hash + id; return hash; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -