|
|
@@ -2,10 +2,11 @@ package se.citerus.dddsample.tracking.core.domain.patterns.valueobject;
|
|
2
|
2
|
|
|
3
|
3
|
import org.apache.commons.lang.builder.EqualsBuilder;
|
|
4
|
4
|
import org.apache.commons.lang.builder.HashCodeBuilder;
|
|
|
5
|
+import static se.citerus.dddsample.tracking.core.domain.patterns.OrmUtils.unwrapOrmProxy;
|
|
5
|
6
|
|
|
6
|
7
|
/**
|
|
7
|
8
|
* Supporting base class for value objects.
|
|
8
|
|
- *
|
|
|
9
|
+ * <p/>
|
|
9
|
10
|
* While the ValueObject interface makes the pattern properties explicit,
|
|
10
|
11
|
* this class is less general and is suited for this particular application.
|
|
11
|
12
|
* </p>
|
|
|
@@ -21,7 +22,7 @@ public abstract class ValueObjectSupport<T extends ValueObject> implements Value
|
|
21
|
22
|
@SuppressWarnings("UnusedDeclaration")
|
|
22
|
23
|
private final Long _primaryKey = null;
|
|
23
|
24
|
private transient int _cachedHashCode = 0;
|
|
24
|
|
- private final static String[] EXCLUDED_FIELDS = {"_primaryKey", "_cachedHashCode"};
|
|
|
25
|
+ private static final String[] EXCLUDED_FIELDS = {"_primaryKey", "_cachedHashCode"};
|
|
25
|
26
|
|
|
26
|
27
|
/**
|
|
27
|
28
|
* @param other The other value object.
|
|
|
@@ -29,7 +30,7 @@ public abstract class ValueObjectSupport<T extends ValueObject> implements Value
|
|
29
|
30
|
*/
|
|
30
|
31
|
@Override
|
|
31
|
32
|
public final boolean sameValueAs(final T other) {
|
|
32
|
|
- return other != null && EqualsBuilder.reflectionEquals(this, other, EXCLUDED_FIELDS);
|
|
|
33
|
+ return other != null && EqualsBuilder.reflectionEquals(unwrapOrmProxy(this), unwrapOrmProxy(other), EXCLUDED_FIELDS);
|
|
33
|
34
|
}
|
|
34
|
35
|
|
|
35
|
36
|
/**
|
|
|
@@ -56,16 +57,17 @@ public abstract class ValueObjectSupport<T extends ValueObject> implements Value
|
|
56
|
57
|
}
|
|
57
|
58
|
|
|
58
|
59
|
/**
|
|
59
|
|
- * @param o other object
|
|
|
60
|
+ * @param other other object
|
|
60
|
61
|
* @return True if other object has the same value as this value object.
|
|
61
|
62
|
*/
|
|
62
|
|
- @SuppressWarnings({"SimplifiableIfStatement", "unchecked"})
|
|
|
63
|
+ @SuppressWarnings({"SimplifiableIfStatement", "unchecked", "EqualsWhichDoesntCheckParameterClass"})
|
|
63
|
64
|
@Override
|
|
64
|
|
- public final boolean equals(final Object o) {
|
|
65
|
|
- if (this == o) return true;
|
|
66
|
|
- if (o == null || getClass() != o.getClass()) return false;
|
|
|
65
|
+ public final boolean equals(final Object other) {
|
|
|
66
|
+ if (other == null) return false;
|
|
|
67
|
+ if (this == other) return true;
|
|
|
68
|
+ if (unwrapOrmProxy(this).getClass() != unwrapOrmProxy(other).getClass()) return false;
|
|
67
|
69
|
|
|
68
|
|
- return sameValueAs((T) o);
|
|
|
70
|
+ return sameValueAs((T) other);
|
|
69
|
71
|
}
|
|
70
|
72
|
|
|
71
|
73
|
}
|