Java Code Examples for org.hibernate.criterion.Order

The following examples show how to use org.hibernate.criterion.Order. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
protected ProbandListStatusEntry handleFindRecentStatus(
		Long trialId, Long probandId, Timestamp maxRealTimestamp)
		throws Exception {
	org.hibernate.Criteria statusEntryCriteria = createStatusEntryCriteria(null);
	if (maxRealTimestamp != null) {
		statusEntryCriteria.add(Restrictions.le("realTimestamp", maxRealTimestamp));
	}
	if (trialId != null || probandId != null) {
		Criteria listEntryCriteria = statusEntryCriteria.createCriteria("listEntry");
		if (trialId != null) {
			listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
		}
		if (probandId != null) {
			listEntryCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
		}
	}
	statusEntryCriteria.addOrder(Order.desc("realTimestamp"));
	statusEntryCriteria.addOrder(Order.desc("id"));
	statusEntryCriteria.setMaxResults(1);
	return (ProbandListStatusEntry) statusEntryCriteria.uniqueResult();
}
 
Example 2
/**
 * @inheritDoc
 */
@Override
protected Signature handleFindRecentSignature(SignatureModule module, Long id) {
	org.hibernate.Criteria signatureCriteria = this.getSession().createCriteria(Signature.class);
	if (module != null) {
		signatureCriteria.add(Restrictions.eq("module", module));
		if (id != null) {
			switch (module) {
				case TRIAL_SIGNATURE:
					signatureCriteria.add(Restrictions.eq("trial.id", id.longValue()));
					break;
				case ECRF_SIGNATURE:
					signatureCriteria.add(Restrictions.eq("ecrfStatusEntry.id", id.longValue()));
					break;
				default:
			}
		}
	}
	signatureCriteria.addOrder(Order.desc("id"));
	signatureCriteria.setMaxResults(1);
	return (Signature) signatureCriteria.uniqueResult();
}
 
Example 3
Source Project: kardio   Source File: CountersDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get all the Counters information from DB
 */
@SuppressWarnings("unchecked")
private List<Counters> getAllCounters() {
    Session session = sessionFactory.openSession();
    Criteria counterCriteria = session.createCriteria(CounterEntity.class, "counter");
    counterCriteria.addOrder(Order.asc("counter.position"));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("counter.counterId"));
    projectionList.add(Projections.property("counter.counterName"));
    projectionList.add(Projections.property("counter.position"));
    projectionList.add(Projections.property("counter.delInd"));

    counterCriteria.setProjection(projectionList);
    List<Counters> counterList = new ArrayList<Counters>();
    for (Object[] counterObj : (List<Object[]>) counterCriteria.list()) {
        Counters counter = new Counters();
        counter.setCounterId(Integer.parseInt(String.valueOf(counterObj[0])));
        counter.setCounterName(String.valueOf(counterObj[1]));
        counter.setPosition(Integer.parseInt(String.valueOf(counterObj[2])));
        counter.setDelInd(Integer.parseInt(String.valueOf(counterObj[3])));
        counterList.add(counter);
    }
    session.close();
    return counterList;
}
 
Example 4
Source Project: lemon   Source File: HibernateBasicDao.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获得所有记录,带排序参数.
 * 
 * @param <T>
 *            实体类型
 * @param entityClass
 *            实体类型
 * @param orderBy
 *            排序字段名
 * @param isAsc
 *            是否正序排列
 * @return 返回结果列表
 */
@Transactional(readOnly = true)
public <T> List<T> getAll(Class<T> entityClass, String orderBy,
        boolean isAsc) {
    if (StringUtils.hasText(orderBy)) {
        Criteria criteria = this.getSession().createCriteria(entityClass);

        if (isAsc) {
            criteria.addOrder(Order.asc(orderBy));
        } else {
            criteria.addOrder(Order.desc(orderBy));
        }

        return criteria.list();
    } else {
        return this.getAll(entityClass);
    }
}
 
