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
This commit is contained in:
Steven van Beelen 2018-12-18 14:49:30 +01:00
parent 11b1112771
commit 3553fb7506
4 changed files with 90 additions and 16 deletions

View File

@ -1,24 +1,42 @@
package com.baeldung.axon.commands;
import java.util.Objects;
import org.axonframework.commandhandling.TargetAggregateIdentifier;
import org.axonframework.modelling.command.TargetAggregateIdentifier;
public class CreateMessageCommand {
@TargetAggregateIdentifier
private final String id;
private final String text;
public CreateMessageCommand(String id, String text) {
this.id = id;
this.text = text;
}
public String getId() {
return id;
}
public String getText() {
return text;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CreateMessageCommand that = (CreateMessageCommand) o;
return Objects.equals(id, that.id) && Objects.equals(text, that.text);
}
@Override
public int hashCode() {
return Objects.hash(id, text);
}
}

View File

@ -1,18 +1,36 @@
package com.baeldung.axon.commands;
import java.util.Objects;
import org.axonframework.commandhandling.TargetAggregateIdentifier;
import org.axonframework.modelling.command.TargetAggregateIdentifier;
public class MarkReadMessageCommand {
@TargetAggregateIdentifier
private final String id;
public MarkReadMessageCommand(String id) {
this.id = id;
}
public String getId() {
return id;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MarkReadMessageCommand that = (MarkReadMessageCommand) o;
return Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}

View File

@ -1,20 +1,39 @@
package com.baeldung.axon.events;
import java.util.Objects;
public class MessageCreatedEvent {
private final String id;
private final String text;
public MessageCreatedEvent(String id, String text) {
this.id = id;
this.text = text;
}
public String getId() {
return id;
}
public String getText() {
return text;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MessageCreatedEvent that = (MessageCreatedEvent) o;
return Objects.equals(id, that.id) && Objects.equals(text, that.text);
}
@Override
public int hashCode() {
return Objects.hash(id, text);
}
}

View File

@ -1,14 +1,33 @@
package com.baeldung.axon.events;
import java.util.Objects;
public class MessageReadEvent {
private final String id;
public MessageReadEvent(String id) {
this.id = id;
}
public String getId() {
return id;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MessageReadEvent that = (MessageReadEvent) o;
return Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}