-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added possibility for query hints (#155)
* feat: added possibility for query hints * feat: improvements and tests * fix: format
- Loading branch information
1 parent
470e5f6
commit 7979ef6
Showing
11 changed files
with
419 additions
and
144 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
:project-version: 2.20.0 | ||
:project-version: | ||
:quarkus-version: 3.9.3 | ||
|
||
:examples-dir: ./../examples/ |
274 changes: 137 additions & 137 deletions
274
docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
22 changes: 22 additions & 0 deletions
22
extensions/jpa/tests/src/main/java/org/tkit/quarkus/jpa/test/Child.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,22 @@ | ||
package org.tkit.quarkus.jpa.test; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
|
||
import org.tkit.quarkus.jpa.models.TraceableEntity; | ||
|
||
@Entity | ||
@Table(name = "TEST_CHILD") | ||
public class Child extends TraceableEntity { | ||
@Column(name = "MFE_ID", nullable = false) | ||
private String mfeId; | ||
|
||
public String getMfeId() { | ||
return mfeId; | ||
} | ||
|
||
public void setMfeId(String mfeId) { | ||
this.mfeId = mfeId; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
extensions/jpa/tests/src/main/java/org/tkit/quarkus/jpa/test/ChildDAO.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,9 @@ | ||
package org.tkit.quarkus.jpa.test; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.tkit.quarkus.jpa.daos.AbstractDAO; | ||
|
||
@ApplicationScoped | ||
public class ChildDAO extends AbstractDAO<Child> { | ||
} |
27 changes: 27 additions & 0 deletions
27
extensions/jpa/tests/src/main/java/org/tkit/quarkus/jpa/test/Parent.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.tkit.quarkus.jpa.test; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.persistence.*; | ||
|
||
import org.tkit.quarkus.jpa.models.TraceableEntity; | ||
|
||
@Entity | ||
@NamedEntityGraph(name = "Parent.loadChildren", includeAllAttributes = true) | ||
@Table(name = "TEST_PARENT") | ||
public class Parent extends TraceableEntity { | ||
|
||
@OneToMany(fetch = LAZY, cascade = CascadeType.ALL, orphanRemoval = true) | ||
@JoinColumn(name = "PARENT_GUID") | ||
private List<Child> children; | ||
|
||
public List<Child> getChildren() { | ||
return children; | ||
} | ||
|
||
public void setChildren(List<Child> children) { | ||
this.children = children; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
extensions/jpa/tests/src/main/java/org/tkit/quarkus/jpa/test/ParentDAO.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,34 @@ | ||
package org.tkit.quarkus.jpa.test; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.transaction.Transactional; | ||
|
||
import org.tkit.quarkus.jpa.daos.AbstractDAO; | ||
import org.tkit.quarkus.jpa.daos.Page; | ||
import org.tkit.quarkus.jpa.daos.PageResult; | ||
|
||
@ApplicationScoped | ||
public class ParentDAO extends AbstractDAO<Parent> { | ||
|
||
@Transactional(Transactional.TxType.NOT_SUPPORTED) | ||
Parent loadById(String id) { | ||
var cb = this.getEntityManager().getCriteriaBuilder(); | ||
var cq = cb.createQuery(Parent.class); | ||
var root = cq.from(Parent.class); | ||
|
||
cq.where(cb.equal(root.get("id"), id)); | ||
Parent p = this.getEntityManager().createQuery(cq) | ||
.setHint(HINT_LOAD_GRAPH, this.getEntityManager().getEntityGraph("Parent.loadChildren")).getSingleResult(); | ||
this.getEntityManager().detach(p); | ||
return p; | ||
} | ||
|
||
PageResult<Parent> loadPage() { | ||
var cb = this.getEntityManager().getCriteriaBuilder(); | ||
var cq = cb.createQuery(Parent.class); | ||
var root = cq.from(Parent.class); | ||
|
||
cq.where(root.get("id").isNotNull()); | ||
return this.createPageQuery(cq, Page.of(0, 10), "Parent.loadChildren").getPageResult(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
extensions/jpa/tests/src/main/java/org/tkit/quarkus/jpa/test/ParentRestController.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,56 @@ | ||
package org.tkit.quarkus.jpa.test; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.*; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.tkit.quarkus.jpa.models.TraceableEntity; | ||
|
||
@Path("parent") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Transactional(Transactional.TxType.NOT_SUPPORTED) | ||
@ApplicationScoped | ||
public class ParentRestController { | ||
@Inject | ||
ParentDAO parentDAO; | ||
|
||
@GET | ||
@Path("{id}") | ||
public Response find(@PathParam("id") String id) { | ||
Parent tmp = parentDAO.loadById(id); | ||
if (tmp == null) { | ||
return Response.status(Response.Status.NOT_FOUND).build(); | ||
} | ||
System.out.println("_____________________________________"); | ||
System.out.println(tmp.getChildren().get(0).getMfeId()); | ||
return Response.ok(tmp).build(); | ||
} | ||
|
||
@GET | ||
public Response create() { | ||
Parent tmp = new Parent(); | ||
Child c1 = new Child(); | ||
c1.setMfeId("mfe1"); | ||
Child c2 = new Child(); | ||
c2.setMfeId("mfe2"); | ||
tmp.setChildren(List.of(c1, c2)); | ||
// Sibling sibling = siblingDAO.create(new Sibling()); | ||
// tmp.setSibling(sibling); | ||
parentDAO.create(tmp); | ||
|
||
return Response.ok(tmp).build(); | ||
} | ||
|
||
@GET | ||
@Path("page") | ||
public Response getPageResult() { | ||
return Response.ok(parentDAO.loadPage().getStream() | ||
.map(parent -> parent.getChildren().stream().map(TraceableEntity::getId).toList()).toList()).build(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
extensions/jpa/tests/src/test/java/org/tkit/quarkus/jpa/test/ParentDAOTest.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,64 @@ | ||
package org.tkit.quarkus.jpa.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
|
||
@QuarkusTest | ||
@DisplayName("Parent DAO tests") | ||
public class ParentDAOTest extends AbstractTest { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ParentDAOTest.class); | ||
|
||
@Test | ||
public void searchParentTest() { | ||
Parent create = given() | ||
.get("parent") | ||
.then() | ||
.log().all() | ||
.statusCode(Response.Status.OK.getStatusCode()) | ||
.extract().body().as(Parent.class); | ||
|
||
Parent find = given() | ||
.contentType(ContentType.JSON) | ||
.pathParam("id", create.getId()) | ||
.get("parent/{id}") | ||
.then() | ||
.log().all() | ||
.statusCode(Response.Status.OK.getStatusCode()) | ||
.extract().body().as(Parent.class); | ||
|
||
Assertions.assertNotNull(find); | ||
Assertions.assertEquals(create.getId(), find.getId()); | ||
} | ||
|
||
@Test | ||
public void loadPageResult() { | ||
given() | ||
.get("parent") | ||
.then() | ||
.log().all() | ||
.statusCode(Response.Status.OK.getStatusCode()) | ||
.extract().body().as(Parent.class); | ||
|
||
var find = given() | ||
.contentType(ContentType.JSON) | ||
.get("parent/page") | ||
.then() | ||
.log().all() | ||
.statusCode(Response.Status.OK.getStatusCode()) | ||
.contentType(ContentType.JSON) | ||
.extract().asString(); | ||
|
||
Assertions.assertNotNull(find); | ||
} | ||
} |