Commit e5e76a48cbf758635de081950872a0f36d1e8813

Authored by jcartign
1 parent fd5e74ca

Add persistence annotations to domain objects

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