1
2
3
4
5
6 package com.hack23.cia.model.core.impl;
7
8 import java.io.Serializable;
9
10 import javax.persistence.MappedSuperclass;
11 import javax.persistence.Transient;
12
13 import org.apache.commons.lang.builder.EqualsBuilder;
14 import org.apache.commons.lang.builder.HashCodeBuilder;
15
16 /***
17 * The Class BaseEntity.
18 */
19 @MappedSuperclass
20 public abstract class BaseEntity implements Serializable {
21
22 /*** The Constant serialVersionUID. */
23 private static final long serialVersionUID = 1L;
24
25
26
27
28 @Override
29 public final boolean equals(final Object obj) {
30 if (obj == null) { return false; }
31 if (obj == this) { return true; }
32 if (obj.getClass() != getClass()) {
33 return false;
34 }
35 final BaseEntity baseEntity = (BaseEntity) obj;
36 return new EqualsBuilder().appendSuper(true)
37 .append(getId(), baseEntity.getId())
38 .append(getVersion(), baseEntity.getVersion())
39 .isEquals();
40
41 }
42
43 /***
44 * Gets the id.
45 *
46 * @return the id
47 */
48 @Transient
49 public abstract Long getId();
50
51 /***
52 * Gets the version.
53 *
54 * @return the version
55 */
56 @Transient
57 public abstract Long getVersion();
58
59
60
61
62 @Override
63 public final int hashCode() {
64 return HashCodeBuilder.reflectionHashCode(getClass().getName() + ":" + getId() + ":" + getVersion());
65 }
66
67 /***
68 * Checks if is new.
69 *
70 * @return true, if is new
71 */
72 @Transient
73 public boolean isNew() {
74 return this.getId() == null;
75 }
76 }