diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/base/README.tpl.qute.md b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/base/README.tpl.qute.md new file mode 100644 index 0000000000000..7cdaa26f3658b --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/base/README.tpl.qute.md @@ -0,0 +1,2 @@ +{#include readme-header /} + diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/codestart.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/codestart.yml new file mode 100644 index 0000000000000..602e73e9aff92 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/codestart.yml @@ -0,0 +1,12 @@ +name: hibernate-orm-rest-data-codestart +ref: hibernate-orm-rest-data +tags: extension-codestart +type: code +metadata: + title: REST Data with Panache + description: Generating Jakarta REST resources with Panache + related-guide-section: https://quarkus.io/guides/rest-data-panache +language: + base: + dependencies: + - io.quarkus:quarkus-hibernate-orm-rest-data-panache \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-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-rest-data-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java new file mode 100644 index 0000000000000..da7feaf7fb42b --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/java/src/main/java/org/acme/MyEntity.tpl.qute.java @@ -0,0 +1,30 @@ +package org.acme; + +import io.quarkus.hibernate.orm.panache.PanacheEntity; +import jakarta.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() { + * MyEntity entity1 = new MyEntity(); + * entity1.field = "field-1"; + * entity1.persist(); + * + * List entities = MyEntity.listAll(); + * } + * } + */ +@Entity +public class MyEntity extends PanacheEntity { + public String field; +} + diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/java/src/main/java/org/acme/MyEntityResource.tpl.qute.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/java/src/main/java/org/acme/MyEntityResource.tpl.qute.java new file mode 100644 index 0000000000000..76599da6c1f3a --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-rest-data-codestart/java/src/main/java/org/acme/MyEntityResource.tpl.qute.java @@ -0,0 +1,6 @@ +package org.acme; + +import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource; + +public interface MyEntityResource extends PanacheEntityResource { +} \ No newline at end of file diff --git a/extensions/panache/hibernate-orm-rest-data-panache/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/panache/hibernate-orm-rest-data-panache/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 5ba895f562471..58f184270d67a 100644 --- a/extensions/panache/hibernate-orm-rest-data-panache/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/panache/hibernate-orm-rest-data-panache/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -16,3 +16,7 @@ metadata: - "data" - "web" status: "stable" + codestart: + name: "hibernate-orm-rest-data" + languages: [ "java" ] + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmRestDataCodestartIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmRestDataCodestartIT.java new file mode 100644 index 0000000000000..79ff531637c19 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmRestDataCodestartIT.java @@ -0,0 +1,31 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; +import io.quarkus.maven.dependency.ArtifactKey; + +public class HibernateOrmRestDataCodestartIT { + + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .codestarts("hibernate-orm-rest-data") + .extension(ArtifactKey.ga("io.quarkus", "quarkus-jdbc-h2")) + .extension(ArtifactKey.ga("io.quarkus", "quarkus-resteasy-reactive-jackson")) + .languages(JAVA) + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource(JAVA, "org.acme.MyEntity"); + codestartTest.checkGeneratedSource(JAVA, "org.acme.MyEntityResource"); + } + + @Test + void testBuild() 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 9cccca1c54fbe..01cfb89fad5d4 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 @@ -40,6 +40,7 @@ class QuarkusCodestartBuildIT extends PlatformAwareTestBase { "spring-web-codestart", "picocli-codestart", "hibernate-orm-codestart", + "hibernate-orm-rest-data-codestart", "reactive-messaging-codestart"); @BeforeAll diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java new file mode 100644 index 0000000000000..35b44bfd2e384 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntity.java @@ -0,0 +1,30 @@ +package ilove.quark.us; + +import io.quarkus.hibernate.orm.panache.PanacheEntity; +import jakarta.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: + * . + * + * Usage (more example on the documentation) + * + * {@code + * public void doSomething() { + * MyEntity entity1 = new MyEntity(); + * entity1.field = "field-1"; + * entity1.persist(); + * + * List entities = MyEntity.listAll(); + * } + * } + */ +@Entity +public class MyEntity extends PanacheEntity { + public String field; +} + diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntityResource.java b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntityResource.java new file mode 100644 index 0000000000000..032bff3f1f37a --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_java_ilove_quark_us_MyEntityResource.java @@ -0,0 +1,6 @@ +package ilove.quark.us; + +import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource; + +public interface MyEntityResource extends PanacheEntityResource { +} \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_resources_import.sql b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_resources_import.sql new file mode 100644 index 0000000000000..16aa5235ec238 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/HibernateOrmRestDataCodestartIT/testContent/src_main_resources_import.sql @@ -0,0 +1,6 @@ +-- 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(1, 'field-1'); +-- insert into myentity (id, field) values(2, 'field-2'); +-- insert into myentity (id, field) values(3, 'field-3'); +-- alter sequence myentity_seq restart with 4; \ No newline at end of file