1
2
3
4
5 package org.directdemocracyportal.democracy.model.application;
6
7 import java.util.Date;
8
9 import javax.persistence.CascadeType;
10 import javax.persistence.Entity;
11 import javax.persistence.GeneratedValue;
12 import javax.persistence.GenerationType;
13 import javax.persistence.Id;
14 import javax.persistence.JoinColumn;
15 import javax.persistence.OneToOne;
16 import javax.persistence.Temporal;
17 import javax.persistence.TemporalType;
18
19 import org.directdemocracyportal.democracy.model.core.BaseEntity;
20 import org.hibernate.annotations.Cache;
21 import org.hibernate.annotations.CacheConcurrencyStrategy;
22
23 /***
24 * The Class UserSession.
25 */
26 @Entity
27 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
28 public class UserSession extends BaseEntity
29 {
30
31 /*** The Constant serialVersionUID. */
32 private static final long serialVersionUID = -2831588433419103923L;
33
34 /*** The id. */
35 private Long id;
36
37 /*** The user. */
38 private User user;
39
40 /*** The session id. */
41 private String sessionId;
42
43 /*** The created at. */
44 private Date createdAt;
45
46 /*** The ended at. */
47 private Date endedAt;
48
49 /*** The active. */
50 private boolean active;
51
52 /***
53 * Instantiates a new user session.
54 */
55 public UserSession() {
56 }
57
58 /***
59 * Instantiates a new user session.
60 *
61 * @param user the user
62 * @param sessionId the session id
63 * @param createdAt the created at
64 */
65 public UserSession(User user, String sessionId, Date createdAt) {
66 this.user = user;
67 this.sessionId = sessionId;
68 this.createdAt = createdAt;
69 this.active = true;
70 this.endedAt = null;
71 }
72
73
74
75
76
77
78 @Override
79 @Id
80 @GeneratedValue(strategy = GenerationType.AUTO)
81 public Long getId() {
82 return this.id;
83 }
84
85 /***
86 * Sets the id.
87 *
88 * @param id the new id
89 */
90 public void setId(Long id) {
91 this.id = id;
92 }
93
94 /***
95 * Checks if is active.
96 *
97 * @return true, if is active
98 */
99 public boolean isActive() {
100 return active;
101 }
102
103 /***
104 * Sets the active.
105 *
106 * @param active the new active
107 */
108 public void setActive(boolean active) {
109 this.active = active;
110 }
111
112 /***
113 * Gets the created at.
114 *
115 * @return the created at
116 */
117 @Temporal(TemporalType.DATE)
118 public Date getCreatedAt() {
119 return createdAt;
120 }
121
122 /***
123 * Sets the created at.
124 *
125 * @param createdAt the new created at
126 */
127 public void setCreatedAt(Date createdAt) {
128 this.createdAt = createdAt;
129 }
130
131 /***
132 * Gets the ended at.
133 *
134 * @return the ended at
135 */
136 @Temporal(TemporalType.DATE)
137 public Date getEndedAt() {
138 return endedAt;
139 }
140
141 /***
142 * Sets the ended at.
143 *
144 * @param endedAt the new ended at
145 */
146 public void setEndedAt(Date endedAt) {
147 this.endedAt = endedAt;
148 }
149
150 /***
151 * Gets the session id.
152 *
153 * @return the session id
154 */
155 public String getSessionId() {
156 return sessionId;
157 }
158
159 /***
160 * Sets the session id.
161 *
162 * @param sessionId the new session id
163 */
164 public void setSessionId(String sessionId) {
165 this.sessionId = sessionId;
166 }
167
168 /***
169 * Gets the user.
170 *
171 * @return the user
172 */
173 @OneToOne(cascade = CascadeType.ALL)
174 @JoinColumn
175 public User getUser() {
176 return user;
177 }
178
179 /***
180 * Sets the user.
181 *
182 * @param user the new user
183 */
184 public void setUser(User user) {
185 this.user = user;
186 }
187 }