下面列出了org.hibernate.criterion.Restrictions#lt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static org.hibernate.criterion.Criterion getRestrictionCriterion(RestrictionCriterionTypes restriction, String propertyName, Object value,
org.hibernate.type.NullableType type) {
if (PROPERTY_NAME_REGEXP.matcher(propertyName).find()) {
switch (restriction) {
case GT:
return Restrictions.gt(propertyName, value);
case GE:
return Restrictions.ge(propertyName, value);
case LT:
return Restrictions.lt(propertyName, value);
case LE:
return Restrictions.le(propertyName, value);
default:
throw new IllegalArgumentException(MessageFormat.format(UNSUPPORTED_BINARY_RESTRICTION_CRITERION_TYPE, restriction.toString()));
}
} else {
return Restrictions.sqlRestriction(MessageFormat.format(restriction.toString(), propertyName),
//" "substr({alias}.logical_path, 1, length(?)) = ?",
new Object[] { value },
new org.hibernate.type.NullableType[] { type });
}
}
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
Property property = queryPath.getProperty();
if ( property.isCollection() )
{
Integer value = QueryUtils.parseValue( Integer.class, args.get( 0 ) );
if ( value == null )
{
throw new QueryException( "Left-side is collection, and right-side is not a valid integer, so can't compare by size." );
}
return Restrictions.sizeLt( queryPath.getPath(), value );
}
return Restrictions.lt( queryPath.getPath(), args.get( 0 ) );
}
/**
* 取一份卷子回答的数据
*/
public Page<SurveyAnswer> answerPage(Page<SurveyAnswer> page,String surveyId){
Criterion cri1=Restrictions.eq("surveyId", surveyId);
Criterion cri2=Restrictions.lt("handleState", 2);
page.setOrderBy("endAnDate");
page.setOrderDir("desc");
page=findPage(page, cri1, cri2);
return page;
}
/**
* 按属性条件参数创建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;
}
/** {@inheritDoc} */
@Override
public Object visit(PropertyIsLessThan filter, Object userData) {
String propertyName = getPropertyName(filter.getExpression1());
String finalName = parsePropertyName(propertyName, userData);
Object literal = getLiteralValue(filter.getExpression2());
return Restrictions.lt(finalName, castLiteral(literal, propertyName));
}
/** {@inheritDoc} */
@Override
public Object visit(Before before, Object extraData) {
String propertyName = getPropertyName(before.getExpression1());
String finalName = parsePropertyName(propertyName, before);
Object literal = getLiteralValue(before.getExpression2());
if (literal instanceof Date) {
return Restrictions.lt(finalName, literal);
} else {
throw new UnsupportedOperationException("visit(Object userData)");
}
}
private Criterion internalCriterionComparative(
BinaryOperator operator, String property, Object value)
{
Criterion criterion;
switch (operator)
{
case EQ:
{
criterion = Restrictions.eq(property, value);
break;
}
case NE:
{
criterion = Restrictions.ne(property, value);
break;
}
case GT:
{
criterion = Restrictions.gt(property, value);
break;
}
case GE:
{
criterion = Restrictions.ge(property, value);
break;
}
case LT:
{
criterion = Restrictions.lt(property, value);
break;
}
case LE:
{
criterion = Restrictions.le(property, value);
break;
}
default:
throw new UnsupportedOperationException(
"Unsupported operation: " + operator.toUriLiteral());
}
return criterion;
}
public Criterion build(String propertyName, Object value) {
return Restrictions.lt(propertyName, value);
}
/**
* 按属性条件参数创建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;
}