diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/ManagerSupport.java b/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java similarity index 88% rename from modules/dbsupport/src/main/java/org/jpos/ee/ManagerSupport.java rename to modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java index 354b09d6b9..c6039f4870 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/ManagerSupport.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java @@ -23,29 +23,25 @@ import javax.persistence.NoResultException; import javax.persistence.Query; import javax.persistence.criteria.*; -import java.lang.reflect.ParameterizedType; import java.util.ArrayList; import java.util.List; import java.util.Map; -/** - * Created by jr on 6/6/17. - */ -public class ManagerSupport { +public class DBManager { protected DB db; private Class clazz; - public ManagerSupport(DB db) { + public DBManager(DB db, Class clazz) { this.db = db; - clazz = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + this.clazz = clazz; } public int getItemCount() { CriteriaBuilder criteriaBuilder = db.session().getCriteriaBuilder(); CriteriaQuery query = criteriaBuilder.createQuery(Long.class); Root root = query.from(clazz); - Predicate[] predicates = buildPredicates(root); + Predicate[] predicates = buildFilters(root); if (predicates != null) query.where(predicates); query.select(criteriaBuilder.count(root)); @@ -64,7 +60,7 @@ public List getAll(int offset, int limit, Map orders) { orderList.add(order); } } - Predicate[] predicates = buildPredicates(root); + Predicate[] predicates = buildFilters(root); if (predicates != null) query.where(predicates); query.select(root); @@ -108,7 +104,7 @@ private CriteriaQuery createQueryByParam(String param, Object value, boolean Predicate equals = criteriaBuilder.equal(root.get(param), value); query.where(equals); if (withFilter) { - Predicate[] predicates = buildPredicates(root); + Predicate[] predicates = buildFilters(root); if (predicates != null) { //overrides previous predicates query.where(criteriaBuilder.and(criteriaBuilder.and(predicates), equals)); @@ -118,6 +114,6 @@ private CriteriaQuery createQueryByParam(String param, Object value, boolean return query; } - protected Predicate[] buildPredicates(Root root) { return null; } + protected Predicate[] buildFilters(Root root) { return null; } } diff --git a/modules/eeuser/src/main/java/org/jpos/ee/ConsumerManager.java b/modules/eeuser/src/main/java/org/jpos/ee/ConsumerManager.java index be2472c46f..99033400bb 100644 --- a/modules/eeuser/src/main/java/org/jpos/ee/ConsumerManager.java +++ b/modules/eeuser/src/main/java/org/jpos/ee/ConsumerManager.java @@ -19,23 +19,22 @@ package org.jpos.ee; import org.hibernate.HibernateException; -import org.hibernate.criterion.Restrictions; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.util.*; @SuppressWarnings("unused") -public class ConsumerManager extends ManagerSupport { +public class ConsumerManager extends DBManager { private User user; public ConsumerManager (DB db) { - super(db); + super(db,Consumer.class); } public ConsumerManager(DB db, User user) { - super(db); + super(db,Consumer.class); this.user = user; } @@ -50,7 +49,7 @@ public List getConsumers (User user) { return getAll(); } - protected Predicate[] buildPredicates(Root root) { + protected Predicate[] buildFilters(Root root) { Predicate notDeleted = db.session.getCriteriaBuilder().isFalse(root.get("deleted")); if (user != null) { Predicate p = db.session().getCriteriaBuilder().equal(root.get("user"),user.getId()); diff --git a/modules/eeuser/src/main/java/org/jpos/ee/RevisionManager.java b/modules/eeuser/src/main/java/org/jpos/ee/RevisionManager.java index a781a31c24..821dc300ac 100644 --- a/modules/eeuser/src/main/java/org/jpos/ee/RevisionManager.java +++ b/modules/eeuser/src/main/java/org/jpos/ee/RevisionManager.java @@ -34,10 +34,10 @@ import javax.persistence.criteria.Root; @SuppressWarnings("unused") -public class RevisionManager extends ManagerSupport { +public class RevisionManager extends DBManager { public RevisionManager (DB db) { - super(db); + super(db,Revision.class); } @SuppressWarnings("unchecked") public List getRevisionsByRef (String ref) diff --git a/modules/eeuser/src/main/java/org/jpos/ee/RoleManager.java b/modules/eeuser/src/main/java/org/jpos/ee/RoleManager.java index fc14a29fa4..46abb2651a 100644 --- a/modules/eeuser/src/main/java/org/jpos/ee/RoleManager.java +++ b/modules/eeuser/src/main/java/org/jpos/ee/RoleManager.java @@ -18,10 +18,10 @@ package org.jpos.ee; -public class RoleManager extends ManagerSupport { +public class RoleManager extends DBManager { public RoleManager (DB db) { - super(db); + super(db,Role.class); } public Role getRoleByName (String name) { diff --git a/modules/eeuser/src/main/java/org/jpos/ee/UserManager.java b/modules/eeuser/src/main/java/org/jpos/ee/UserManager.java index 9b9f4d4138..622c0877f6 100644 --- a/modules/eeuser/src/main/java/org/jpos/ee/UserManager.java +++ b/modules/eeuser/src/main/java/org/jpos/ee/UserManager.java @@ -21,17 +21,12 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.Map; import org.bouncycastle.util.Arrays; import org.bouncycastle.util.encoders.Base64; -import org.hibernate.Criteria; import org.hibernate.HibernateException; -import org.hibernate.criterion.Restrictions; -import org.hibernate.query.criteria.internal.OrderImpl; import org.jpos.iso.ISOUtil; import org.jpos.security.SystemSeed; @@ -42,7 +37,7 @@ /** * @author Alejandro Revilla */ -public class UserManager extends ManagerSupport { +public class UserManager extends DBManager { VERSION version; @@ -51,7 +46,7 @@ public UserManager (DB db) { } public UserManager (DB db, VERSION version) { - super (db); + super (db, User.class); this.version = version; } @@ -92,7 +87,7 @@ public List findAll () throws HibernateException { } @Override - protected Predicate[] buildPredicates(Root root) { + protected Predicate[] buildFilters(Root root) { return new Predicate[] { db.session().getCriteriaBuilder().isFalse(root.get("deleted")) }; diff --git a/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/AccountManager.java b/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/AccountManager.java index a78bcf3a15..9f758556ca 100644 --- a/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/AccountManager.java +++ b/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/AccountManager.java @@ -20,7 +20,7 @@ import org.hibernate.query.criteria.internal.OrderImpl; import org.jpos.ee.DB; -import org.jpos.ee.ManagerSupport; +import org.jpos.ee.DBManager; import org.jpos.gl.Account; import org.jpos.gl.CompositeAccount; @@ -32,11 +32,11 @@ /** * Created by jr on 8/8/17. */ -public class AccountManager extends ManagerSupport { +public class AccountManager extends DBManager { public AccountManager(DB db) { - super(db); + super(db,Account.class); } public List getAllChildren(int offset, int limit, Map orders, Account parent) throws Exception { diff --git a/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/GLTransactionManager.java b/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/GLTransactionManager.java index c4c5fd1267..4bc5aabc9e 100644 --- a/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/GLTransactionManager.java +++ b/modules/qi-minigl/src/main/java/org/jpos/qi/minigl/GLTransactionManager.java @@ -19,32 +19,32 @@ package org.jpos.qi.minigl; import org.jpos.ee.DB; -import org.jpos.ee.ManagerSupport; +import org.jpos.ee.DBManager; import org.jpos.gl.GLTransaction; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.util.Date; -public class GLTransactionManager extends ManagerSupport { +public class GLTransactionManager extends DBManager { private Date start; private Date end; private Long journalId; public GLTransactionManager(DB db) { - super(db); + super(db,GLTransaction.class); } public GLTransactionManager(DB db, Long journalId, Date start, Date end) { - super(db); + super(db,GLTransaction.class); this.start = start; this.end = end; this.journalId = journalId; } @Override - protected Predicate[] buildPredicates(Root root) { + protected Predicate[] buildFilters(Root root) { db.session().enableFetchProfile("eager"); Predicate journalPredicate = null; if (journalId != null) { diff --git a/modules/sysconfig/src/main/java/org/jpos/ee/SysConfigManager.java b/modules/sysconfig/src/main/java/org/jpos/ee/SysConfigManager.java index ae567082b4..391019f13b 100644 --- a/modules/sysconfig/src/main/java/org/jpos/ee/SysConfigManager.java +++ b/modules/sysconfig/src/main/java/org/jpos/ee/SysConfigManager.java @@ -30,14 +30,14 @@ import javax.persistence.criteria.*; @SuppressWarnings("unused") -public class SysConfigManager extends ManagerSupport { +public class SysConfigManager extends DBManager { private String prefix = ""; public SysConfigManager (DB db) { - super(db); + super(db,SysConfig.class); } public SysConfigManager (DB db, String prefix) { - super(db); + super(db,SysConfig.class); this.prefix = prefix; } public void setPrefix (String prefix) { @@ -130,7 +130,7 @@ public List getAll () { } @Override - protected Predicate[] buildPredicates(Root root) { + protected Predicate[] buildFilters(Root root) { Predicate[] predicates = new Predicate[] { db.session().getCriteriaBuilder().like(root.get("id"),prefix + "%") }; diff --git a/modules/syslog/src/main/java/org/jpos/ee/SysLogManager.java b/modules/syslog/src/main/java/org/jpos/ee/SysLogManager.java index 1fd05f6c59..70839b8b7e 100644 --- a/modules/syslog/src/main/java/org/jpos/ee/SysLogManager.java +++ b/modules/syslog/src/main/java/org/jpos/ee/SysLogManager.java @@ -26,7 +26,7 @@ @SuppressWarnings("unused") -public class SysLogManager extends ManagerSupport { +public class SysLogManager extends DBManager { boolean autoCommit; /** @@ -34,7 +34,7 @@ public class SysLogManager extends ManagerSupport { * (open/begin/commit/close is not required). */ public SysLogManager () { - super (new DB()); + super (new DB(),SysLog.class); autoCommit = true; } @@ -45,7 +45,7 @@ public SysLogManager () { * @param db the DB instance */ public SysLogManager (DB db) { - super(db); + super(db,SysLog.class); autoCommit = false; } @@ -55,7 +55,7 @@ public SysLogManager (DB db) { * @param autoCommit true if we want this manager to auto-commit log events */ public SysLogManager (DB db, boolean autoCommit) { - super(db); + super(db, SysLog.class); this.autoCommit = autoCommit; }