Java Code Examples for org.hibernate.Criteria#list()

The following examples show how to use org.hibernate.Criteria#list() . These examples are extracted from open source projects. 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
@Override
public List<ConfidenceData> getDataByCrisisAttributeLabelGranularity(String crisisCode, String attributeCode, String labelCode, Long granularity) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.eq("granularity", granularity));
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 2
@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 3
@Override
public List<TagData> getDataByCrisisAttributeLabelGranularity(String crisisCode, String attributeCode, String labelCode, Long granularity) {
	Criteria criteria = getCurrentSession().createCriteria(TagData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.eq("granularity", granularity));
	criteria.add(criterion); 		
	try {
		List<TagData> objList = (List<TagData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception in getDataByCrisisAttributeLabelGranularity for crisisCode : " + crisisCode
				+ " attributeCode : " + attributeCode + " labelCode : " + labelCode
				+ " granularity : " + granularity, e);
	}
	return null;
}
 
Example 4
Source Project: sailfish-core   File: HibernateStorage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> List<T> getAllEntities(Class<T> entityClass, List<Criterion> criterions, String orderField, boolean orderAsc) {
	
	Session session = null;
	
	try {
           session = sessionFactory.openSession();
		
		Criteria criteria = session.createCriteria(entityClass);
		
		for (Criterion criterion : criterions) {
			criteria.add(criterion);
		}

           criteria.addOrder(orderAsc ? Order.asc(orderField) : Order.desc(orderField));
           criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
		
		return criteria.list();
		
	} finally {
           if(session != null) {
               session.close();
           }
	}
	
}
 
Example 5
Source Project: TinyMooc   File: BaseServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public List<?> getByPage(DetachedCriteria dCriteria, int pageSize) {

    int curPage = PageHelper.getCurPage();
    Criteria criteria = dCriteria.getExecutableCriteria(getCurrentSession());
    criteria.setFirstResult((curPage - 1) * pageSize);
    criteria.setMaxResults(pageSize);
    List<?> list = criteria.list();
    return list;
}
 
Example 6
Source Project: uflo   File: GetTaskAppointorCommand.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<TaskAppointor> execute(Context context) {
	Criteria criteria=context.getSession().createCriteria(TaskAppointor.class);
	criteria.add(Restrictions.eq("processInstanceId", processInstanceId));
	criteria.add(Restrictions.eq("taskNodeName", taskNodeName));
	return criteria.list();
}
 
Example 7
@Override
@SuppressWarnings(SUPPRESS_UNCHECKED)
public List<Repository> getAll() {
    final Criteria criteria = sessionService.getSession().createCriteria(Repository.class);
    List<Repository> list = criteria.list();
    HibernateLazyInitializer.initCollection(list);
    return list;
}
 
Example 8
/**
 * @inheritDoc
 */
@Override
protected Collection<InventoryBooking> handleFindByCourse(Long courseId, PSFVO psf) throws Exception {
	Criteria bookingCriteria = createBookingCriteria();
	SubCriteriaMap criteriaMap = new SubCriteriaMap(InventoryBooking.class, bookingCriteria);
	if (courseId != null) {
		bookingCriteria.add(Restrictions.eq("course.id", courseId.longValue()));
	}
	CriteriaUtil.applyPSFVO(criteriaMap, psf);
	return bookingCriteria.list();
}
 
Example 9
@Override
public List<Reference> getAllReferences(Requirement requirement) {
    final Criteria crit = sessionService.getSession().createCriteria(Reference.class);
    crit.createAlias("requirement", "req");
    crit.add(Restrictions.eq("req.name", requirement.getName()));
    crit.createAlias("req.repository", REPO);
    crit.add(Restrictions.eq(REPO_UID, requirement.getRepository().getUid()));

    @SuppressWarnings(SUPPRESS_UNCHECKED)
    List<Reference> references = crit.list();
    HibernateLazyInitializer.initCollection(references);
    return references;
}
 
Example 10
@SuppressWarnings("unchecked")
@Override
public List<E> getMaxOrderByCriteria(Criterion criterion, String orderBy) {
	Criteria criteria = getCurrentSession().createCriteria(entityClass);
	criteria.add(criterion);
	criteria.addOrder(Order.desc(orderBy));
	criteria.setMaxResults(1);
	try {
		return criteria.list();
	} catch (HibernateException e) {
		logger.error("Error in getMaxOrderByCriteria for criteria : " + criteria.toString(),e);
		return null;
	}
}
 
Example 11
@SuppressWarnings("unchecked")
public Set<SyllabusData> findPublicSyllabusData() {
    HibernateCallback<List<SyllabusData>> hcb = session -> {
      Criteria crit = session.createCriteria(SyllabusDataImpl.class)
                  .add(Expression.eq(VIEW, "yes"))
                  .setFetchMode(ATTACHMENTS, FetchMode.EAGER);

      return crit.list();
    };
    return new HashSet<>(getHibernateTemplate().execute(hcb));
}
 