Example 5
Source Project: icure-backend   Source File: DrugsDAOImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Mpp> getMedecinePackagesFromIngredients(String searchString, String lang, List<String> types, int first, int count) {
	log.debug("Getting medecine packages from ingredients for " + searchString + " from " + first + ", count=" + count);
	Session sess = getSessionFactory().getCurrentSession();
	Criteria c = sess.createCriteria(Mpp.class);
	addLangRestriction(c, lang);
	addTypesRestriction(c, types);

	c.createAlias("compositions", "comp").createAlias("comp.ingredient", "ingrd");
	c.add(Restrictions.or(Restrictions.ilike("name", searchString, MatchMode.START),
			Restrictions.ilike("ingrd.name", searchString, MatchMode.START)));

	c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
	c.setFirstResult(first);
	c.setMaxResults(count);
	c.addOrder(Order.asc("name"));
	List<Mpp> result = c.list();
	return result;
}
 
Example 6
@Override
public List<String> getAllLocations(String siteId) throws DataAccessException {
			DetachedCriteria criteria = DetachedCriteria.forClass(
			SignupMeeting.class).setProjection(Projections.distinct(Projections.projectionList()
				    	    .add(Projections.property("location"), "location") )).setResultTransformer(
			Criteria.DISTINCT_ROOT_ENTITY)				
			.addOrder(Order.asc("location")).createCriteria("signupSites")
			.add(Restrictions.eq("siteId", siteId));
	
	List<String> locations = (List<String>) getHibernateTemplate().findByCriteria(criteria);
	
	if(locations !=null && !locations.isEmpty()){
		return locations;
	}
	
	return null;
}
 
Example 7
Source Project: projectforge-webapp   Source File: Kost1Dao.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<Kost1DO> getList(final BaseSearchFilter filter)
{
  final KostFilter myFilter;
  if (filter instanceof KostFilter) {
    myFilter = (KostFilter) filter;
  } else {
    myFilter = new KostFilter(filter);
  }
  final QueryFilter queryFilter = new QueryFilter(myFilter);
  if (myFilter.isActive() == true) {
    queryFilter.add(Restrictions.eq("kostentraegerStatus", KostentraegerStatus.ACTIVE));
  } else if (myFilter.isNonActive() == true) {
    queryFilter.add(Restrictions.eq("kostentraegerStatus", KostentraegerStatus.NONACTIVE));
  } else if (myFilter.isEnded() == true) {
    queryFilter.add(Restrictions.eq("kostentraegerStatus", KostentraegerStatus.ENDED));
  } else if (myFilter.isNotEnded() == true) {
    queryFilter.add(Restrictions.or(Restrictions.ne("kostentraegerStatus", ProjektStatus.ENDED), Restrictions.isNull("kostentraegerStatus")));
  }
  queryFilter.addOrder(Order.asc("nummernkreis")).addOrder(Order.asc("bereich")).addOrder(Order.asc("teilbereich")).addOrder(Order.asc("endziffer"));
  return getList(queryFilter);
}
 
Example 8
Source Project: uflo   Source File: HistoryProcessVariableQueryImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void buildCriteria(Criteria criteria,boolean queryCount){
	if(!queryCount && firstResult>0){
		criteria.setFirstResult(firstResult);			
	}
	if(!queryCount && maxResults>0){
		criteria.setMaxResults(maxResults);			
	}
	if(historyProcessInstanceId>0){
		criteria.add(Restrictions.eq("historyProcessInstanceId",historyProcessInstanceId));
	}
	if(StringUtils.isNotEmpty(key)){
		criteria.add(Restrictions.eq("key", key));
	}
	
	if(!queryCount){
		for(String ascProperty:ascOrders){
			criteria.addOrder(Order.asc(ascProperty));
		}
		for(String descProperty:descOrders){
			criteria.addOrder(Order.desc(descProperty));
		}
	}
}
 
