-
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
b43d49e
commit 0308fdc
Showing
10 changed files
with
174 additions
and
83 deletions.
There are no files selected for viewing
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
31 changes: 0 additions & 31 deletions
31
...sion-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
...starts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.tpl.qute.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,67 @@ | ||
package org.acme | ||
|
||
{#if !input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache-kotlin')} | ||
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. | ||
* | ||
* \{@code | ||
* @Inject | ||
* lateinit var em:EntityManager; | ||
* | ||
* fun doSomething() { | ||
* val entity1 = MyKotlinEntity(); | ||
* entity1.field = "field-1" | ||
* em.persist(entity1); | ||
* | ||
* val entities:List<MyKotlinEntity> = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
class MyKotlinEntity { | ||
@get:GeneratedValue | ||
@get:Id | ||
var id: Long? = null | ||
var field: String? = null | ||
} | ||
{/if} | ||
{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache-kotlin')} | ||
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 = MyKotlinEntity(); | ||
* entity1.field = "field-1" | ||
* entity1.persist() | ||
* | ||
* val entities:List<MyKotlinEntity> = MyKotlinEntity.listAll() | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
class MyKotlinEntity: PanacheEntity() { | ||
companion object: PanacheCompanion<MyKotlinEntity> { | ||
fun byName(name: String) = list("name", name) | ||
} | ||
|
||
lateinit var field: String | ||
} | ||
{/if} |
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
1 change: 0 additions & 1 deletion
1
...tools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.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
30 changes: 30 additions & 0 deletions
30
...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,30 @@ | ||
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") | ||
.extension(new ArtifactKey("io.quarkus", "quarkus-jdbc-h2")) | ||
.extension(new ArtifactKey("io.quarkus", "quarkus-hibernate-orm-panache-kotlin")) | ||
.languages(KOTLIN) | ||
.build(); | ||
|
||
@Test | ||
void testContent() throws Throwable { | ||
codestartTest.checkGeneratedSource("org.acme.MyKotlinEntity"); | ||
} | ||
|
||
@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
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 |
---|---|---|
|
@@ -28,4 +28,4 @@ class MyKotlinEntity { | |
@get:Id | ||
var id: Long? = null | ||
var field: String? = null | ||
} | ||
} |
47 changes: 15 additions & 32 deletions
47
..._/HibernateOrmPanacheCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.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 |
---|---|---|
@@ -1,47 +1,30 @@ | ||
package ilove.quark.us; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
|
||
import javax.persistence.Entity; | ||
|
||
|
||
/** | ||
* Example JPA 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. | ||
* | ||
* To use it, get access to a JPA EntityManager via injection. | ||
* This uses the active record pattern, you can also use the repository pattern instead: | ||
* . | ||
* | ||
* {@code | ||
* @Inject | ||
* EntityManager em; | ||
* Usage (more example on the documentation) | ||
* | ||
* {@code | ||
* public void doSomething() { | ||
* MyEntity entity1 = new MyEntity(); | ||
* entity1.setField("field-1"); | ||
* em.persist(entity1); | ||
* entity1.field = "field-1"; | ||
* entity1.persist(); | ||
* | ||
* List<MyEntity> entities = em.createQuery("from MyEntity", MyEntity.class).getResultList(); | ||
* List<MyEntity> entities = MyEntity.listAll(); | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
public class MyEntity { | ||
private Long id; | ||
private String field; | ||
|
||
@Id | ||
@GeneratedValue | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public void setField(String field) { | ||
this.field = field; | ||
} | ||
public class MyEntity extends PanacheEntity { | ||
public String field; | ||
} |
34 changes: 34 additions & 0 deletions
34
...rmPanacheKotlinCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.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 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: | ||
* . | ||
* | ||
* Usage (more example on the documentation) | ||
* | ||
* {@code | ||
* | ||
* fun doSomething() { | ||
* val entity1 = MyKotlinEntity(); | ||
* entity1.field = "field-1" | ||
* entity1.persist() | ||
* | ||
* val entities:List<MyKotlinEntity> = MyKotlinEntity.listAll() | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
class MyKotlinEntity: PanacheEntity() { | ||
companion object: PanacheCompanion<MyKotlinEntity> { | ||
fun byName(name: String) = list("name", name) | ||
} | ||
|
||
lateinit var field: String | ||
} |