From 277b1906329ad1cbd0038bf9b383b25f3ae6af69 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Fri, 20 Jan 2023 09:59:05 +0100 Subject: [PATCH] Fix HibernateOrm and panache codestarts --- .../main/java/org/acme/MyEntity.tpl.qute.java | 3 +- .../main/kotlin/org/acme/MyKotlinEntity.kt | 31 ----------------- .../org/acme/MyKotlinEntity.tpl.qute.kt | 3 +- ...Test.java => HibernateOrmCodestartIT.java} | 13 ++++--- ...va => HibernateOrmPanacheCodestartIT.java} | 5 +-- ...HibernateOrmPanacheKotlinCodestartIT.java} | 5 +-- ...src_main_java_ilove_quark_us_MyEntity.java | 0 ...in_kotlin_ilove_quark_us_MyKotlinEntity.kt | 6 ++-- .../testContent/src_main_resources_import.sql | 5 +++ ...src_main_java_ilove_quark_us_MyEntity.java | 0 .../testContent/src_main_resources_import.sql | 5 +++ ...in_kotlin_ilove_quark_us_MyKotlinEntity.kt | 34 +++++++++++++++++++ .../testContent/src_main_resources_import.sql | 5 +++ ...in_kotlin_ilove_quark_us_MyKotlinEntity.kt | 31 ----------------- 14 files changed, 68 insertions(+), 78 deletions(-) delete mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt rename integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/{HibernateOrmCodestartTest.java => HibernateOrmCodestartIT.java} (56%) rename integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/{HibernateOrmPanacheCodestartTest.java => HibernateOrmPanacheCodestartIT.java} (82%) rename integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/{HibernateOrmPanacheKotlinCodestartTest.java => HibernateOrmPanacheKotlinCodestartIT.java} (82%) rename integration-tests/devtools/src/test/resources/__snapshots__/{HibernateOrmCodestartTest => HibernateOrmCodestartIT}/testContent/src_main_java_ilove_quark_us_MyEntity.java (100%) rename integration-tests/devtools/src/test/resources/__snapshots__/{HibernateOrmCodestartTest => HibernateOrmCodestartIT}/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt (96%) create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_resources_import.sql rename integration-tests/devtools/src/test/resources/__snapshots__/{HibernateOrmPanacheCodestartTest => HibernateOrmPanacheCodestartIT}/testContent/src_main_java_ilove_quark_us_MyEntity.java (100%) create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_resources_import.sql create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_resources_import.sql delete mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java index ae11050e3e1c8..51b4a1aae3679 100644 --- a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java @@ -31,8 +31,7 @@ public class MyEntity { public String field; } -{/if} -{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache')} +{#else} import io.quarkus.hibernate.orm.panache.PanacheEntity; import javax.persistence.Entity; diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt deleted file mode 100644 index 6ff0beb08ccda..0000000000000 --- a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.acme - -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.Id - -/** - * Example JPA entity. - * - * To use it, get access to a JPA EntityManager via injection. - * - * ```kotlin - * @Inject - * lateinit var em:EntityManager; - * - * fun doSomething() { - * val entity1 = MyKotlinEntity(); - * entity1.field = "field-1" - * em.persist(entity1); - * - * val entities:List = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() - * } - * ``` - */ -@Entity -class MyKotlinEntity { - @get:GeneratedValue - @get:Id - var id: Long? = null - var field: String? = null -} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt index 71793b36ebafb..3d8a51d8c6513 100644 --- a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.kt @@ -30,8 +30,7 @@ class MyKotlinEntity { var id: Long? = null var field: String? = null } -{/if} -{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache-kotlin')} +{#else} import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion import javax.persistence.Entity diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartIT.java similarity index 56% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartIT.java index 545c3371cb542..2e15e57133b3b 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartIT.java @@ -1,6 +1,7 @@ package io.quarkus.devtools.codestarts.quarkus; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -8,23 +9,25 @@ import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; import io.quarkus.maven.dependency.ArtifactKey; -public class HibernateOrmCodestartTest { +public class HibernateOrmCodestartIT { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() .codestarts("hibernate-orm") .extension(ArtifactKey.ga("io.quarkus", "quarkus-jdbc-h2")) - .languages(JAVA) + .languages(JAVA, KOTLIN) .build(); @Test void testContent() throws Throwable { - codestartTest.checkGeneratedSource("org.acme.MyEntity"); - codestartTest.checkGeneratedSource(QuarkusCodestartCatalog.Language.KOTLIN, "org.acme.MyKotlinEntity"); + codestartTest.checkGeneratedSource(JAVA, "org.acme.MyEntity"); + codestartTest.checkGeneratedSource(KOTLIN, "org.acme.MyKotlinEntity"); + codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql"); + codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql"); } @Test - void buildAllProjectsForLocalUse() throws Throwable { + void testBuild() throws Throwable { codestartTest.buildAllProjects(); } } diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartIT.java similarity index 82% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartIT.java index 0c9c49c2e2d1e..51e1baabf7228 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheCodestartIT.java @@ -8,7 +8,7 @@ import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; import io.quarkus.maven.ArtifactKey; -public class HibernateOrmPanacheCodestartTest { +public class HibernateOrmPanacheCodestartIT { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() @@ -21,10 +21,11 @@ public class HibernateOrmPanacheCodestartTest { @Test void testContent() throws Throwable { codestartTest.checkGeneratedSource("org.acme.MyEntity"); + codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql"); } @Test - void buildAllProjectsForLocalUse() throws Throwable { + void testBuild() throws Throwable { codestartTest.buildAllProjects(); } } diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartIT.java similarity index 82% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartIT.java index 7fe535c799a6e..7ae2f83db17b4 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartIT.java @@ -8,7 +8,7 @@ import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; import io.quarkus.maven.ArtifactKey; -public class HibernateOrmPanacheKotlinCodestartTest { +public class HibernateOrmPanacheKotlinCodestartIT { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() @@ -21,10 +21,11 @@ public class HibernateOrmPanacheKotlinCodestartTest { @Test void testContent() throws Throwable { codestartTest.checkGeneratedSource("org.acme.MyKotlinEntity"); + codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql"); } @Test - void buildAllProjectsForLocalUse() throws Throwable { + void testBuild() throws Throwable { codestartTest.buildAllProjects(); } } diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java similarity index 100% rename from integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java rename to integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt similarity index 96% rename from integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt rename to integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt index 1bacaf93ee59b..ae6ca99d523eb 100644 --- a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt @@ -9,7 +9,7 @@ import javax.persistence.Id * * To use it, get access to a JPA EntityManager via injection. * - * ```kotlin + * {@code * @Inject * lateinit var em:EntityManager; * @@ -20,7 +20,7 @@ import javax.persistence.Id * * val entities:List = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() * } - * ``` + * } */ @Entity class MyKotlinEntity { @@ -28,4 +28,4 @@ class MyKotlinEntity { @get:Id var id: Long? = null var field: String? = null -} \ No newline at end of file +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_resources_import.sql b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_resources_import.sql new file mode 100644 index 0000000000000..fa2ea10dafe7e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmCodestartIT/testContent/src_main_resources_import.sql @@ -0,0 +1,5 @@ +-- This file allow to write SQL commands that will be emitted in test and dev. +-- The commands are commented as their support depends of the database +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3'); \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java similarity index 100% rename from integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java rename to integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_resources_import.sql b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_resources_import.sql new file mode 100644 index 0000000000000..fa2ea10dafe7e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartIT/testContent/src_main_resources_import.sql @@ -0,0 +1,5 @@ +-- This file allow to write SQL commands that will be emitted in test and dev. +-- The commands are commented as their support depends of the database +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3'); \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt new file mode 100644 index 0000000000000..0c21af1ce75f3 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt @@ -0,0 +1,34 @@ +package ilove.quark.us + +import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity +import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion +import javax.persistence.Entity + +/** + * Example JPA entity defined as a Kotlin Panache Entity. + * An ID field of Long type is provided, if you want to define your own ID field extends PanacheEntityBase instead. + * + * This uses the active record pattern, you can also use the repository pattern instead: + * . + * + * Usage (more example on the documentation) + * + * {@code + * + * fun doSomething() { + * val entity1 = MyKotlinEntity(); + * entity1.field = "field-1" + * entity1.persist() + * + * val entities:List = MyKotlinEntity.listAll() + * } + * } + */ +@Entity +class MyKotlinEntity: PanacheEntity() { + companion object: PanacheCompanion { + fun byName(name: String) = list("name", name) + } + + lateinit var field: String +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_resources_import.sql b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_resources_import.sql new file mode 100644 index 0000000000000..fa2ea10dafe7e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartIT/testContent/src_main_resources_import.sql @@ -0,0 +1,5 @@ +-- This file allow to write SQL commands that will be emitted in test and dev. +-- The commands are commented as their support depends of the database +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2'); +-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3'); \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt deleted file mode 100644 index 1bacaf93ee59b..0000000000000 --- a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt +++ /dev/null @@ -1,31 +0,0 @@ -package ilove.quark.us - -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.Id - -/** - * Example JPA entity. - * - * To use it, get access to a JPA EntityManager via injection. - * - * ```kotlin - * @Inject - * lateinit var em:EntityManager; - * - * fun doSomething() { - * val entity1 = MyKotlinEntity(); - * entity1.field = "field-1" - * em.persist(entity1); - * - * val entities:List = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() - * } - * ``` - */ -@Entity -class MyKotlinEntity { - @get:GeneratedValue - @get:Id - var id: Long? = null - var field: String? = null -} \ No newline at end of file