Mercurial > hg > openmind
view src/main/java/org/mpi/openmind/repository/bo/Node.java @ 33:e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
more comments in code.
author | casties |
---|---|
date | Fri, 26 Aug 2016 11:42:41 +0200 |
parents | c23ae718fdd3 |
children | 5737ab564b94 |
line wrap: on
line source
package org.mpi.openmind.repository.bo; import java.io.Serializable; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; import javax.persistence.Transient; import org.mpi.openmind.repository.utils.ArabicNormalizerUtils; import org.mpi.openmind.repository.utils.NormalizerUtils; import org.mpi.openmind.repository.utils.RomanizationLoC; /** * * @author jurzua */ @Entity @Table(name="node") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="node_type", discriminatorType=DiscriminatorType.STRING) @DiscriminatorValue("NODE") public abstract class Node implements Serializable, Cloneable { private static final long serialVersionUID = 1L; public static String TYPE_TBOX = "TBox"; public static String TYPE_ABOX = "ABox"; public static String TYPE_VARIABLE = "Variable"; public static String TYPE_FORMULA = "Formula"; public static String TYPE_LINK = "Link"; public static String SYS_STATUS_CURRENT_VERSION = "CURRENT_VERSION"; public static String SYS_STATUS_PREVIOUS_VERSION = "PREVIOUS_VERSION"; private static SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss" ); @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="row_id") private Long rowId; @Transient private Date dateModification; public String getTimeStamp(){ return DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.SHORT).format(getDateModification()); } public Date getDateModification() { dateModification = new Date(this.modificationTime); return dateModification; } public void setDateModification(Date dateModification) { this.dateModification = dateModification; } @Transient private List<View> views = new ArrayList<View>(); public void addView(View view){ if(view != null){ this.views.add(view); } } public List<View> getViews() { return views; } public void setViews(List<View> views) { this.views = views; } @Column(name="long_value") private Long longValue; @Column(name="binary_value") private byte[] binaryValue; @Column(name="object_class") private String objectClass; @Column(name="user") private String user; //@Type(type = "org.hibernate.type.NumericBooleanType") @Column(name="public") private Boolean isPublic = Boolean.FALSE; public String getUser() { return user; } public void setUser(String user) { this.user = user; } public String getObjectClass() { return objectClass; } public void setObjectClass(String objectClass) { this.objectClass = objectClass; } public Long getLongValue() { return longValue; } public void setLongValue(Long longValue) { this.longValue = longValue; } public byte[] getBinaryValue() { return binaryValue; } public void setBinaryValue(byte[] binaryValue) { this.binaryValue = binaryValue; } @Column(name="modification_time") private Long modificationTime; @Column(name="id") private Long id; //lenght 16777215= Medium text @Column(name="own_value", columnDefinition="mediumtext") private String ownValue; //, length=16777215 @Column(name="normalized_own_value", columnDefinition="mediumtext") private String normalizedOwnValue; //, length=16777215 @Column(name="normalized_arabic_own_value", columnDefinition="mediumtext") private String normalizedArabicOwnValue; @Column(name="version") private Long version; @Column(name="status") private String status; @Column(name="system_status") private String systemStatus; @Column(name="type") private String type; @Column(name="content_type") private String contentType; /** * Returns true if the entity was made persistent. * It means the fields 'id' and 'rowId' are not null. * @return */ public boolean isPersistent(){ if(this.getId() == null || this.getRowId() == null) return false; else return true; } public void increaseVersion(){ if(this.version == null){ this.version = new Long(1); }else{ this.version++; } } public String getOwnValue() { return ownValue; } public void setOwnValue(String ownValue) { this.ownValue = ownValue; this.normalizedOwnValue = NormalizerUtils.normalize(ownValue); this.normalizedArabicOwnValue = ArabicNormalizerUtils.normalize(ownValue); } public void autoNormalize(){ this.normalizedOwnValue = NormalizerUtils.normalize(ownValue); this.normalizedArabicOwnValue = ArabicNormalizerUtils.normalize(ownValue); } public String getRomanizationLoC(){ return RomanizationLoC.convert(this.ownValue); } public String getNormalizedOwnValue() { return normalizedOwnValue; } public void setNormalizedOwnValue(String normalizedOwnValue) { this.normalizedOwnValue = normalizedOwnValue; } public String getNormalizedArabicOwnValue() { return normalizedArabicOwnValue; } public void setNormalizedArabicOwnValue(String normalizedArabicOwnValue) { this.normalizedArabicOwnValue = normalizedArabicOwnValue; } public String getContentType() { return contentType; } public void setContentType(String contentType) { this.contentType = contentType; } public Long getRowId() { return rowId; } public void setRowId(Long rowId) { this.rowId = rowId; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Long getModificationTime() { return modificationTime; } public void setModificationTime(Long modificationTime) { this.modificationTime = modificationTime; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getSystemStatus() { return systemStatus; } /** * Set the system_status of this Node. * * @param systemStatus */ public void setSystemStatus(String systemStatus) { this.systemStatus = systemStatus; } public String getType() { return type; } public void setType(String type) { this.type = type; } public Long getVersion() { return version; } public void setVersion(Long version) { this.version = version; } /* @Override public int hashCode() { int hash = 0; hash += (rowId != null ? rowId.hashCode() : 0); return hash; }*/ @Override public int hashCode() { if(this.rowId == null){ return super.hashCode(); }else{ return rowId.hashCode(); } } /** * Clones this object and every object contained by it. * This method was implemented because the cache. The cache must return a cloned version of a object, * otherwise when the object is modified, it becomes dirty and the cache could not recognize the change of the state. */ @Override public Object clone() { try { Node clone = (Node)super.clone(); clone.setViews(new ArrayList<View>()); for(View view : this.views){ clone.addView((View)view.clone()); } return clone; } catch (CloneNotSupportedException e) { throw new InternalError(e.toString()); } } public Boolean getIsPublic() { return isPublic; } public void setIsPublic(Boolean isPublic) { this.isPublic = isPublic; } public String getPrivacity(){ if(isPublic != null) return (isPublic) ? "public" : "private"; return "private"; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Node)) { return false; } Node other = (Node) object; if(this.rowId != null && other.rowId != null && this.rowId.longValue() == other.rowId.longValue()) return true; /* if ((this.rowId == null && other.rowId != null) || (this.rowId != null && !this.rowId.equals(other.rowId))) { return false; }*/ return false; } @Override public String toString() { String rowIdString = (this.getRowId() == null) ? "" : "rowId=" + this.getRowId() + ", "; String idString = (this.getId() == null) ? "" : "id=" + getId() + ", "; return "Node[" + rowIdString + idString + "name=" + this.getObjectClass() + ", ownValue=" + this.getOwnValue() + ", sysStatus=" + this.getSystemStatus() + "]"; } }