Example 12
/**
 * lookup System with specified digital server id which are foreign_entitled
 *
 * @param id the digital server id
 * @return server corresponding to the given id
 */
@SuppressWarnings("unchecked")
public static Server lookupForeignSystemByDigitalServerId(String id) {
    Criteria criteria = getSession().createCriteria(Server.class);
    criteria.add(Restrictions.eq("digitalServerId", id));
    for (Server server : (List<Server>) criteria.list()) {
        if (server.hasEntitlement(EntitlementManager.getByName("foreign_entitled"))) {
            return server;
        }
    }
    return null;
}
 
Example 13
Source Project: sdudoc   File: BookDaoImpl.java    License: MIT License 5 votes vote down vote up
@Override
public Pager<Book> searchByAuthor(String author, int pageNo, int pageSize) {
	Session session = sessionFactory.getCurrentSession();
	Criteria criteria = session.createCriteria(Book.class);
	criteria.add(Restrictions.like("authors", "%"+author+"%"));
	long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
	criteria.setProjection(null);
//	criteria.addOrder(Order.desc("clickTimes"));
	criteria.setFirstResult((pageNo - 1) * pageSize);
	criteria.setMaxResults(pageSize);
	List<Book> results = criteria.list();
	Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results);
	return page;
}
 
Example 14
@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());
	}
}
 
Example 15
Source Project: Spring-MVC-Blueprints   File: LoginDaoImpl.java    License: MIT License 5 votes vote down vote up
@Transactional
@SuppressWarnings("unchecked")
@Override
public List<HrmsLogin> getAdminUsers() {
	Session session = this.sessionFactory.getCurrentSession();
	Criteria crit = session.createCriteria(HrmsLogin.class);
	crit.add(Restrictions.like("role","admin"));

	List<HrmsLogin> users = crit.list();
	
	return users;
}
 
Example 16
@Override
public List<E> findByCriteria(Criterion criterion, Integer count) {
    Criteria criteria = getCurrentSession().createCriteria(entityClass);
    criteria.add(criterion);

    if(count != null){
        criteria.setMaxResults(count);
    }
    return criteria.list();
}
 
Example 17
/**
 * Returns list of channel architectures
 * @return list of channel architectures
 */
public static List<ChannelArch> getChannelArchitectures() {
    Session session = getSession();
    Criteria criteria = session.createCriteria(ChannelArch.class);
    return criteria.list();
}
 
Example 18
public <T> List<T> queryForObjects() throws Exception
{
	Criteria criteria = getSession().createCriteria(_entityClass);
	return criteria.list();
}
 
Example 19
@Override
public List<K8sContainerStatus> getAllContainersOfParent(String startDate, String endDate, int envId, String componentIdsStrg) throws ParseException {
	
	final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
	List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg);

	Date sDate = sdf1.parse(startDate);
	Date eDate = sdf1.parse(endDate);
	Session session = sessionFactory.openSession();
	Criteria containerCriteria = session.createCriteria(K8sPodsContainersEntity.class, "contSts");
	containerCriteria.createCriteria("contSts.component", "component");
	containerCriteria.createCriteria("contSts.environment", "environment");
	containerCriteria.add(Restrictions.ge("contSts.statusDate", sDate ));
	containerCriteria.add(Restrictions.le("contSts.statusDate", eDate ));
	if(envId != 0){
	   containerCriteria.add(Restrictions.eq("environment.environmentId", envId));
	}
	containerCriteria.add(Restrictions.eq("environment.envLock", 0));
	if(comIdList != null && comIdList.size() != 0){
		containerCriteria.add(Restrictions.in("component.parentComponent.componentId", comIdList));
	}
	
	ProjectionList projectionList = DaoUtil.getContainerStatusProjectionList();
	containerCriteria.setProjection(projectionList);
    @SuppressWarnings("unchecked")
	List<Object[]> conList = containerCriteria.list();
    List<K8sContainerStatus> contStatusList = new ArrayList<K8sContainerStatus>();
       for (Object[] aRow : conList) {
       	K8sContainerStatus contStatus = new K8sContainerStatus();
           Integer comId = (Integer) aRow[0];
           contStatus.setComponentId(comId);
           Date statsDate = (Date) aRow[1];
           contStatus.setStatusDate(statsDate.toString());
           long totalCont = (long) aRow[2];
           contStatus.setTotalContainers(totalCont);
           contStatusList.add(contStatus);   		
       } 	    
       session.close();
       return contStatusList;
        
}
 
Example 20
Source Project: Spring-MVC-Blueprints   File: ReportDaoImpl.java    License: MIT License 3 votes vote down vote up
@Transactional
@Override
public Tblstudents getStudentId(String username) {
		
	Session session = this.sessionFactory.getCurrentSession();
	Criteria crit = session.createCriteria(Tblstudents.class);
	crit.add(Restrictions.like("username",username));
	
	List<Tblstudents> students = crit.list();
	
	return students.get(0);
   
}