Example 9
@Override
protected Collection<String> handleFindSections(Long trialId, Long ecrfId, String sectionPrefix, Integer limit) throws Exception {
	org.hibernate.Criteria ecrfFieldCriteria = createEcrfFieldCriteria();
	if (trialId != null) {
		ecrfFieldCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	if (ecrfId != null) {
		ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
	}
	CategoryCriterion.apply(ecrfFieldCriteria, new CategoryCriterion(sectionPrefix, "section", MatchMode.START));
	ecrfFieldCriteria.addOrder(Order.asc("section"));
	ecrfFieldCriteria.setProjection(Projections.distinct(Projections.property("section")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ECRF_FIELD_SECTION_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.ECRF_FIELD_SECTION_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), ecrfFieldCriteria);
	return ecrfFieldCriteria.list();
}
 
Example 10
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public List<SignupMeeting> getSignupMeetings(String siteId, Date startDate,
		Date endDate) {
	DetachedCriteria criteria = DetachedCriteria.forClass(
			SignupMeeting.class).setResultTransformer(
			Criteria.DISTINCT_ROOT_ENTITY)
			.add(Restrictions.ge("endTime", startDate))
			.add(Restrictions.lt("startTime", endDate))
			.addOrder(Order.asc("startTime")).createCriteria("signupSites")
			.add(Restrictions.eq("siteId", siteId));

	return (List<SignupMeeting>) getHibernateTemplate().findByCriteria(criteria);
}
 
Example 11
@Override
protected Collection<String> handleFindCategoryPreferredRubricLabels(
		String preferredRubricLabelInfix, Integer limit) throws Exception {
	org.hibernate.Criteria opsSystCategoryCriteria = this.getSession().createCriteria(OpsSystCategory.class);
	opsSystCategoryCriteria.setCacheable(true);
	CategoryCriterion.apply(opsSystCategoryCriteria, new CategoryCriterion(preferredRubricLabelInfix, "preferredRubricLabel", MatchMode.ANYWHERE));
	opsSystCategoryCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("preferredRubricLabel", ""), Restrictions.isNull("preferredRubricLabel"))));
	opsSystCategoryCriteria.addOrder(Order.asc("preferredRubricLabel"));
	opsSystCategoryCriteria.setProjection(Projections.distinct(Projections.property("preferredRubricLabel")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.OPS_SYST_CATEGORY_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.OPS_SYST_CATEGORY_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), opsSystCategoryCriteria);
	return opsSystCategoryCriteria.list();
}
 
Example 12
Source Project: primefaces-blueprints   Source File: ProductService.java    License: The Unlicense 5 votes vote down vote up
public List getAllOrders() {
    org.hibernate.Transaction tx = getSession().beginTransaction();
    List list = getSession().createCriteria(com.packtpub.pf.blueprint.persistence.entity.Order.class)
            .addOrder(Order.desc("createDate")).list();
    tx.commit();
    getSession().close();
    _log.info("Added Successfully....");
    return list;
}
 
Example 13
Source Project: ctsms   Source File: CountryDaoImpl.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<CountryVO> handleFindCountries(String countryNameInfix,
		String countryCodeInfix, Integer limit) throws Exception {
	org.hibernate.Criteria countryCriteria = createCountryCriteria();
	CategoryCriterion.applyAnd(countryCriteria,
			new CategoryCriterion(countryNameInfix, "countryName", MatchMode.ANYWHERE),
			new CategoryCriterion(countryCodeInfix, "countryCode", MatchMode.ANYWHERE));
	countryCriteria.addOrder(Order.asc("countryName"));
	CriteriaUtil.applyLimit(limit,
			Settings.getIntNullable(SettingCodes.COUNTRY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.COUNTRY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT),
			countryCriteria);
	return countryCriteria.list();
}
 
Example 14
Source Project: spacewalk   Source File: ActionChainFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets all action chains for a user.
 * @param requestor the user whose chains we're looking for
 * @return action chains
 */
@SuppressWarnings("unchecked")
public static List<ActionChain> getActionChains(User requestor) {
    return getSession()
        .createCriteria(ActionChain.class)
        .add(Restrictions.eq("user", requestor))
        .addOrder(Order.asc("label"))
        .list();
}
 
Example 15
/**
 * Internal search for events. Applies the sort and optionally the limit/offset.
 */
protected List<TriggerEvent> getTriggerEvents(Date after, Date before, List<String> jobs, String triggerName, TriggerEvent.TRIGGER_EVENT_TYPE[] types, Integer first, Integer size) {
    final Criteria criteria = buildCriteria(after, before, jobs, triggerName, types);
    // We put the newest items first as generally that's what people are most interested in.
    criteria.addOrder(Order.desc("time"));
    // Sort by event type so that if the time of 2 events is the same the fired event happens before
    // the completed event.
    criteria.addOrder(Order.asc("eventType"));
    if (first != null && size != null)
    {
        criteria.setFirstResult(first).setMaxResults(size);
    }
    return criteria.list();
}
 
