Java Code Examples for org.hibernate.criterion.Restrictions#like()

The following examples show how to use org.hibernate.criterion.Restrictions#like() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CriteriaParameter.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: CmsDictionaryDaoImpl.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public CmsDictionary findByValue(String type,String value){
	Criterion cron_type=null,cron_value=null;
	if(StringUtils.isNotBlank(type)){
		cron_type = Restrictions.like("type",type);
	}
	if(StringUtils.isNotBlank(value)){
		cron_value = Restrictions.like("value",value);
	}
	List<CmsDictionary>li=findByCriteria(cron_type,cron_value);
	if(li!=null&&li.size()>0){
		return li.get(0);
	}else{
		return null;
	}
}
 
Example 3
Source File: HibernateDao.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 按属性条件参数创建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;
}
 
Example 4
Source File: CategoryCriterion.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Criterion getCategoryCriterionRestriction(CategoryCriterion categoryCriterion) {
	Criterion restriction = null;
	if (categoryCriterion.prefix != null && categoryCriterion.prefix.length() > 0) {
		if (categoryCriterion.caseSensitive) {
			restriction = Restrictions.like(categoryCriterion.field, categoryCriterion.prefix, categoryCriterion.matchMode);
		} else {
			restriction = Restrictions.ilike(categoryCriterion.field, categoryCriterion.prefix, categoryCriterion.matchMode);
		}
	} else if (EmptyPrefixModes.NON_EMPTY_ROWS.equals(categoryCriterion.emptyPrefixMode)) {
		restriction = Restrictions.not(Restrictions.or(Restrictions.eq(categoryCriterion.field, ""), Restrictions.isNull(categoryCriterion.field)));
	} else if (EmptyPrefixModes.EMPTY_ROWS.equals(categoryCriterion.emptyPrefixMode)) {
		restriction = Restrictions.or(Restrictions.eq(categoryCriterion.field, ""), Restrictions.isNull(categoryCriterion.field));
	}
	return restriction;
}
 
Example 5
Source File: LikeOperator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    if ( caseSensitive )
    {
        return Restrictions.like( queryPath.getPath(), String.valueOf( args.get( 0 ) ).replace( "%", "\\%" ), matchMode );
    }
    else
    {
        return Restrictions.ilike( queryPath.getPath(), String.valueOf( args.get( 0 ) ).replace( "%", "\\%" ), matchMode );
    }
}
 
Example 6
Source File: CmsDictionaryDaoImpl.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
public Pagination getPage(String queryType,int pageNo, int pageSize) {
	Criteria crit = createCriteria();
	if(StringUtils.isNotBlank(queryType)){
		Criterion cron = Restrictions.like("type",queryType);
		crit.add(cron);
	}
	Pagination page = findByCriteria(crit, pageNo, pageSize);
	return page;
}
 
Example 7
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Object visit(PropertyIsLike filter, Object userData) {
	String propertyName = getPropertyName(filter.getExpression());
	String finalName = parsePropertyName(propertyName, userData);

	String value = filter.getLiteral();
	value = value.replaceAll("\\*", "%");
	value = value.replaceAll("\\?", "_");
	if (filter.isMatchingCase()) {
		return Restrictions.like(finalName, value);
	} else {
		return Restrictions.ilike(finalName, value);
	}
}
 
Example 8
Source File: CmsDictionaryDaoImpl.java    From Lottery with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public List<CmsDictionary> getList(String type){
	Criterion cron = Restrictions.like("type",type); 
	return findByCriteria(cron);
}
 
Example 9
Source File: LikeRestriction.java    From base-framework with Apache License 2.0 4 votes vote down vote up
public Criterion build(String propertyName, Object value) {
	return Restrictions.like(propertyName, value.toString(), MatchMode.ANYWHERE);
}
 
Example 10
Source File: HibernateUtils.java    From lemon with Apache License 2.0 2 votes vote down vote up
/**
 * 按属性条件参数创建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;
}
 
Example 11
Source File: LLikeRestriction.java    From base-framework with Apache License 2.0 2 votes vote down vote up
public Criterion build(String propertyName, Object value) {
	
	return Restrictions.like(propertyName, value.toString(), MatchMode.END);
}
 
Example 12
Source File: RLikeRestriction.java    From base-framework with Apache License 2.0 2 votes vote down vote up
public Criterion build(String propertyName, Object value) {
	
	return Restrictions.like(propertyName, value.toString(), MatchMode.START);
}