Skip to content
Snippets Groups Projects
Commit 1c45fb44 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

deprecated criteria api replaced

parent 71b309f1
No related branches found
No related tags found
1 merge request!782Resolve "Replace deprecated APIs"
......@@ -2,11 +2,13 @@ package lcsb.mapviewer.persist.dao;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.Dialect;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -165,12 +167,15 @@ public abstract class BaseDao<T> {
* @return number of all elements in database
*/
public long getCount() {
if (removableColumn == null) {
return (Long) getSession().createCriteria(this.clazz).setProjection(Projections.rowCount()).uniqueResult();
} else {
return (Long) getSession().createCriteria(this.clazz).add(Restrictions.eq(removableColumn, false))
.setProjection(Projections.rowCount()).uniqueResult();
CriteriaBuilder builder = getSession().getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<T> root = criteria.from(this.clazz);
if (removableColumn != null) {
criteria.where(builder.equal(root.get(removableColumn), false));
}
criteria.select(builder.count(root));
return getSession().createQuery(criteria).getSingleResult();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment