Blame view

src/main/java/fr/plil/sio/persistence/api/Right.java 1.81 KB
fd5e74ca   jcartign   First student ver...
1
2
  package fr.plil.sio.persistence.api;
  
4c446810   msahmane   Ajout des annotat...
3
  import java.io.Serializable;
d41edfbc   jcartign   Migrate modificat...
4
5
  import java.util.LinkedList;
  import java.util.List;
fb8c34cc   msahmane   RightJPA à 100%, ...
6
  import javax.persistence.CascadeType;
4c446810   msahmane   Ajout des annotat...
7
8
9
10
11
12
13
14
15
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Table;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.OneToMany;
d41edfbc   jcartign   Migrate modificat...
16
17
18
19
20
21
  
  /**
   * A right is unique by itd ID, i.e. it can exist two rights with the same name in the database.
   * A right may have a parent, null else.
   * A right can have zero, one or more siblings.
   */
4c446810   msahmane   Ajout des annotat...
22
23
24
25
26
27
28
  @Entity
  @Table(name = "RIGHT_T")
  public class Right implements Serializable{
      
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "RIGHT_ID")
fd5e74ca   jcartign   First student ver...
29
30
      private Long id;
  
4c446810   msahmane   Ajout des annotat...
31
      @Column(name = "NAME_C")
fd5e74ca   jcartign   First student ver...
32
33
      private String name;
  
e5e76a48   jcartign   Add persistence a...
34
      /// the parent right
9ae0ef87   msahmane   Amélioration des ...
35
      @ManyToOne(optional = true)
fb8c34cc   msahmane   RightJPA à 100%, ...
36
      @JoinColumn(name = "PARENT")
fd5e74ca   jcartign   First student ver...
37
      private Right parent;
4c446810   msahmane   Ajout des annotat...
38
      
9ae0ef87   msahmane   Amélioration des ...
39
      @ManyToOne(optional = true)
4c446810   msahmane   Ajout des annotat...
40
41
      @JoinColumn(name = "GROUP_ID")
      private Group group;
fd5e74ca   jcartign   First student ver...
42
  
e5e76a48   jcartign   Add persistence a...
43
      /// the sibling right(s), eventually empty
fb8c34cc   msahmane   RightJPA à 100%, ...
44
      @OneToMany(mappedBy = "parent", cascade = CascadeType.REMOVE)
d41edfbc   jcartign   Migrate modificat...
45
      private List<Right> siblings = new LinkedList<>();
fd5e74ca   jcartign   First student ver...
46
  
d41edfbc   jcartign   Migrate modificat...
47
      public List<Right> getSiblings() {
fd5e74ca   jcartign   First student ver...
48
49
50
          return siblings;
      }
  
d41edfbc   jcartign   Migrate modificat...
51
      public void setSiblings(List<Right> siblings) {
fd5e74ca   jcartign   First student ver...
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
          this.siblings = siblings;
      }
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Right getParent() {
          return parent;
      }
  
      public void setParent(Right parent) {
          this.parent = parent;
      }
  }