Skip to content

Commit 3553fb7

Browse files
committed
BAEL-2435 Update commands and events
-Change TargetAggregateIdentifier import statement to the new location -Add equals/hashcode as best practice for commands and events -Add description -Change parent to parent-boot-2 to leverage a spring boot start up approach
1 parent 11b1112 commit 3553fb7

4 files changed

Lines changed: 90 additions & 16 deletions

File tree

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
package com.baeldung.axon.commands;
22

3+
import java.util.Objects;
34

4-
import org.axonframework.commandhandling.TargetAggregateIdentifier;
5+
import org.axonframework.modelling.command.TargetAggregateIdentifier;
56

67
public class CreateMessageCommand {
7-
8+
89
@TargetAggregateIdentifier
910
private final String id;
1011
private final String text;
11-
12+
1213
public CreateMessageCommand(String id, String text) {
1314
this.id = id;
1415
this.text = text;
1516
}
16-
17+
1718
public String getId() {
1819
return id;
1920
}
20-
21+
2122
public String getText() {
2223
return text;
2324
}
25+
26+
@Override
27+
public boolean equals(Object o) {
28+
if (this == o) {
29+
return true;
30+
}
31+
if (o == null || getClass() != o.getClass()) {
32+
return false;
33+
}
34+
CreateMessageCommand that = (CreateMessageCommand) o;
35+
return Objects.equals(id, that.id) && Objects.equals(text, that.text);
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return Objects.hash(id, text);
41+
}
2442
}
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
package com.baeldung.axon.commands;
22

3+
import java.util.Objects;
34

4-
import org.axonframework.commandhandling.TargetAggregateIdentifier;
5+
import org.axonframework.modelling.command.TargetAggregateIdentifier;
56

67
public class MarkReadMessageCommand {
7-
8+
89
@TargetAggregateIdentifier
910
private final String id;
10-
11+
1112
public MarkReadMessageCommand(String id) {
1213
this.id = id;
1314
}
14-
15+
1516
public String getId() {
1617
return id;
1718
}
19+
20+
@Override
21+
public boolean equals(Object o) {
22+
if (this == o) {
23+
return true;
24+
}
25+
if (o == null || getClass() != o.getClass()) {
26+
return false;
27+
}
28+
MarkReadMessageCommand that = (MarkReadMessageCommand) o;
29+
return Objects.equals(id, that.id);
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return Objects.hash(id);
35+
}
1836
}
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
package com.baeldung.axon.events;
22

3+
import java.util.Objects;
4+
35
public class MessageCreatedEvent {
4-
6+
57
private final String id;
68
private final String text;
7-
9+
810
public MessageCreatedEvent(String id, String text) {
911
this.id = id;
1012
this.text = text;
1113
}
12-
14+
1315
public String getId() {
1416
return id;
1517
}
16-
18+
1719
public String getText() {
1820
return text;
1921
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) {
26+
return true;
27+
}
28+
if (o == null || getClass() != o.getClass()) {
29+
return false;
30+
}
31+
MessageCreatedEvent that = (MessageCreatedEvent) o;
32+
return Objects.equals(id, that.id) && Objects.equals(text, that.text);
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(id, text);
38+
}
2039
}
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
package com.baeldung.axon.events;
22

3+
import java.util.Objects;
4+
35
public class MessageReadEvent {
4-
6+
57
private final String id;
6-
8+
79
public MessageReadEvent(String id) {
810
this.id = id;
911
}
10-
12+
1113
public String getId() {
1214
return id;
1315
}
16+
17+
@Override
18+
public boolean equals(Object o) {
19+
if (this == o) {
20+
return true;
21+
}
22+
if (o == null || getClass() != o.getClass()) {
23+
return false;
24+
}
25+
MessageReadEvent that = (MessageReadEvent) o;
26+
return Objects.equals(id, that.id);
27+
}
28+
29+
@Override
30+
public int hashCode() {
31+
return Objects.hash(id);
32+
}
1433
}

0 commit comments

Comments
 (0)