Commit 4c446810b427c5f9ff757b74c1163abd21497c9d

Authored by msahmane
1 parent 62ed607d

Ajout des annotations

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