1
22
23 package com.liferay.lock.model.impl;
24
25 import com.liferay.lock.model.Lock;
26
27 import java.util.Date;
28
29
35 public class LockImpl implements Lock {
36
37 public LockImpl(
38 String className, Comparable<?> pk, long companyId, long userId,
39 long expirationTime) {
40
41 _className = className;
42 _pk = pk;
43 _companyId = companyId;
44 _userId = userId;
45 _expirationTime = expirationTime;
46 _date = new Date();
47 }
48
49 public String getClassName() {
50 return _className;
51 }
52
53 public Comparable<?> getPrimaryKey() {
54 return _pk;
55 }
56
57 public long getCompanyId() {
58 return _companyId;
59 }
60
61 public long getUserId() {
62 return _userId;
63 }
64
65 public long getExpirationTime() {
66 return _expirationTime;
67 }
68
69 public void setExpirationTime(long expirationTime) {
70 _expirationTime = expirationTime;
71 _date = new Date();
72 }
73
74 public boolean isExpired() {
75 if (_expirationTime <= 0) {
76 return false;
77 }
78 else {
79 Date now = new Date();
80
81 if (now.getTime() > (_date.getTime() + _expirationTime)) {
82 return true;
83 }
84 else {
85 return false;
86 }
87 }
88 }
89
90 public Date getDate() {
91 return _date;
92 }
93
94 public int compareTo(Lock lock) {
95 if (lock == null) {
96 return -1;
97 }
98
99 int value = 0;
100 value = getClassName().compareTo(lock.getClassName());
101
102 if (value != 0) {
103 return value;
104 }
105
106 value = ((Comparable<Object>)getPrimaryKey()).compareTo(
107 lock.getPrimaryKey());
108
109 if (value != 0) {
110 return value;
111 }
112
113 value = getDate().compareTo(lock.getDate());
114
115 if (value != 0) {
116 return value;
117 }
118
119 return 0;
120 }
121
122 public boolean equals(Lock lock) {
123 if (lock == null) {
124 return false;
125 }
126
127 if (getClassName().equals(lock.getClassName()) &&
128 getPrimaryKey().equals(lock.getPrimaryKey())) {
129
130 return true;
131 }
132 else {
133 return false;
134 }
135 }
136
137 public int hashCode() {
138 return getClassName().hashCode() + getPrimaryKey().hashCode();
139 }
140
141 private String _className;
142 private Comparable<?> _pk;
143 private long _companyId;
144 private long _userId;
145 private long _expirationTime;
146 private Date _date;
147
148 }