-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hibernate ORM with Panache in Kotlin codestart
- Loading branch information
1 parent
0cf2a8e
commit 2bb47a6
Showing
9 changed files
with
193 additions
and
17 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...nsion-codestarts/hibernate-orm-panache-kotlin-codestart/base/README.tpl.qute.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{#include readme-header /} |
12 changes: 12 additions & 0 deletions
12
...estarts/quarkus/extension-codestarts/hibernate-orm-panache-kotlin-codestart/codestart.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
34 changes: 34 additions & 0 deletions
34
...ate-orm-panache-kotlin-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinPanacheEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <code>PanacheEntityBase</code> 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> = MyKotlinPanacheEntity.listAll() | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
class MyKotlinPanacheEntity: PanacheEntity() { | ||
companion object: PanacheCompanion<MyKotlinPanacheEntity> { | ||
fun byName(name: String) = list("name", name) | ||
} | ||
|
||
lateinit var field: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...t/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmPanacheKotlinCodestartTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...nateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyPanacheEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <code>PanacheEntityBase</code> 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<MyPanacheEntity> entities = MyPanacheEntity.listAll(); | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
public class MyPanacheEntity extends PanacheEntity { | ||
public String field; | ||
} |
30 changes: 30 additions & 0 deletions
30
...eCodestartTest/testNoHibernateResources/src_main_java_ilove_quark_us_MyPanacheEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MyPanacheEntity> entities = MyPanacheEntity.listAll(); | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
public class MyPanacheEntity extends PanacheEntity { | ||
public String field; | ||
} |
34 changes: 34 additions & 0 deletions
34
...heKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinPanacheEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> = MyKotlinPanacheEntity.listAll() | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
class MyKotlinPanacheEntity: PanacheEntity() { | ||
companion object: PanacheCompanion<MyKotlinPanacheEntity> { | ||
fun byName(name: String) = list("name", name) | ||
} | ||
|
||
lateinit var field: String | ||
} |