View Javadoc

1   /*
2    * Copyright (C) 2007 Alf Mikula
3    * 
4    * This file is part of PromoteGo.
5    *
6    * PromoteGo is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * PromoteGo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with PromoteGo.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.promotego.beans;
20  
21  import javax.persistence.GeneratedValue;
22  import javax.persistence.GenerationType;
23  import javax.persistence.Id;
24  import javax.persistence.MappedSuperclass;
25  
26  import org.apache.commons.lang.builder.EqualsBuilder;
27  import org.apache.commons.lang.builder.HashCodeBuilder;
28  import org.apache.commons.lang.builder.ToStringBuilder;
29  import org.promotego.exceptions.NestedException;
30  
31  @MappedSuperclass
32  public class BeanSupport<T> implements Cloneable
33  {
34      private Long m_id;
35  
36      @Id
37      @GeneratedValue(strategy = GenerationType.AUTO)
38      public Long getId()
39      {
40          return m_id;
41      }
42  
43      public void setId(Long id)
44      {
45          m_id = id;
46      }
47  
48      @SuppressWarnings("unchecked")
49      @Override
50      public T clone()
51      {
52          try
53          {
54              return (T)super.clone();
55          }
56          catch (CloneNotSupportedException e)
57          {
58              // No way to handle this exception, which should never occur
59              throw NestedException.wrap(e);
60          }
61      }
62  
63      @Override
64      public boolean equals(Object anotherObject)
65      {
66          return EqualsBuilder.reflectionEquals(this, anotherObject);
67      }
68  
69      @Override
70      public int hashCode()
71      {
72          return HashCodeBuilder.reflectionHashCode(this);
73      }
74  
75      @Override
76      public String toString()
77      {
78          return ToStringBuilder.reflectionToString(this).toString();
79      }
80  }