Example 16
/**
 * {@inheritDoc}
 */
protected Collection<DataTableColumn> handleFindByUserTableColumn(Long userId, String tableName, String columnName) {
	org.hibernate.Criteria tableColumnCriteria = createDataTableColumnCriteria();
	tableColumnCriteria.add(Restrictions.eq("user.id", userId.longValue()));
	if (tableName != null) {
		tableColumnCriteria.add(Restrictions.eq("tableName", tableName));
	}
	if (columnName != null) {
		tableColumnCriteria.add(Restrictions.eq("columnName", columnName));
	}
	tableColumnCriteria.addOrder(Order.asc("id"));
	return tableColumnCriteria.list();
}
 
Example 17
@Override
protected Collection<String> handleFindTitles(Long trialDepartmentId,
		Long staffId, Long trialId, String titleInfix, Integer limit)
		throws Exception {
	Criteria dutyRosterCriteria = createDutyRosterTurnCriteria("dutyRosterTurn");
	Criteria trialCriteria = null;
	if (trialDepartmentId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.LEFT_JOIN);
	} else if (trialId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.INNER_JOIN);
	}
	if (trialDepartmentId != null || trialId != null) {
		if (trialDepartmentId != null) {
			trialCriteria.add(Restrictions.or(Restrictions.isNull("dutyRosterTurn.trial"), Restrictions.eq("department.id", trialDepartmentId.longValue())));
		}
		if (trialId != null) {
			trialCriteria.add(Restrictions.idEq(trialId.longValue()));
		}
	}
	if (staffId != null) {
		dutyRosterCriteria.add(Restrictions.eq("staff.id", staffId.longValue()));
	}
	CategoryCriterion.apply(dutyRosterCriteria, new CategoryCriterion(titleInfix, "title", MatchMode.ANYWHERE));
	dutyRosterCriteria.addOrder(Order.asc("title"));
	dutyRosterCriteria.setProjection(Projections.distinct(Projections.property("title")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.DUTY_ROSTER_TURN_TITLE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.DUTY_ROSTER_TURN_TITLE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), dutyRosterCriteria);
	return dutyRosterCriteria.list();
}
 
Example 18
public List getAll() {
	HibernateCallback<List> callback = session -> {
           return session.createCriteria(RWikiCurrentObject.class)
                   .addOrder(Order.desc("version"))
				.list();
       };
	return new ListProxy(getHibernateTemplate().execute(callback), this);
}
 
Example 19
Source Project: primefaces-blueprints   Source File: DAOService.java    License: The Unlicense 5 votes vote down vote up
public List<Movie> getMoviesByUserId(User u) {
    org.hibernate.Transaction tx = getSession().beginTransaction();
    List list = getSession().createCriteria(Movie.class)
            .add(Restrictions.eq("user", u))
            .addOrder(Order.desc("releaseDate")).list();
    tx.commit();
    getSession().close();
    _log.info("Listed Successfully....");
    return list;
}
 
Example 20
Source Project: TinyMooc   Source File: PrivateMailServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List userMailList(String userId) {
    User user = new User();
    user.setUserId(userId);

    List<Message> msgList = getCurrentSession().createCriteria(Message.class)
            .add(Restrictions.eq("userByReceiverId", user))
            .addOrder(Order.desc("sendDate")).list();
    return msgList;
}
 
Example 21
@Override
public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count) {
    Criteria c = sessionFactory.getCurrentSession().createCriteria(clazz);
    c.setMaxResults(count);
    c.add(Restrictions.eq("status", Job.Status.NEW));
    c.addOrder(Order.asc("categoryPriority"));
    c.addOrder(Order.asc("submitTime"));
    return c.list();
}
 
