From dba90f76bdfd152e870429cb47299602024edf4f Mon Sep 17 00:00:00 2001 From: Johannes Beck Date: Sat, 17 Feb 2024 20:42:50 +0100 Subject: [PATCH] Add SchemaExport --- pom.xml | 19 ++++++++++++++- src/main/java/x1/stomp/model/Action.java | 3 +++ src/main/java/x1/stomp/model/Command.java | 1 + src/main/java/x1/stomp/model/Share.java | 2 +- .../java/x1/stomp/test/SchemaExportTest.java | 24 +++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/test/java/x1/stomp/test/SchemaExportTest.java diff --git a/pom.xml b/pom.xml index a1165ead..6626126e 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 0.8.10 1.8.0.Final 5.0.1.Final - 1.15.0 + 1.16.0 @@ -202,6 +202,7 @@ io.opentelemetry opentelemetry-api + provided io.micrometer @@ -348,6 +349,22 @@ 42.7.1 provided + + org.hibernate.orm + hibernate-ant + 6.4.2.Final + test + + + com.fasterxml + classmate + provided + + + org.hibernate.common + hibernate-commons-annotations + provided + org.jboss.logmanager jboss-logmanager diff --git a/src/main/java/x1/stomp/model/Action.java b/src/main/java/x1/stomp/model/Action.java index addd9156..ba9295de 100644 --- a/src/main/java/x1/stomp/model/Action.java +++ b/src/main/java/x1/stomp/model/Action.java @@ -1,5 +1,8 @@ package x1.stomp.model; +import org.eclipse.microprofile.openapi.annotations.media.Schema; + +@Schema(description = "Executable action") public enum Action { SUBSCRIBE, UNSUBSCRIBE diff --git a/src/main/java/x1/stomp/model/Command.java b/src/main/java/x1/stomp/model/Command.java index 22313e2f..8cc730cc 100644 --- a/src/main/java/x1/stomp/model/Command.java +++ b/src/main/java/x1/stomp/model/Command.java @@ -11,6 +11,7 @@ @XmlRootElement(name = "command") @JsonRootName(value = "command") @JsonInclude(value = JsonInclude.Include.NON_NULL) +@Schema(description = "Action to execute for a share") public class Command { @NotNull private Action action; diff --git a/src/main/java/x1/stomp/model/Share.java b/src/main/java/x1/stomp/model/Share.java index 7aaec5db..0cd9d656 100644 --- a/src/main/java/x1/stomp/model/Share.java +++ b/src/main/java/x1/stomp/model/Share.java @@ -58,7 +58,7 @@ public Share(@NotNull @Size(min = 1, max = 25) @Pattern(regexp = "[A-Z0-9.]*", @NotNull @Size(min = 1, max = 25) @Pattern(regexp = "[A-Z0-9.]*", message = "must contain only letters and dots") - @Column + @Column(length = 25) @Schema(required = true, description = "Stock symbol", example = "MSFT") @XmlAttribute private String key; diff --git a/src/test/java/x1/stomp/test/SchemaExportTest.java b/src/test/java/x1/stomp/test/SchemaExportTest.java new file mode 100644 index 00000000..102dc585 --- /dev/null +++ b/src/test/java/x1/stomp/test/SchemaExportTest.java @@ -0,0 +1,24 @@ +package x1.stomp.test; + +import java.util.EnumSet; + +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.PostgreSQLDialect; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; +import org.junit.jupiter.api.Test; + +import x1.stomp.model.Share; + +public class SchemaExportTest { + @Test + public void testSchemaExport() { + MetadataSources metadata = new MetadataSources( + new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, PostgreSQLDialect.class.getName()) + .applySetting(AvailableSettings.DEFAULT_SCHEMA, "stocks").build()); + new SchemaExport().setOutputFile("target/ddl.sql").setFormat(true).create(EnumSet.of(TargetType.SCRIPT), + metadata.addAnnotatedClass(Share.class).buildMetadata()); + } +}