Skip to content

Commit

Permalink
Fix HibernateOrm and panache codestarts
Browse files Browse the repository at this point in the history
(cherry picked from commit 277b190)
  • Loading branch information
ia3andy authored and gsmet committed Jan 28, 2023
1 parent 81b88f6 commit 33432b7
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class MyEntity {

public String field;
}
{/if}
{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache')}
{#else}
import io.quarkus.hibernate.orm.panache.PanacheEntity;
import javax.persistence.Entity;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class MyKotlinEntity {
var id: Long? = null
var field: String? = null
}
{/if}
{#if input.selected-extensions-ga.contains('io.quarkus:quarkus-hibernate-orm-panache-kotlin')}
{#else}
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion
import javax.persistence.Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
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;

import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
import io.quarkus.maven.dependency.ArtifactKey;

public class HibernateOrmCodestartTest {
public class HibernateOrmCodestartIT {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("hibernate-orm")
.extension(ArtifactKey.ga("io.quarkus", "quarkus-jdbc-h2"))
.languages(JAVA)
.languages(JAVA, KOTLIN)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.MyEntity");
codestartTest.checkGeneratedSource(QuarkusCodestartCatalog.Language.KOTLIN, "org.acme.MyKotlinEntity");
codestartTest.checkGeneratedSource(JAVA, "org.acme.MyEntity");
codestartTest.checkGeneratedSource(KOTLIN, "org.acme.MyKotlinEntity");
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql");
codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql");
}

@Test
void buildAllProjectsForLocalUse() throws Throwable {
void testBuild() throws Throwable {
codestartTest.buildAllProjects();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
import io.quarkus.maven.ArtifactKey;

public class HibernateOrmPanacheCodestartTest {
public class HibernateOrmPanacheCodestartIT {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
Expand All @@ -21,10 +21,11 @@ public class HibernateOrmPanacheCodestartTest {
@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.MyEntity");
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/import.sql");
}

@Test
void buildAllProjectsForLocalUse() throws Throwable {
void testBuild() throws Throwable {
codestartTest.buildAllProjects();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
import io.quarkus.maven.ArtifactKey;

public class HibernateOrmPanacheKotlinCodestartTest {
public class HibernateOrmPanacheKotlinCodestartIT {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
Expand All @@ -21,10 +21,11 @@ public class HibernateOrmPanacheKotlinCodestartTest {
@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.MyKotlinEntity");
codestartTest.assertThatGeneratedFileMatchSnapshot(KOTLIN, "src/main/resources/import.sql");
}

@Test
void buildAllProjectsForLocalUse() throws Throwable {
void testBuild() throws Throwable {
codestartTest.buildAllProjects();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import javax.persistence.Id
*
* To use it, get access to a JPA EntityManager via injection.
*
* ```kotlin
* {@code
* @Inject
* lateinit var em:EntityManager;
*
Expand All @@ -20,12 +20,12 @@ import javax.persistence.Id
*
* 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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- 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(nextval('hibernate_sequence'), 'field-1');
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2');
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3');
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- 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(nextval('hibernate_sequence'), 'field-1');
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2');
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3');
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- 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(nextval('hibernate_sequence'), 'field-1');
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2');
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3');

This file was deleted.

0 comments on commit 33432b7

Please sign in to comment.