Example 22
@Override
protected Collection<ECRFFieldStatusEntry> handleFindByListEntryEcrfFieldIndex(ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId, Long index, boolean last,
		boolean sort, PSFVO psf) throws Exception {
	org.hibernate.Criteria ecrfFieldStatusEntryCriteria = createEcrfFieldStatusEntryCriteria("ecrfFieldStatusEntry0");
	if (queue != null) {
		ecrfFieldStatusEntryCriteria.add(Restrictions.eq("queue", queue));
	}
	ecrfFieldStatusEntryCriteria.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
	ecrfFieldStatusEntryCriteria.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue()));
	if (index != null) {
		ecrfFieldStatusEntryCriteria.add(Restrictions.eq("index", index.longValue()));
	} else {
		ecrfFieldStatusEntryCriteria.add(Restrictions.isNull("index"));
	}
	if (last) {
		// uncorrelated - fast:
		// value with max id only:
		applyEcrfFieldStatusEntryMaxIdSubCriteria(ecrfFieldStatusEntryCriteria, null, null, queue, probandListEntryId, ecrfFieldId, index);
	}
	SubCriteriaMap criteriaMap = new SubCriteriaMap(ECRFFieldStatusEntry.class, ecrfFieldStatusEntryCriteria);
	CriteriaUtil.applyPSFVO(criteriaMap, psf);
	if (sort) { // after applyPSFVO
		ecrfFieldStatusEntryCriteria.addOrder(Order.asc("index"));
		ecrfFieldStatusEntryCriteria.addOrder(Order.desc("id"));
	}
	return ecrfFieldStatusEntryCriteria.list();
}
 
Example 23
Source Project: onedev   Source File: DefaultPullRequestManager.java    License: MIT License 5 votes vote down vote up
private CriteriaQuery<PullRequest> buildCriteriaQuery(Session session, @Nullable Project targetProject, 
		EntityQuery<PullRequest> requestQuery) {
	CriteriaBuilder builder = session.getCriteriaBuilder();
	CriteriaQuery<PullRequest> query = builder.createQuery(PullRequest.class);
	Root<PullRequest> root = query.from(PullRequest.class);
	
	query.where(getPredicates(targetProject, requestQuery.getCriteria(), root, builder));

	List<javax.persistence.criteria.Order> orders = new ArrayList<>();
	for (EntitySort sort: requestQuery.getSorts()) {
		if (sort.getDirection() == Direction.ASCENDING) {
			orders.add(builder.asc(PullRequestQuery.getPath(
					root, PullRequest.ORDER_FIELDS.get(sort.getField()))));
		} else {
			orders.add(builder.desc(PullRequestQuery.getPath(
					root, PullRequest.ORDER_FIELDS.get(sort.getField()))));
		}
	}

	if (orders.isEmpty()) {
		orders.add(builder.asc(PullRequestQuery.getPath(root, PullRequest.PROP_CLOSE_INFO + "." + CloseInfo.PROP_STATUS)));
		orders.add(builder.desc(PullRequestQuery.getPath(root, PullRequest.PROP_LAST_UPDATE + "." + LastUpdate.PROP_DATE)));
	}
	query.orderBy(orders);
	
	return query;
}
 
Example 24
@Override
protected Collection<TrialTagValue> handleFindByTrialExcelPayoffsSorted(Long trialId,
		Boolean excel, Boolean payoffs) throws Exception {
	org.hibernate.Criteria tagValueCriteria = createTagValueCriteria();
	tagValueCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	Criteria tagCriteria = tagValueCriteria.createCriteria("tag", CriteriaSpecification.INNER_JOIN);
	if (excel != null) {
		tagCriteria.add(Restrictions.eq("excel", excel.booleanValue()));
	}
	if (payoffs != null) {
		tagCriteria.add(Restrictions.eq("payoffs", payoffs.booleanValue()));
	}
	tagCriteria.addOrder(Order.asc("nameL10nKey"));
	return tagValueCriteria.list();
}
 
