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

项目:DWSurvey    文件:HibernateDao.java   
/**
 * 按属性条件参数创建Criterion,辅助函数.
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) {
    AssertUtils.hasText(propertyName, "propertyName不能为空");
    Criterion criterion = null;
    //根据MatchType构造criterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
        break;
    case NE:
        criterion = Restrictions.ne(propertyName, propertyValue);
    }
    return criterion;
}
项目:bdf2    文件:HibernateDao.java   
private void buildCriterions(Collection<com.bstek.dorado.data.provider.Criterion> criterions,
        org.hibernate.criterion.Junction dc) {
    for (com.bstek.dorado.data.provider.Criterion c : criterions) {
        if (c instanceof SingleValueFilterCriterion) {
            SingleValueFilterCriterion fc = (SingleValueFilterCriterion) c;
            dc.add(this.buildCriterion(fc));
        }
        if (c instanceof Junction) {
            Junction jun = (Junction) c;
            org.hibernate.criterion.Junction junction = null;
            if (jun instanceof Or) {
                junction = Restrictions.disjunction();
            } else if (jun instanceof And) {
                junction = Restrictions.conjunction();
            }
            Collection<com.bstek.dorado.data.provider.Criterion> subCriterions = jun.getCriterions();
            if (subCriterions != null) {
                buildCriterions(subCriterions, dc);
            }
            dc.add(junction);
        }
    }
}
项目:lemon    文件:HibernateGenericDao.java   
/**
 * 根据entityClass,生成带排序的Criteria.
 * 
 * @param <T>
 *            实体类型
 * @param entityClass
 *            类型
 * @param orderBy
 *            排序字段名
 * @param isAsc
 *            是否正序
 * @param criterions
 *            条件
 * @return Criteria
 */
public <T> Criteria createCriteria(Class<T> entityClass, String orderBy,
        boolean isAsc, Criterion... criterions) {
    if (StringUtils.hasText(orderBy)) {
        Criteria criteria = createCriteria(entityClass, criterions);

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

        return criteria;
    } else {
        return createCriteria(entityClass, criterions);
    }
}
项目:DWSurvey    文件:SurveyAnswerManagerImpl.java   
@Override
public SurveyAnswer getTimeInByIp(SurveyDetail surveyDetail, String ip) {
    String surveyId = surveyDetail.getDirId();
    Criterion eqSurveyId = Restrictions.eq("surveyId", surveyId);
    Criterion eqIp = Restrictions.eq("ipAddr", ip);

    int minute = surveyDetail.getEffectiveTime();
    Date curdate = new Date();
    Calendar calendarDate = Calendar.getInstance();
    calendarDate.setTime(curdate);
    calendarDate.set(Calendar.MINUTE, calendarDate.get(Calendar.MINUTE)
            - minute);
    Date date = calendarDate.getTime();

    Criterion gtEndDate = Restrictions.gt("endAnDate", date);
    return surveyAnswerDao.findFirst("endAnDate", true, eqSurveyId, eqIp,
            gtEndDate);

}
项目:DWSurvey    文件:QuestionManagerImpl.java   
@Override
    public List<Question> findStatsRowVarQus(SurveyDirectory survey) {
        Criterion criterion1=Restrictions.eq("belongId", survey.getId());
        Criterion criterion2=Restrictions.eq("tag", 2);

//      Criterion criterion31=Restrictions.ne("quType", QuType.FILLBLANK);
//      Criterion criterion32=Restrictions.ne("quType", QuType.MULTIFILLBLANK);
//      Criterion criterion33=Restrictions.ne("quType", QuType.ANSWER);
//      
////        Criterion criterion3=Restrictions.or(criterion31, criterion32);
//      //where s=2 and (fds !=1 or fds!=2 )
//      return questionDao.find(criterion1,criterion2,criterion31,criterion32,criterion33);

        Criterion criterion31=Restrictions.ne("quType", QuType.FILLBLANK);
        Criterion criterion32=Restrictions.ne("quType", QuType.MULTIFILLBLANK);
        Criterion criterion33=Restrictions.ne("quType", QuType.ANSWER);
        Criterion criterion34=Restrictions.ne("quType", QuType.CHENCHECKBOX);
        Criterion criterion35=Restrictions.ne("quType", QuType.CHENFBK);
        Criterion criterion36=Restrictions.ne("quType", QuType.CHENRADIO);
        Criterion criterion37=Restrictions.ne("quType", QuType.ENUMQU);
        Criterion criterion38=Restrictions.ne("quType", QuType.ORDERQU);
        Criterion criterion39=Restrictions.ne("quType", QuType.SCORE);

        return questionDao.find(criterion1,criterion2,criterion31,criterion32,criterion33,criterion34,criterion35,criterion36,criterion37,criterion38,criterion39);
//      return null;
    }
