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