1 | package com.reallifedeveloper.common.application.eventstore; | |
2 | ||
3 | import java.time.ZonedDateTime; | |
4 | ||
5 | import org.checkerframework.checker.nullness.qual.Nullable; | |
6 | ||
7 | import jakarta.persistence.Column; | |
8 | import jakarta.persistence.Entity; | |
9 | import jakarta.persistence.GeneratedValue; | |
10 | import jakarta.persistence.GenerationType; | |
11 | import jakarta.persistence.Id; | |
12 | import jakarta.persistence.Table; | |
13 | ||
14 | import com.reallifedeveloper.common.domain.ErrorHandling; | |
15 | ||
16 | /** | |
17 | * A representation of a {@link com.reallifedeveloper.common.domain.event.DomainEvent} that can be stored in a database. | |
18 | * | |
19 | * @author RealLifeDeveloper | |
20 | */ | |
21 | @Entity | |
22 | @Table(name = "stored_event") | |
23 | public class StoredEvent { | |
24 | ||
25 | private static final int MAX_EVENT_BODY_LENGTH = 8000; | |
26 | ||
27 | @Id | |
28 | @GeneratedValue(strategy = GenerationType.AUTO) | |
29 | @Column(name = "stored_event_id") | |
30 | private @Nullable Long id; | |
31 | ||
32 | @Column(name = "event_type", nullable = false) | |
33 | private String eventType; | |
34 | ||
35 | @Column(name = "event_body", length = MAX_EVENT_BODY_LENGTH, nullable = false) | |
36 | private String eventBody; | |
37 | ||
38 | @Column(name = "occurred_on", nullable = false) | |
39 | private ZonedDateTime occurredOn; | |
40 | ||
41 | @Column(name = "version", nullable = false) | |
42 | private Integer version; | |
43 | ||
44 | /** | |
45 | * Creates a new {@code StoredEvent} with the given attributes. | |
46 | * | |
47 | * @param eventType the class name of the domain event, as given by {@code event.getClass().getName()} | |
48 | * @param eventBody a string representation of the domain event | |
49 | * @param occurredOn the date and time the domain event occurred | |
50 | * @param version the version of the domain event | |
51 | * | |
52 | * @throws IllegalArgumentException if any argument is {@code null} | |
53 | */ | |
54 | public StoredEvent(String eventType, String eventBody, ZonedDateTime occurredOn, int version) { | |
55 |
1
1. <init> : removed call to com/reallifedeveloper/common/domain/ErrorHandling::checkNull → KILLED |
ErrorHandling.checkNull("Arguments must not be null: eventType=%s, eventBody=%s, occurredOn=%s, version=" + version, eventType, |
56 | eventBody, occurredOn); | |
57 | this.eventType = eventType; | |
58 | this.eventBody = eventBody; | |
59 | this.occurredOn = occurredOn; | |
60 | this.version = version; | |
61 | } | |
62 | ||
63 | /** | |
64 | * Required by Hibernate. | |
65 | */ | |
66 | /* package-private */ StoredEvent() { | |
67 | // Intentionally empty | |
68 | } | |
69 | ||
70 | /** | |
71 | * Gives the ID of this {@code StoredEvent}. Note that this is not the same as the ID of the domain event itself. | |
72 | * | |
73 | * @return the ID of this {@code StoredEvent} | |
74 | */ | |
75 | public @Nullable Long id() { | |
76 |
1
1. id : replaced Long return value with 0L for com/reallifedeveloper/common/application/eventstore/StoredEvent::id → KILLED |
return id; |
77 | } | |
78 | ||
79 | /** | |
80 | * Gives the class name of the domain event represented by this {@code StoredEvent}. | |
81 | * | |
82 | * @return the class name of the domain event | |
83 | */ | |
84 | public String eventType() { | |
85 |
1
1. eventType : replaced return value with "" for com/reallifedeveloper/common/application/eventstore/StoredEvent::eventType → KILLED |
return eventType; |
86 | } | |
87 | ||
88 | /** | |
89 | * Gives the string representation of the domain event represented by this {@code StoredEvent}. | |
90 | * | |
91 | * @return a string representation of the domain event | |
92 | */ | |
93 | public String eventBody() { | |
94 |
1
1. eventBody : replaced return value with "" for com/reallifedeveloper/common/application/eventstore/StoredEvent::eventBody → KILLED |
return eventBody; |
95 | } | |
96 | ||
97 | /** | |
98 | * Gives the date and time the domain event represented by this {@code StoredEvent} occurred. | |
99 | * | |
100 | * @return the date and time the domain event occurred | |
101 | */ | |
102 | public ZonedDateTime occurredOn() { | |
103 |
1
1. occurredOn : replaced return value with null for com/reallifedeveloper/common/application/eventstore/StoredEvent::occurredOn → KILLED |
return occurredOn; |
104 | } | |
105 | ||
106 | /** | |
107 | * Gives the version of the domain event represented by this {@code StoredEvent}. | |
108 | * | |
109 | * @return the version of the domain event | |
110 | */ | |
111 | public Integer version() { | |
112 |
1
1. version : replaced Integer return value with 0 for com/reallifedeveloper/common/application/eventstore/StoredEvent::version → KILLED |
return version; |
113 | } | |
114 | ||
115 | @Override | |
116 | public String toString() { | |
117 |
1
1. toString : replaced return value with "" for com/reallifedeveloper/common/application/eventstore/StoredEvent::toString → KILLED |
return "StoredEvent{id=" + id() + ", eventType=" + eventType() + ", eventBody=" + eventBody() + ", occurredOn=" + occurredOn() |
118 | + ", version=" + version() + "}"; | |
119 | } | |
120 | ||
121 | } | |
Mutations | ||
55 |
1.1 |
|
76 |
1.1 |
|
85 |
1.1 |
|
94 |
1.1 |
|
103 |
1.1 |
|
112 |
1.1 |
|
117 |
1.1 |