Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for connection pool managers with Hibernate #318

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ freemarker = '2.3.32'
jsonSchemaValidator = '2.2.14'
guava = '33.0.0-jre'
jakartaActivation = '2.0.1'
hibernate = '6.6.1.Final'
hibernate = '6.6.2.Final'
dom4j = '2.1.4'
jdbcPostgresql = '42.7.2'
jdbcMysql = '8.0.33'
Expand Down Expand Up @@ -44,10 +44,12 @@ freemarker = { module = 'org.freemarker:freemarker', version.ref = 'freemarker'
jsonSchemaValidator = { module = 'com.github.java-json-tools:json-schema-validator', version.ref = 'jsonSchemaValidator' }
guava = { module = 'com.google.guava:guava', version.ref = 'guava' }
jakartaActivation = { module = 'com.sun.activation:jakarta.activation', version.ref = 'jakartaActivation' }
hibernate = { module = 'org.hibernate:hibernate-core', version.ref='hibernate' }
hibernate = { module = 'org.hibernate.orm:hibernate-core', version.ref='hibernate' }
hibernateToolsOrm = { module='org.hibernate.tool:hibernate-tools-orm', version.ref='hibernate' }
hibernateToolsUtils = { module='org.hibernate.tool:hibernate-tools-utils', version.ref='hibernate' }
hibernateAgroal = { module='org.hibernate:hibernate-agroal', version.ref='hibernate' }
hibernateC3p0 = { module='org.hibernate.orm:hibernate-c3p0', version.ref='hibernate' }
hibernateHikari = { module='org.hibernate.orm:hibernate-hikaricp', version.ref='hibernate' }
dom4j = { module = 'org.dom4j:dom4j', version.ref='dom4j' }
jdbcPostgresql = { module = 'org.postgresql:postgresql', version.ref='jdbcPostgresql' }
jdbcMysql = { module = 'mysql:mysql-connector-java', version.ref='jdbcMysql' }
Expand All @@ -65,4 +67,3 @@ jackson = [
"jacksonDatabind",
"jacksonDataTypeJSR310"
]

25 changes: 9 additions & 16 deletions modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@

package org.jpos.ee;

// import org.hibernate.query.criteria.internal.OrderImpl;

import jakarta.persistence.NoResultException;
import jakarta.persistence.criteria.*;
import org.hibernate.query.Query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import java.util.*;

public class DBManager<T> {

Expand Down Expand Up @@ -56,12 +52,11 @@ public int getItemCount() {

public int getItemCount(DBFilter<T>... filters) {
CriteriaBuilder cb = db.session().getCriteriaBuilder();
// CriteriaQuery<Card> query = createCriteriaQuery(false, (DBFilter<Card>) null);
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
Root<T> root = countQuery.from(clazz);
Predicate combinedPredicate = cb.and(
Arrays.stream(filters)
.filter(f -> f != null)
.filter(Objects::nonNull)
.map(f -> f.createPredicate(cb, root))
.toArray(Predicate[]::new)
);
Expand All @@ -80,7 +75,7 @@ public int getItemCount(DBFilter<T>... filters) {

}
public List<T> getAll(int offset, int limit, Map<String,Boolean> orders) {
return this.getAll(offset, limit, orders, null);
return this.getAll(offset, limit, orders, (DBFilter<T>) null);
}

public List<T> getAll(int offset, int limit, Map<String,Boolean> orders, DBFilter<T>... filters) {
Expand All @@ -91,13 +86,13 @@ public List<T> getAll(int offset, int limit, Map<String,Boolean> orders, DBFilte
//ORDERS
if (orders != null) {
orders.forEach((key, value) ->
orderList.add(value ? criteriaBuilder.asc(root.get(key)) : criteriaBuilder.desc(root.get(key)))
orderList.add(Boolean.TRUE.equals(value) ? criteriaBuilder.asc(root.get(key)) : criteriaBuilder.desc(root.get(key)))
);
}
Predicate combinedPredicate = null;
if (filters != null) {
combinedPredicate = criteriaBuilder.and(Arrays.stream(filters)
.filter(f -> f != null)
.filter(Objects::nonNull)
.map(f -> f.createPredicate(criteriaBuilder, root))
.toArray(Predicate[]::new));
}
Expand All @@ -115,10 +110,9 @@ public List<T> getAll(int offset, int limit, Map<String,Boolean> orders, DBFilte
if (limit != -1) {
queryImp.setMaxResults(limit);
}
List<T> list = queryImp
return queryImp
.setFirstResult(offset)
.getResultList();
return list;
}

public List<T> getAll() {
Expand Down Expand Up @@ -155,10 +149,9 @@ public List<T> getItemsByParam(int offset, int limit, String param, Object value
if (limit != -1) {
queryImp.setMaxResults(limit);
}
List<T> list = queryImp
return queryImp
.setFirstResult(offset)
.getResultList();
return list;
} catch (NoResultException nre) {
return null;
}
Expand Down Expand Up @@ -211,7 +204,7 @@ public List<T> queryItems(DBFilter<T> filter) {
* Arbitrary query over the entity type (T) of this manager
* Example usage:
* <pre>
* List&le;T&ge results = queryItems( (cb, root) ->
* List&le;T&ge; results = queryItems( (cb, root) ->
* cb.or(
* cb.greaterThanOrEqualTo(root.get("property"), value),
* cb.isNotNull(root.get("otherProperty")
Expand Down