项目:DWSurvey    文件:QuestionBankManagerImpl.java   
@Override
public Page<QuestionBank> findPage(Page<QuestionBank> page, QuestionBank entity) {
    page.setOrderBy("createDate");
    page.setOrderDir("desc");

    List<Criterion> criterions=new ArrayList<Criterion>();
    criterions.add(Restrictions.eq("visibility", 1));
    criterions.add(Restrictions.eq("dirType", 2));
    criterions.add(Restrictions.eq("bankState", 1));

    Integer bankTag = entity.getBankTag();
    if(bankTag==null){
        bankTag=0;
    }
    criterions.add(Restrictions.eq("bankTag", bankTag));
    String groupId1 = entity.getGroupId1();
    String groupId2 = entity.getGroupId2();
    if(groupId1!=null && !"".equals(groupId1)){
        criterions.add(Restrictions.eq("groupId1", groupId1));
    }
    if(groupId2!=null && !"".equals(groupId2)){
        criterions.add(Restrictions.eq("groupId2", groupId2));
    }
    return questionBankDao.findPageList(page, criterions);
}
项目:bdf2    文件:HibernateDao.java   
private void buildCriterions(Collection<com.bstek.dorado.data.provider.Criterion> criterions, DetachedCriteria dc) {
    for (com.bstek.dorado.data.provider.Criterion c : criterions) {
        if (c instanceof SingleValueFilterCriterion) {
            SingleValueFilterCriterion fc = (SingleValueFilterCriterion) c;
            dc.add(this.buildCriterion(fc));
        }
        if (c instanceof Junction) {
            Junction jun = (Junction) c;
            org.hibernate.criterion.Junction junction = null;
            if (jun instanceof Or) {
                junction = Restrictions.disjunction();
            } else if (jun instanceof And) {
                junction = Restrictions.conjunction();
            }
            Collection<com.bstek.dorado.data.provider.Criterion> subCriterions = jun.getCriterions();
            if (subCriterions != null) {
                buildCriterions(subCriterions, junction);
            }
            dc.add(junction);
        }
    }
}
项目:dswork    文件:HibernateDao.java   
/**
 * 创建Criteria对象
 * @param criterions 可变条件Restrictions<br />
 * &nbsp; &nbsp; criteria.add(Restrictions.eq(propertyName, value));
 * @return Criteria
 */
