Java Code Examples for org.hibernate.criterion.Criterion#toString()

The following examples show how to use org.hibernate.criterion.Criterion#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoreDBServiceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<E> getAllByCriteria(Criterion criterion) {
	List<E> fetchedList = new ArrayList<E>();
	Session session = getCurrentSession();
	Criteria criteria = session.createCriteria(entityClass);
	criteria.add(criterion);
	
	try {	
		fetchedList = criteria.list();
		return fetchedList;
	} catch (Exception e) {
		logger.error("getAllByCriteria failed, criteria = " + criterion.toString(), e);
		throw new HibernateException("getAllByCriteria failed, criteria = " + criterion.toString());
	}
}
 
Example 2
Source File: CoreDBServiceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<E> getByCriteriaWithLimit(Criterion criterion, Integer count) {
	List<E> fetchedList = new ArrayList<E>();
	Session session = getCurrentSession();
	Criteria criteria = session.createCriteria(entityClass);
	criteria.add(criterion);
	if(count != null && count > 0){
		criteria.setMaxResults(count);
	}
	try {	
		fetchedList = criteria.list();
		return fetchedList;
	} catch (Exception e) {
		logger.error("getByCriteriaWithLimit failed, criteria = " + criterion.toString(), e);
		throw new HibernateException("getByCriteriaWithLimit failed, criteria = " + criterion.toString());
	}
}
 
Example 3
Source File: CoreDBServiceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<E> getByCriteriaByOrder(Criterion criterion, String order, String[] orderBy, Integer count) {
	List<E> fetchedList = new ArrayList<E>();
	Session session = getCurrentSession();
	Criteria criteria = session.createCriteria(entityClass);
	criteria.add(criterion);
	for(int i = 0; i< orderBy.length; i++){
		if (order != null && order.equalsIgnoreCase("desc")) {
			criteria.addOrder(Order.desc(orderBy[i]));
		} else {
			criteria.addOrder(Order.asc(orderBy[i]));
		}
	}
	if(count != null && count > 0){
		criteria.setMaxResults(count);
	}
	try {	
		fetchedList = criteria.list();
		return fetchedList;
	} catch (Exception e) {
		logger.error("getByCriteriaWithLimit failed, criteria = " + criterion.toString(), e);
		throw new HibernateException("getByCriteriaByOrder failed, criteria = " + criterion.toString());
	}
}
 
Example 4
Source File: CoreDBServiceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public E getByCriterionID(Criterion criterion) {
	try {
		Criteria criteria = getCurrentSession().createCriteria(entityClass);
		criteria.add(criterion);
		return (E) criteria.uniqueResult();
	} catch (Exception e) {
		logger.error("getByCriterionID failed, criteria = " + criterion.toString(), e);
		throw new HibernateException("getByCriterionID failed, criteria = " + criterion.toString());
	}
}
 
Example 5
Source File: CoreDBServiceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public E getByCriteria(Criterion criterion) {
	try {
		Criteria criteria = getCurrentSession().createCriteria(entityClass);
		criteria.add(criterion);
		List<E> fetchedList = criteria.list();
		return (fetchedList != null && !fetchedList.isEmpty()) ? (E) fetchedList.get(0) : null;
	} catch (Exception e) {
		logger.error("getByCriteria failed, criteria = " + criterion.toString(), e);
		throw new HibernateException("getByCriteria failed, criteria = " + criterion.toString());
	}
}
 
Example 6
Source File: CoreDBServiceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<E> getByCriteriaWithAliasByOrder(Criterion criterion, String order, String[] orderBy, Integer count, String aliasTable, Criterion aliasCriterion) {
	Session session = getCurrentSession();
	List<E> fetchedList = new ArrayList<E>();
	//logger.info("Entity: " + entityClass + ", current Session = " + session);
	Criteria criteria = session.createCriteria(entityClass);
	criteria.add(criterion); 
	criteria.createAlias(aliasTable, aliasTable, org.hibernate.sql.JoinType.LEFT_OUTER_JOIN).add(aliasCriterion);
	if (orderBy != null) {
		for(int i = 0; i< orderBy.length; i++){
			if (order != null && order.equalsIgnoreCase("desc")) {
				criteria.addOrder(Order.desc(orderBy[i]));
			} else {
				criteria.addOrder(Order.asc(orderBy[i]));
			}
		}
	}
	if(count != null && count > 0){
		criteria.setMaxResults(count);
	}
	try {	
		fetchedList = criteria.list();
		return fetchedList;
	} catch (Exception e) {
		logger.error("getByCriteriaWithAliasByOrder failed, criteria = " + criterion.toString(), e);
		throw new HibernateException("getByCriteriaWithAliasByOrder failed, criteria = " + criterion.toString());
	}
}
 
Example 7
Source File: CoreDBServiceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<E> getByCriteriaWithInnerJoinByOrder(Criterion criterion, String order, String[] orderBy, Integer count, String aliasTable, Criterion aliasCriterion) {
	Session session = getCurrentSession();
	List<E> fetchedList = new ArrayList<E>();
	//logger.info("Entity: " + entityClass + ", current Session = " + session);
	Criteria criteria = session.createCriteria(entityClass);
	criteria.add(criterion); 
	criteria.createAlias(aliasTable, aliasTable, org.hibernate.sql.JoinType.INNER_JOIN).add(aliasCriterion);
	if (orderBy != null) {
		for(int i = 0; i< orderBy.length; i++){
			if (order != null && order.equalsIgnoreCase("desc")) {
				criteria.addOrder(Order.desc(orderBy[i]));
			} else {
				criteria.addOrder(Order.asc(orderBy[i]));
			}
		}
	}
	if(count != null && count > 0){
		criteria.setMaxResults(count);
	}
	try {	
		fetchedList = criteria.list();
		return fetchedList;
	} catch (Exception e) {
		logger.error("getByCriteriaWithInnerJoinByOrder failed, criteria = " + criterion.toString(), e);
		throw new HibernateException("getByCriteriaWithInnerJoinByOrder failed, criteria = " + criterion.toString());
	}
}