org.hibernate.criterion.Restrictions#in ( )源码实例Demo

下面列出了org.hibernate.criterion.Restrictions#in ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Knowage-Server   文件: CriteriaParameter.java
public Criterion toHibernateCriterion() {
	Criterion restriction = null;
	switch (getMatch()) {
	case LIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE);
		break;
	case ILIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE).ignoreCase();
		break;
	case NOT_EQ:
		restriction = Restrictions.ne(getName(), getValue());
		break;
	case IN:
		restriction = Restrictions.in(getName(), (Object[]) getValue());
		break;
	case NOT_IN:
		restriction = Restrictions.not(Restrictions.in(getName(), (Object[]) getValue()));
		break;
	default:
		restriction = Restrictions.eq(getName(), getValue());
		break;
	}
	return restriction;
}
 
源代码2 项目: ctsms   文件: JobDaoImpl.java
@Override
protected Collection<Job> handleFindPending(Long departmentId, Boolean daily, Boolean weekly, Boolean monthly) throws Exception {
	org.hibernate.Criteria jobCriteria = createJobCriteria();
	if (departmentId != null) {
		jobCriteria.createCriteria("modifiedUser").add(Restrictions.eq("department.id", departmentId.longValue()));
	}
	if (daily != null || weekly != null || monthly != null) {
		org.hibernate.Criteria typeCriteria = jobCriteria.createCriteria("type");
		if (daily != null) {
			typeCriteria.add(Restrictions.eq("daily", daily.booleanValue()));
		}
		if (weekly != null) {
			typeCriteria.add(Restrictions.eq("weekly", weekly.booleanValue()));
		}
		if (monthly != null) {
			typeCriteria.add(Restrictions.eq("monthly", monthly.booleanValue()));
		}
	}
	Restrictions.in("status", new Object[] {
			JobStatus.CREATED,
			JobStatus.FAILED,
			JobStatus.OK
	});
	jobCriteria.addOrder(Order.asc("id"));
	return jobCriteria.list();
}
 
源代码3 项目: sakai   文件: HibernateCriterionUtils.java
public static Criterion CriterionInRestrictionSplitter(String property, Collection<?> values) {
    Objects.requireNonNull(property);
    Objects.requireNonNull(values);

    Criterion criterion = null;
    List<?> list = new ArrayList<>(values);
    int listSize = list.size();

    for (int i = 0; i < listSize; i += MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
        List<?> subList;
        if (listSize > i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
            subList = list.subList(i, (i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST));
        } else {
            subList = list.subList(i, listSize);
        }
        if (criterion == null) {
            criterion = Restrictions.in(property, subList);
        } else {
            criterion = Restrictions.or(criterion, Restrictions.in(property, subList));
        }
    }
    return criterion;
}
 
源代码4 项目: sakai   文件: HibernateCriterionUtils.java
public static Criterion CriterionInRestrictionSplitter(String property, Collection<?> values) {
    Objects.requireNonNull(property);
    Objects.requireNonNull(values);

    Criterion criterion = null;
    List<?> list = new ArrayList<>(values);
    int listSize = list.size();

    for (int i = 0; i < listSize; i += MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
        List<?> subList;
        if (listSize > i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
            subList = list.subList(i, (i + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST));
        } else {
            subList = list.subList(i, listSize);
        }
        if (criterion == null) {
            criterion = Restrictions.in(property, subList);
        } else {
            criterion = Restrictions.or(criterion, Restrictions.in(property, subList));
        }
    }
    return criterion;
}
 
源代码5 项目: dhis2-core   文件: InOperator.java
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    Property property = queryPath.getProperty();

    if ( property.isCollection() )
    {
        return Restrictions.in( queryPath.getPath(), getValue( Collection.class, queryPath.getProperty().getItemKlass(), args.get( 0 ) ) );
    }

    return Restrictions.in( queryPath.getPath(), getValue( Collection.class, queryPath.getProperty().getKlass(), args.get( 0 ) ) );
}
 
源代码6 项目: geomajas-project-server   文件: CriteriaVisitor.java
/** {@inheritDoc} */
@Override
public Object visit(Id filter, Object userData) {
	String idName;
	try {
		idName = featureModel.getEntityMetadata().getIdentifierPropertyName();
	} catch (LayerException e) {
		log.warn("Cannot read idName, defaulting to 'id'", e);
		idName = HIBERNATE_ID;
	}
	Collection<?> c = (Collection<?>) castLiteral(filter.getIdentifiers(), idName);
	return Restrictions.in(idName, c);
}
 