protected Criteria createCriteria(Criterion... criterions)
{
    //final Class _class = getEntityClass();
    Criteria criteria = (Criteria)getHibernateTemplate().execute(new HibernateCallback()
    {
        public Criteria doInHibernate(Session session) throws HibernateException//, SQLException
        {
            //return session.createCriteria(_class);
            return session.createCriteria(getEntityClass());
        }
    });// QBC方式
    for(Criterion c : criterions)
    {
        criteria.add(c);
    }
    return criteria;
}
项目:Equella    文件:OAuthServiceImpl.java   
@Transactional
@Override
public void userDeletedEvent(UserDeletedEvent event)
{
    // The super behaviour is to orphan things and we want most OAuthClients
    // to stick around, so let owned ones be orphaned first.
    super.userDeletedEvent(event);

    // ...but, clients that are locked to the user being deleted are
    // useless, so we'll delete those.
    Criterion c1 = Restrictions.eq("userId", event.getUserID());
    Criterion c2 = Restrictions.eq("institution", CurrentInstitution.get());
    for( OAuthClient oc : clientDao.findAllByCriteria(c1, c2) )
    {
        delete(oc, false);
    }

    tokenDao.deleteAllForUser(event.getUserID());
}
项目:Equella    文件:ConfigurationServiceImpl.java   
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException
{
    StringBuilder buffer = new StringBuilder();
    buffer.append('(');
    int i = 0;
    for( Criterion crit : criterion )
    {
        if( i != 0 )
        {
            buffer.append(' ');
            buffer.append(op);
            buffer.append(' ');
        }
        buffer.append(crit.toSqlString(criteria, criteriaQuery));
        i++;
    }
    buffer.append(')');
    return buffer.toString();
}
项目:Equella    文件:ItemDefinitionServiceImpl.java   
@Override
public Set<String> enumerateCategories()
{
    Criterion crit = getInstitutionCriterion();

    Set<String> results = new TreeSet<String>(Format.STRING_COMPARATOR);
    for( ItemDefinition itemdef : getDao().findAllByCriteria(crit) )
    {
        String category = itemdef.getWizardcategory();
        if( category != null )
        {
            results.add(category);
        }
    }

    return results;
}
项目:lams    文件:CriteriaImpl.java   
private Subcriteria(Criteria parent, String path, String alias, JoinType joinType, Criterion withClause) {
    this.alias = alias;
    this.path = path;
    this.parent = parent;
    this.joinType = joinType;
    this.withClause = withClause;
    this.hasRestriction = withClause != null;
    CriteriaImpl.this.subcriteriaList.add( this );
}
项目:DWSurvey    文件:SurveyDirectoryManagerImpl.java   
@Transactional
public void delete(SurveyDirectory parentDirectory) {
    String id=parentDirectory.getId();
    //目录ID,为1的为系统默认注册用户目录不能删除
    if(!"1".equals(id)){
        //设为不可见
        parentDirectory.setVisibility(0);
        Criterion criterion=Restrictions.eq("parentId", parentDirectory.getId());
        List<SurveyDirectory> directories=findList(criterion);
        if(directories!=null){
            for (SurveyDirectory surveyDirectory : directories) {
                delete(surveyDirectory);
            }
        }
    }
}
项目:DocIT    文件:GenericHibernateDAO.java   
protected List<T> findByCriteria(Criterion... criterion) {
     Criteria crit = getSession().createCriteria(getPersistentClass());
     for (Criterion c : criterion) {
         crit.add(c);
     }
     return crit.list();
}
项目:DWSurvey    文件:SurveyDirectoryManagerImpl.java   
@Override
public List<SurveyDirectory> findByIndex() {
    Criterion cri1=Restrictions.eq("visibility", 1);
    Criterion cri2=Restrictions.eq("parentId", "402880e5428a2dca01428a2f1f290000");
    Criterion cri3=Restrictions.eq("surveyTag", 1);
    Criterion cri4=Restrictions.isNull("sid");
    Page<SurveyDirectory> page=new Page<SurveyDirectory>();
    page.setOrderBy("createDate");
    page.setOrderDir("desc");
    page.setPageSize(10);
    List<SurveyDirectory> surveys = surveyDirectoryDao.findPage(page, cri1,cri2,cri3,cri4).getResult();
    return surveys;
}
项目:infotaf    文件:PgDao.java   
public List<Pg> getPgsByRole(String role){
    logger.debug("IN - role: {}", role);
    Criterion whereRole = Restrictions.eq("role.role", role);

    List<Pg> pg = getSession()
            .createCriteria(Pg.class)
            .createAlias("roles", "role")
            .add(whereRole)
            .list();
    return pg;
}
项目:DWSurvey    文件:SurveyAnswerManagerImpl.java   
@Override
public List<SurveyAnswer> answersByIp(String surveyId, String ip) {
    Criterion criterionSurveyId = Restrictions.eq("surveyId", surveyId);
    Criterion criterionIp = Restrictions.eq("ipAddr", ip);
    List<SurveyAnswer> answers = surveyAnswerDao.find(criterionSurveyId,
            criterionIp);
    return answers;
}
项目:lemon    文件:HibernateGenericDao.java   
/**
 * 根据entityClass生成对应类型的Criteria.
 * 
 * @param entityClass
 *            实体类型
 * @param criterions
 *            条件
 * @return Criteria
 */
