Skip to content

Commit

Permalink
feat: revert hint from page query (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored May 6, 2024
1 parent 46bc915 commit 39f4e98
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 400 deletions.
2 changes: 1 addition & 1 deletion docs/modules/tkit-quarkus/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:project-version:
:project-version: 2.22.0
:quarkus-version: 3.9.3

:examples-dir: ./../examples/
274 changes: 137 additions & 137 deletions docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,6 @@ public PagedQuery<T> createPageQuery(CriteriaQuery<T> query, Page page) {
return new PagedQuery<>(getEntityManager(), query, page, idAttributeName);
}

/**
* Creates the page query of the DAO {@code <T>} type.
*
* @param query the criteria query
* @param page the page for the query
* @param hint query hint
* @return the new page query instance
*/
public PagedQuery<T> createPageQuery(CriteriaQuery<T> query, Page page, String hint) {
return new PagedQuery<>(getEntityManager(), query, page, idAttributeName, hint);
}

/**
* Creates the page query of the DAO {@code <T>} type.
*
Expand All @@ -150,19 +138,6 @@ public <E> PagedQuery<E> createPageQueryCustom(CriteriaQuery<E> query, Page page
return new PagedQuery<>(em, query, page, idAttributeName);
}

/**
* Creates the page query of the custom {@code <E>} type
*
* @param query the criteria query
* @param page the page for the query
* @param hint query hint
* @param <E> the entity type of the paged query.
* @return the new page query instance
*/
public <E> PagedQuery<E> createPageQueryCustom(CriteriaQuery<E> query, Page page, String hint) {
return new PagedQuery<>(em, query, page, idAttributeName, hint);
}

/**
* Finds all entities.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public class PagedQuery<T> {
*/
private Page page;

/**
* Query hint
*/
private String hint;

/**
* Default constructor.
*
Expand All @@ -56,32 +51,17 @@ public class PagedQuery<T> {
* @param page the start page.
*/
public PagedQuery(EntityManager em, CriteriaQuery<T> criteria, Page page, String idAttributeName) {
this(em, criteria, page, idAttributeName, null);
}

/**
* Constructor including query hint.
*
* @param em the entity manager.
* @param criteria the search criteria
* @param page the start page.
* @param hint custom query hint
*/
public PagedQuery(EntityManager em, CriteriaQuery<T> criteria, Page page, String idAttributeName, String hint) {
this.em = em;
this.criteria = setDefaultSorting(em, criteria, idAttributeName);
this.page = page;
this.countCriteria = createCountCriteria(em, criteria);
this.hint = hint;
}

public PageResult<T> getPageResult() {
try {
var q = em.createQuery(countCriteria);
if (hint != null) {
q.setHint(AbstractDAO.HINT_LOAD_GRAPH, em.getEntityGraph(hint));
}

// get count
var q = em.createQuery(countCriteria);
Long count = q.getSingleResult();
// return empty page for count zero
if (count == 0) {
Expand All @@ -90,9 +70,6 @@ public PageResult<T> getPageResult() {

// get stream
var sq = em.createQuery(criteria);
if (hint != null) {
sq.setHint(AbstractDAO.HINT_LOAD_GRAPH, em.getEntityGraph(hint));
}
Stream<T> stream = sq
.setFirstResult(page.number() * page.size())
.setMaxResults(page.size())
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 39f4e98

Please sign in to comment.