Skip to content

Commit

Permalink
Hibernate ORM with Panache in Kotlin codestart
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Jan 4, 2022
1 parent b43d49e commit 0308fdc
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache')}
[Related Hibernate with Panache section...](https://quarkus.io/guides/hibernate-orm-panache)
{/if}

{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache-kotlin')}
[Related Hibernate with Panache in Kotlin section...](https://quarkus.io/guides/hibernate-orm-panache-kotlin)
{/if}

This file was deleted.

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}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ metadata:
config:
- "quarkus.datasource."
- "quarkus.hibernate-orm."
codestart:
name: "hibernate-orm"
languages: [ "kotlin" ]
artifact: "io.quarkus:quarkus-project-core-extension-codestarts"
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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;
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -38,8 +40,7 @@ class QuarkusCodestartBuildIT extends PlatformAwareTestBase {
"spring-web-codestart",
"picocli-codestart",
"hibernate-orm-codestart",
"reactive-messaging-codestart",
"hibernate-orm-panache-codestart");
"reactive-messaging-codestart");

@BeforeAll
static void setUp() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class MyKotlinEntity {
@get:Id
var id: Long? = null
var field: String? = null
}
}
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;
}
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
}

0 comments on commit 0308fdc

Please sign in to comment.