From c3a97411f1d0809b5e578e78b51f2bb462ef5fd1 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Tue, 1 Jun 2021 13:43:37 +0200 Subject: [PATCH] Add quarkus.hibernate-orm.scripts.generation.delimiter config property This property represents the statement delimiter used for the generation of the DDL scripts. The property defaults to `;`. Resolves #17514 --- .../FastBootHibernatePersistenceProvider.java | 2 ++ .../HibernateOrmRuntimeConfigPersistenceUnit.java | 7 +++++++ .../src/main/resources/ddlgeneration.properties | 1 + .../io/quarkus/it/panache/DDLGenerationPMT.java | 15 ++++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java index 34858d5c20b04..069fa90768f83 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java @@ -340,6 +340,8 @@ private static void injectRuntimeConfiguration(String persistenceUnitName, runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_HALT_ON_ERROR, "true"); } + runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_DELIMITER, + persistenceUnitConfig.scripts.generation.delimiter); runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_SCRIPTS_ACTION, persistenceUnitConfig.scripts.generation.generation); diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java index f55957d183657..fd6296333d119 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmRuntimeConfigPersistenceUnit.java @@ -107,6 +107,12 @@ public static class HibernateOrmConfigPersistenceUnitScriptGeneration { @ConfigItem(name = ConfigItem.PARENT, defaultValue = "none") public String generation = "none"; + /** + * Specifies the statement delimiter to be used for the generated DDL scripts. + */ + @ConfigItem + public String delimiter = ";"; + /** * Filename or URL where the database create DDL file should be generated. */ @@ -121,6 +127,7 @@ public static class HibernateOrmConfigPersistenceUnitScriptGeneration { public boolean isAnyPropertySet() { return !"none".equals(generation) + || !";".equals(delimiter) || createTarget.isPresent() || dropTarget.isPresent(); } diff --git a/integration-tests/hibernate-orm-panache/src/main/resources/ddlgeneration.properties b/integration-tests/hibernate-orm-panache/src/main/resources/ddlgeneration.properties index de27a48e388a8..c08b2a9c08c4c 100644 --- a/integration-tests/hibernate-orm-panache/src/main/resources/ddlgeneration.properties +++ b/integration-tests/hibernate-orm-panache/src/main/resources/ddlgeneration.properties @@ -6,6 +6,7 @@ quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect quarkus.hibernate-orm.database.generation=drop-and-create quarkus.hibernate-orm.scripts.generation=drop-and-create +quarkus.hibernate-orm.scripts.generation.delimiter=\n/ quarkus.hibernate-orm.scripts.generation.create-target=create.sql quarkus.hibernate-orm.scripts.generation.drop-target=drop.sql diff --git a/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/DDLGenerationPMT.java b/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/DDLGenerationPMT.java index a03dabfd089e5..5f94cdf248067 100644 --- a/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/DDLGenerationPMT.java +++ b/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/DDLGenerationPMT.java @@ -3,6 +3,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.is; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.jupiter.api.Test; @@ -33,11 +37,16 @@ public class DDLGenerationPMT { private ProdModeTestResults prodModeTestResults; @Test - public void test() { + public void test() throws IOException { RestAssured.when().get("/no-paging-test").then().body(is("OK")); - assertThat(prodModeTestResults.getBuildDir().resolve("quarkus-app/create.sql").toFile()).exists(); - assertThat(prodModeTestResults.getBuildDir().resolve("quarkus-app/drop.sql").toFile()).exists(); + Path createSqlPath = prodModeTestResults.getBuildDir().resolve("quarkus-app/create.sql"); + assertThat(createSqlPath.toFile()).exists(); + assertThat(new String(Files.readAllBytes(createSqlPath))).contains("\n/"); + + Path dropSqlPath = prodModeTestResults.getBuildDir().resolve("quarkus-app/drop.sql"); + assertThat(dropSqlPath.toFile()).exists(); + assertThat(new String(Files.readAllBytes(dropSqlPath))).contains("\n/"); } }