| 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 | /* package-private */ | |
| 64 | /** | |
| 65 | * Required by Hibernate. | |
| 66 | */ | |
| 67 | @SuppressWarnings("NullAway") | |
| 68 | StoredEvent() { | |
| 69 | // Intentionally empty | |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * Gives the ID of this {@code StoredEvent}. Note that this is not the same as the ID of the domain event itself. | |
| 74 | * | |
| 75 | * @return the ID of this {@code StoredEvent} | |
| 76 | */ | |
| 77 | public @Nullable Long id() { | |
| 78 |
1
1. id : replaced Long return value with 0L for com/reallifedeveloper/common/application/eventstore/StoredEvent::id → KILLED |
return id; |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Gives the class name of the domain event represented by this {@code StoredEvent}. | |
| 83 | * | |
| 84 | * @return the class name of the domain event | |
| 85 | */ | |
| 86 | public String eventType() { | |
| 87 |
1
1. eventType : replaced return value with "" for com/reallifedeveloper/common/application/eventstore/StoredEvent::eventType → KILLED |
return eventType; |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * Gives the string representation of the domain event represented by this {@code StoredEvent}. | |
| 92 | * | |
| 93 | * @return a string representation of the domain event | |
| 94 | */ | |
| 95 | public String eventBody() { | |
| 96 |
1
1. eventBody : replaced return value with "" for com/reallifedeveloper/common/application/eventstore/StoredEvent::eventBody → KILLED |
return eventBody; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Gives the date and time the domain event represented by this {@code StoredEvent} occurred. | |
| 101 | * | |
| 102 | * @return the date and time the domain event occurred | |
| 103 | */ | |
| 104 | public ZonedDateTime occurredOn() { | |
| 105 |
1
1. occurredOn : replaced return value with null for com/reallifedeveloper/common/application/eventstore/StoredEvent::occurredOn → KILLED |
return occurredOn; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * Gives the version of the domain event represented by this {@code StoredEvent}. | |
| 110 | * | |
| 111 | * @return the version of the domain event | |
| 112 | */ | |
| 113 | public Integer version() { | |
| 114 |
1
1. version : replaced Integer return value with 0 for com/reallifedeveloper/common/application/eventstore/StoredEvent::version → KILLED |
return version; |
| 115 | } | |
| 116 | ||
| 117 | @Override | |
| 118 | public String toString() { | |
| 119 |
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() |
| 120 | + ", version=" + version() + "}"; | |
| 121 | } | |
| 122 | ||
| 123 | } | |
Mutations | ||
| 55 |
1.1 |
|
| 78 |
1.1 |
|
| 87 |
1.1 |
|
| 96 |
1.1 |
|
| 105 |
1.1 |
|
| 114 |
1.1 |
|
| 119 |
1.1 |