源代码7 项目: AIDR   文件: DocumentResourceFacadeImp.java
@Override
public List<DocumentDTO> getDocumentForNominalLabelAndCrisis(List<Long> nominalLabelID, Long crisisId) {
	
	List<DocumentDTO> dtoList = new ArrayList<DocumentDTO>();
	
	if (nominalLabelID != null) {
		String aliasTable = "documentNominalLabels";
		String aliasTableKeyField = "documentNominalLabels.id.nominalLabelId";
		Criteria criteria = null;
		
		try {
			
			Criterion criterion = Restrictions.conjunction()
					.add(Restrictions.eq("collection.id", crisisId))
					.add(Restrictions.eq("hasHumanLabels", true));
			
			Criterion aliasCriterion =  Restrictions.in(aliasTableKeyField, nominalLabelID);
			
			// get just the documentIDs
			Projection projection = Projections.property("documentId");
			
			//List<Document> docList = this.getByCriteriaWithInnerJoinByOrder(criterion, "DESC", orderBy, null, aliasTable, aliasCriterion);
			criteria = createCriteria(criterion, null, null, null, aliasTable, aliasCriterion, null, JoinType.INNER_JOIN);
			List<Document> docList = criteria.list();
			
			if (docList != null && !docList.isEmpty()) {
				for (Document doc : docList) {
					DocumentDTO dto = new DocumentDTO(doc);
					dtoList.add(dto);
				}
			}
		} catch (Exception e) {
			logger.error("getDocumentCountForNominalLabelAndCrisis failed, criteria = " + criteria.toString(), e);
		}
	}
	
	return dtoList;
}
 
源代码8 项目: freehealth-connector   文件: DrugsDAOImpl.java
private Criterion getTypesCriterion(List<String> types) {
    return Restrictions.in("type", types);
}
 
源代码9 项目: icure-backend   文件: DrugsDAOImpl.java
private Criterion getTypesCriterion(List<String> types) {
	return Restrictions.in("type", types);
}
 
源代码10 项目: projectforge-webapp   文件: BookDao.java
@Override
public List<BookDO> getList(final BaseSearchFilter filter)
{
  final BookFilter myFilter;
  if (filter instanceof BookFilter) {
    myFilter = (BookFilter) filter;
  } else {
    myFilter = new BookFilter(filter);
  }
  final QueryFilter queryFilter = new QueryFilter(myFilter);
  if (StringUtils.isBlank(myFilter.getSearchString()) == true) {
    Collection<BookStatus> col = null;
    if (myFilter.isPresent() == true || myFilter.isMissed() == true || myFilter.isDisposed() == true) {
      col = new ArrayList<BookStatus>();
      if (myFilter.isPresent() == true) {
        // Book must be have status 'present'.
        col.add(BookStatus.PRESENT);
      }
      if (myFilter.isMissed() == true) {
        // Book must be have status 'missed'.
        col.add(BookStatus.MISSED);
      }
      if (myFilter.isDisposed() == true) {
        // Book must be have status 'disposed'.
        col.add(BookStatus.DISPOSED);
      }
    }
    myFilter.setIgnoreDeleted(false);
    if (col != null) {
      final Criterion inCrit = Restrictions.in("status", col);
      if (myFilter.isDeleted() == true) {
        queryFilter.add(Restrictions.or(inCrit, Restrictions.eq("deleted", true)));
        myFilter.setIgnoreDeleted(true);
      } else {
        queryFilter.add(inCrit);
      }
    }
  }
  queryFilter.addOrder(Order.desc("created"));
  queryFilter.addOrder(Order.asc("authors"));
  return getList(queryFilter);
}
 
源代码11 项目: base-framework   文件: InRestriction.java
public Criterion buildRestriction(String propertyName, Object[] values) {
	return Restrictions.in(propertyName,values);
}
 
源代码12 项目: lemon   文件: HibernateGenericDao.java
/**
 * find by ids.
 * 
 * @param entityClass
 *            Class
 * @param ids
 *            List
 * @param <T>
 *            generic
 * @return List
 */
@Transactional(readOnly = true)
public <T> List<T> findByIds(Class<T> entityClass, List ids) {
    Assert.notEmpty(ids);

    String idName = this.getIdName(entityClass);
    Criterion criterion = Restrictions.in(idName, ids);

    return this.find(entityClass, criterion);
}
 
源代码13 项目: lemon   文件: HibernateUtils.java
/**
 * 按属性条件参数创建Criterion,辅助函数.
 * 
 * @param propertyName
 *            String
 * @param propertyValue
 *            Object
 * @param matchType
 *            MatchType
 * @return Criterion
 */
public static Criterion buildCriterion(String propertyName,
        Object propertyValue, MatchType matchType) {
    Assert.hasText(propertyName, "propertyName不能为空");

    Criterion criterion = null;

    // 根据MatchType构造criterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);

        break;

    case NOT:
        criterion = Restrictions.ne(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 IN:
        criterion = Restrictions.in(propertyName,
                (Collection) propertyValue);

        break;

    case INL:
        criterion = Restrictions.isNull(propertyName);

        break;

    case NNL:
        criterion = Restrictions.isNotNull(propertyName);

        break;

    default:
        criterion = Restrictions.eq(propertyName, propertyValue);

        break;
    }

    return criterion;
}