当前位置: 首页>>代码示例>>Java>>正文


Java Criteria.likeIgnoreCase方法代码示例

本文整理汇总了Java中org.apache.deltaspike.data.api.criteria.Criteria.likeIgnoreCase方法的典型用法代码示例。如果您正苦于以下问题:Java Criteria.likeIgnoreCase方法的具体用法?Java Criteria.likeIgnoreCase怎么用?Java Criteria.likeIgnoreCase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.deltaspike.data.api.criteria.Criteria的用法示例。


在下文中一共展示了Criteria.likeIgnoreCase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exampleLike

import org.apache.deltaspike.data.api.criteria.Criteria; //导入方法依赖的package包/类
/**
 * @param criteria        a pre populated criteria to add example based <code>like</code> restrictions
 * @param example         An entity whose attribute's value will be used for creating a criteria
 * @param usingAttributes attributes from example entity to consider.
 * @return A criteria restricted by example using <code>likeIgnoreCase</code> for comparing attributes
 * @throws RuntimeException If no attribute is provided.
 */
public Criteria exampleLike(Criteria criteria, T example, SingularAttribute<T, String>... usingAttributes) {

    if (usingAttributes == null || usingAttributes.length == 0) {
        throw new RuntimeException("Please provide attributes to example criteria.");
    }

    if (criteria == null) {
        criteria = criteria();
    }

    for (SingularAttribute<T, ?> attribute : usingAttributes) {
        if (attribute.getJavaMember() instanceof Field) {
            Field field = (Field) attribute.getJavaMember();
            field.setAccessible(true);
            try {

                Object value = field.get(example);
                if (value != null) {
                    LOG.fine(String.format("Adding restriction by example on attribute %s using value %s.", attribute.getName(), value));
                    criteria.likeIgnoreCase(attribute, value.toString());
                }
            } catch (IllegalAccessException e) {
                LOG.warning(String.format("Could not get value from field %s of entity %s.", field.getName(), example.getClass().getName()));
            }
        }
    }
    return criteria;
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:36,代码来源:CrudService.java

示例2: configRestrictions

import org.apache.deltaspike.data.api.criteria.Criteria; //导入方法依赖的package包/类
protected Criteria<Car, Car> configRestrictions(Filter<Car> filter) {

        Criteria<Car, Car> criteria = criteria();

        //create restrictions based on parameters map
        if (filter.hasParam("id")) {
            criteria.eq(Car_.id, filter.getIntParam("id"));
        }

        if (filter.hasParam("minPrice") && filter.hasParam("maxPrice")) {
            criteria.between(Car_.price, filter.getDoubleParam("minPrice"), filter.getDoubleParam("maxPrice"));
        } else if (filter.hasParam("minPrice")) {
            criteria.gtOrEq(Car_.price, filter.getDoubleParam("minPrice"));
        } else if (filter.hasParam("maxPrice")) {
            criteria.ltOrEq(Car_.price, filter.getDoubleParam("maxPrice"));
        }

        //create restrictions based on filter entity
        if (filter.getEntity() != null) {
            Car filterEntity = filter.getEntity();
            if (filterEntity.hasModel()) {
                criteria.likeIgnoreCase(Car_.model, "%" + filterEntity.getModel());
            }

            if (filterEntity.getPrice() != null) {
                criteria.eq(Car_.price, filterEntity.getPrice());
            }

            if (filterEntity.hasName()) {
                criteria.likeIgnoreCase(Car_.name, "%" + filterEntity.getName() + "%");
            }
        }
        return criteria;
    }
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:35,代码来源:CarService.java


注:本文中的org.apache.deltaspike.data.api.criteria.Criteria.likeIgnoreCase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。