From 23a46b4be35277e06ec89f48730eeb694e686be8 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 15:40:06 +0000
Subject: [PATCH] add fdx-commons and fdx-consultation
---
fdx-consultation/fdxconsultation-dao-ifaces/src/main/java/com/megatim/fdxconsultation/dao/ifaces/abstracts/CustomDAOWithCriteriaEntityIfaces.java | 76 ++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/fdx-consultation/fdxconsultation-dao-ifaces/src/main/java/com/megatim/fdxconsultation/dao/ifaces/abstracts/CustomDAOWithCriteriaEntityIfaces.java b/fdx-consultation/fdxconsultation-dao-ifaces/src/main/java/com/megatim/fdxconsultation/dao/ifaces/abstracts/CustomDAOWithCriteriaEntityIfaces.java
new file mode 100644
index 0000000..736cf9d
--- /dev/null
+++ b/fdx-consultation/fdxconsultation-dao-ifaces/src/main/java/com/megatim/fdxconsultation/dao/ifaces/abstracts/CustomDAOWithCriteriaEntityIfaces.java
@@ -0,0 +1,76 @@
+package com.megatim.fdxconsultation.dao.ifaces.abstracts;
+
+import com.megatim.fdxcommons.model.pojo.CriteriaEntityFromView;
+import com.megatim.fdxcommons.tools.database.tables.dto.JpqlQueryElement;
+import com.megatim.fdxcommons.model.pojo.OrderByDefinition;
+import com.megatim.fdxcommons.tools.database.queries.metadata.jpql.JpqlQueryParam;
+import com.megatim.fdxcommons.tools.database.tables.JpqlTable;
+import java.util.List;
+import javax.persistence.EntityGraph;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+/**
+ *
+ * @author ASUS
+ */
+public interface CustomDAOWithCriteriaEntityIfaces<T, ID> {
+
+ default T save(T entity) {
+ return getEntityManager().merge(entity);
+ }
+
+ default void delete(T entity) {
+ getEntityManager().remove(entity);
+ }
+
+ public Class<T> getManagedEntityClass();
+
+ public EntityManager getEntityManager();
+
+ public T getById(ID id);
+
+ public default List<T> findAll(CriteriaEntityFromView criterion, List<String> fetchEagerFields, List<OrderByDefinition> orderByFields) throws Exception {
+ EntityGraph<T> entityGraph = getEntityManager().createEntityGraph(getManagedEntityClass());
+ fetchEagerFields.stream().forEach(f -> entityGraph.addAttributeNodes(f));
+ JpqlQueryElement jpqlQueryElt = new JpqlTable(criterion, getManagedEntityClass()).selectQuery(orderByFields);
+ System.out.println("****************** query " + jpqlQueryElt.getQuery());
+ Query query = getEntityManager().createQuery(jpqlQueryElt.getQuery());
+ setRealParams(query, jpqlQueryElt.getParameters());
+ query.setHint("javax.persistence.loadgraph", entityGraph);
+
+ return query.getResultList();
+ }
+
+ public default long count(CriteriaEntityFromView criterion) throws Exception {
+ JpqlQueryElement jpqlQueryElt = new JpqlTable(criterion, getManagedEntityClass()).countQuery();
+ Query query = getEntityManager().createQuery(jpqlQueryElt.getQuery());
+ System.out.println("****************** query " + jpqlQueryElt.getQuery());
+ setRealParams(query, jpqlQueryElt.getParameters());
+
+ return (long) query.getSingleResult();
+ }
+
+ public default List<T> findWithPagination(CriteriaEntityFromView criterion, List<String> fetchEagerFields, List<OrderByDefinition> orderByFields, Integer pageNumber, Integer pageSize) throws Exception {
+ EntityGraph<T> entityGraph = getEntityManager().createEntityGraph(getManagedEntityClass());
+ fetchEagerFields.stream().forEach(f -> entityGraph.addAttributeNodes(f));
+ JpqlQueryElement jpqlQueryElt = new JpqlTable(criterion, getManagedEntityClass()).selectQuery(orderByFields);
+ System.out.println("****************** query " + jpqlQueryElt.getQuery());
+ Query query = getEntityManager().createQuery(jpqlQueryElt.getQuery());
+ setRealParams(query, jpqlQueryElt.getParameters());
+
+ query.setHint("javax.persistence.loadgraph", entityGraph);
+ query.setFirstResult((pageNumber - 1) * pageSize);
+ query.setMaxResults(pageSize);
+
+ return query.getResultList();
+ }
+
+ public default void setRealParams(Query query, List<JpqlQueryParam> params) {
+ int index = 1;
+ for (JpqlQueryParam p : params) {
+ query.setParameter(index, p.getParamValue());
+ index++;
+ }
+ }
+}
--
Gitblit v1.10.0