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 Nov 23, 2021
1 parent 0cf2a8e commit 2bb47a6
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#include readme-header /}
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
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
}
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-panache-kotlin"
languages: [ "kotlin" ]
artifact: "io.quarkus:quarkus-project-core-extension-codestarts"
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();
}
}
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,16 +14,30 @@
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 {

private static final Path testDirPath = Paths.get("target/quarkus-codestart-build-test");

private static final Set<String> 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 {
Expand Down
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;
}
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;
}
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
}

0 comments on commit 2bb47a6

Please sign in to comment.