comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:3e62083dbcbf
1 package de.mpiwg.gazetteer.bo;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5
6 import javax.persistence.Column;
7 import javax.persistence.Entity;
8 import javax.persistence.GeneratedValue;
9 import javax.persistence.GenerationType;
10 import javax.persistence.Id;
11 import javax.persistence.Inheritance;
12 import javax.persistence.InheritanceType;
13 import javax.persistence.Temporal;
14 import javax.persistence.TemporalType;
15
16 @Entity
17 @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
18 public abstract class DBEntry {
19
20 private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy-HH:mm");
21
22 public DBEntry(){}
23
24 @Id
25 @GeneratedValue(strategy = GenerationType.TABLE)
26 @Column(name="id")
27 protected Long id;
28
29 @Temporal(TemporalType.TIMESTAMP)
30 @Column(name="creationDate")
31 private Date creationDate;
32
33 @Temporal(TemporalType.TIMESTAMP)
34 @Column(name="lastChangeDate")
35 private Date lastChangeDate;
36
37 public boolean isPersistent(){
38 if(this.getId() == null){
39 return false;
40 }else{
41 return true;
42 }
43 }
44
45 public Long getId() {
46 return id;
47 }
48
49 public void setId(Long id) {
50 this.id = id;
51 }
52
53 public Date getCreationDate() {
54 return creationDate;
55 }
56
57 public void setCreationDate(Date creationDate) {
58 this.creationDate = creationDate;
59 }
60
61 public Date getLastChangeDate() {
62 return lastChangeDate;
63 }
64
65 public void setLastChangeDate(Date lastChangeDate) {
66 this.lastChangeDate = lastChangeDate;
67 }
68
69 public String getFomattedLastChange(){
70 if(this.lastChangeDate != null)
71 return DATE_FORMAT.format(this.lastChangeDate);
72 return null;
73 }
74
75 public String getFomattedCreation(){
76 if(this.creationDate != null)
77 return DATE_FORMAT.format(this.creationDate);
78 return null;
79 }
80
81
82 public String getInfo(){
83 if(isPersistent()){
84 StringBuilder sb = new StringBuilder("id=" + id);
85
86 if(creationDate != null){
87 sb.append(", creation date=" + creationDate);
88 }
89
90 if(lastChangeDate != null){
91 sb.append(", last change=" + lastChangeDate);
92 }
93 return sb.toString();
94 }
95 return new String();
96 }
97
98 @Override
99 public boolean equals(Object object) {
100 // TODO: Warning - this method won't work in the case the id fields are not set
101 if (!(object instanceof DBEntry)) {
102 return false;
103 }
104 DBEntry other = (DBEntry) object;
105
106 if(this.id != null && other.id != null && this.id.longValue() == other.id.longValue())
107 return true;
108
109 return false;
110 }
111
112 @Override
113 public String toString(){
114 StringBuilder sb = new StringBuilder();
115 sb.append(this.getClass().toString());
116 sb.append(" [id=" + this.id + "] ");
117 return sb.toString();
118 }
119 }