|
|
@@ -22,11 +22,17 @@ public class CargoRepositoryHibernate extends HibernateRepository implements Car
|
|
22
|
22
|
// Query for id and then perform a standard load()
|
|
23
|
23
|
// to use metadata-defined query and lazy proxy access
|
|
24
|
24
|
Long id = (Long) getSession().
|
|
25
|
|
- createQuery("select id from Cargo where trackingId = :tid").
|
|
26
|
|
- setParameter("tid", tid).
|
|
27
|
|
- uniqueResult();
|
|
|
25
|
+ createQuery("select id from Cargo where trackingId = :tid").
|
|
|
26
|
+ setParameter("tid", tid).
|
|
|
27
|
+ uniqueResult();
|
|
|
28
|
+
|
|
|
29
|
+ if (id != null) {
|
|
|
30
|
+ return (Cargo) getSession().get(Cargo.class, id);
|
|
|
31
|
+ } else {
|
|
|
32
|
+ return null;
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
28
|
35
|
|
|
29
|
|
- return (Cargo) getSession().load(Cargo.class, id);
|
|
30
|
36
|
}
|
|
31
|
37
|
|
|
32
|
38
|
public void save(Cargo cargo) {
|
|
|
@@ -35,8 +41,8 @@ public class CargoRepositoryHibernate extends HibernateRepository implements Car
|
|
35
|
41
|
// Delete orphaned itineraries - conceptually the responsibility
|
|
36
|
42
|
// of the Cargo aggregate
|
|
37
|
43
|
final List<Itinerary> orphans = getSession().
|
|
38
|
|
- createQuery("from Itinerary where cargo = null").
|
|
39
|
|
- list();
|
|
|
44
|
+ createQuery("from Itinerary where cargo = null").
|
|
|
45
|
+ list();
|
|
40
|
46
|
for (Itinerary orphan : orphans) {
|
|
41
|
47
|
getSession().delete(orphan);
|
|
42
|
48
|
}
|
|
|
@@ -45,7 +51,7 @@ public class CargoRepositoryHibernate extends HibernateRepository implements Car
|
|
45
|
51
|
public TrackingId nextTrackingId() {
|
|
46
|
52
|
final String random = UUID.randomUUID().toString().toUpperCase();
|
|
47
|
53
|
return new TrackingId(
|
|
48
|
|
- random.substring(0, random.indexOf("-"))
|
|
|
54
|
+ random.substring(0, random.indexOf("-"))
|
|
49
|
55
|
);
|
|
50
|
56
|
}
|
|
51
|
57
|
|