Commit 78294e2c4ab4f35bda1ced137fe8704da250a402

Authored by jcartign
1 parent 0bd6dc75

Add clean domain objects

src/main/java/fr/plil/sio/persistence/api/Group.java
1 1 package fr.plil.sio.persistence.api;
2 2  
3   -import javax.persistence.*;
4 3 import java.util.LinkedList;
5 4 import java.util.List;
6 5  
... ... @@ -9,28 +8,20 @@ import java.util.List;
9 8 * A group contains a list of rights unique by their ID (no two groups with the same ID can exist in the database).
10 9 */
11 10  
12   -@Entity
13   -@Table(name = "GROUP_T")
14 11 public class Group {
15 12  
16   - @Id
17   - @GeneratedValue(strategy = GenerationType.AUTO)
18   - @Column(name = "GROUP_ID")
19 13 private Long id;
20 14  
21   - @Column(name = "NAME_C")
22 15 private String name;
23 16  
24 17 /**
25 18 * Users in the group.
26 19 */
27   - @OneToMany(mappedBy = "group")
28 20 private List<User> users = new LinkedList<>();
29 21  
30 22 /**
31 23 * List of rights. The list CANNOT contains duplicate rights.
32 24 */
33   - @OneToMany
34 25 private List<Right> rights = new LinkedList<>();
35 26  
36 27 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.*;
4 3 import java.util.LinkedList;
5 4 import java.util.List;
6 5  
... ... @@ -10,25 +9,16 @@ import java.util.List;
10 9 * A right can have zero, one or more siblings.
11 10 */
12 11  
13   -@Entity
14   -@Table(name = "RIGHT_T")
15 12 public class Right {
16 13  
17   - @Id
18   - @GeneratedValue(strategy = GenerationType.AUTO)
19   - @Column(name = "RIGHT_ID")
20 14 private Long id;
21 15  
22   - @Column(name = "NAME_C")
23 16 private String name;
24 17  
25 18 /// the parent right
26   - @ManyToOne
27   - @JoinColumn(name = "PARENT_C")
28 19 private Right parent;
29 20  
30 21 /// the sibling right(s), eventually empty
31   - @OneToMany(mappedBy = "parent")
32 22 private List<Right> siblings = new LinkedList<>();
33 23  
34 24 public List<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 3 /**
6 4 * An user MUST have a group in the database.
7 5 * An user is unique by it name, i.e. database cannot contain two user with the same name or the same ID.
8 6 */
9 7  
10   -@Entity
11   -@Table(name = "USER_T")
12 8 public class User {
13 9  
14   - @Id
15   - @GeneratedValue(strategy = GenerationType.AUTO)
16   - @Column(name = "USER_ID")
17 10 private Long id;
18 11  
19   - @Column(name = "NAME_C")
20 12 private String name;
21 13  
22   - @ManyToOne
23   - @JoinColumn(name = "GROUP_C")
24 14 private Group group;
25 15  
26 16 public Long getId() {
... ...