-
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.
- Loading branch information
Showing
4 changed files
with
185 additions
and
0 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
27 changes: 27 additions & 0 deletions
27
...tor/src/quarkusOrmPanache/java/org/hibernate/jpamodelgen/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.hibernate.jpamodelgen.test.ormPanache; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
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; | ||
|
||
@Entity | ||
public class PanacheBook extends PanacheEntity { | ||
public @Id 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); | ||
} |
18 changes: 18 additions & 0 deletions
18
...arkusOrmPanache/java/org/hibernate/jpamodelgen/test/ormPanache/PanacheBookRepository.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.jpamodelgen.test.ormPanache; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.annotations.processing.Find; | ||
import org.hibernate.annotations.processing.HQL; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepository; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class PanacheBookRepository implements PanacheRepository<PanacheBook> { | ||
@Find | ||
public native List<PanacheBook> findBook(String isbn); | ||
|
||
@HQL("WHERE isbn = :isbn") | ||
public native List<PanacheBook> hqlBook(String isbn); | ||
} |
75 changes: 75 additions & 0 deletions
75
...arkusOrmPanache/java/org/hibernate/jpamodelgen/test/ormPanache/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,75 @@ | ||
/* | ||
* 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.jpamodelgen.test.ormPanache; | ||
|
||
import org.hibernate.jpamodelgen.test.util.CompilationTest; | ||
import org.hibernate.jpamodelgen.test.util.TestUtil; | ||
import org.hibernate.jpamodelgen.test.util.WithClasses; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import jakarta.persistence.EntityManager; | ||
|
||
import static org.hibernate.jpamodelgen.test.util.TestUtil.getMetamodelClassFor; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** | ||
* @author Gavin King | ||
*/ | ||
public class QuarkusOrmPanacheTest extends CompilationTest { | ||
@Test | ||
@WithClasses({ PanacheBook.class }) | ||
public void testPanacheEntityMetamodel() throws Exception { | ||
// Panache entity | ||
System.out.println( TestUtil.getMetaModelSourceAsString( PanacheBook.class ) ); | ||
Class<?> entityClass = getMetamodelClassFor( PanacheBook.class ); | ||
Assertions.assertNotNull(entityClass); | ||
|
||
// Make sure it has the proper supertype | ||
Class<?> superclass = entityClass.getSuperclass(); | ||
if(superclass != null) { | ||
Assertions.assertEquals("io.quarkus.hibernate.orm.panache.PanacheEntity_", superclass.getName()); | ||
} | ||
|
||
// Panache static native method generates a static method | ||
Method method = entityClass.getDeclaredMethod("hqlBook", EntityManager.class, String.class); | ||
Assertions.assertNotNull(method); | ||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers())); | ||
|
||
// Panache static native method generates a static method | ||
method = entityClass.getDeclaredMethod("findBook", EntityManager.class, String.class); | ||
Assertions.assertNotNull(method); | ||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers())); | ||
} | ||
|
||
@Test | ||
@WithClasses({ PanacheBook.class, PanacheBookRepository.class }) | ||
public void testPanacheRepositoryMetamodel() throws Exception { | ||
// Panache repository | ||
System.out.println( TestUtil.getMetaModelSourceAsString( PanacheBookRepository.class ) ); | ||
Class<?> repositoryClass = getMetamodelClassFor( PanacheBookRepository.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()); | ||
} | ||
|
||
// Panache native method generates a static method | ||
Method method = repositoryClass.getDeclaredMethod("hqlBook", EntityManager.class, String.class); | ||
Assertions.assertNotNull(method); | ||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers())); | ||
|
||
// Panache native method generates a static method | ||
method = repositoryClass.getDeclaredMethod("findBook", EntityManager.class, String.class); | ||
Assertions.assertNotNull(method); | ||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers())); | ||
} | ||
} |