1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.directdemocracyportal.democracy.model.core; |
6 | |
|
7 | |
import java.util.HashSet; |
8 | |
import java.util.Set; |
9 | |
|
10 | |
import javax.persistence.CascadeType; |
11 | |
import javax.persistence.Entity; |
12 | |
import javax.persistence.FetchType; |
13 | |
import javax.persistence.GeneratedValue; |
14 | |
import javax.persistence.GenerationType; |
15 | |
import javax.persistence.Id; |
16 | |
import javax.persistence.Inheritance; |
17 | |
import javax.persistence.InheritanceType; |
18 | |
import javax.persistence.ManyToMany; |
19 | |
import javax.persistence.OneToMany; |
20 | |
|
21 | |
import org.hibernate.annotations.Cache; |
22 | |
import org.hibernate.annotations.CacheConcurrencyStrategy; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
@Entity |
31 | |
@Inheritance(strategy = InheritanceType.JOINED) |
32 | |
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) |
33 | |
public abstract class Agent extends BaseEntity |
34 | |
{ |
35 | |
|
36 | |
|
37 | |
private Long id; |
38 | |
|
39 | |
|
40 | |
private String name; |
41 | |
|
42 | |
|
43 | 19 | private Set<Role> roles = new HashSet<Role>(); |
44 | |
|
45 | |
|
46 | 19 | private Set<Resource> resources = new HashSet<Resource>(); |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 19 | public Agent() { |
52 | 19 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 0 | public Agent(String name) { |
60 | 0 | this.name = name; |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
@Override |
69 | |
@Id |
70 | |
@GeneratedValue(strategy = GenerationType.AUTO) |
71 | |
public Long getId() { |
72 | 9 | return id; |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public void setId(Long id) { |
81 | 5 | this.id = id; |
82 | 5 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public String getName() { |
90 | 0 | return name; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void setName(String name) { |
99 | 0 | this.name = name; |
100 | 0 | } |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
@ManyToMany(fetch = FetchType.LAZY) |
108 | |
public Set<Role> getRoles() { |
109 | 0 | return roles; |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public void setRoles(Set<Role> roles) { |
118 | 0 | this.roles = roles; |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@Override |
127 | |
public int hashCode() { |
128 | |
final int prime = 31; |
129 | 4 | int result = 1; |
130 | 4 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
131 | 4 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
132 | 4 | return result; |
133 | |
} |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
@Override |
141 | |
public boolean equals(Object obj) { |
142 | 3 | if (this == obj) |
143 | 1 | return true; |
144 | 2 | if (obj == null) |
145 | 0 | return false; |
146 | 2 | if (getClass() != obj.getClass()) |
147 | 0 | return false; |
148 | 2 | final Agent other = (Agent) obj; |
149 | 2 | if (id == null) { |
150 | 0 | if (other.id != null) |
151 | 0 | return false; |
152 | 2 | } else if (!id.equals(other.id)) |
153 | 1 | return false; |
154 | 1 | if (name == null) { |
155 | 1 | if (other.name != null) |
156 | 0 | return false; |
157 | 0 | } else if (!name.equals(other.name)) |
158 | 0 | return false; |
159 | 1 | return true; |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL, fetch = FetchType.LAZY) |
168 | |
public Set<Resource> getResources() { |
169 | 0 | return resources; |
170 | |
} |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public void setResources(Set<Resource> resources) { |
178 | 0 | this.resources = resources; |
179 | 0 | } |
180 | |
} |