下面列出了org.hibernate.criterion.Restrictions#le ( ) 实例代码,或者点击链接到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.sizeLe( queryPath.getPath(), value );
}
return Restrictions.le( queryPath.getPath(), args.get( 0 ) );
}
/**
* 按属性条件参数创建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;
}
/**
* 设置between(之间)查询条件
*
* @param keyname
* @param keyvalue1
* @param keyvalue2
*/
public void between(String keyname, Object keyvalue1, Object keyvalue2) {
Criterion c = null;// 写入between查询条件
if (!keyvalue1.equals(null) && !keyvalue2.equals(null)) {
c = Restrictions.between(keyname, keyvalue1, keyvalue2);
} else if (!keyvalue1.equals(null)) {
c = Restrictions.ge(keyname, keyvalue1);
} else if (!keyvalue2.equals(null)) {
c = Restrictions.le(keyname, keyvalue2);
}
criterionList.add(c);
}
/** {@inheritDoc} */
@Override
public Object visit(PropertyIsLessThanOrEqualTo filter, Object userData) {
String propertyName = getPropertyName(filter.getExpression1());
String finalName = parsePropertyName(propertyName, userData);
Object literal = getLiteralValue(filter.getExpression2());
return Restrictions.le(finalName, castLiteral(literal, propertyName));
}
/**
* 设置between(之间)查询条件
*
* @param keyname
* @param keyvalue1
* @param keyvalue2
*/
public void between(String keyname, Object keyvalue1, Object keyvalue2) {
Criterion c = null;// 写入between查询条件
if (oConvertUtils.isNotEmpty(keyvalue1) && oConvertUtils.isNotEmpty(keyvalue2)) {
c = Restrictions.between(keyname, keyvalue1, keyvalue2);
} else if (oConvertUtils.isNotEmpty(keyvalue1)) {
c = Restrictions.ge(keyname, keyvalue1);
} else if (oConvertUtils.isNotEmpty(keyvalue2)) {
c = Restrictions.le(keyname, keyvalue2);
}
criterionList.add(c);
}
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.le(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;
}