-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-17960: Fix proper default session type for JD repositories even i…
…n Quarkus And tests
- Loading branch information
Showing
12 changed files
with
185 additions
and
12 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
6 changes: 6 additions & 0 deletions
6
...model-generator/src/jakartaData/java/io/quarkus/hibernate/orm/panache/_PanacheEntity.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,6 @@ | ||
package io.quarkus.hibernate.orm.panache; | ||
|
||
// workaround until Quarkus is published with this class | ||
public interface _PanacheEntity { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...jakartaData/java/org/hibernate/processor/test/data/quarkus/JakartaDataBookRepository.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,18 @@ | ||
package org.hibernate.processor.test.data.quarkus; | ||
|
||
import java.util.List; | ||
|
||
|
||
import jakarta.data.repository.CrudRepository; | ||
import jakarta.data.repository.Find; | ||
import jakarta.data.repository.Query; | ||
import jakarta.data.repository.Repository; | ||
|
||
@Repository | ||
public interface JakartaDataBookRepository extends CrudRepository<PanacheBook, Long> { | ||
@Find | ||
public List<PanacheBook> findBook(String isbn); | ||
|
||
@Query("WHERE isbn = :isbn") | ||
public List<PanacheBook> hqlBook(String isbn); | ||
} |
25 changes: 25 additions & 0 deletions
25
...generator/src/jakartaData/java/org/hibernate/processor/test/data/quarkus/PanacheBook.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,25 @@ | ||
package org.hibernate.processor.test.data.quarkus; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.annotations.NaturalId; | ||
import org.hibernate.annotations.processing.Find; | ||
import org.hibernate.annotations.processing.HQL; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
import jakarta.persistence.Entity; | ||
|
||
@Entity | ||
public class PanacheBook extends PanacheEntity { | ||
public @NaturalId String isbn; | ||
public @NaturalId String title; | ||
public @NaturalId String author; | ||
public String text; | ||
public int pages; | ||
|
||
@Find | ||
public static native List<PanacheBook> findBook(String isbn); | ||
|
||
@HQL("WHERE isbn = :isbn") | ||
public static native List<PanacheBook> hqlBook(String isbn); | ||
} |
62 changes: 62 additions & 0 deletions
62
...src/jakartaData/java/org/hibernate/processor/test/data/quarkus/QuarkusOrmPanacheTest.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,62 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.processor.test.data.quarkus; | ||
|
||
import org.hibernate.StatelessSession; | ||
import org.hibernate.processor.test.util.CompilationTest; | ||
import org.hibernate.processor.test.util.TestUtil; | ||
import org.hibernate.processor.test.util.WithClasses; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.persistence.EntityManager; | ||
|
||
import static org.hibernate.processor.test.util.TestUtil.getMetamodelClassFor; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** | ||
* @author Gavin King | ||
*/ | ||
public class QuarkusOrmPanacheTest extends CompilationTest { | ||
|
||
@Test | ||
@WithClasses({ PanacheBook.class, JakartaDataBookRepository.class }) | ||
public void testJakartaDataRepositoryMetamodel() throws Exception { | ||
// JD repository | ||
System.out.println( TestUtil.getMetaModelSourceAsString( JakartaDataBookRepository.class ) ); | ||
Class<?> repositoryClass = getMetamodelClassFor( JakartaDataBookRepository.class ); | ||
Assertions.assertNotNull( repositoryClass ); | ||
|
||
// Make sure it has the proper supertype | ||
Class<?> superclass = repositoryClass.getSuperclass(); | ||
if ( superclass != null ) { | ||
Assertions.assertEquals( "java.lang.Object", superclass.getName() ); | ||
} | ||
Class<?>[] interfaces = repositoryClass.getInterfaces(); | ||
Assertions.assertEquals( 1, interfaces.length ); | ||
Assertions.assertEquals( JakartaDataBookRepository.class.getName(), interfaces[0].getName() ); | ||
|
||
// Annotated method generates an instance method | ||
Method method = repositoryClass.getDeclaredMethod( "hqlBook", String.class ); | ||
Assertions.assertNotNull( method ); | ||
Assertions.assertFalse( Modifier.isStatic( method.getModifiers() ) ); | ||
|
||
// Annotated method generates an instance method | ||
method = repositoryClass.getDeclaredMethod( "findBook", String.class ); | ||
Assertions.assertNotNull( method ); | ||
Assertions.assertFalse( Modifier.isStatic( method.getModifiers() ) ); | ||
|
||
// Make sure we have the proper constructor | ||
Constructor<?> constructor = repositoryClass.getDeclaredConstructor( StatelessSession.class ); | ||
Assertions.assertNotNull( constructor ); | ||
Assertions.assertTrue( constructor.isAnnotationPresent( Inject.class ) ); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
...rator/src/quarkusHrPanache/java/io/quarkus/hibernate/reactive/panache/_PanacheEntity.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,6 @@ | ||
package io.quarkus.hibernate.reactive.panache; | ||
|
||
// workaround until Quarkus is published with this class | ||
public interface _PanacheEntity { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...arkusHrPanache/java/org/hibernate/processor/test/hrPanache/JakartaDataBookRepository.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,24 @@ | ||
// Not supported yet: https://hibernate.atlassian.net/browse/HHH-17960 | ||
//package org.hibernate.processor.test.hrPanache; | ||
// | ||
//import java.util.List; | ||
// | ||
//import org.hibernate.reactive.mutiny.Mutiny; | ||
// | ||
//import io.smallrye.mutiny.Uni; | ||
//import jakarta.data.repository.CrudRepository; | ||
//import jakarta.data.repository.Find; | ||
//import jakarta.data.repository.Query; | ||
//import jakarta.data.repository.Repository; | ||
// | ||
//@Repository | ||
//public interface JakartaDataBookRepository extends CrudRepository<PanacheBook, Long> { | ||
// | ||
// public Uni<Mutiny.StatelessSession> session(); | ||
// | ||
// @Find | ||
// public Uni<List<PanacheBook>> findBook(String isbn); | ||
// | ||
// @Query("WHERE isbn = :isbn") | ||
// public Uni<List<PanacheBook>> hqlBook(String isbn); | ||
//} |
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
6 changes: 2 additions & 4 deletions
6
...rator/src/quarkusOrmPanache/java/org/hibernate/processor/test/ormPanache/PanacheBook.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
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