Skip to content

Commit

Permalink
Merge pull request #96 from barspi/master
Browse files Browse the repository at this point in the history
DBManager.byId() convenience method, and fix unchecked assignment
  • Loading branch information
ar authored Mar 14, 2019
2 parents 8816904 + 023a9cb commit d3185f6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.hibernate.query.criteria.internal.OrderImpl;

import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.persistence.criteria.*;
import org.hibernate.query.Query;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -37,6 +37,11 @@ public DBManager(DB db, Class<T> clazz) {
this.clazz = clazz;
}

/** Convenience method */
public T byId(Long id) {
return db.session().get(clazz, id);
}

public int getItemCount() {
CriteriaBuilder criteriaBuilder = db.session().getCriteriaBuilder();
CriteriaQuery<Long> query = criteriaBuilder.createQuery(Long.class);
Expand Down Expand Up @@ -65,7 +70,7 @@ public List<T> getAll(int offset, int limit, Map<String,Boolean> orders) {
query.where(predicates);
query.select(root);
query.orderBy(orderList);
Query queryImp = db.session().createQuery(query);
Query<T> queryImp = db.session().createQuery(query);
if (limit != -1) {
queryImp.setMaxResults(limit);
}
Expand Down

0 comments on commit d3185f6

Please sign in to comment.