Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HibernateOrmCodestart #30501

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.