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