forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test jpamodelgen in Quarkus applications
- Loading branch information
Showing
11 changed files
with
514 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-integration-tests-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-integration-test-hibernate-orm-jpamodelgen</artifactId> | ||
<name>Quarkus - Integration Tests - Hibernate ORM with jpamodelgen</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm-panache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jdbc-h2</artifactId> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm-panache-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jdbc-h2-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.hibernate.orm</groupId> | ||
<artifactId>hibernate-jpamodelgen</artifactId> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
26 changes: 26 additions & 0 deletions
26
...gen/src/main/java/io/quarkus/it/hibernate/jpamodelgen/MyPanacheStaticMetamodelEntity.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,26 @@ | ||
package io.quarkus.it.hibernate.jpamodelgen; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
|
||
@Entity | ||
public class MyPanacheStaticMetamodelEntity extends PanacheEntity { | ||
|
||
@Column(unique = true) | ||
public String name; | ||
|
||
MyPanacheStaticMetamodelEntity() { | ||
} | ||
|
||
public MyPanacheStaticMetamodelEntity(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MyPanacheEntity [id=" + id + ", name=" + name + "]"; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...n/src/main/java/io/quarkus/it/hibernate/jpamodelgen/MyPanacheStaticMetamodelResource.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,68 @@ | ||
package io.quarkus.it.hibernate.jpamodelgen; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.DELETE; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.query.criteria.JpaRoot; | ||
import org.jboss.resteasy.reactive.RestPath; | ||
|
||
@ApplicationScoped | ||
@Produces("application/json") | ||
@Consumes("application/json") | ||
@Path("/panache/static-metamodel/") | ||
public class MyPanacheStaticMetamodelResource { | ||
|
||
@Inject | ||
Session session; | ||
|
||
@POST | ||
@Transactional | ||
public void create(MyPanacheStaticMetamodelEntity entity) { | ||
session.persist(entity); | ||
} | ||
|
||
@GET | ||
@Transactional | ||
@Path("/by/name/{name}") | ||
public MyPanacheStaticMetamodelEntity getByName(@RestPath String name) { | ||
var b = session.getCriteriaBuilder(); | ||
var query = b.createQuery(MyPanacheStaticMetamodelEntity.class); | ||
var e = query.from(MyPanacheStaticMetamodelEntity_.class_); | ||
query.where(e.get(MyPanacheStaticMetamodelEntity_.name).equalTo(name)); | ||
return session.createQuery(query).uniqueResultOptional().orElseThrow(NotFoundException::new); | ||
} | ||
|
||
@POST | ||
@Transactional | ||
@Path("/rename/{before}/to/{after}") | ||
public void rename(@RestPath String before, @RestPath String after) { | ||
var b = session.getCriteriaBuilder(); | ||
var query = b.createCriteriaUpdate(MyPanacheStaticMetamodelEntity.class); | ||
// Cast to work around https://hibernate.atlassian.net/browse/HHH-17682 | ||
var e = (JpaRoot<MyPanacheStaticMetamodelEntity>) query.getRoot(); | ||
query.where(e.get(MyPanacheStaticMetamodelEntity_.name).equalTo(before)); | ||
query.set(e.get(MyPanacheStaticMetamodelEntity_.name), after); | ||
session.createMutationQuery(query).executeUpdate(); | ||
} | ||
|
||
@DELETE | ||
@Transactional | ||
@Path("/by/name/{name}") | ||
public void deleteByName(@RestPath String name) { | ||
var b = session.getCriteriaBuilder(); | ||
var query = b.createCriteriaDelete(MyPanacheStaticMetamodelEntity.class); | ||
// Cast to work around https://hibernate.atlassian.net/browse/HHH-17682 | ||
var e = (JpaRoot<MyPanacheStaticMetamodelEntity>) query.getRoot(); | ||
query.where(e.get(MyPanacheStaticMetamodelEntity_.name).equalTo(name)); | ||
session.createMutationQuery(query).executeUpdate(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...pamodelgen/src/main/java/io/quarkus/it/hibernate/jpamodelgen/MyStaticMetamodelEntity.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,30 @@ | ||
package io.quarkus.it.hibernate.jpamodelgen; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class MyStaticMetamodelEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
public Integer id; | ||
|
||
@Column(unique = true) | ||
public String name; | ||
|
||
MyStaticMetamodelEntity() { | ||
} | ||
|
||
public MyStaticMetamodelEntity(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MyOrmEntity [id=" + id + ", name=" + name + "]"; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...modelgen/src/main/java/io/quarkus/it/hibernate/jpamodelgen/MyStaticMetamodelResource.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,68 @@ | ||
package io.quarkus.it.hibernate.jpamodelgen; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.DELETE; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.query.criteria.JpaRoot; | ||
import org.jboss.resteasy.reactive.RestPath; | ||
|
||
@ApplicationScoped | ||
@Produces("application/json") | ||
@Consumes("application/json") | ||
@Path("/static-metamodel/") | ||
public class MyStaticMetamodelResource { | ||
|
||
@Inject | ||
Session session; | ||
|
||
@POST | ||
@Transactional | ||
public void create(MyStaticMetamodelEntity entity) { | ||
session.persist(entity); | ||
} | ||
|
||
@GET | ||
@Transactional | ||
@Path("/by/name/{name}") | ||
public MyStaticMetamodelEntity getByName(@RestPath String name) { | ||
var b = session.getCriteriaBuilder(); | ||
var query = b.createQuery(MyStaticMetamodelEntity.class); | ||
var e = query.from(MyStaticMetamodelEntity_.class_); | ||
query.where(e.get(MyStaticMetamodelEntity_.name).equalTo(name)); | ||
return session.createQuery(query).uniqueResultOptional().orElseThrow(NotFoundException::new); | ||
} | ||
|
||
@POST | ||
@Transactional | ||
@Path("/rename/{before}/to/{after}") | ||
public void rename(@RestPath String before, @RestPath String after) { | ||
var b = session.getCriteriaBuilder(); | ||
var query = b.createCriteriaUpdate(MyStaticMetamodelEntity.class); | ||
// Cast to work around https://hibernate.atlassian.net/browse/HHH-17682 | ||
var e = (JpaRoot<MyStaticMetamodelEntity>) query.getRoot(); | ||
query.where(e.get(MyStaticMetamodelEntity_.name).equalTo(before)); | ||
query.set(e.get(MyStaticMetamodelEntity_.name), after); | ||
session.createMutationQuery(query).executeUpdate(); | ||
} | ||
|
||
@DELETE | ||
@Transactional | ||
@Path("/by/name/{name}") | ||
public void deleteByName(@RestPath String name) { | ||
var b = session.getCriteriaBuilder(); | ||
var query = b.createCriteriaDelete(MyStaticMetamodelEntity.class); | ||
// Cast to work around https://hibernate.atlassian.net/browse/HHH-17682 | ||
var e = (JpaRoot<MyStaticMetamodelEntity>) query.getRoot(); | ||
query.where(e.get(MyStaticMetamodelEntity_.name).equalTo(name)); | ||
session.createMutationQuery(query).executeUpdate(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
integration-tests/hibernate-orm-jpamodelgen/src/main/resources/application.properties
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,2 @@ | ||
quarkus.datasource.jdbc.max-size=8 | ||
quarkus.hibernate-orm.database.generation=drop-and-create |
8 changes: 8 additions & 0 deletions
8
...lgen/src/test/java/io/quarkus/it/hibernate/jpamodelgen/HibernateJpaModelGenInGraalIT.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,8 @@ | ||
package io.quarkus.it.hibernate.jpamodelgen; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class HibernateJpaModelGenInGraalIT extends HibernateJpaModelGenTest { | ||
|
||
} |
Oops, something went wrong.