View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.tasksrs.model;
18  
19  import static javax.persistence.CascadeType.ALL;
20  import static javax.persistence.GenerationType.IDENTITY;
21  
22  import java.io.Serializable;
23  import java.util.ArrayList;
24  import java.util.List;
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.OneToMany;
31  
32  /**
33   * User entity
34   *
35   * @author Oliver Kiss
36   */
37  @SuppressWarnings("serial")
38  @Entity
39  public class User implements Serializable {
40  
41      @Id
42      @GeneratedValue(strategy = IDENTITY)
43      private Long id;
44  
45      @Column(unique = true)
46      private String username;
47  
48      @OneToMany(cascade = ALL, mappedBy = "owner")
49      @Column(updatable = false)
50      private List<Task> tasks = new ArrayList<Task>();
51  
52      public User() {
53      }
54  
55      public User(String username) {
56          this.username = username;
57      }
58  
59      public Long getId() {
60          return id;
61      }
62  
63      public void setId(Long id) {
64          this.id = id;
65      }
66  
67      public String getUsername() {
68          return username;
69      }
70  
71      public void setUsername(String username) {
72          this.username = username;
73      }
74  
75      public List<Task> getTasks() {
76          return tasks;
77      }
78  
79      public void setTasks(List<Task> tasks) {
80          this.tasks = tasks;
81      }
82  
83      @Override
84      public int hashCode() {
85          final int prime = 31;
86          int result = 1;
87          result = prime * result + ((username == null) ? 0 : username.hashCode());
88          return result;
89      }
90  
91      @Override
92      public boolean equals(Object obj) {
93          if (this == obj)
94              return true;
95          if (obj == null)
96              return false;
97          if (getClass() != obj.getClass())
98              return false;
99          User other = (User) obj;
100         if (username == null) {
101             if (other.username != null)
102                 return false;
103         } else if (!username.equals(other.username))
104             return false;
105         return true;
106     }
107 }