瀏覽代碼

A few minor method name changes and documentation imrpovements

peter_backlund 17 年之前
父節點
當前提交
cd3020da7a
共有 16 個文件被更改,包括 32 次插入32 次删除
  1. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/application/impl/BookingServiceImpl.java
  2. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/application/impl/HandlingEventServiceImpl.java
  3. 4
    6
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/CargoRepository.java
  4. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Delivery.java
  5. 5
    6
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactory.java
  6. 5
    4
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventRepository.java
  7. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryHibernate.java
  8. 4
    2
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryHibernate.java
  9. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/facade/internal/BookingServiceFacadeImpl.java
  10. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/application/BookingServiceTest.java
  11. 2
    2
      dddsample/src/test/java/se/citerus/dddsample/application/HandlingEventServiceTest.java
  12. 2
    2
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java
  13. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java
  14. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/CargoRepositoryInMem.java
  15. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/HandlingEventRepositoryInMem.java
  16. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/scenario/CargoLifecycleScenarioTest.java

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/application/impl/BookingServiceImpl.java 查看文件

46
 
46
 
47
     final Cargo cargo = new Cargo(trackingId, origin, routeSpecification);
47
     final Cargo cargo = new Cargo(trackingId, origin, routeSpecification);
48
 
48
 
49
-    cargoRepository.save(cargo);
49
+    cargoRepository.store(cargo);
50
     logger.info("Booked new cargo with tracking id " + cargo.trackingId().idString());
50
     logger.info("Booked new cargo with tracking id " + cargo.trackingId().idString());
51
 
51
 
52
     return cargo.trackingId();
52
     return cargo.trackingId();

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/application/impl/HandlingEventServiceImpl.java 查看文件

43
          state of the handling event aggregate (but not the cargo aggregate -
43
          state of the handling event aggregate (but not the cargo aggregate -
44
          that happens asynchronously!)
44
          that happens asynchronously!)
45
        */
45
        */
46
-      handlingEventRepository.save(event);
46
+      handlingEventRepository.store(event);
47
 
47
 
48
       /* Publish an event stating that a cargo has been handled. */
48
       /* Publish an event stating that a cargo has been handled. */
49
       applicationEvents.cargoWasHandled(event);
49
       applicationEvents.cargoWasHandled(event);

+ 4
- 6
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/CargoRepository.java 查看文件

24
    *
24
    *
25
    * @param cargo cargo to save
25
    * @param cargo cargo to save
26
    */
26
    */
27
-  void save(Cargo cargo);
27
+  void store(Cargo cargo);
28
 
28
 
29
   /**
29
   /**
30
-   * TODO
31
-   * this might be too complex a procedure to belong in the repository -
32
-   * introduce a TrackingIdFactory (or perhaps a CargoFactory).
33
-   *
34
-   * @return A new generated tracking Id.
30
+   * @return A unique, generated tracking Id.
35
    */
31
    */
36
   TrackingId nextTrackingId();
32
   TrackingId nextTrackingId();
37
 
33
 
34
+  // TODO perhaps it belongs in a factory instead
35
+
38
 }
36
 }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Delivery.java 查看文件

117
     }
117
     }
118
   }
118
   }
119
 
119
 
120
-  // TODO add currentCarrierMovement
120
+  // TODO add currentCarrierMovement (?)
121
 
121
 
