View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   
6   package com.hack23.cia.model.application.impl.common;
7   
8   import java.util.Date;
9   import java.util.List;
10  
11  import javax.persistence.CascadeType;
12  import javax.persistence.DiscriminatorColumn;
13  import javax.persistence.DiscriminatorType;
14  import javax.persistence.DiscriminatorValue;
15  import javax.persistence.Entity;
16  import javax.persistence.EnumType;
17  import javax.persistence.Enumerated;
18  import javax.persistence.FetchType;
19  import javax.persistence.GeneratedValue;
20  import javax.persistence.GenerationType;
21  import javax.persistence.Id;
22  import javax.persistence.Inheritance;
23  import javax.persistence.InheritanceType;
24  import javax.persistence.OneToMany;
25  import javax.persistence.Temporal;
26  import javax.persistence.TemporalType;
27  import javax.persistence.Version;
28  
29  import org.hibernate.annotations.Cache;
30  import org.hibernate.annotations.CacheConcurrencyStrategy;
31  
32  import com.hack23.cia.model.core.impl.BaseEntity;
33  
34  /***
35   * The Class User.
36   */
37  @Entity
38  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
39  @DiscriminatorColumn(name = "usertype", discriminatorType = DiscriminatorType.STRING)
40  @DiscriminatorValue("User")
41  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
42  public class User extends BaseEntity {
43  
44      /***
45       * The Enum UserRole.
46       */
47      public enum UserRole {
48  
49          /*** The ADMIN. */
50          ADMIN,
51  
52          /*** The ANYNOMOUS. */
53          ANYNOMOUS,
54  
55          /*** The USER. */
56          USER,
57  
58          /*** The VIP. */
59          VIP
60      }
61  
62      /*** The Constant serialVersionUID. */
63      private static final long serialVersionUID = -1381199844545595026L;
64  
65      /*** The created date. */
66      private Date createdDate;
67  
68      /*** The id. */
69      private Long id;
70  
71      /*** The user role. */
72      private UserRole userRole;
73  
74      /*** The user sessions. */
75      private List<UserSession> userSessions;
76  
77      /*** The version. */
78      private Long version=1L;
79  
80      /***
81       * Instantiates a new user.
82       */
83      public User() {
84      }
85  
86      /***
87       * Gets the created date.
88       *
89       * @return the created date
90       */
91      public Date getCreatedDate() {
92          return this.createdDate;
93      }
94  
95      /*
96       * (non-Javadoc)
97       * 
98       * @see com.hack23.cia.model.core.BaseEntity#getId()
99       */
100     @Override
101     @Id
102     @GeneratedValue(strategy = GenerationType.AUTO)
103     public Long getId() {
104         return id;
105     }
106 
107     /***
108      * Gets the user role.
109      *
110      * @return the user role
111      */
112     @Enumerated(EnumType.STRING)
113     public UserRole getUserRole() {
114         return userRole;
115     }
116 
117     /***
118      * Gets the user sessions.
119      *
120      * @return the user sessions
121      */
122     @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
123     @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
124     public List<UserSession> getUserSessions() {
125         return userSessions;
126     }
127 
128     /* (non-Javadoc)
129      * @see com.hack23.cia.model.core.BaseEntity#getVersion()
130      */
131     @Override
132     @Version
133     public Long getVersion() {
134         return version;
135     }
136 
137     /***
138      * Sets the created date.
139      *
140      * @param createdDate the new created date
141      */
142     @Temporal(TemporalType.DATE)
143     public void setCreatedDate(final Date createdDate) {
144         this.createdDate = createdDate;
145     }
146 
147     /***
148      * Sets the id.
149      *
150      * @param id the new id
151      */
152     public void setId(final Long id) {
153         this.id = id;
154     }
155 
156     /***
157      * Sets the user role.
158      *
159      * @param userRole the new user role
160      */
161     public void setUserRole(final UserRole userRole) {
162         this.userRole = userRole;
163     }
164     
165     /***
166      * Sets the user sessions.
167      *
168      * @param userSessions the new user sessions
169      */
170     public void setUserSessions(final List<UserSession> userSessions) {
171         this.userSessions = userSessions;
172     }
173 
174     /***
175      * Sets the version.
176      *
177      * @param version the new version
178      */
179     public void setVersion(final Long version) {
180         this.version = version;
181     }
182 
183 }