-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathApplicationPersistenceEntity.java
More file actions
79 lines (60 loc) · 1.9 KB
/
Copy pathApplicationPersistenceEntity.java
File metadata and controls
79 lines (60 loc) · 1.9 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
package com.devonfw.quarkus.general.domain.model;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;
/**
* Abstract base class for all {@link PersistenceEntity persistence entities} with an {@link #getId() id} and a
* {@link #getModificationCounter() modificationCounter} (version) field. All persistence entities of this application
* should inherit from this class. It is using JPA annotations at the getters what has several advantages but also
* implies that you have to annotate transient getter methods with the {@link Transient} annotation.
*/
@MappedSuperclass
public abstract class ApplicationPersistenceEntity {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Version
private Integer modificationCounter;
/**
* The constructor.
*/
public ApplicationPersistenceEntity() {
super();
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getModificationCounter() {
return this.modificationCounter;
}
public void setModificationCounter(Integer version) {
this.modificationCounter = version;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
toString(buffer);
return buffer.toString();
}
/**
* Method to extend {@link #toString()} logic.
*
* @param buffer is the {@link StringBuilder} where to {@link StringBuilder#append(Object) append} the string
* representation.
*/
protected void toString(StringBuilder buffer) {
buffer.append(getClass().getSimpleName());
if (this.id != null) {
buffer.append("[id=");
buffer.append(this.id);
buffer.append("]");
}
}
}