Просмотр исходного кода

Encapsulated fields in pattern support classes to avoid name clashes (using "_primaryKey" instead of "id"). Fixed hbm files to reflect change.

Removed unused DomanObjectUtils class.
peter_backlund 17 лет назад
Родитель
Сommit
e4a7fe2fbe

+ 1
- 2
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEvent.java Просмотреть файл

@@ -7,7 +7,6 @@ import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
7 7
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
8 8
 import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
9 9
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
10
-import se.citerus.dddsample.tracking.core.domain.patterns.DomainObjectUtils;
11 10
 import se.citerus.dddsample.tracking.core.domain.patterns.domainevent.DomainEvent;
12 11
 import se.citerus.dddsample.tracking.core.domain.patterns.valueobject.ValueObject;
13 12
 
@@ -159,7 +158,7 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
159 158
   }
160 159
 
161 160
   public Voyage voyage() {
162
-    return DomainObjectUtils.nullSafe(activity.voyage(), Voyage.NONE);
161
+    return activity.voyage() != null ? activity.voyage() : Voyage.NONE;
163 162
   }
164 163
 
165 164
   public Date completionTime() {

+ 1
- 3
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/voyage/Voyage.java Просмотреть файл

@@ -17,9 +17,7 @@ public class Voyage extends EntitySupport<Voyage,VoyageNumber> {
17 17
   private Schedule schedule;
18 18
 
19 19
   // Null object pattern
20
-  public static final Voyage NONE = new Voyage(
21
-    new VoyageNumber(""), Schedule.EMPTY
22
-  );
20
+  public static final Voyage NONE = new Voyage(new VoyageNumber(""), Schedule.EMPTY);
23 21
 
24 22
   public Voyage(final VoyageNumber voyageNumber, final Schedule schedule) {
25 23
     Validate.notNull(voyageNumber, "Voyage number is required");

+ 0
- 29
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/patterns/DomainObjectUtils.java Просмотреть файл

@@ -1,29 +0,0 @@
1
-package se.citerus.dddsample.tracking.core.domain.patterns;
2
-
3
-/**
4
- * Utility code for domain classes.
5
- */
6
-public class DomainObjectUtils {
7
-
8
-  /**
9
-   * @param actual actual value
10
-   * @param safe   a null-safe value
11
-   * @param <T>    type
12
-   * @return actual value, if it's not null, or safe value if the actual value is null.
13
-   */
14
-  public static <T> T nullSafe(T actual, T safe) {
15
-    return actual == null ? safe : actual;
16
-  }
17
-
18
-  // TODO wrappers for some of the commons-lang code:
19
-  //
20
-  // EqualsBuilder that uses sameIdentity/sameValue,
21
-  // better validation (varargs etc) 
22
-
23
-  /**
24
-   * Prevent instantiation.
25
-   */
26
-  private DomainObjectUtils() {
27
-  }
28
-
29
-}

+ 3
- 4
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/patterns/entity/EntitySupport.java Просмотреть файл

@@ -10,6 +10,9 @@ package se.citerus.dddsample.tracking.core.domain.patterns.entity;
10 10
  */
11 11
 public abstract class EntitySupport<T extends Entity, ID> implements Entity<T, ID> {
12 12
 
13
+  @SuppressWarnings("UnusedDeclaration")
14
+  private final Long _primaryKey = null;
15
+  
13 16
   @Override
14 17
   public final boolean sameAs(final T other) {
15 18
     return other != null && this.identity().equals(other.identity());
@@ -31,8 +34,4 @@ public abstract class EntitySupport<T extends Entity, ID> implements Entity<T, I
31 34
     return sameAs((T) o);
32 35
   }
33 36
 
34
-  @SuppressWarnings("UnusedDeclaration")
35
-  // Surrogate primary key
36
-  private Long id;
37
-
38 37
 }

+ 7
- 7
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/patterns/valueobject/ValueObjectSupport.java Просмотреть файл

@@ -19,9 +19,9 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
19 19
 public abstract class ValueObjectSupport<T extends ValueObject> implements ValueObject<T> {
20 20
 
21 21
   @SuppressWarnings("UnusedDeclaration")
22
-  private final Long id = null;
23
-  private transient int cachedHashCode = 0;
24
-  private final static String[] EXCLUDED_FIELDS = {"id", "cachedHashCode"};
22
+  private final Long _primaryKey = null;
23
+  private transient int _cachedHashCode = 0;
24
+  private final static String[] EXCLUDED_FIELDS = {"_primaryKey", "_cachedHashCode"};
25 25
 
26 26
   /**
27 27
    * @param other The other value object.
@@ -38,18 +38,18 @@ public abstract class ValueObjectSupport<T extends ValueObject> implements Value
38 38
   @Override
39 39
   public final int hashCode() {
40 40
     // Using a local variable to ensure that we only do a single read
41
-    // of the cachedHashCode field, to avoid race conditions.
41
+    // of the _cachedHashCode field, to avoid race conditions.
42 42
     // It doesn't matter if several threads compute the hash code and overwrite
43 43
     // each other, but it's important that we never return 0, which could happen
44
-    // with multiple reads of the cachedHashCode field.
44
+    // with multiple reads of the _cachedHashCode field.
45 45
     //
46 46
     // See java.lang.String.hashCode()
47
-    int h = cachedHashCode;
47
+    int h = _cachedHashCode;
48 48
     if (h == 0) {
49 49
       // Lazy initialization of hash code.
50 50
       // Value objects are immutable, so the hash code never changes.
51 51
       h = HashCodeBuilder.reflectionHashCode(this, false);
52
-      cachedHashCode = h;
52
+      _cachedHashCode = h;
53 53
     }
54 54
 
55 55
     return h;

+ 1
- 1
dddsample/tracking/core/src/main/resources/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/Cargo.hbm.xml Просмотреть файл

@@ -7,7 +7,7 @@
7 7
 <hibernate-mapping default-access="field">
8 8
   <class name="se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo" table="Cargo">
9 9
 
10
-    <id name="id" column="id">
10
+    <id name="_primaryKey" column="id">
11 11
       <generator class="org.hibernate.id.IdentityGenerator"/>
12 12
     </id>
13 13
 

+ 1
- 1
dddsample/tracking/core/src/main/resources/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/CarrierMovement.hbm.xml Просмотреть файл

@@ -7,7 +7,7 @@
7 7
 <hibernate-mapping default-access="field">
8 8
   <class name="se.citerus.dddsample.tracking.core.domain.model.voyage.CarrierMovement" table="CarrierMovement" mutable="false">
9 9
 
10
-    <id name="id" column="id">
10
+    <id name="_primaryKey" column="id">
11 11
       <generator class="org.hibernate.id.IdentityGenerator"/>
12 12
     </id>
13 13
 

+ 1
- 1
dddsample/tracking/core/src/main/resources/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/Leg.hbm.xml Просмотреть файл

@@ -6,7 +6,7 @@
6 6
 
7 7
 <hibernate-mapping default-access="field">
8 8
   <class name="se.citerus.dddsample.tracking.core.domain.model.cargo.Leg" table="Leg" mutable="false">
9
-    <id name="id" column="id">
9
+    <id name="_primaryKey" column="id">
10 10
       <generator class="org.hibernate.id.IdentityGenerator"/>
11 11
     </id>
12 12
 

+ 1
- 1
dddsample/tracking/core/src/main/resources/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/Location.hbm.xml Просмотреть файл

@@ -6,7 +6,7 @@
6 6
 
7 7
 <hibernate-mapping default-access="field">
8 8
   <class name="se.citerus.dddsample.tracking.core.domain.model.location.Location" table="Location">
9
-    <id name="id" column="id">
9
+    <id name="_primaryKey" column="id">
10 10
       <generator class="org.hibernate.id.IdentityGenerator"/>
11 11
     </id>
12 12
     <component name="unLocode" unique="true" update="false">

+ 1
- 1
dddsample/tracking/core/src/main/resources/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/Voyage.hbm.xml Просмотреть файл

@@ -7,7 +7,7 @@
7 7
 <hibernate-mapping default-access="field">
8 8
   <class name="se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage" table="Voyage">
9 9
 
10
-    <id name="id" column="id">
10
+    <id name="_primaryKey" column="id">
11 11
       <generator class="org.hibernate.id.IdentityGenerator"/>
12 12
     </id>
13 13