本文整理汇总了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;
}
示例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;
}