Commit e5e76a48cbf758635de081950872a0f36d1e8813
1 parent
fd5e74ca
Add persistence annotations to domain objects
Showing
3 changed files
with
31 additions
and
2 deletions
Show diff stats
src/main/java/fr/plil/sio/persistence/api/Group.java
1 | 1 | package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | +import javax.persistence.*; | |
3 | 4 | import java.util.LinkedList; |
4 | 5 | import java.util.List; |
5 | 6 | import java.util.Set; |
6 | 7 | import java.util.TreeSet; |
7 | 8 | |
9 | +@Entity | |
10 | +@Table(name = "GROUP_T") | |
8 | 11 | public class Group { |
9 | 12 | |
13 | + @Id | |
14 | + @GeneratedValue(strategy = GenerationType.AUTO) | |
15 | + @Column(name = "GROUP_ID") | |
10 | 16 | private Long id; |
11 | 17 | |
18 | + @Column(name = "NAME_C") | |
12 | 19 | private String name; |
13 | 20 | |
14 | 21 | /** |
15 | 22 | * Users in the group. |
16 | 23 | */ |
24 | + @OneToMany(mappedBy = "group") | |
17 | 25 | private Set<User> users = new TreeSet<>(); |
18 | 26 | |
19 | 27 | /** |
20 | 28 | * List of rights. The list CANNOT contains duplicate rights. |
21 | 29 | */ |
30 | + @OneToMany | |
22 | 31 | private List<Right> rights = new LinkedList<>(); |
23 | 32 | |
24 | 33 | public List<Right> getRights() { | ... | ... |
src/main/java/fr/plil/sio/persistence/api/Right.java
1 | 1 | package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | +import javax.persistence.*; | |
3 | 4 | import java.util.HashSet; |
4 | 5 | import java.util.Set; |
5 | 6 | |
7 | +@Entity | |
8 | +@Table(name = "RIGHT_T") | |
6 | 9 | public class Right { |
7 | 10 | |
11 | + @Id | |
12 | + @GeneratedValue(strategy = GenerationType.AUTO) | |
13 | + @Column(name = "RIGHT_ID") | |
8 | 14 | private Long id; |
9 | 15 | |
16 | + @Column(name = "NAME_C") | |
10 | 17 | private String name; |
11 | 18 | |
12 | - /// the parent group | |
19 | + /// the parent right | |
20 | + @ManyToOne | |
21 | + @JoinColumn(name = "PARENT_C") | |
13 | 22 | private Right parent; |
14 | 23 | |
15 | - /// the sibling group(s), eventually empty | |
24 | + /// the sibling right(s), eventually empty | |
25 | + @OneToMany(mappedBy = "parent") | |
16 | 26 | private Set<Right> siblings = new HashSet<>(); |
17 | 27 | |
18 | 28 | public Set<Right> getSiblings() { | ... | ... |
src/main/java/fr/plil/sio/persistence/api/User.java
1 | 1 | package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | +import javax.persistence.*; | |
4 | + | |
5 | +@Entity | |
6 | +@Table(name = "USER_T") | |
3 | 7 | public class User { |
4 | 8 | |
9 | + @Id | |
10 | + @GeneratedValue(strategy = GenerationType.AUTO) | |
11 | + @Column(name = "USER_ID") | |
5 | 12 | private Long id; |
6 | 13 | |
14 | + @Column(name = "NAME_C") | |
7 | 15 | private String name; |
8 | 16 | |
17 | + @ManyToOne | |
18 | + @JoinColumn(name = "GROUP_C") | |
9 | 19 | private Group group; |
10 | 20 | |
11 | 21 | public Long getId() { | ... | ... |