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