122
   private void calculateCurrentVoyage() {
122
   private void calculateCurrentVoyage() {
123
     if (transportStatus().equals(ONBOARD_CARRIER) && lastEvent != null) {
123
     if (transportStatus().equals(ONBOARD_CARRIER) && lastEvent != null) {

+ 5
- 6
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactory.java 查看文件

31
   }
31
   }
32
 
32
 
33
   /**
33
   /**
34
+   * @param registrationTime  time when this event was received by the system
34
    * @param completionTime    when the event was completed, for example finished loading
35
    * @param completionTime    when the event was completed, for example finished loading
35
-   * @param trackingId        tracking id
36
+   * @param trackingId        cargo tracking id
36
    * @param voyageNumber      voyage number
37
    * @param voyageNumber      voyage number
37
    * @param unlocode          United Nations Location Code for the location of the event
38
    * @param unlocode          United Nations Location Code for the location of the event
38
    * @param type              type of event
39
    * @param type              type of event
39
-   * @param registrationTime  time when this event was received by the system
40
-   * @throws UnknownVoyageException
41
-   *                                    if there's not carrier movement with this id
42
-   * @throws UnknownCargoException if there's no cargo with this tracking id
43
-   * @throws UnknownLocationException   if there's no location with this UN Locode
40
+   * @throws UnknownVoyageException   if there's no voyage with this number
41
+   * @throws UnknownCargoException    if there's no cargo with this tracking id
42
+   * @throws UnknownLocationException if there's no location with this UN Locode
44
    * @return A handling event.
43
    * @return A handling event.
45
    */
44
    */
46
   public HandlingEvent createHandlingEvent(Date registrationTime, Date completionTime, TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode, HandlingEvent.Type type)
45
   public HandlingEvent createHandlingEvent(Date registrationTime, Date completionTime, TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode, HandlingEvent.Type type)

+ 5
- 4
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventRepository.java 查看文件

10
 public interface HandlingEventRepository {
10
 public interface HandlingEventRepository {
11
 
11
 
12
   /**
12
   /**
13
-   * Saves a (new) handling event.
13
+   * Stores a (new) handling event.
14
    *
14
    *
15
    * @param event handling event to save
15
    * @param event handling event to save
16
    */
16
    */
17
-  void save(final HandlingEvent event);
17
+  void store(HandlingEvent event);
18
 
18
 
19
 
19
 
20
   /**
20
   /**
21
    * @param trackingId cargo tracking id
21
    * @param trackingId cargo tracking id
22
-   * @return All handling events for this cargo, ordered by completion time.
22
+   * @return All handling events for this cargo
23
    */
23
    */
24
-  List<HandlingEvent> findEventsForCargo(final TrackingId trackingId);
24
+  List<HandlingEvent> findEventsForCargo(TrackingId trackingId);
25
+
25
 }
26
 }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryHibernate.java 查看文件

21
       uniqueResult();
21
       uniqueResult();
22
   }
22
   }
23
 
23
 
24
-  public void save(Cargo cargo) {
24
+  public void store(Cargo cargo) {
25
     getSession().persist(cargo);
25
     getSession().persist(cargo);
26
     getSession().createSQLQuery("delete from Leg where cargo_id = null").executeUpdate();
26
     getSession().createSQLQuery("delete from Leg where cargo_id = null").executeUpdate();
27
   }
27
   }

+ 4
- 2
dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryHibernate.java 查看文件

14
 @Repository
14
 @Repository
15
 public class HandlingEventRepositoryHibernate extends HibernateRepository implements HandlingEventRepository {
15
 public class HandlingEventRepositoryHibernate extends HibernateRepository implements HandlingEventRepository {
16
 
16
 
17
-  public void save(HandlingEvent event) {
17
+  @Override
18
+  public void store(HandlingEvent event) {
18
     getSession().save(event);
19
     getSession().save(event);
19
   }
20
   }
20
 
21
 
22
+  @Override
21
   public List<HandlingEvent> findEventsForCargo(TrackingId tid) {
23
   public List<HandlingEvent> findEventsForCargo(TrackingId tid) {
22
     return getSession().createQuery(
24
     return getSession().createQuery(
23
-            "from HandlingEvent where cargo.trackingId = :tid order by completionTime").
25
+            "from HandlingEvent where cargo.trackingId = :tid").
24
             setParameter("tid", tid).
26
             setParameter("tid", tid).
25
             list();
27
             list();
26
   }
28
   }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/facade/internal/BookingServiceFacadeImpl.java 查看文件

68
     }
68
     }
69
 
69
 
70
     cargo.assignToRoute(itinerary);
70
     cargo.assignToRoute(itinerary);
71
-    cargoRepository.save(cargo);
71
+    cargoRepository.store(cargo);
72
 
72
 
73
     logger.info("Assigned cargo " + trackingId + " to new route");
73
     logger.info("Assigned cargo " + trackingId + " to new route");
74
   }
74
   }

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/application/BookingServiceTest.java 查看文件

37
     expect(locationRepository.find(fromUnlocode)).andReturn(CHICAGO);
37
     expect(locationRepository.find(fromUnlocode)).andReturn(CHICAGO);
38
     expect(locationRepository.find(toUnlocode)).andReturn(STOCKHOLM);
38
     expect(locationRepository.find(toUnlocode)).andReturn(STOCKHOLM);
39
 
39
 
40
-    cargoRepository.save(isA(Cargo.class));
40
+    cargoRepository.store(isA(Cargo.class));
41
 
41
 
42
     replay(cargoRepository, locationRepository);
42
     replay(cargoRepository, locationRepository);
43
 
43
 

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/application/HandlingEventServiceTest.java 查看文件

57
     expect(locationRepository.find(unLocode)).andReturn(STOCKHOLM);
