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.tasks;
18  
19  import static javax.persistence.CascadeType.ALL;
20  import static javax.persistence.GenerationType.IDENTITY;
21  
22  import javax.persistence.*;
23  import java.io.Serializable;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * User entity
29   * 
30   * @author Oliver Kiss
31   */
32  @SuppressWarnings("serial")
33  @Entity
34  public class User implements Serializable {
35  
36      @Id
37      @GeneratedValue(strategy = IDENTITY)
38      private Long id;
39  
40      @Column(unique=true)
41      private String username;
42  
43      @OneToMany(cascade = ALL, mappedBy = "owner")
44      @Column(updatable = false)
45      private List<Task> tasks = new ArrayList<Task>();
46  
47      public User() {
48      }
49  
50      public User(String username) {
51          this.username = username;
52      }
53  
54      public Long getId() {
55          return id;
56      }
57  
58      public void setId(Long id) {
59          this.id = id;
60      }
61  
62      public String getUsername() {
63          return username;
64      }
65  
66      public void setUsername(String username) {
67          this.username = username;
68      }
69  
70      public List<Task> getTasks() {
71          return tasks;
72      }
73  
74      public void setTasks(List<Task> tasks) {
75          this.tasks = tasks;
76      }
77  
78      @Override
79      public int hashCode() {
80          final int prime = 31;
81          int result = 1;
82          result = prime * result + ((username == null) ? 0 : username.hashCode());
83          return result;
84      }
85  
86      @Override
87      public boolean equals(Object obj) {
88          if (this == obj)
89              return true;
90          if (obj == null)
91              return false;
92          if (getClass() != obj.getClass())
93              return false;
94          User other = (User) obj;
95          if (username == null) {
96              if (other.username != null)
97                  return false;
98          } else if (!username.equals(other.username))
99              return false;
100         return true;
101     }
102 
103 }