1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.document.authorization;
17
18 import org.hibernate.annotations.GenericGenerator;
19 import org.hibernate.annotations.Parameter;
20 import org.kuali.rice.core.api.CoreApiServiceLocator;
21 import org.kuali.rice.kim.api.identity.Person;
22 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
23 import org.kuali.rice.krad.UserSession;
24 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.Id;
30 import javax.persistence.Table;
31 import javax.persistence.Transient;
32 import java.sql.Timestamp;
33
34
35
36
37
38
39
40
41
42
43
44 @Entity
45 @Table(name="KRNS_PESSIMISTIC_LOCK_T")
46 public class PessimisticLock extends PersistableBusinessObjectBase {
47
48 private static final long serialVersionUID = -5210762282545093555L;
49
50 public static final String DEFAULT_LOCK_DESCRIPTOR = null;
51
52
53 @Id
54 @GeneratedValue(generator="KRNS_LOCK_S")
55 @GenericGenerator(name="KRNS_LOCK_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
56 @Parameter(name="sequence_name",value="KRNS_LOCK_S"),
57 @Parameter(name="value_column",value="id")
58 })
59 @Column(name="PESSIMISTIC_LOCK_ID")
60 private Long id;
61
62 @Column(name="PRNCPL_ID")
63 private String ownedByPrincipalIdentifier;
64
65 @Column(name="LOCK_DESC_TXT")
66 private String lockDescriptor;
67
68 @Column(name="GNRT_DT")
69 private Timestamp generatedTimestamp;
70
71 @Column(name="DOC_HDR_ID")
72 private String documentNumber;
73
74 @Column(name="SESN_ID")
75 private String sessionId;
76
77 @Transient
78 private Person ownedByUser;
79
80
81
82
83
84
85
86 @Deprecated
87 public PessimisticLock() {}
88
89
90
91
92 public PessimisticLock(String documentNumber, String lockDescriptor, Person user, UserSession userSession) {
93 this.documentNumber = documentNumber;
94 this.ownedByPrincipalIdentifier = user.getPrincipalId();
95 this.lockDescriptor = lockDescriptor;
96 this.generatedTimestamp = CoreApiServiceLocator.getDateTimeService().getCurrentTimestamp();
97 this.sessionId = userSession.getKualiSessionId();
98 }
99
100 public boolean isOwnedByUser(Person user) {
101 return user.getPrincipalId().equals(getOwnedByPrincipalIdentifier());
102 }
103
104
105
106
107 public Long getId() {
108 return this.id;
109 }
110
111
112
113
114 public void setId(Long id) {
115 this.id = id;
116 }
117
118
119
120
121 public String getOwnedByPrincipalIdentifier() {
122 return this.ownedByPrincipalIdentifier;
123 }
124
125
126
127
128 public void setOwnedByPrincipalIdentifier(String ownedByPrincipalIdentifier) {
129 this.ownedByPrincipalIdentifier = ownedByPrincipalIdentifier;
130 }
131
132
133
134
135 public String getLockDescriptor() {
136 return this.lockDescriptor;
137 }
138
139
140
141
142 public void setLockDescriptor(String lockDescriptor) {
143 this.lockDescriptor = lockDescriptor;
144 }
145
146
147
148
149 public Timestamp getGeneratedTimestamp() {
150 return this.generatedTimestamp;
151 }
152
153
154
155
156 public void setGeneratedTimestamp(Timestamp generatedTimestamp) {
157 this.generatedTimestamp = generatedTimestamp;
158 }
159
160
161
162
163 public String getDocumentNumber() {
164 return this.documentNumber;
165 }
166
167
168
169
170 public void setDocumentNumber(String documentNumber) {
171 this.documentNumber = documentNumber;
172 }
173
174
175
176
177 public String getSessionId() {
178 return this.sessionId;
179 }
180
181
182
183
184 public void setSessionId(String sessionId) {
185 this.sessionId = sessionId;
186 }
187
188
189
190
191
192 public Person getOwnedByUser() {
193 ownedByUser = KimApiServiceLocator.getPersonService().updatePersonIfNecessary(ownedByPrincipalIdentifier, ownedByUser);
194 return ownedByUser;
195 }
196
197
198
199
200 public void setOwnedByUser(Person ownedByUser) {
201 this.ownedByUser = ownedByUser;
202 }
203 }
204