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.bo.PersistableBusinessObjectBase;
24
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.Id;
29 import javax.persistence.Table;
30 import javax.persistence.Transient;
31 import java.sql.Timestamp;
32
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 @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) {
89 this.documentNumber = documentNumber;
90 this.ownedByPrincipalIdentifier = user.getPrincipalId();
91 this.lockDescriptor = lockDescriptor;
92 this.generatedTimestamp = CoreApiServiceLocator.getDateTimeService().getCurrentTimestamp();
93 }
94
95 public boolean isOwnedByUser(Person user) {
96 return user.getPrincipalId().equals(getOwnedByPrincipalIdentifier());
97 }
98
99
100
101
102 public Long getId() {
103 return this.id;
104 }
105
106
107
108
109 public void setId(Long id) {
110 this.id = id;
111 }
112
113
114
115
116 public String getOwnedByPrincipalIdentifier() {
117 return this.ownedByPrincipalIdentifier;
118 }
119
120
121
122
123 public void setOwnedByPrincipalIdentifier(String ownedByPrincipalIdentifier) {
124 this.ownedByPrincipalIdentifier = ownedByPrincipalIdentifier;
125 }
126
127
128
129
130 public String getLockDescriptor() {
131 return this.lockDescriptor;
132 }
133
134
135
136
137 public void setLockDescriptor(String lockDescriptor) {
138 this.lockDescriptor = lockDescriptor;
139 }
140
141
142
143
144 public Timestamp getGeneratedTimestamp() {
145 return this.generatedTimestamp;
146 }
147
148
149
150
151 public void setGeneratedTimestamp(Timestamp generatedTimestamp) {
152 this.generatedTimestamp = generatedTimestamp;
153 }
154
155
156
157
158 public String getDocumentNumber() {
159 return this.documentNumber;
160 }
161
162
163
164
165 public void setDocumentNumber(String documentNumber) {
166 this.documentNumber = documentNumber;
167 }
168
169
170
171
172 public Person getOwnedByUser() {
173 ownedByUser = KimApiServiceLocator.getPersonService().updatePersonIfNecessary(ownedByPrincipalIdentifier, ownedByUser);
174 return ownedByUser;
175 }
176
177
178
179
180 public void setOwnedByUser(Person ownedByUser) {
181 this.ownedByUser = ownedByUser;
182 }
183 }
184