Example 25
Source Project: onedev   Source File: DefaultIssueManager.java    License: MIT License 5 votes vote down vote up
private CriteriaQuery<Issue> buildCriteriaQuery(@Nullable Project project, 
		Session session, EntityQuery<Issue> issueQuery) {
	CriteriaBuilder builder = session.getCriteriaBuilder();
	CriteriaQuery<Issue> query = builder.createQuery(Issue.class);
	Root<Issue> root = query.from(Issue.class);
	
	query.where(getPredicates(project, issueQuery.getCriteria(), root, builder));

	List<javax.persistence.criteria.Order> orders = new ArrayList<>();
	for (EntitySort sort: issueQuery.getSorts()) {
		if (Issue.ORDER_FIELDS.containsKey(sort.getField())) {
			if (sort.getDirection() == Direction.ASCENDING)
				orders.add(builder.asc(IssueQuery.getPath(root, Issue.ORDER_FIELDS.get(sort.getField()))));
			else
				orders.add(builder.desc(IssueQuery.getPath(root, Issue.ORDER_FIELDS.get(sort.getField()))));
		} else {
			Join<Issue, IssueField> join = root.join(Issue.PROP_FIELDS, JoinType.LEFT);
			join.on(builder.equal(join.get(IssueField.PROP_NAME), sort.getField()));
			if (sort.getDirection() == Direction.ASCENDING)
				orders.add(builder.asc(join.get(IssueField.PROP_ORDINAL)));
			else
				orders.add(builder.desc(join.get(IssueField.PROP_ORDINAL)));
		}
	}

	if (orders.isEmpty()) {
		orders.add(builder.desc(IssueQuery.getPath(root, Issue.PROP_LAST_UPDATE + "." + LastUpdate.PROP_DATE)));
	}
	query.orderBy(orders);
	
	return query;
}
 
Example 26
@Override
@SuppressWarnings(SUPPRESS_UNCHECKED)
public List<Runner> getAllRunners() {
    final Criteria crit = sessionService.getSession().createCriteria(Runner.class);
    crit.addOrder(Order.asc(NAME));
    List<Runner> list = crit.list();
    HibernateLazyInitializer.initCollection(list);
    return list;
}
 
Example 27
Source Project: TinyMooc   Source File: LabelServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getTenHotLabels() {
    String labels = "";
    List<Label> labelList = (List<Label>) getCurrentSession().createCriteria(Label.class).addOrder(Order.desc("frequency")).list();
    Collections.shuffle(labelList);
    for (int i = 0; i < labelList.size(); i++) {
        labels += labelList.get(i).getLabelName() + ",";
    }
    return labels;
}
 
Example 28
public JobRun getLatestJobRun() throws Exception {
	JobRun r = getHibernateTemplate().execute(session -> {
           JobRun jobRun = null;
           Criteria c = session.createCriteria(JobRunImpl.class);
           c.setMaxResults(1);
           c.addOrder(Order.desc("id"));
           List jobs = c.list();
           if(jobs != null && jobs.size() > 0){
               jobRun = (JobRun) jobs.get(0);
           }
           return jobRun;
       });
	return r;
}
 
Example 29
@Override
protected Collection<String> handleFindValues(Long fieldId, String valueInfix, Integer limit)
		throws Exception {
	org.hibernate.Criteria selectionSetValueCriteria = createSelectionSetValueCriteria();
	if (fieldId != null) {
		selectionSetValueCriteria.add(Restrictions.eq("field.id", fieldId.longValue()));
	}
	CategoryCriterion.apply(selectionSetValueCriteria, new CategoryCriterion(valueInfix, "value", MatchMode.ANYWHERE));
	selectionSetValueCriteria.addOrder(Order.asc("value"));
	selectionSetValueCriteria.setProjection(Projections.distinct(Projections.property("value")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.INPUT_FIELD_SELECTION_SET_VALUE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.INPUT_FIELD_SELECTION_SET_VALUE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), selectionSetValueCriteria);
	return selectionSetValueCriteria.list();
}
 
Example 30
Source Project: icure-backend   Source File: DrugsDAOImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public List<Mpp> getMppsWithInn(String inn, String lang) {
	if (inn != null && lang != null) {
		Session sess = getSessionFactory().getCurrentSession();
		ArrayList<Mpp> result = new ArrayList<>();
		for (Mpp candidate : (Collection<Mpp>) sess.createCriteria(Mpp.class).add(Restrictions.eq("inncluster", inn)).addOrder(Order.asc("index")).list()) {
			if (candidate.getId().getLang().equals(lang)) {
				result.add(candidate);
			}
		}
		return result;
	}
	return new ArrayList<>();
}