@Override public Pager<Book> showBookByDynasty(String dynasty, int pageNo,int pageSize) { System.out.println("-----执行到BookDaoImpl"); Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Book.class); criteria.add(Restrictions.eq("dynasty", dynasty)); 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; }
/** * 分页查询函数,根据entityClass和page参数进行查询. * * @param <T> * 实体类型 * @param entityClass * 实体类型 * @param page * 分页里包含的各种参数 * @return 含总记录数和当前页数据的Page对象. */ @Transactional(readOnly = true) public <T> Page pagedQuery(Class<T> entityClass, Page page) { Criteria criteria = createCriteria(entityClass); if (page.isOrderEnabled()) { for (int i = 0; i < page.getOrderBys().size(); i++) { String orderBy = page.getOrderBys().get(i); String order = page.getOrders().get(i); if ("ASC".equals(page.getOrders().get(i))) { criteria.addOrder(Order.asc(orderBy)); } else { criteria.addOrder(Order.desc(orderBy)); } } } Page resultPage = this.pagedQuery(criteria, page.getPageNo(), page.getPageSize()); resultPage.setOrderBys(page.getOrderBys()); resultPage.setOrders(page.getOrders()); return resultPage; }
@Override public List<App> search(Short catalog, Integer subCatalog, int page, int rows, String keywords, String sort, String order) { Criteria cri = searchByFilter(catalog, subCatalog, keywords); if (subCatalog != null) { cri.add(Restrictions.eq("subCatalog", subCatalog)); } // cri.addOrder(Order.asc("auditCatalog")); if (sort != null && !sort.isEmpty()) { HibernateHelper.addOrder(cri, sort, order); } else { if (order != null && "asc".equals(order)) { cri.addOrder(Order.asc("downloads")); } else { cri.addOrder(Order.desc("downloads")); } } if ("marketName".equals(sort)) { cri.addOrder(Order.desc("downloads")); } // cri.addOrder(Order.asc("name")); cri.setMaxResults(rows); cri.setFirstResult(HibernateHelper.firstResult(page, rows)); List<App> list = HibernateHelper.list(cri); return list; }
/** * @inheritDoc */ @Override protected Collection<String> handleFindZipCodes(String countryName, String zipCodePrefix, String cityName, String streetName, Integer limit) { org.hibernate.Criteria streetCriteria = createStreetCriteria(); if (!CommonUtil.isEmptyString(countryName)) { streetCriteria.add(Restrictions.eq("countryName", countryName)); } CategoryCriterion.apply(streetCriteria, new CategoryCriterion(zipCodePrefix, "zipCode", MatchMode.START)); if (!CommonUtil.isEmptyString(cityName)) { streetCriteria.add(Restrictions.eq("cityName", cityName)); } if (!CommonUtil.isEmptyString(streetName)) { streetCriteria.add(Restrictions.eq("streetName", streetName)); } streetCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("zipCode", ""), Restrictions.isNull("zipCode")))); streetCriteria.addOrder(Order.asc("zipCode")); streetCriteria.setProjection(Projections.distinct(Projections.property("zipCode"))); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ZIP_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.ZIP_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), streetCriteria); return streetCriteria.list(); }
@Override public List<App> search(Short catalog, Integer subCatalog, int page, int rows, String keywords, Integer id, String sort, String order) { Criteria cri = searchByFilter(catalog, subCatalog, keywords, id); if (subCatalog != null) { cri.add(Restrictions.eq("subCatalog", subCatalog)); } // cri.addOrder(Order.asc("auditCatalog")); if (sort != null && !sort.isEmpty()) { HibernateHelper.addOrder(cri, sort, order); } else { if (order != null && "asc".equals(order)) { cri.addOrder(Order.asc("downloadRank")); } else { cri.addOrder(Order.desc("downloadRank")); } } if ("marketName".equals(sort)) { cri.addOrder(Order.desc("downloadRank")); } // cri.addOrder(Order.asc("name")); cri.setMaxResults(rows); cri.setFirstResult(HibernateHelper.firstResult(page, rows)); List<App> list = HibernateHelper.list(cri); return list; }
@Override public List<ViewTagApps> search(Integer tagId, Integer catalog, Short tagType, int page, int rows, String keywords, String sort, String order) { Criteria cri = searchByFilter(tagId, catalog, tagType, keywords); if (sort != null && !sort.isEmpty()) { HibernateHelper.addOrder(cri, sort, order); } else { if (order != null && "asc".equals(order)) { cri.addOrder(Order.asc("id")); } else { cri.addOrder(Order.desc("id")); } } cri.setMaxResults(rows); cri.setFirstResult(HibernateHelper.firstResult(page, rows)); List<ViewTagApps> list = HibernateHelper.list(cri); return list; }
@Override @Transactional @SuppressWarnings("unchecked") public Collection<ReferencedURL> getRecheckingBatch(final long startId, final int batchSize) { return (Collection<ReferencedURL>) getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria(ReferencedURL.class); policy.addRequiresCheckingCriteria(c); c.add(Restrictions.ge("id", startId)); c.addOrder(Order.asc("id")); c.setMaxResults(batchSize); return c.list(); } }); }
private void buildCriteria(Criteria criteria,boolean queryCount){ if(!queryCount && firstResult>0){ criteria.setFirstResult(firstResult); } if(!queryCount && maxResults>0){ criteria.setMaxResults(maxResults); } if(processInstanceId>0){ criteria.add(Restrictions.eq("processInstanceId", processInstanceId)); } if(rootProcessInstanceId>0){ criteria.add(Restrictions.eq("rootProcessInstanceId", rootProcessInstanceId)); } 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)); } } }
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)); } } }
@Override protected Collection<ECRFFieldValue> handleFindByListEntryEcrfFieldIndex(Long probandListEntryId, Long ecrfFieldId, Long index, boolean auditTrail, boolean sort, PSFVO psf) throws Exception { org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria("ecrfFieldValue0"); ecrfFieldValueCriteria.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue())); ecrfFieldValueCriteria.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue())); if (index != null) { ecrfFieldValueCriteria.add(Restrictions.eq("index", index.longValue())); } else { ecrfFieldValueCriteria.add(Restrictions.isNull("index")); } if (!auditTrail) { // uncorrelated - fast: // value with max id only: applyEcrfFieldValueMaxIdSubCriteria(ecrfFieldValueCriteria, null, null, probandListEntryId, ecrfFieldId, index); } SubCriteriaMap criteriaMap = new SubCriteriaMap(ECRFFieldValue.class, ecrfFieldValueCriteria); CriteriaUtil.applyPSFVO(criteriaMap, psf); if (sort) { // after applyPSFVO ecrfFieldValueCriteria.addOrder(Order.asc("index")); ecrfFieldValueCriteria.addOrder(Order.desc("id")); } return ecrfFieldValueCriteria.list(); }
@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(); }
private static void applySortOrders(org.hibernate.Criteria listEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria, org.hibernate.Criteria ecrfFieldValueCriteria) { if (listEntryCriteria != null) { listEntryCriteria.addOrder(Order.asc("trial")); listEntryCriteria.addOrder(Order.asc("position")); } if (ecrfFieldCriteria != null) { ecrfFieldCriteria.addOrder(Order.asc("trial")); ecrfFieldCriteria.addOrder(Order.asc("ecrf")); ecrfFieldCriteria.addOrder(Order.asc("section")); } if (ecrfFieldValueCriteria != null) { ecrfFieldValueCriteria.addOrder(Order.asc("index")); } if (ecrfFieldCriteria != null) { ecrfFieldCriteria.addOrder(Order.asc("position")); } if (ecrfFieldValueCriteria != null) { ecrfFieldValueCriteria.addOrder(Order.asc("id")); } }
@Override protected Collection<TrialTagValue> handleFindByTrialExcelPayoffsSorted(Long trialId, Boolean payoffs, Boolean excel) 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(); }
@Override protected Collection<AspSubstance> handleFindAspSubstances(String nameInfix, Integer limit) throws Exception { org.hibernate.Criteria aspSubstanceCriteria = createAspSubstanceCriteria(true); applyAspSubstanceNameCriterions(aspSubstanceCriteria, nameInfix); aspSubstanceCriteria.addOrder(Order.asc("name")); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ASP_SUBSTANCE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.ASP_SUBSTANCE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), aspSubstanceCriteria); if (MATCH_ASP_NAME || MATCH_ASP_REGISTRATION_NUMBER || MATCH_ATC_CODE_CODE) { // ProjectionList projectionList = Projections.projectionList().add(Projections.id()); // projectionList.add(Projections.property("name")); // List aspSubstances = aspSubstanceCriteria.setProjection(Projections.distinct(projectionList)).list(); // Iterator it = aspSubstances.iterator(); // ArrayList result = new ArrayList(aspSubstances.size()); // while (it.hasNext()) { // result.add(this.load((Long) ((Object[]) it.next())[0])); // } // return result; return CriteriaUtil.listDistinctRoot(aspSubstanceCriteria, this, "name"); } else { return aspSubstanceCriteria.list(); } }
@Override public List<MarketApp> search(EnumMarket enumMarket, Short catalog, Integer subCatalog, int page, int rows, String keywords, String sort, String order) { Criteria cri = searchByFilter(enumMarket, catalog, subCatalog, keywords); if (sort != null && !sort.isEmpty()) { HibernateHelper.addOrder(cri, sort, order); } else { if (order != null && "asc".equals(order)) { cri.addOrder(Order.asc("id")); } else { cri.addOrder(Order.desc("id")); } } cri.setMaxResults(rows); cri.setFirstResult(HibernateHelper.firstResult(page, rows)); List<MarketApp> list = HibernateHelper.list(cri); return list; }
/** * Retrieve all existing defined settings * @param request Request object * @throws Exception */ private void getSettingsList(HttpServletRequest request) throws Exception { WebTable.setOrder(sessionContext,"managerSettings.ord",request.getParameter("ord"),1); // Create web table instance WebTable webTable = new WebTable( 2, "Manager Settings", "managerSettings.do?ord=%%", new String[] {"Setting", "Value"}, new String[] {"left", "left"}, null ); for (Settings s: SettingsDAO.getInstance().findAll(Order.asc("key"))) { String onClick = "onClick=\"document.location='managerSettings.do?op=Edit&id=" + s.getUniqueId() + "';\""; String value = sessionContext.getUser().getProperty(s.getKey(), s.getDefaultValue()); webTable.addLine(onClick, new String[] {s.getDescription(), value}, new String[] {s.getDescription(), value}); } request.setAttribute("table", webTable.printTable(WebTable.getOrder(sessionContext,"managerSettings.ord"))); }
@Override public List<CheckIn> getCheckIns(int user_id) { List<CheckIn> checkIns=new ArrayList<CheckIn>(); Session session=HibernateUtils.getSession();//生成Session实例 Transaction tx=session.beginTransaction();//生成事务实例 try { //select * from checkin where user_id=user_id order by checkin_time asc checkIns= session.createCriteria(CheckIn.class).add(Restrictions.eq("user_id", user_id)).addOrder(Order.asc("checkin_time")).list(); tx.commit();//提交事务 } catch (Exception e) { e.printStackTrace(); tx.rollback(); }finally { HibernateUtils.closeSession();//关闭session实例 } return checkIns; }
@Override protected Collection<ECRF> handleFindByTrialGroupSorted(Long trialId, Long groupId) throws Exception { org.hibernate.Criteria ecrfCriteria = createEcrfCriteria(null); if (trialId != null) { ecrfCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (groupId != null) { ecrfCriteria.add(Restrictions.eq("group.id", groupId.longValue())); } else { ecrfCriteria.add(Restrictions.isNull("group.id")); } // Restrictions.isNull("group.id"))); // if (visitId != null) { // ecrfCriteria.add(Restrictions.or(Restrictions.eq("visit.id", visitId.longValue()), // Restrictions.isNull("visit.id"))); // } // if (active != null) { // ecrfCriteria.add(Restrictions.eq("active", active.booleanValue())); // } // if (sort) { ecrfCriteria.addOrder(Order.asc("trial")); ecrfCriteria.addOrder(Order.asc("position")); // } return ecrfCriteria.list(); }
@Override public List<String> getName(Session session, short catalog, Integer subCatalog, Integer currentPage, Integer pageSize) { Criteria cri = session.createCriteria(App.class); cri.setProjection(Projections.distinct(Projections.property("name"))); cri.add(Restrictions.eq("catalog", catalog)); cri.add(Restrictions.eq("hidden", false)); if (subCatalog != null) { cri.add(Restrictions.eq("subCatalog", subCatalog)); } cri.addOrder(Order.asc("name")); if (currentPage != null && pageSize != null) { cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize)); cri.setMaxResults(pageSize); } List<String> list = HibernateHelper.list(cri); return list; }
private static DetachedCriteria createFlowsCriteria(FlowFinderCriteria finderCriteria) { DetachedCriteria criteria = DetachedCriteria.forClass(Flow.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setFetchMode("parts", FetchMode.JOIN) // eager .add(ge("creationTime", finderCriteria.getFrom())) .addOrder(Order.desc("identifier")); if (finderCriteria.getApplication() != null) { // constrain query to a certain application name criteria.add(eq("application", finderCriteria .getApplication())); } if (finderCriteria.getTo() != null) { // there's an upper limit to creationTime property criteria.add(Restrictions .le("creationTime", finderCriteria.getTo())); } return criteria; }
@Override protected Collection<InventoryBooking> handleFindByCourseSorted(Long courseId, Boolean isRelevantForCourseAppointments, boolean sort) throws Exception { Criteria bookingCriteria = createBookingCriteria(); if (courseId != null) { bookingCriteria.add(Restrictions.eq("course.id", courseId.longValue())); } if (isRelevantForCourseAppointments != null) { bookingCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN).createCriteria("category", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("relevantForCourseAppointments", isRelevantForCourseAppointments.booleanValue())); } if (sort) { bookingCriteria.addOrder(Order.asc("start")); } return bookingCriteria.list(); }
/** * 设置分页参数到Criteria对象,辅助函数. */ protected Criteria setPageRequestToCriteria(final Criteria c, final PageRequest pageRequest) { AssertUtils.isTrue(pageRequest.getPageSize() > 0, "Page Size must larger than zero"); c.setFirstResult(pageRequest.getOffset()); c.setMaxResults(pageRequest.getPageSize()); if (pageRequest.isOrderBySetted()) { for (PageRequest.Sort sort : pageRequest.getSort()) { if (PageRequest.Sort.ASC.equals(sort.getDir())) { c.addOrder(Order.asc(sort.getProperty())); } else { c.addOrder(Order.desc(sort.getProperty())); } } } return c; }
@SuppressWarnings("unchecked") public List<AdmUser> findAllUsers() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("firstName")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<AdmUser> users = (List<AdmUser>) criteria.list(); // No need to fetch userProfiles since we are not showing them on list page. Let them lazy load. // Uncomment below lines for eagerly fetching of userProfiles if you want. /* for(User user : users){ Hibernate.initialize(user.getUserProfiles()); }*/ return users; }
/** * 分页查询函数,根据entityClass和page参数进行查询. * * @param <T> * 实体类型 * @param entityClass * 实体类型 * @param page * 分页里包含的各种参数 * @param criterions * 条件 * @return 含总记录数和当前页数据的Page对象. */ @Transactional(readOnly = true) public <T> Page pagedQuery(Class<T> entityClass, Page page, Criterion... criterions) { Criteria criteria = createCriteria(entityClass, criterions); if (page.isOrderEnabled()) { criteria = createCriteria(entityClass, criterions); for (int i = 0; i < page.getOrderBys().size(); i++) { String orderBy = page.getOrderBys().get(i); String order = page.getOrders().get(i); if ("ASC".equals(page.getOrders().get(i))) { criteria.addOrder(Order.asc(orderBy)); } else { criteria.addOrder(Order.desc(orderBy)); } } } Page resultPage = this.pagedQuery(criteria, page.getPageNo(), page.getPageSize()); resultPage.setOrderBys(page.getOrderBys()); resultPage.setOrders(page.getOrders()); return resultPage; }
/** * @inheritDoc */ protected Collection<ECRFFieldStatusType> handleFindByQueue(ECRFFieldStatusQueue queue, Boolean system) { org.hibernate.Criteria ecrfFieldStatusTypeCriteria = createEcrfFieldStatusTypeCriteria(); if (queue != null) { ecrfFieldStatusTypeCriteria.add(Restrictions.eq("queue", queue)); } applySystemCriterions(ecrfFieldStatusTypeCriteria,system); ecrfFieldStatusTypeCriteria.addOrder(Order.asc("id")); return ecrfFieldStatusTypeCriteria.list(); }
public Pager<Book> showBookByClickTimes(int pageNo, int pageSize) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Book.class); 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; }
@SuppressWarnings("unchecked") @Override public Pager<SysLog> listLogByUserPage(int userId, int pageNo, int pageSize) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(SysLog.class); criteria.add(Restrictions.eq("user.id", userId)); long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue(); criteria.setProjection(null); criteria.addOrder(Order.desc("time")); criteria.setFirstResult((pageNo - 1) * pageSize); criteria.setMaxResults(pageSize); List<SysLog> results = criteria.list(); return new Pager<SysLog>(pageSize, pageNo, recordTotal, results); }
@Override protected ECRFFieldStatusType handleGetValidationFailed() throws Exception { org.hibernate.Criteria ecrfFieldStatusTypeCriteria = createEcrfFieldStatusTypeCriteria(); ecrfFieldStatusTypeCriteria.add(Restrictions.eq("validationFailed", true)); ecrfFieldStatusTypeCriteria.addOrder(Order.desc("id")); ecrfFieldStatusTypeCriteria.setMaxResults(1); return (ECRFFieldStatusType) ecrfFieldStatusTypeCriteria.uniqueResult(); }
@Override protected Collection<String> handleFindCostTypes(Long trialDepartmentId, Long trialId, Long probandDepartmentId, Long probandId, String costTypePrefix, Integer limit) throws Exception { org.hibernate.Criteria moneyTransferCriteria = createMoneyTransferCriteria("moneyTransfer"); applyCostTypeCriterions(moneyTransferCriteria, trialDepartmentId, trialId, probandDepartmentId, probandId); CategoryCriterion.apply(moneyTransferCriteria, new CategoryCriterion(costTypePrefix, "costType", MatchMode.START)); moneyTransferCriteria.addOrder(Order.asc("costType")); moneyTransferCriteria.setProjection(Projections.distinct(Projections.property("costType"))); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.MONEY_TRANSFER_COST_TYPE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.MONEY_TRANSFER_COST_TYPE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), moneyTransferCriteria); return moneyTransferCriteria.list(); }
private void searchSort(String sort, String order, Criteria cri) { if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) { HibernateHelper.addOrder(cri, sort, order); } else { if (StringUtils.isNotBlank(order) && "asc".equals(order.toLowerCase())) { cri.addOrder(Order.asc("id")); } else { cri.addOrder(Order.desc("id")); } } }
@Override @SuppressWarnings("unchecked") public List<T> findAllByCriteria(@Nullable final Order order, final int firstResult, final int maxResults, final Criterion... criterion) { return getHibernateTemplate().executeFind(new TLEHibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { Criteria criteria = createCriteria(session, criterion); if( order != null ) { criteria.addOrder(order); } if( firstResult > 0 ) { criteria.setFirstResult(firstResult); } if( maxResults >= 0 ) { criteria.setMaxResults(maxResults); } return criteria.list(); } }); }
@Override protected Collection<ECRF> handleFindByTrialActiveSorted(Long trialId, Boolean active, boolean sort, PSFVO psf) throws Exception { org.hibernate.Criteria ecrfCriteria = createEcrfCriteria(null); SubCriteriaMap criteriaMap = new SubCriteriaMap(ECRF.class, ecrfCriteria); if (trialId != null) { ecrfCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } // if (groupId != null) { // ecrfCriteria.add(Restrictions.or(Restrictions.eq("group.id", groupId.longValue()), // Restrictions.isNull("group.id"))); // } // if (visitId != null) { // ecrfCriteria.add(Restrictions.or(Restrictions.eq("visit.id", visitId.longValue()), // Restrictions.isNull("visit.id"))); // } if (active != null) { ecrfCriteria.add(Restrictions.eq("active", active.booleanValue())); } CriteriaUtil.applyPSFVO(criteriaMap, psf); if (sort) { ecrfCriteria.addOrder(Order.asc("trial")); Criteria visitCriteria = ecrfCriteria.createCriteria("visit", CriteriaSpecification.LEFT_JOIN); visitCriteria.addOrder(Order.asc("token")); Criteria groupCriteria = ecrfCriteria.createCriteria("group", CriteriaSpecification.LEFT_JOIN); groupCriteria.addOrder(Order.asc("token")); // ecrfCriteria.addOrder(Order.asc("position")); ecrfCriteria.addOrder(Order.asc("position")); } return ecrfCriteria.list(); }
/** * @inheritDoc */ @Override protected Collection<TrialStatusType> handleFindInitialStates() { org.hibernate.Criteria trialStatusTypeCriteria = createTrialStatusTypeCriteria(); trialStatusTypeCriteria.add(Restrictions.eq("initial", true)); trialStatusTypeCriteria.addOrder(Order.asc("id")); return trialStatusTypeCriteria.list(); }
private void searchSort(String sort, String order, Criteria cri) { if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) { HibernateHelper.addOrder(cri, sort, order); } else { if (StringUtils.isNotBlank(order) && "desc".equals(order.toLowerCase())) { cri.addOrder(Order.desc("rank")); } else { cri.addOrder(Order.asc("rank")); } } }
@Override protected InputFieldSelectionSetValue handleGetFieldPreset( Long fieldId) throws Exception { org.hibernate.Criteria selectionSetValueCriteria = createSelectionSetValueCriteria(); selectionSetValueCriteria.add(Restrictions.eq("field.id", fieldId.longValue())); selectionSetValueCriteria.add(Restrictions.eq("preset", true)); selectionSetValueCriteria.addOrder(Order.asc("id")); selectionSetValueCriteria.setMaxResults(1); return (InputFieldSelectionSetValue) selectionSetValueCriteria.uniqueResult(); }
@Override public List<Tag> list(TagType tagType) { Criteria cri = getSession().createCriteria(Tag.class); if (null != tagType) { // 注释原因: tagType是枚举类型(int) Tag实体tagType属性是Short类型 不能直接把int 转化成 // short 类型 cri.add(Restrictions.eq("tagType", Short.valueOf(tagType.getVal()))); } cri.addOrder(Order.desc("rank")); return HibernateHelper.list(cri); }
@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(); }
@Override protected Collection<String> handleFindAspAtcCodeCodes(String codePrefix, Integer limit) throws Exception { org.hibernate.Criteria aspAtcCodeCriteria = this.getSession().createCriteria(AspAtcCode.class); aspAtcCodeCriteria.setCacheable(true); CategoryCriterion.apply(aspAtcCodeCriteria, new CategoryCriterion(codePrefix, "code", MatchMode.START)); aspAtcCodeCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("code", ""), Restrictions.isNull("code")))); aspAtcCodeCriteria.add(Restrictions.eq("revision", Settings.getString(SettingCodes.ASP_REVISION, Bundle.SETTINGS, DefaultSettings.ASP_REVISION))); aspAtcCodeCriteria.addOrder(Order.asc("code")); aspAtcCodeCriteria.setProjection(Projections.distinct(Projections.property("code"))); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ASP_ATC_CODE_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.ASP_ATC_CODE_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), aspAtcCodeCriteria); return aspAtcCodeCriteria.list(); }
@Override protected Collection<String> handleFindCityNames(String countryNameInfix, String zipCodePrefix, String cityNameInfix, Integer limit) throws Exception { org.hibernate.Criteria zipCriteria = createZipCriteria(); applyZipCriterions(zipCriteria, countryNameInfix, zipCodePrefix, cityNameInfix); zipCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("cityName", ""), Restrictions.isNull("cityName")))); zipCriteria.addOrder(Order.asc("cityName")); zipCriteria.setProjection(Projections.distinct(Projections.property("cityName"))); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.CITY_NAME_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.CITY_NAME_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), zipCriteria); return zipCriteria.list(); }
@Override public List<App> getByPackageName(String pkname) { Criteria cri = getSession().createCriteria(App.class); cri.add(Restrictions.eq("pkname", pkname)); cri.addOrder(Order.desc("versionCode")); List<App> apps = HibernateHelper.list(cri); return apps; }