57
     expect(locationRepository.find(unLocode)).andReturn(STOCKHOLM);
58
 
58
 
59
     // TODO: does not inspect the handling event instance in a sufficient way
59
     // TODO: does not inspect the handling event instance in a sufficient way
60
-    handlingEventRepository.save(isA(HandlingEvent.class));
60
+    handlingEventRepository.store(isA(HandlingEvent.class));
61
     applicationEvents.cargoWasHandled(isA(HandlingEvent.class));
61
     applicationEvents.cargoWasHandled(isA(HandlingEvent.class));
62
 
62
 
63
     replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
63
     replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
71
     final TrackingId trackingId = new TrackingId("ABC");
71
     final TrackingId trackingId = new TrackingId("ABC");
72
     expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
72
     expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
73
 
73
 
74
-    handlingEventRepository.save(isA(HandlingEvent.class));
74
+    handlingEventRepository.store(isA(HandlingEvent.class));
75
     applicationEvents.cargoWasHandled(isA(HandlingEvent.class));
75
     applicationEvents.cargoWasHandled(isA(HandlingEvent.class));
76
 
76
 
77
     expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
77
     expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java 查看文件

112
     Location destination = locationRepository.find(MELBOURNE.unLocode());
112
     Location destination = locationRepository.find(MELBOURNE.unLocode());
113
 
113
 
114
     Cargo cargo = new Cargo(trackingId, origin, new RouteSpecification(origin, destination, new Date()));
114
     Cargo cargo = new Cargo(trackingId, origin, new RouteSpecification(origin, destination, new Date()));
115
-    cargoRepository.save(cargo);
115
+    cargoRepository.store(cargo);
116
 
116
 
117
     flush();
117
     flush();
118
 
118
 
139
 
139
 
140
     cargo.assignToRoute(newItinerary);
140
     cargo.assignToRoute(newItinerary);
141
 
141
 
142
-    cargoRepository.save(cargo);
142
+    cargoRepository.store(cargo);
143
     flush();
143
     flush();
144
 
144
 
145
     assertEquals(1, sjt.queryForInt("select count(*) from Leg where cargo_id = ?", cargoId));
145
     assertEquals(1, sjt.queryForInt("select count(*) from Leg where cargo_id = ?", cargoId));

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java 查看文件

39
     Date registrationTime = new Date(20);
39
     Date registrationTime = new Date(20);
40
     HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, HandlingEvent.Type.CLAIM, location);
40
     HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, HandlingEvent.Type.CLAIM, location);
41
 
41
 
42
-    handlingEventRepository.save(event);
42
+    handlingEventRepository.store(event);
43
 
43
 
44
     flush();
44
     flush();
45
 
45
 

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/CargoRepositoryInMem.java 查看文件

41
     return cargoDb.get(trackingId.idString());
41
     return cargoDb.get(trackingId.idString());
42
   }
42
   }
43
 
43
 
44
-  public void save(final Cargo cargo) {
44
+  public void store(final Cargo cargo) {
45
     cargoDb.put(cargo.trackingId().idString(), cargo);
45
     cargoDb.put(cargo.trackingId().idString(), cargo);
46
   }
46
   }
47
 
47
 

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/HandlingEventRepositoryInMem.java 查看文件

82
   }
82
   }
83
 
83
 
84
 
84
 
85
-  public void save(HandlingEvent event) {
85
+  public void store(HandlingEvent event) {
86
     eventDB.put(event.cargo().trackingId().idString(), event);
86
     eventDB.put(event.cargo().trackingId().idString(), event);
87
   }
87
   }
88
 
88
 

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/scenario/CargoLifecycleScenarioTest.java 查看文件

238
     handlingEventRepository = new HandlingEventRepository() {
238
     handlingEventRepository = new HandlingEventRepository() {
239
       Map<TrackingId, List<HandlingEvent>> eventMap = new HashMap<TrackingId, List<HandlingEvent>>();
239
       Map<TrackingId, List<HandlingEvent>> eventMap = new HashMap<TrackingId, List<HandlingEvent>>();
240
 
240
 
241
-      public void save(HandlingEvent event) {
241
+      public void store(HandlingEvent event) {
242
         final TrackingId trackingId = event.cargo().trackingId();
242
         final TrackingId trackingId = event.cargo().trackingId();
243
         List<HandlingEvent> list = eventMap.get(trackingId);
243
         List<HandlingEvent> list = eventMap.get(trackingId);
244
         if (list == null) {
244
         if (list == null) {