Java 类org.hibernate.criterion.Projections 实例源码

项目:Equella    文件:BasicItemSerializerProvider.java   
@Override
public void prepareItemQuery(ItemSerializerState state)
{
    final DetachedCriteria criteria = state.getItemQuery();
    final ProjectionList projection = state.getItemProjection();

    if( state.hasCategory(ItemSerializerService.CATEGORY_BASIC) )
    {
        projection.add(Projections.property("name.id"), NAME_ALIAS);
        projection.add(Projections.property("description.id"), DESC_ALIAS);
    }

    if( state.hasCategory(ItemSerializerService.CATEGORY_METADATA) )
    {
        criteria.createAlias("itemXml", "itemXml");
        projection.add(Projections.property("itemXml.xml"), METADATA_ALIAS);
    }
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<App> getAppsOfDropMarket(Session session, String marketName, Integer currentPage, Integer pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("pkname"));
    proList.add(Projections.property("signatureSha1"));
    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(proList);
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App();
            e.setPkname((String) obj[0]);
            e.setSignatureSha1((String) obj[1]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
项目:dhus-core    文件:NetworkUsageDao.java   
public long getDownloadedSizeByUserSince (final User user, final Date date)
{
   Long result =
         getHibernateTemplate ().execute (new HibernateCallback<Long> ()
         {
            @Override
            public Long doInHibernate (Session session)
                  throws HibernateException, SQLException
            {
               Criteria criteria = session.createCriteria (
                     NetworkUsage.class);
               criteria.setProjection (Projections.sum ("size"));
               criteria.add (Restrictions.eq ("isDownload", true));
               criteria.add (Restrictions.eq ("user", user));
               criteria.add (Restrictions.gt ("date", date));
               return (Long) criteria.uniqueResult ();
            }
         });
   return (result == null) ? 0 : result;
}
项目:OSWf-OSWorkflow-fork    文件:HibernatePersistentVarsDAO.java   
@SuppressWarnings("unchecked")
protected Collection<String> getKeysImpl(Session session, Long piid, String prefix, Type type) throws HibernateException {

    if( piid == null )
        return Collections.EMPTY_LIST;

    Criteria criteria = session.createCriteria(getPersistentClass())
        .add(Restrictions.eq("processInstanceId", piid))
        .setProjection(Projections.property("key"));

    if (prefix != null)
        criteria.add(Restrictions.ilike("key", prefix, MatchMode.START));

    if(type != null)
        criteria.add(Restrictions.eq("type", type.getValue()));

    return criteria.list();
}
项目:FlashBoard    文件:UserDaoImpl.java   
@Override
public List<String> getAllNewUsers(){
    Session session = HibernateUtil.getSession();
    List<String> newUsers = new ArrayList<>();

    Criteria criteria;

    try {
        criteria = session.createCriteria(User.class);
        newUsers = criteria.add(Restrictions.like("approved", false)).setProjection(Projections.property("username")).list();
    }
    catch(HibernateException he) {
        he.printStackTrace();
    }finally {
        session.close();
    }

    if(newUsers.isEmpty()) {
        newUsers = null; 
    }

    return newUsers;
}
项目:FlashBoard    文件:UserDaoImpl.java   
@SuppressWarnings("unchecked")
@Override
public List<String> getAllPromotees(){
    Session session = HibernateUtil.getSession();
    List<String> promotees = new ArrayList<>();

    Criteria criteria;

    try {
        criteria = session.createCriteria(User.class);
        promotees = criteria.add(Restrictions.ge("avgScore", 70.0))
                .add(Restrictions.like("approved", true))
                .setProjection(Projections.property("username")).list();
    }
    catch(HibernateException he) {
        he.printStackTrace();
    }finally {
        session.close();
    }

    if(promotees.isEmpty()) {
        promotees = null; 
    }

    return promotees;
}
项目:ctsms    文件:InputFieldDaoImpl.java   
@Override
protected long handleGetEcrfFieldMaxSelectionSetValueCount(Long trialId) throws Exception {
    org.hibernate.Criteria inputFieldCriteria = createInputFieldCriteria();
    inputFieldCriteria.add(
            Restrictions.in("fieldType", SELECT_FIELD_TYPES)); // no AUTOCOMPLETE!
    org.hibernate.Criteria ecrfFieldCriteria = inputFieldCriteria.createCriteria("ecrfFields", "ecrfFields0", CriteriaSpecification.INNER_JOIN);
    ecrfFieldCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));

    org.hibernate.Criteria selectionSetValueCriteria = inputFieldCriteria.createCriteria("selectionSetValues","inputFieldSelectionSetValues", CriteriaSpecification.INNER_JOIN);

    inputFieldCriteria.setProjection(Projections.projectionList()
            .add(Projections.groupProperty("ecrfFields0.id"))
            .add(Projections.alias(Projections.count("inputFieldSelectionSetValues.id"),"selectionSetValuesCount")));

    inputFieldCriteria.addOrder(Order.desc("selectionSetValuesCount"));
    inputFieldCriteria.setMaxResults(1);
    long maxSelectionSetValues = 0l;
    try {
        maxSelectionSetValues = (Long) ((Object[]) inputFieldCriteria.list().iterator().next())[1];
    } catch (Exception e) {

    }
    return maxSelectionSetValues;
}
项目:ctsms    文件:UserPermissionProfileDaoImpl.java   
@Override
protected long handleGetCount(
        Long userId, PermissionProfile profile, PermissionProfileGroup profileGroup, Boolean active)
                throws Exception {
    org.hibernate.Criteria userPermissionProfileCritria = createUserPermissionProfileCriteria();
    if (userId != null) {
        userPermissionProfileCritria.add(Restrictions.eq("user.id", userId.longValue()));
    }
    if (profile != null) {
        userPermissionProfileCritria.add(Restrictions.eq("profile", profile));
    }
    if (profileGroup != null) {
        userPermissionProfileCritria.add(Restrictions.in("profile", PermissionProfileGrouping.getProfilesFromPermissionProfileGroup(profileGroup)));
    }
    if (active != null) {
        userPermissionProfileCritria.add(Restrictions.eq("active", active.booleanValue()));
    }
    return (Long) userPermissionProfileCritria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:ctsms    文件:ECRFFieldValueDaoImpl.java   
@Override
protected long handleGetCount(Long probandListEntryId, Long ecrfId, String section, boolean excludeAuditTrail, Boolean optional) throws Exception {
    org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria("ecrfFieldValue0");
    // if (probandListEntryId != null) {
    ecrfFieldValueCriteria.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
    // }
    org.hibernate.Criteria ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0"); // , CriteriaSpecification.INNER_JOIN);
    ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
    // if (series != null) {
    // ecrfFieldCriteria.add(Restrictions.eq("series", series.booleanValue()));
    // }
    if (optional != null) {
        ecrfFieldCriteria.add(Restrictions.eq("optional", optional.booleanValue()));
    }
    if (section != null && section.length() > 0) {
        ecrfFieldCriteria.add(Restrictions.eq("section", section));
    } else {
        ecrfFieldCriteria.add(Restrictions.or(Restrictions.eq("section", ""), Restrictions.isNull("section")));
    }
    if (excludeAuditTrail) {
        applyEcrfFieldValueMaxIdSubCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, null, probandListEntryId, null);
    }
    return (Long) ecrfFieldValueCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:ctsms    文件:InventoryBookingDaoImpl.java   
@Override
protected long handleGetCount(Long inventoryId, Long probandId, Long trialId,
        Long courseId, Long onBehalfOfId) throws Exception {
    Criteria bookingCriteria = createBookingCriteria();
    if (inventoryId != null) {
        bookingCriteria.add(Restrictions.eq("inventory.id", inventoryId.longValue()));
    }
    if (probandId != null) {
        bookingCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
    }
    if (trialId != null) {
        bookingCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
    }
    if (courseId != null) {
        bookingCriteria.add(Restrictions.eq("course.id", courseId.longValue()));
    }
    if (onBehalfOfId != null) {
        bookingCriteria.add(Restrictions.eq("onBehalfOf.id", onBehalfOfId.longValue()));
    }
    return (Long) bookingCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:admin-shiro    文件:AdminService.java   
@SuppressWarnings("unchecked")
public Pagination<AdminDO> pageAdminsByConditions(Integer pageIndex, Integer pageSize, Map<String, Object> params){
    //获取记录总数
    Criteria criteria = daoSupport.createCriteria(AdminDO.class);
    //相当于 select count(uid)
    criteria.setProjection(Projections.count("uid"));
    //设置查询条件
    if (Objects.nonNull(params)) {
        criteria.add(Restrictions.allEq(params));
    }
    criteria.add(Restrictions.eq("editEnable", Boolean.TRUE));
    Long total = (Long) criteria.uniqueResult();

    //开始查询列表,首先清除count查询所用Projection
    criteria.setProjection(null);
    criteria.setFirstResult((pageIndex - 1)* pageSize);
    criteria.setMaxResults(pageIndex * pageSize);
    List<AdminDO> admins = criteria.list();

    Pagination<AdminDO> pagination = new Pagination<AdminDO>(Long.valueOf(pageIndex), Long.valueOf(pageSize), total);
    pagination.setItems(admins);
    return pagination;
}
项目:ctsms    文件:InquiryValueDaoImpl.java   
@Override
protected long handleGetCount(Long trialId, Boolean active, Boolean activeSignup, Long probandId) throws Exception {
    org.hibernate.Criteria inquiryValueCriteria = createInquiryValueCriteria();
    if (probandId != null) {
        inquiryValueCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
    }
    if (trialId != null || active != null) {
        org.hibernate.Criteria inquiryCriteria = inquiryValueCriteria.createCriteria("inquiry", CriteriaSpecification.INNER_JOIN);
        if (trialId != null) {
            inquiryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
        }
        if (active != null) {
            inquiryCriteria.add(Restrictions.eq("active", active.booleanValue()));
        }
        if (activeSignup != null) {
            inquiryCriteria.add(Restrictions.eq("activeSignup", activeSignup.booleanValue()));
        }
    }
    return (Long) inquiryValueCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:SandBoxNGSB    文件:QuoteDAOImpl.java   
@Override
public QuotePE getLast(String sigle) {
    Session session = getSession();

    DetachedCriteria  maxDate = DetachedCriteria.forClass(QuotePE.class);
    maxDate.add(Restrictions.eq("symbol", sigle));
    maxDate.setProjection(Projections.max("creationDateTime"));

    Criteria criteria = session.createCriteria(QuotePE.class);
    criteria.add(Restrictions.eq("symbol", sigle));
    criteria.add(Property.forName("creationDateTime").eq(maxDate));

    QuotePE pe = (QuotePE) criteria.uniqueResult();
    session.close();

    return pe;
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public long countForSearchingRolling(Short catalog, Integer subCatalog, String keywords) {
    Criteria cri = getSession().createCriteria(Rollinfo.class);
    Criteria appCriteria = cri.createCriteria("app", JoinType.LEFT_OUTER_JOIN);

    if (catalog != null) {
        appCriteria.add(Restrictions.eq("catalog", catalog));
    }
    if (subCatalog != null) {
        appCriteria.add(Restrictions.eq("subCatalog", subCatalog));
    }

    if (keywords != null && !keywords.isEmpty()) {
        appCriteria.add(Restrictions.like("name", keywords, MatchMode.START));
    }
    cri.setProjection(Projections.rowCount());
    List<Long> list = HibernateHelper.list(cri);
    return list.get(0);
}
项目:ctsms    文件:ECRFFieldValueDaoImpl.java   
@Override
protected Long handleGetMaxIndex(Long probandListEntryId, Long ecrfId, String section) throws Exception {
    org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria(null);
    if (probandListEntryId != null) {
        ecrfFieldValueCriteria.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
    }
    ecrfFieldValueCriteria.add(Restrictions.isNotNull("index"));
    org.hibernate.Criteria ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField");
    ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
    ecrfFieldCriteria.add(Restrictions.eq("series", true));
    if (section != null && section.length() > 0) {
        ecrfFieldCriteria.add(Restrictions.eq("section", section));
    } else {
        ecrfFieldCriteria.add(Restrictions.or(Restrictions.eq("section", ""), Restrictions.isNull("section")));
    }
    return (Long) ecrfFieldValueCriteria.setProjection(Projections.max("index")).uniqueResult();
}
项目:ctsms    文件:ProbandAddressDaoImpl.java   
@Override
protected long handleGetCount(Long probandId, Boolean deliver, Boolean afnus, Boolean wireTransfer) throws Exception {
    org.hibernate.Criteria probandAddressCriteria = createAddressCriteria();
    if (probandId != null) {
        probandAddressCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
    }
    if (deliver != null) {
        probandAddressCriteria.add(Restrictions.eq("deliver", deliver.booleanValue()));
    }
    if (afnus != null) {
        probandAddressCriteria.add(Restrictions.eq("afnus", afnus.booleanValue()));
    }
    if (wireTransfer != null) {
        probandAddressCriteria.add(Restrictions.eq("wireTransfer", wireTransfer.booleanValue()));
    }
    return (Long) probandAddressCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:ctsms    文件:StreetDaoImpl.java   
/**
 * @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();
}
项目:ctsms    文件:ECRFFieldValueDaoImpl.java   
@Override
protected long handleGetCount(Long probandListEntryId, Long ecrfId, boolean excludeAuditTrail, Boolean series, Boolean optional) throws Exception {
    org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria("ecrfFieldValue0");
    // if (probandListEntryId != null) {
    ecrfFieldValueCriteria.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
    // }
    org.hibernate.Criteria ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0"); // , CriteriaSpecification.INNER_JOIN);
    ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
    // if (ecrfId != null) {
    // ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0", CriteriaSpecification.INNER_JOIN);
    // ecrfFieldValueCriteria.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue()));
    // }
    // org.hibernate.Criteria ecrfFieldCriteria = null;
    if (series != null) {
        ecrfFieldCriteria.add(Restrictions.eq("series", series.booleanValue()));
    }
    if (optional != null) {
        ecrfFieldCriteria.add(Restrictions.eq("optional", optional.booleanValue()));
    }
    if (excludeAuditTrail) {
        applyEcrfFieldValueMaxIdSubCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, null, probandListEntryId, null);
    }
    return (Long) ecrfFieldValueCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:ctsms    文件:ProbandContactDetailValueDaoImpl.java   
@Override
protected long handleGetCount(Long probandId, Boolean notify, Boolean na, Boolean email, Boolean phone) throws Exception {
    org.hibernate.Criteria probandContactDetailValueCriteria = createContactDetailValueCriteria();
    if (probandId != null) {
        probandContactDetailValueCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
    }
    if (notify != null) {
        probandContactDetailValueCriteria.add(Restrictions.eq("notify", notify.booleanValue()));
    }
    if (na != null) {
        probandContactDetailValueCriteria.add(Restrictions.eq("na", na.booleanValue()));
    }
    if (email != null || phone != null) {
        org.hibernate.Criteria typeCriteria = probandContactDetailValueCriteria.createCriteria("type");
        if (email != null) {
            typeCriteria.add(Restrictions.eq("email", email.booleanValue()));
        }
        if (phone != null) {
            typeCriteria.add(Restrictions.eq("phone", phone.booleanValue()));
        }
    }
    return (Long) probandContactDetailValueCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:dhus-core    文件:HibernateDao.java   
public int count (DetachedCriteria detached)
{
   Session session = getSessionFactory ().getCurrentSession ();
   Criteria criteria = detached.getExecutableCriteria (session);
   criteria.setProjection(Projections.rowCount());
   Object result = criteria.uniqueResult ();
   return ((Number) result).intValue ();
}
项目:ctsms    文件:MimeTypeDaoImpl.java   
@Override
protected long handleGetCount(String mimeType,
        FileModule module) throws Exception {
    org.hibernate.Criteria mimeTypeCriteria = createMimeTypeCriteria();
    if (mimeType != null && mimeType.length() > 0) {
        mimeTypeCriteria.add(Restrictions.eq("mimeType", mimeType));
    }
    if (module != null) {
        mimeTypeCriteria.add(Restrictions.eq("module", module));
    }
    return (Long) mimeTypeCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:ctsms    文件:ProbandListEntryTagValueDaoImpl.java   
@Override
protected long handleGetCountByField(Long inputFieldId) throws Exception {
    org.hibernate.Criteria listEntryTagValueCriteria = createListEntryTagValueCriteria();
    if (inputFieldId != null) {
        org.hibernate.Criteria tagCriteria = listEntryTagValueCriteria.createCriteria("tag", CriteriaSpecification.INNER_JOIN);
        tagCriteria.add(Restrictions.eq("field.id", inputFieldId.longValue()));
    }
    return (Long) listEntryTagValueCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:lemon    文件:HibernateGenericDao.java   
/**
 * 获得总记录数.
 * 
 * @param criteria
 *            条件
 * @return 总数
 */
@Transactional(readOnly = true)
public Integer getCount(Criteria criteria) {
    Object result = criteria.setProjection(Projections.rowCount())
            .uniqueResult();

    return HibernateUtils.getNumber(result);
}
项目:sdudoc    文件:BookDaoImpl.java   
@Override
public Pager<Book> showBookByStyle(String style, int pageNo, int pageSize) {

    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Book.class);
    criteria.add(Restrictions.eq("bookStyle", style));
    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;
}
项目:ctsms    文件:ProbandDaoImpl.java   
@Override
protected long handleGetChildrenCount(Long probandId) throws Exception {
    org.hibernate.Criteria probandCriteria = createProbandCriteria(null);
    probandCriteria.add(Restrictions.idEq(probandId.longValue()));
    org.hibernate.Criteria parentsCriteria = probandCriteria.createCriteria("parents", CriteriaSpecification.INNER_JOIN);
    return (Long) parentsCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:ctsms    文件:ProbandListEntryTagDaoImpl.java   
@Override
protected long handleGetCountByField(Long inputFieldId) throws Exception {
    org.hibernate.Criteria listEntryTagCriteria = createListEntryTagCriteria();
    if (inputFieldId != null) {
        listEntryTagCriteria.add(Restrictions.eq("field.id", inputFieldId.longValue()));
    }
    return (Long) listEntryTagCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:sdudoc    文件:BookDaoImpl.java   
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;

}
项目:ctsms    文件:FileDaoImpl.java   
@Override
protected long handleGetCount(FileModule module, Long id, String logicalPath,
        Boolean active, Boolean image, String mimeType) throws Exception {
    org.hibernate.Criteria fileCriteria = createFileCriteria();
    applyModuleIdCriterions(fileCriteria, module, id);
    if (logicalPath != null && logicalPath.length() > 0) {
        fileCriteria.add(Restrictions.eq("logicalPath", CommonUtil.fixLogicalPathFolderName(logicalPath)));
    }
    if (active != null) {
        fileCriteria.add(Restrictions.eq("active", active.booleanValue()));
    }
    applyContentTypeCriterions(fileCriteria, image, mimeType);
    return (Long) fileCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
项目:sdudoc    文件:LogDaoImpl.java   
@SuppressWarnings("unchecked")
@Override
public Pager<SysLog> listLogAllByPage(int pageNo, int pageSize) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(SysLog.class);
    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);
}
项目:sdudoc    文件:CollectDaoImpl.java   
@Override
public Pager<Collect> listCollectsByUser(int userId, int pageNo, int pageSize) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Collect.class);
    criteria.add(Restrictions.eq("userId", userId));
    long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
    criteria.setProjection(null);
    criteria.addOrder(Order.desc("collectDate"));
    criteria.setFirstResult((pageNo - 1) * pageSize);
    criteria.setMaxResults(pageSize);
    List<Collect> results = criteria.list();
    return new Pager<Collect>(pageSize, pageNo, recordTotal, results);
}
项目:ctsms    文件:PermissionDaoImpl.java   
@Override
protected Collection<Permission> handleFindByServiceMethodUser(
        String serviceMethod, Long userId, Boolean profilePermissionActive,
        Boolean userPermissionProfileActive) throws Exception {
    org.hibernate.Criteria permissionCritria = createPermissionCriteria();
    if (serviceMethod != null) {
        permissionCritria.add(Restrictions.eq("serviceMethod", serviceMethod));
    }
    if (userId != null || profilePermissionActive != null || userPermissionProfileActive != null) {
        org.hibernate.Criteria profilePermissionCritria = permissionCritria.createCriteria("profilePermissions", CriteriaSpecification.LEFT_JOIN);
        if (profilePermissionActive != null) {
            profilePermissionCritria.add(Restrictions.eq("active", profilePermissionActive.booleanValue()));
        }
        if (userId != null || userPermissionProfileActive != null) {
            DetachedCriteria subQuery = DetachedCriteria.forClass(UserPermissionProfileImpl.class, "userPermissionProfile"); // IMPL!!!!
            subQuery.setProjection(Projections.projectionList().add(Projections.property("profile")));
            if (userId != null) {
                subQuery.add(Restrictions.eq("user.id", userId.longValue()));
            }
            if (userPermissionProfileActive != null) {
                subQuery.add(Restrictions.eq("active", userPermissionProfileActive.booleanValue()));
            }
            profilePermissionCritria.add(Subqueries.propertyIn("profile", subQuery));
        }
    }
    return permissionCritria.list();
}
项目:ctsms    文件:AspSubstanceDaoImpl.java   
@Override
protected Collection<String> handleFindAspSubstanceNames(String nameInfix, Integer limit) {
    org.hibernate.Criteria aspSubstanceCriteria = createAspSubstanceCriteria(true);
    applyAspSubstanceNameCriterions(aspSubstanceCriteria, nameInfix);
    aspSubstanceCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("name", ""), Restrictions.isNull("name"))));
    aspSubstanceCriteria.addOrder(Order.asc("name"));
    aspSubstanceCriteria.setProjection(Projections.distinct(Projections.property("name")));
    CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ASP_SUBSTANCE_NAME_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
            DefaultSettings.ASP_SUBSTANCE_NAME_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), aspSubstanceCriteria);
    return aspSubstanceCriteria.list();
}
项目:Equella    文件:ItemSerializerState.java   
public void addPrivilege(String priv)
{
    if( privileges.isEmpty() )
    {
        addOwnerQuery();
        addCollectionQuery();
        addStatusQuery();
        itemProjection.add(Projections.property("metadataSecurityTargets"), SECURITY_ALIAS);
    }
    privileges.add(priv);
}
项目:Equella    文件:ItemSerializerState.java   
public void addStatusQuery()
{
    if( !statusAdded )
    {
        itemProjection.add(Projections.property("status"), STATUS_ALIAS);
        statusAdded = true;
    }

}
项目:ctsms    文件:MimeTypeDaoImpl.java   
@Override
protected Collection<String> handleFindFileNameExtensions(FileModule module, Boolean image)
        throws Exception {
    org.hibernate.Criteria mimeTypeCriteria = createMimeTypeCriteria();
    if (module != null) {
        mimeTypeCriteria.add(Restrictions.eq("module", module));
    }
    if (image != null) {
        mimeTypeCriteria.add(Restrictions.eq("image", image.booleanValue()));
    }
    mimeTypeCriteria.setProjection(Projections.distinct(Projections.property("fileNameExtensions")));
    return mimeTypeCriteria.list();
}
项目:Equella    文件:AllVersionsWhereClause.java   
@Override
public void addWhere(ItemSerializerState state)
{
    ProjectionList projections = state.getItemProjection();
    DetachedCriteria criteria = state.getItemQuery();
    criteria.add(Restrictions.eq("uuid", uuid));
    criteria.addOrder(Order.asc(PROPERTY_VERSION));
    projections.add(Projections.property(PROPERTY_VERSION), ALIAS_VERSION);
}
项目:ctsms    文件:IcdSystCategoryDaoImpl.java   
@Override
protected Collection<String> handleFindCategoryPreferredRubricLabels(
        String preferredRubricLabelInfix, Integer limit) throws Exception {
    org.hibernate.Criteria icdSystCategoryCriteria = this.getSession().createCriteria(IcdSystCategory.class);
    icdSystCategoryCriteria.setCacheable(true);
    CategoryCriterion.apply(icdSystCategoryCriteria, new CategoryCriterion(preferredRubricLabelInfix, "preferredRubricLabel", MatchMode.ANYWHERE));
    icdSystCategoryCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("preferredRubricLabel", ""), Restrictions.isNull("preferredRubricLabel"))));
    // icdSystCategoryCriteria.add(Restrictions.eq("revision",
    // Settings.getString(SettingCodes.ICD_SYSTEMATICS_REVISION, Bundle.SETTINGS, DefaultSettings.ICD_SYSTEMATICS_REVISION)));
    icdSystCategoryCriteria.addOrder(Order.asc("preferredRubricLabel"));
    icdSystCategoryCriteria.setProjection(Projections.distinct(Projections.property("preferredRubricLabel")));
    CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ICD_SYST_CATEGORY_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
            DefaultSettings.ICD_SYST_CATEGORY_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), icdSystCategoryCriteria);
    return icdSystCategoryCriteria.list();
}
项目:ctsms    文件:OpsSystBlockDaoImpl.java   
@Override
protected Collection<String> handleFindBlockPreferredRubricLabels(
        String preferredRubricLabelInfix, Integer limit) throws Exception {
    org.hibernate.Criteria opsSystBlockCriteria = this.getSession().createCriteria(OpsSystBlock.class);
    opsSystBlockCriteria.setCacheable(true);
    CategoryCriterion.apply(opsSystBlockCriteria, new CategoryCriterion(preferredRubricLabelInfix, "preferredRubricLabel", MatchMode.ANYWHERE));
    opsSystBlockCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("preferredRubricLabel", ""), Restrictions.isNull("preferredRubricLabel"))));
    // opsSystBlockCriteria.add(Restrictions.eq("revision", Settings.getString(SettingCodes.OPS_SYSTEMATICS_REVISION, Bundle.SETTINGS,
    // DefaultSettings.OPS_SYSTEMATICS_REVISION)));
    opsSystBlockCriteria.addOrder(Order.asc("preferredRubricLabel"));
    opsSystBlockCriteria.setProjection(Projections.distinct(Projections.property("preferredRubricLabel")));
    CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.OPS_SYST_BLOCK_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
            DefaultSettings.OPS_SYST_BLOCK_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), opsSystBlockCriteria);
    return opsSystBlockCriteria.list();
}
项目:ctsms    文件:TitleDaoImpl.java   
@Override
protected Collection<String> handleFindTitles(String titlePrefix, Integer limit)
        throws Exception {
    org.hibernate.Criteria titleCriteria = this.getSession().createCriteria(Title.class);
    titleCriteria.setCacheable(true);
    CategoryCriterion.apply(titleCriteria, new CategoryCriterion(titlePrefix, "title", MatchMode.START));
    titleCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("title", ""), Restrictions.isNull("title"))));
    titleCriteria.addOrder(Order.asc("title"));
    titleCriteria.setProjection(Projections.distinct(Projections.property("title")));
    CriteriaUtil.applyLimit(limit,
            Settings.getIntNullable(SettingCodes.TITLE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.TITLE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT),
            titleCriteria);
    return titleCriteria.list();
}
项目:ctsms    文件:InventoryTagValueDaoImpl.java   
@Override
protected long handleGetCount(
        Long inventoryId) throws Exception {
    org.hibernate.Criteria tagValueCriteria =createTagValueCriteria();
    if (inventoryId != null) {
        tagValueCriteria.add(Restrictions.eq("inventory.id", inventoryId.longValue()));
    }
    return (Long) tagValueCriteria.setProjection(Projections.rowCount()).uniqueResult();
}