diff src/main/java/de/mpiwg/gazetteer/bo/DBEntry.java @ 0:3e62083dbcbf

First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Thu, 23 Apr 2015 15:46:01 +0200
parents
children 95bf4ac726e6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/bo/DBEntry.java	Thu Apr 23 15:46:01 2015 +0200
@@ -0,0 +1,119 @@
+package de.mpiwg.gazetteer.bo;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.persistence.Column;
+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.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
+public abstract class DBEntry {
+	
+	private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy-HH:mm");
+	
+	public DBEntry(){}
+	
+	@Id
+    @GeneratedValue(strategy = GenerationType.TABLE)
+    @Column(name="id")
+    protected Long id;
+	
+	@Temporal(TemporalType.TIMESTAMP)
+    @Column(name="creationDate")
+	private Date creationDate;
+	
+	@Temporal(TemporalType.TIMESTAMP)
+    @Column(name="lastChangeDate")
+	private Date lastChangeDate;
+	
+	public boolean isPersistent(){
+	    	if(this.getId() == null){
+	    		return false;
+	    	}else{
+	    		return true;
+	    	}	
+    }
+	
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+	
+	public Date getCreationDate() {
+		return creationDate;
+	}
+
+	public void setCreationDate(Date creationDate) {
+		this.creationDate = creationDate;
+	}
+
+	public Date getLastChangeDate() {
+		return lastChangeDate;
+	}
+
+	public void setLastChangeDate(Date lastChangeDate) {
+		this.lastChangeDate = lastChangeDate;
+	}
+
+	public String getFomattedLastChange(){
+		if(this.lastChangeDate != null)
+			return DATE_FORMAT.format(this.lastChangeDate);
+		return null;
+	}
+	
+	public String getFomattedCreation(){
+		if(this.creationDate != null)
+			return DATE_FORMAT.format(this.creationDate);
+		return null;
+	}
+	
+	
+	public String getInfo(){
+		if(isPersistent()){
+			StringBuilder sb = new StringBuilder("id=" + id);
+			
+			if(creationDate != null){
+				sb.append(", creation date=" + creationDate);
+			}
+			
+			if(lastChangeDate != null){
+				sb.append(", last change=" + lastChangeDate);
+			}				
+			return sb.toString();	
+		}
+		return new String();
+	}
+	
+	@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 DBEntry)) {
+            return false;
+        }
+        DBEntry other = (DBEntry) object;
+        
+        if(this.id != null && other.id != null && this.id.longValue() == other.id.longValue())
+        	return true;
+        
+        return false;
+    }
+	
+	@Override
+	public String toString(){
+		StringBuilder sb = new StringBuilder();
+		sb.append(this.getClass().toString());
+		sb.append(" [id=" + this.id + "] ");
+		return sb.toString();
+	}
+}
\ No newline at end of file