GenericEventChild.java
2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package fi.insomnia.bortal.model;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.utilities.PasswordFunctions;
@MappedSuperclass
public abstract class GenericEventChild implements EventChildInterface {
private static final Logger logger = LoggerFactory.getLogger(GenericEventChild.class);
/**
*
*/
private static final long serialVersionUID = -9041737052951021560L;
@EmbeddedId
private EventPk id;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
public GenericEventChild(LanEvent event) {
id = new EventPk(event);
}
public GenericEventChild() {
super();
}
public GenericEventChild(EventPk eventPk) {
id = eventPk;
}
@Override
public final boolean equals(Object object) {
if (!this.getClass().equals(object.getClass())) {
logger.debug("Classes dont match {} {}", getClass(), object.getClass());
return false;
}
GenericEventChild other = (GenericEventChild) object;
if (tempId != null && tempId.equals(other.tempId)) {
return true;
}
if (this.id == null) {
if (other.id != null) {
return false;
}
logger.debug("Ids are null. Resorting to randomidcheck!");
return getRandomId().equals(other.tempId);
}
return this.id.equals(other.id);
}
@Transient
private String tempId;
private String getRandomId() {
if (tempId == null) {
tempId = PasswordFunctions.generateRandomString(10);
}
return tempId;
}
@Override
public final EventPk getId() {
return id;
}
@Override
public final void setId(EventPk id) {
this.id = id;
}
@Override
public final int getJpaVersionField() {
return jpaVersionField;
}
@Override
public final void setJpaVersionField(int jpaVersionField) {
this.jpaVersionField = jpaVersionField;
}
@Override
public final int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : getRandomId().hashCode());
return hash;
}
}