diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/base/README.tpl.qute.md b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/base/README.tpl.qute.md new file mode 100644 index 00000000000000..405280158877db --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/base/README.tpl.qute.md @@ -0,0 +1 @@ +{#include readme-header /} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/codestart.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/codestart.yml new file mode 100644 index 00000000000000..3e76d175cbfbf3 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/codestart.yml @@ -0,0 +1,12 @@ +name: hibernate-orm-panache-kotlin-codestart +ref: hibernate-orm-panache-kotlin +tags: extension-codestart +type: code +metadata: + title: Hibernate ORM with Panache in Kotlin + description: Create your first JPA entity with Hibernate with Panache in Kotlin + related-guide-section: https://quarkus.io/guides/hibernate-orm-panache-kotlin +language: + base: + dependencies: + - io.quarkus:quarkus-hibernate-orm-panache-kotlin diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinPanacheEntity.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinPanacheEntity.kt new file mode 100644 index 00000000000000..17570e73ee403d --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinPanacheEntity.kt @@ -0,0 +1,34 @@ +package org.acme + +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: + * {@see https://quarkus.io/guides/hibernate-orm-panache-kotlin#defining-your-repository}. + * + * Usage (more example on the documentation) + * + * {@code + * + * fun doSomething() { + * val entity1 = MyKotlinPanacheEntity(); + * entity1.field = "field-1" + * entity1.persist() + * + * val entities:List = MyKotlinPanacheEntity.listAll() + * } + * } + */ +@Entity +class MyKotlinPanacheEntity: PanacheEntity() { + companion object: PanacheCompanion { + fun byName(name: String) = list("name", name) + } + + lateinit var field: String +} diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/resources/META-INF/quarkus-extension.yaml index f00c0f1c3f7844..d400cef84511cf 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -15,3 +15,7 @@ metadata: config: - "quarkus.datasource." - "quarkus.hibernate-orm." + codestart: + name: "hibernate-orm-panache-kotlin" + languages: [ "kotlin" ] + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" 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/HibernateOrmPanacheKotlinCodestartTest.java new file mode 100644 index 00000000000000..ef79dceaf925d2 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java @@ -0,0 +1,29 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; +import io.quarkus.maven.ArtifactKey; + +public class HibernateOrmPanacheKotlinCodestartTest { + + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .codestarts("hibernate-orm-panache-kotlin") + .extension(new ArtifactKey("io.quarkus", "quarkus-jdbc-h2")) + .languages(KOTLIN) + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource("org.acme.MyKotlinPanacheEntity"); + } + + @Test + void buildAllProjectsForLocalUse() throws Throwable { + codestartTest.buildAllProjects(); + } +} diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java index 07f2b41733e936..f755a993abbd73 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java @@ -1,19 +1,7 @@ package io.quarkus.devtools.codestarts.quarkus; -import com.google.common.collect.Sets; -import io.quarkus.devtools.codestarts.Codestart; -import io.quarkus.devtools.codestarts.CodestartProjectDefinition; -import io.quarkus.devtools.project.BuildTool; -import io.quarkus.devtools.testing.PlatformAwareTestBase; -import io.quarkus.devtools.testing.SnapshotTesting; -import io.quarkus.devtools.testing.WrapperRunner; -import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTesting; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.nio.file.Path; @@ -26,8 +14,22 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import com.google.common.collect.Sets; + +import io.quarkus.devtools.codestarts.Codestart; +import io.quarkus.devtools.codestarts.CodestartProjectDefinition; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.testing.PlatformAwareTestBase; +import io.quarkus.devtools.testing.SnapshotTesting; +import io.quarkus.devtools.testing.WrapperRunner; +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTesting; @TestInstance(TestInstance.Lifecycle.PER_CLASS) class QuarkusCodestartBuildIT extends PlatformAwareTestBase { @@ -35,7 +37,7 @@ class QuarkusCodestartBuildIT extends PlatformAwareTestBase { private static final Path testDirPath = Paths.get("target/quarkus-codestart-build-test"); private static final Set EXCLUDED = Sets.newHashSet("spring-web-codestart", "picocli-codestart", - "hibernate-orm-codestart", "hibernate-orm-panache-codestart"); + "hibernate-orm-codestart", "hibernate-orm-panache-codestart", "hibernate-orm-panache-kotlin-codestart"); @BeforeAll static void setUp() throws IOException { diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyPanacheEntity.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyPanacheEntity.java new file mode 100644 index 00000000000000..c3e8fed5a3fe97 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyPanacheEntity.java @@ -0,0 +1,30 @@ +package ilove.quark.us; + +import io.quarkus.hibernate.orm.panache.PanacheEntity; + +import javax.persistence.Entity; + + +/** + * Example JPA entity defined as a 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: + * {@see https://quarkus.io/guides/hibernate-orm-panache#solution-2-using-the-repository-pattern}. + * + * Usage (more example on the documentation) + * + * {@code + * public void doSomething() { + * MyPanacheEntity entity1 = new MyPanacheEntity(); + * entity1.field = "field-1"; + * entity1.persist(); + * + * List entities = MyPanacheEntity.listAll(); + * } + * } + */ +@Entity +public class MyPanacheEntity extends PanacheEntity { + public String field; +} \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testNoHibernateResources/src_main_java_ilove_quark_us_MyPanacheEntity.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testNoHibernateResources/src_main_java_ilove_quark_us_MyPanacheEntity.java new file mode 100644 index 00000000000000..c91c5bc2413e3e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheCodestartTest/testNoHibernateResources/src_main_java_ilove_quark_us_MyPanacheEntity.java @@ -0,0 +1,30 @@ +package ilove.quark.us; + +import io.quarkus.hibernate.orm.panache.PanacheEntity; + +import javax.persistence.Entity; + + +/** + * Example JPA entity defined as a PanacheEntity. + * 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: + * {@see https://quarkus.io/guides/hibernate-orm-panache#solution-2-using-the-repository-pattern}. + * + * Usage (more example on the documentation) + * + * {@code + * public void doSomething() { + * MyPanacheEntity entity1 = new MyPanacheEntity(); + * entity1.field = "field-1"; + * entity1.persist(); + * + * List entities = MyPanacheEntity.listAll(); + * } + * } + */ +@Entity +public class MyPanacheEntity extends PanacheEntity { + public String field; +} \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinPanacheEntity.kt b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinPanacheEntity.kt new file mode 100644 index 00000000000000..4f97d9301d1b09 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinPanacheEntity.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 PanacheEntity. + * 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: + * {@see https://quarkus.io/guides/hibernate-orm-panache-kotlin#defining-your-repository}. + * + * Usage (more example on the documentation) + * + * {@code + * + * fun doSomething() { + * val entity1 = MyKotlinPanacheEntity(); + * entity1.field = "field-1" + * entity1.persist() + * + * val entities:List = MyKotlinPanacheEntity.listAll() + * } + * } + */ +@Entity +class MyKotlinPanacheEntity: PanacheEntity() { + companion object: PanacheCompanion { + fun byName(name: String) = list("name", name) + } + + lateinit var field: String +}