public Criteria createCriteria(Class entityClass, Criterion... criterions) {
    Criteria criteria = this.getSession().createCriteria(entityClass);

    for (Criterion c : criterions) {
        criteria.add(c);
    }

    return criteria;
}
项目:Equella    文件:GenericDaoImpl.java   
@Override
@SuppressWarnings("unchecked")
public T findByCriteria(final Criterion... criterion)
{
    return (T) getHibernateTemplate().execute(new TLEHibernateCallback()
    {
        @Override
        public Object doInHibernate(Session session) throws HibernateException
        {
            Criteria criteria = createCriteria(session, criterion);
            return criteria.uniqueResult();
        }
    });
}
项目:DWSurvey    文件:QuChenRowManagerImpl.java   
public int getOrderById(String quId){
    Criterion criterion=Restrictions.eq("quId", quId);
    QuChenRow quChenRow=quChenRowDao.findFirst("orderById", false, criterion);
    if(quChenRow!=null){
        return quChenRow.getOrderById();
    }
    return 0;
}
项目:Equella    文件:GenericDaoImpl.java   
@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();
        }
    });
}
项目:infotaf    文件:ParamDao.java   
public Param getParam(String key){
    logger.debug("IN - key: {}", key);
    Criterion whereKey = Restrictions.eq("key", key);

    Param param = (Param) getSession()
            .createCriteria(Param.class)
            .add(whereKey)
            .uniqueResult();
    return param;
}
项目:Equella    文件:AbstractEntityServiceImpl.java   
protected final void validateBean(B bean, boolean overrideSystem) throws InvalidDataException
{
    if( !overrideSystem && bean.isSystemType() )
    {
        throw new ModifyingSystemTypeException();
    }

    List<ValidationError> errors = new ArrayList<ValidationError>();

    // Ask the full implementation to do any checking
    doValidationBean(bean, errors);

    // Only one uuid per institution
    Criterion c4 = Restrictions.eq("uuid", bean.getUuid());
    Criterion c5 = Restrictions.eq("institution", CurrentInstitution.get());
    Criterion c6 = Restrictions.ne("id", bean.getId());

    if( entityDao.countByCriteria(c4, c5, c6) > 0 )
    {
        errors.add(new ValidationError("uuid",
            CurrentLocale.get("com.tle.core.services.entity.generic.validation.unique.uuid")));
    }

    if( !errors.isEmpty() )
    {
        throw new InvalidDataException(errors);
    }
}
项目:Equella    文件:AbstractEntityServiceImpl.java   
protected final void validate(@Nullable EntityEditingSession<B, T> session, T entity, boolean overrideSystem)
    throws InvalidDataException
{
    if( !overrideSystem )
    {
        ensureNonSystem(entity);
    }

    List<ValidationError> errors = new ArrayList<ValidationError>();

    // Ask the full implementation to do any checking
    doValidation(session, entity, errors);

    // Only one uuid per institution
    Criterion c4 = Restrictions.eq("uuid", entity.getUuid());
    Criterion c5 = Restrictions.eq("institution", CurrentInstitution.get());
    Criterion c6 = Restrictions.ne("id", entity.getId());

    if( entityDao.countByCriteria(c4, c5, c6) > 0 )
    {
        errors.add(new ValidationError("uuid",
            CurrentLocale.get("com.tle.core.services.entity.generic.validation.unique.uuid")));
    }

    if( !errors.isEmpty() )
    {
        throw new InvalidDataException(errors);
    }
}
项目:DWSurvey    文件:UserManagerImpl.java   
@Override
public User findEmailUn(String id, String email) {
    List<Criterion> criterions=new ArrayList<Criterion>();
    criterions.add(Restrictions.eq("email", email));
    if(id!=null && !"".equals(id)){
        criterions.add(Restrictions.ne("id", id));  
    }
    return userDao.findFirst(criterions);
}
项目:Equella    文件:StagingDaoImpl.java   
@Override
public void deleteAllForUserSession(String userSession)
{
    Criterion[] cs = {Restrictions.eq("userSession", userSession)};
    for( Staging s : findAllByCriteria(cs) )
    {
        getHibernateTemplate().delete(s);
    }
}
项目:Equella    文件:DrmServiceImpl.java   
@Override
public DrmAcceptance getAgreement(String userID, Item item)
{
    Criterion c1 = Restrictions.eq("item", item);
    Criterion c2 = Restrictions.eq("user", userID);
    DrmAcceptance acceptance = dao.findByCriteria(c1, c2);
    if( acceptance == null )
    {
        throw new NotFoundException(
            "User " + userID + " has not accepted an agreement for item: " + item.toString());
    }
    return acceptance;
}
项目:Equella    文件:DrmServiceImpl.java   
@Override
public Pair<Long, List<DrmAcceptance>> enumerateAgreements(Item item, int limit, int offset, boolean sortByName,
    Date startDate, Date endDate)
{
    Criterion[] criterion = prepareCriterion(item, startDate, endDate);

    long total = dao.countByCriteria(criterion);

    Order order = Order.desc(sortByName ? "user" : "date"); //$NON-NLS-2$
    List<DrmAcceptance> acceptances = dao.findAllByCriteria(order, offset, limit, criterion);

    return new Pair<Long, List<DrmAcceptance>>(total, acceptances);
}
项目:Equella    文件:DrmServiceImpl.java   
private Criterion[] prepareCriterion(Item item, Date startDate, Date endDate)
{
    List<Criterion> critList = new ArrayList<Criterion>();
    critList.add(Restrictions.eq("item", item));
    if( startDate != null && endDate != null )
    {
        critList.add(Restrictions.between("date", startDate, endDate));
    }
    return critList.toArray(new Criterion[critList.size()]);
}
项目:Equella    文件:DrmServiceImpl.java   
private void delete(Criterion... criterion)
{
    for( DrmAcceptance acceptance : dao.findAllByCriteria(criterion) )
    {
        dao.delete(acceptance);
    }
}
项目:Equella    文件:TLEGroupServiceImpl.java   
@Override
public List<TLEGroup> search(String query)
{
    Criterion c1 = Restrictions.ilike("name", query.replace('*', '%'));
    Criterion c2 = Restrictions.eq("institution", CurrentInstitution.get());

    return dao.findAllByCriteria(Order.asc("name"), -1, c1, c2);
}
项目:infotaf    文件:ManipDao.java   
public Manip getManip(String name){
    logger.debug("IN - name: {}", name);
    Criterion whereName = Restrictions.eq("nom", name);

    Manip manip = (Manip) getSession()
                .createCriteria(Manip.class)
                .add(whereName)
                .uniqueResult();
    return manip;
}
项目:Equella    文件:ConfigurationServiceImpl.java   
@Override
@Transactional
public Map<String, String> getAllProperties()
{
    Criterion crit = getInstitutionCriterion();
    List<ConfigurationProperty> all = configurationDao.findAllByCriteria(crit);
    return PropertyBeanFactory.fill(all);
}
项目:Equella    文件:ConfigurationServiceImpl.java   
private Criterion getInstitutionCriterion()
{
    Institution inst = CurrentInstitution.get();
    if( inst != null )
    {
        return Restrictions.eq("key.institutionId", inst.getDatabaseId());
    }
    throw new IllegalStateException("Configuration properties can only be retrieved from within an institution");
}
项目:DWSurvey    文件:SimpleHibernateDao.java   
@Override
public Criteria createCriteria(final Criterion... criterions) {
    Criteria criteria = getSession().createCriteria(entityClass);
    for (Criterion c : criterions) {
        criteria.add(c);
    }
    return criteria;
}
项目:DWSurvey    文件:SurveyDetailManagerImpl.java   
private SurveyDetail findUn(String dirId){
    Criterion criterion=Restrictions.eq("dirId", dirId);
     List<SurveyDetail> details=surveyDetailDao.find(criterion);
     if(details!=null && details.size()>0){
         return details.get(0);
     }
     return null;
}
项目:Equella    文件:TermServiceImpl.java   
private Criterion getSearchRestrictionCriterion(SelectionRestriction restriction)
{
    switch( restriction )
    {
        case TOP_LEVEL_ONLY:
            return Restrictions.isNull("parent");

        case LEAF_ONLY:
            return Restrictions.sqlRestriction("lft + 1 = rht");

        default:
            return null;
    }
}
项目:Equella    文件:TLEAclManagerImpl.java   
@Override
@Transactional
public void deleteExpiredAccessEntries()
{
    Criterion c1 = Restrictions.isNotNull("expiry");
    Criterion c2 = Restrictions.lt("expiry", new Date());
    for( AccessEntry entry : aclDao.findAllByCriteria(c1, c2) )
    {
        aclDao.delete(entry);
    }
}
项目:Layer-Query    文件:CustomCriteriaImpl.java   
private Subcriteria(Criteria parent, String path, String alias, JoinType joinType, Criterion withClause) {
    this.alias = alias;
    this.path = path;
    this.parent = parent;
    this.joinType = joinType;
    this.withClause = withClause;
    this.hasRestriction = withClause != null;
    CustomCriteriaImpl.this.subcriteriaList.add(this);
}
项目:DWSurvey    文件:SurveyDirectoryManagerImpl.java   
@Override
public SurveyDirectory getSurveyBySid(String sid) {
    Criterion criterion=Restrictions.eq("sid", sid);
    SurveyDirectory surveyDirectory = surveyDirectoryDao.findUnique(criterion);
    getSurveyDetail(surveyDirectory.getId(),surveyDirectory);
    return surveyDirectory;
}