Skip to content

Commit

Permalink
fix(citrus-spring-boot-simulator): add database indexes on frequently…
Browse files Browse the repository at this point in the history
… visited columns

Signed-off-by: Timon Borter <[email protected]>
  • Loading branch information
bbortt committed Apr 12, 2024
1 parent 030cf56 commit d024379
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.io.Serializable;
Expand All @@ -44,13 +46,24 @@

import static java.util.Arrays.stream;
import static lombok.AccessLevel.NONE;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;

/**
* JPA entity for representing inbound and outbound messages
*/
@Getter
@Setter
@Entity
@Table(
name = "message",
indexes = {
@Index(name = "idx_message_direction", columnList = "direction"),
@Index(name = "idx_message_scenario_execution_execution_id", columnList = "scenario_execution_execution_id")
},
uniqueConstraints = {
@UniqueConstraint(name = "uk_citrus_message_id", columnNames = {"citrus_message_id"})
}
)
@ToString
public class Message extends AbstractAuditingEntity<Message, Long> implements Serializable {

Expand Down Expand Up @@ -106,9 +119,10 @@ public void setDirection(Direction direction) {
this.direction = direction.id;
}

public void addHeader(MessageHeader messageHeader) {
public Message addHeader(MessageHeader messageHeader) {
headers.add(messageHeader);
messageHeader.setMessage(this);
return this;
}

public Long getScenarioExecutionId() {
Expand Down Expand Up @@ -197,7 +211,7 @@ public MessageBuilder headers(Map<String, Object> headers) {
headers.entrySet().stream()
.map(header -> {
if (header.getValue() != null
&& StringUtils.isNotEmpty(header.getValue().toString())) {
&& isNotEmpty(header.getValue().toString())) {
return new MessageHeader(header.getKey(), header.getValue().toString());
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2023 the original author or authors.
* Copyright 2006-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,10 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
Expand All @@ -43,6 +45,14 @@
@Getter
@Setter
@Entity
@Table(
name = "message_header",
indexes = {
@Index(name = "idx_message_header_name", columnList = "name"),
@Index(name = "idx_message_header_value", columnList = "header_value"),
@Index(name = "idx_message_id", columnList = "message_id")
}
)
@ToString
public class MessageHeader extends AbstractAuditingEntity<MessageHeader, Long> implements Serializable {

Expand All @@ -66,7 +76,7 @@ public class MessageHeader extends AbstractAuditingEntity<MessageHeader, Long> i
@NotNull
@ToString.Exclude
@ManyToOne(optional = false)
@JoinColumn(nullable = false)
@JoinColumn(name = "message_id", nullable = false)
@JsonIgnoreProperties(value = {"headers", "scenarioExecution"}, allowSetters = true)
private Message message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -40,6 +42,12 @@
@Getter
@Setter
@Entity
@Table(
name = "scenario_action",
indexes = {
@Index(name = "idx_scenario_action_scenario_execution_execution_id", columnList = "scenario_execution_execution_id")
}
)
@ToString
public class ScenarioAction implements Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand All @@ -48,6 +50,14 @@
@Getter
@Setter
@Entity
@Table(
name = "scenario_execution",
indexes = {
@Index(name = "idx_scenario_execution_scenario_name", columnList = "scenario_name"),
@Index(name = "idx_scenario_execution_start_date", columnList = "start_date"),
@Index(name = "idx_scenario_execution_status", columnList = "status"),
}
)
@ToString
public class ScenarioExecution implements Serializable {

Expand Down Expand Up @@ -119,19 +129,22 @@ public void setErrorMessage(String errorMessage) {
this.errorMessage = EntityUtils.truncateToColumnSize(getClass(), "errorMessage", errorMessage);
}

public void addScenarioParameter(ScenarioParameter scenarioParameter) {
public ScenarioExecution addScenarioParameter(ScenarioParameter scenarioParameter) {
scenarioParameters.add(scenarioParameter);
scenarioParameter.setScenarioExecution(this);
return this;
}

public void addScenarioAction(ScenarioAction scenarioAction) {
public ScenarioExecution addScenarioAction(ScenarioAction scenarioAction) {
scenarioActions.add(scenarioAction);
scenarioAction.setScenarioExecution(this);
return this;
}

public void addScenarioMessage(Message scenarioMessage) {
public ScenarioExecution addScenarioMessage(Message scenarioMessage) {
scenarioMessages.add(scenarioMessage);
scenarioMessage.setScenarioExecution(this);
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
Expand All @@ -45,6 +47,12 @@
@Getter
@Setter
@Entity
@Table(
name = "scenario_parameter",
indexes = {
@Index(name = "idx_scenario_parameter_scenario_execution_execution_id", columnList = "scenario_execution_execution_id")
}
)
@ToString
public class ScenarioParameter extends AbstractAuditingEntity<ScenarioParameter, Long> implements Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import jakarta.persistence.Embeddable;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapsId;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
Expand Down Expand Up @@ -57,6 +59,12 @@
@Getter
@Setter
@Entity
@Table(
name="test_parameter",
indexes = {
@Index(name="idx_test_parameter_test_result_id", columnList = "test_result_id")
}
)
@ToString
public class TestParameter extends AbstractAuditingEntity<TestParameter, TestParameter.TestParameterId> implements Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Getter;
Expand Down Expand Up @@ -56,6 +58,14 @@
@Getter
@Setter
@Entity
@Table(
name = "test_result",
indexes = {
@Index(name = "idx_failure_type", columnList = "failure_type"),
@Index(name = "idx_test_result_class_name", columnList = "class_name"),
@Index(name = "idx_test_result_test_name", columnList = "test_name")
}
)
@ToString
public class TestResult extends AbstractAuditingEntity<TestResult, Long> implements Serializable {

Expand Down Expand Up @@ -152,8 +162,10 @@ public Status getStatus() {
return Status.fromId(status);
}

public void addTestParameter(TestParameter testParameter) {
public TestResult addTestParameter(TestParameter testParameter) {
testParameters.add(testParameter);
testParameter.setTestResult(this);
return this;
}

private int convertToStatus(String resultName) {
Expand Down

0 comments on commit d024379

Please sign in to comment.