本文整理汇总了Java中javax.persistence.criteria.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于javax.persistence.criteria包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExpression
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T, N extends Number> Expression<N> getExpression(CriteriaBuilder cb, Root<T> root, String input) {
StringTokenizer tokenizer = new StringTokenizer(input, "+-*/", true);
Expression<N> expr = getPath(root, tokenizer.nextToken());
if (tokenizer.hasMoreTokens()) {
String op = tokenizer.nextToken();
String name = tokenizer.nextToken();
Expression<N> expr2 = getPath(root, name);
if ("+".equals(op)) {
expr = cb.sum(expr, expr2);
} else if ("-".equals(op)) {
expr = cb.diff(expr, expr2);
} else if ("*".equals(op)) {
expr = cb.prod(expr, expr2);
} else if ("/".equals(op)) {
expr = (Expression<N>) cb.quot(expr, expr2);
}
}
return expr;
}
示例2: getFullTestSearchExpression
import javax.persistence.criteria.Expression; //导入依赖的package包/类
private static Expression<Boolean> getFullTestSearchExpression(CriteriaBuilder cb, String searchString) {
return cb.function("fts", Boolean.class, cb.literal(searchString));
}
示例3: getFullTestSearchRanking
import javax.persistence.criteria.Expression; //导入依赖的package包/类
private static Expression<Double> getFullTestSearchRanking(CriteriaBuilder cb, String searchString) {
return cb.function("ts_rank", Double.class, cb.literal(searchString));
}
示例4: getPredicateGlobalSearch
import javax.persistence.criteria.Expression; //导入依赖的package包/类
private Predicate getPredicateGlobalSearch(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder cb,
Predicate predicate) {
// check whether a global filter value exists
final String globalFilterValue = input.getSearch().getValue();
if (globalFilterValue != null && globalFilterValue.trim().length() > 0) {
LOGGER.fine("filtre global: {"+ globalFilterValue+"}");
Predicate matchOneColumnPredicate = cb.disjunction();
// add a 'WHERE .. LIKE' clause on each searchable column
for (final DatatableColumn column : input.getColumns()) {
if (column.getSearchable()) {
LOGGER.log(Level.FINE, "filtre global pour colonne: {}", column);
final Expression<String> expression = DatatableHelper.getExpression(root, column.getData(), String.class);
matchOneColumnPredicate = cb.or(matchOneColumnPredicate,
cb.like(cb.lower(expression), getLikeFilterValue(globalFilterValue), ESCAPE_CHAR));
}
}
predicate = cb.and(predicate, matchOneColumnPredicate);
}
return predicate;
}
示例5: toPredicate
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
public Predicate toPredicate(final Root<?> leveringsautorisatieRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
final Root<Dienstbundel> dienstbundelRoot = query.from(Dienstbundel.class);
// Join dienst op leveringsautorisatie
final Predicate joinPredicateLeveringsautorisatie = leveringsautorisatieRoot.get(ID).in(dienstbundelRoot.get(LEVERINGSAUTORISATIE).get(ID));
// Dienstbundel
final Expression<String> attributeExpression = cb.lower(cb.function(UNACCENT, String.class, dienstbundelRoot.get("naam")));
final Expression<String> valueExpression =
cb.lower(
cb.function(
UNACCENT,
String.class,
cb.concat(cb.concat(cb.literal(WILDCARD), cb.literal(value.toString())), cb.literal(WILDCARD))));
final Predicate dienstBundelPredicate = cb.like(attributeExpression, valueExpression);
return cb.and(joinPredicateLeveringsautorisatie, dienstBundelPredicate);
}
示例6: set
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
public <Y> Linu set(Path<Y> attribute, Expression<? extends Y> value) {
if (!beforeMethodInvoke()) {
return this;
}
criteria.set(attribute, value);
return this;
}
示例7: filtrarPorNome
import javax.persistence.criteria.Expression; //导入依赖的package包/类
public List<Pessoa> filtrarPorNome(String filtro){
final CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
final CriteriaQuery<Pessoa> cquery = cb.createQuery(Pessoa.class);
final Root<Pessoa> root = cquery.from(Pessoa.class);
final List<Predicate> condicoes = new ArrayList<Predicate>();
Expression<String> path = root.get("nome");
condicoes.add(cb.like(path, "%"+filtro+"%"));
cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
List<Pessoa> pessoas = getEntityManager().createQuery(cquery).getResultList();
return pessoas;
}
示例8: buildJpaPredicate
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Predicate buildJpaPredicate(CriteriaBuilder cb, Root<?> root) {
Expression<Y> path = QueryFormHelper.getPath(root, field);
Y num = (Y) value;
return cb.lessThan(path, num);
}
示例9: buildJpaPredicate
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
public Predicate buildJpaPredicate(CriteriaBuilder cb, Root<?> root) {
Expression<?> path = QueryFormHelper.getPath(root,field);
return cb.isNull(path);
}
示例10: buildJpaPredicate
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked" })
public Predicate buildJpaPredicate(CriteriaBuilder cb, Root<?> root) {
Expression<Y> path = QueryFormHelper.getPath(root, field);
Y num = (Y) value;
return cb.lessThanOrEqualTo(path, num);
}
示例11: buildJpaPredicate
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate buildJpaPredicate(CriteriaBuilder builder, Root root) {
Expression<Comparable> path = QueryFormHelper.getPath(root, field);
Comparable value1 = (Comparable) Array.get(value, 0);
Comparable value2 = (Comparable) Array.get(value, 1);
return builder.between(path, value1, value2);
}
示例12: like
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
public T like(Expression<String> x, Expression<String> pattern, char escapeChar) {
if (!beforeMethodInvoke()) {
return (T) this;
}
add(cb.like(x, pattern, escapeChar));
return (T) this;
}
示例13: lessThan
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@Override
public <Y extends Comparable<? super Y>> T lessThan(String x, Y y) {
if (!beforeMethodInvoke()) {
return (T) this;
}
Expression<Y> xe = root.get(x);
add(cb.lessThan(xe, y));
return (T) this;
}
示例14: getPredicate
import javax.persistence.criteria.Expression; //导入依赖的package包/类
/**
* Return a predicate from a rule.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private Predicate getPredicate(final Root<U> root, final CriteriaBuilder cb, final BasicRule rule, final CriteriaQuery<?> query) {
if (rule.getOp() == RuleOperator.CT) {
return getCustomPredicate(root, cb, rule, query);
}
final Expression expression = getOrmPath(root, rule);
if (expression == null) {
// Non matched expression, ignore it...
log.info(String.format("SQL injection attack ? Unable to map request rule for property %s", rule.getField()));
return null;
}
return getPredicate(cb, rule, expression);
}
示例15: buildPredicate
import javax.persistence.criteria.Expression; //导入依赖的package包/类
@SuppressWarnings ({ "unchecked", "rawtypes" })
protected Predicate buildPredicate(Path<T> root, SearchField field)
{
Path<T> tt = (!field.getField().contains(".")) ? root.get(field.getField()) : fetchNestedPath(root, field.getField());
CriteriaBuilder criteriaBuilder = this.entitymanager.getCriteriaBuilder();
Class<?> javaType = tt.getJavaType();
if (!classCompatibleWithOperator(javaType, field.getOperator()))
{
throw new RuntimeException("operator incompatible with field");
}
Object valueObject = convertStringValueToObject(field.getValue(), javaType);
switch (field.getOperator())
{
case GE:
return criteriaBuilder.greaterThan((Expression) tt, (Comparable) valueObject);
case GTE:
return criteriaBuilder.greaterThanOrEqualTo((Expression) tt, (Comparable) valueObject);
case LE:
return criteriaBuilder.lessThan((Expression) tt, (Comparable) valueObject);
case LTE:
return criteriaBuilder.lessThanOrEqualTo((Expression) tt, (Comparable) valueObject);
case NE:
return criteriaBuilder.notEqual(tt, valueObject);
case EX:
return criteriaBuilder.like((Expression) tt, "%"+field.getValue()+"%");
default:
{
//EQ
return criteriaBuilder.equal(tt, valueObject);
}
}
}