Java Code Examples for javax.persistence.criteria.Expression#getJavaType()
The following examples show how to use
javax.persistence.criteria.Expression#getJavaType() .
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: ComparableSpecification.java From specification-arg-resolver with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Expression<?> rootPath = path(root); Class<?> typeOnPath = rootPath.getJavaType(); return makePredicate(cb, (Expression<? extends Comparable>) rootPath, (Comparable) converter.convert(comparedTo, typeOnPath)); // the line below actually works (!), if Y doesn't need to extend Comparable. --tpd //return this.makePredicate(cb, rootPath.as(typeOnPath.asSubclass(typeOnPath)), // converter.convert(comparedTo, typeOnPath)); // the line below DOES work, but using the casts above is probably more efficient. //return this.makePredicate(cb, rootPath.as(typeOnPath.asSubclass(Comparable.class)), // (Comparable) converter.convert(comparedTo, typeOnPath)); }
Example 2
Source File: ComparisonPredicate.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings( {"unchecked"}) public <N extends Number> ComparisonPredicate( CriteriaBuilderImpl criteriaBuilder, ComparisonOperator comparisonOperator, Expression<N> leftHandSide, Number rightHandSide) { super( criteriaBuilder ); this.comparisonOperator = comparisonOperator; this.leftHandSide = leftHandSide; Class type = leftHandSide.getJavaType(); if ( Number.class.equals( type ) ) { this.rightHandSide = new LiteralExpression( criteriaBuilder, rightHandSide ); } else { N converted = (N) ValueHandlerFactory.convert( rightHandSide, type ); this.rightHandSide = new LiteralExpression<N>( criteriaBuilder, converted ); } }
Example 3
Source File: InPredicate.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Constructs an <tt>IN</tt> predicate against a given expression with the given literal value list. * * @param criteriaBuilder The query builder from which this originates. * @param expression The expression. * @param values The value list. */ public InPredicate( CriteriaBuilderImpl criteriaBuilder, Expression<? extends T> expression, Collection<T> values) { super( criteriaBuilder ); this.expression = expression; this.values = new ArrayList<Expression<? extends T>>( values.size() ); final Class<? extends T> javaType = expression.getJavaType(); ValueHandlerFactory.ValueHandler<? extends T> valueHandler = javaType != null && ValueHandlerFactory.isNumeric(javaType) ? ValueHandlerFactory.determineAppropriateHandler((Class<? extends T>) javaType) : new ValueHandlerFactory.NoOpValueHandler<T>(); for ( T value : values ) { this.values.add( new LiteralExpression<T>( criteriaBuilder, valueHandler.convert( value ) ) ); } }
Example 4
Source File: JpaQueryUtils.java From we-cmdb with Apache License 2.0 | 5 votes |
public static void processInOperator(CriteriaBuilder cb, List<Predicate> predicates, Filter filter, Expression filterExpr) { Class<?> expectedType = filterExpr.getJavaType(); if (!(filter.getValue() instanceof List)) { throw new InvalidArgumentException("Filter value should be list for 'in' operator."); } List<?> values = (List<?>) filter.getValue(); if (expectedType == null) { if (filter.getValue() instanceof List) { expectedType = ((List) filter.getValue()).get(0).getClass(); } else { expectedType = filter.getValue().getClass(); } } CriteriaBuilder.In<Object> in = null; if (expectedType.equals(String.class)) { in = cb.in(cb.upper(filterExpr)); } else { in = cb.in(filterExpr); } for (Object val : values) { if (String.class.equals(expectedType)) { in.value(String.valueOf(val).toUpperCase()); } else if (val.getClass().equals(expectedType)) { in.value(val); } else { in.value(ClassUtils.toObject(expectedType, String.valueOf(val))); } } predicates.add(in); }
Example 5
Source File: JpaCriteriaQueryBackend.java From katharsis-framework with Apache License 2.0 | 5 votes |
private Expression<?> handleConversions(Expression<?> expression, FilterOperator operator) { // convert to String for LIKE operators if (expression.getJavaType() != String.class && (operator == FilterOperator.LIKE)) { return expression.as(String.class); } else { return expression; } }
Example 6
Source File: UnaryArithmeticOperation.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) public UnaryArithmeticOperation( CriteriaBuilderImpl criteriaBuilder, Operation operation, Expression<T> operand) { super( criteriaBuilder, (Class)operand.getJavaType() ); this.operation = operation; this.operand = operand; }
Example 7
Source File: Between.java From specification-arg-resolver with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) { Expression<Comparable<Object>> targetExpression = path(root); Class<?> typeOnPath = targetExpression.getJavaType(); Comparable<Object> lowerBoundary = (Comparable<Object>) converter.convert(lowerBoundaryStr, typeOnPath); Comparable<Object> upperBoundary = (Comparable<Object>) converter.convert(upperBoundaryStr, typeOnPath); return criteriaBuilder.between(targetExpression, lowerBoundary, upperBoundary); }
Example 8
Source File: JpaCriteriaQueryBackend.java From crnk-framework with Apache License 2.0 | 5 votes |
private Expression<?> handleConversions(Expression<?> expression, FilterOperator operator) { // convert to String for LIKE operators if (expression.getJavaType() != String.class && (operator == FilterOperator.LIKE)) { return expression.as(String.class); } else { return expression; } }
Example 9
Source File: JpaQueryUtils.java From wecube-platform with Apache License 2.0 | 5 votes |
public static void processInOperator(CriteriaBuilder cb, List<Predicate> predicates, Filter filter, Expression filterExpr) { Class<?> expectedType = filterExpr.getJavaType(); if (!(filter.getValue() instanceof List)) { throw new WecubeCoreException("Filter value should be list for 'in' operator."); } List<?> values = (List<?>) filter.getValue(); if (expectedType == null) { if (filter.getValue() instanceof List) { expectedType = ((List) filter.getValue()).get(0).getClass(); } else { expectedType = filter.getValue().getClass(); } } CriteriaBuilder.In<Object> in = null; if (expectedType.equals(String.class)) { in = cb.in(cb.upper(filterExpr)); } else { in = cb.in(filterExpr); } for (Object val : values) { if (String.class.equals(expectedType)) { in.value(String.valueOf(val).toUpperCase()); } else if (val.getClass().equals(expectedType)) { in.value(val); } else { in.value(ClassUtils.toObject(expectedType, String.valueOf(val))); } } predicates.add(in); }
Example 10
Source File: JpaQueryUtils.java From wecube-platform with Apache License 2.0 | 5 votes |
public static void processEqualsOperator(CriteriaBuilder cb, List<Predicate> predicates, Filter filter, Expression filterExpr) { Object value = filter.getValue(); Class expectedType = filterExpr.getJavaType(); if (value instanceof String && expectedType.equals(Timestamp.class)) {//datetime java.util.Date date = DateUtils.convertToTimestamp((String) value); predicates.add(cb.equal(filterExpr, new Timestamp(date.getTime()))); } else if (String.class.equals(expectedType)) {//string predicates.add(cb.equal(cb.upper(filterExpr), (String) filter.getValue().toString().toUpperCase())); } else { predicates.add(cb.equal(filterExpr, ClassUtils.toObject(expectedType, value))); } }
Example 11
Source File: JpaQueryUtils.java From we-cmdb with Apache License 2.0 | 5 votes |
public static void processEqualsOperator(CriteriaBuilder cb, List<Predicate> predicates, Filter filter, Expression filterExpr) { Object value = filter.getValue(); Class expectedType = filterExpr.getJavaType(); if (value instanceof String && expectedType.equals(Timestamp.class)) {// datetime java.util.Date date = DateUtils.convertToTimestamp((String) value); predicates.add(cb.equal(filterExpr, new Timestamp(date.getTime()))); } else if (String.class.equals(expectedType)) {// string predicates.add(cb.equal(cb.upper(filterExpr), (String) filter.getValue().toString().toUpperCase())); } else { predicates.add(cb.equal(filterExpr, ClassUtils.toObject(expectedType, value))); } }
Example 12
Source File: AggregationFunction.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings({ "unchecked" }) public SUM(CriteriaBuilderImpl criteriaBuilder, Expression<N> expression) { super( criteriaBuilder, (Class<N>)expression.getJavaType(), NAME , expression); // force the use of a ValueHandler resetJavaType( expression.getJavaType() ); }
Example 13
Source File: AggregationFunction.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings({ "unchecked" }) public MIN(CriteriaBuilderImpl criteriaBuilder, Expression<N> expression) { super( criteriaBuilder, ( Class<N> ) expression.getJavaType(), NAME , expression); }
Example 14
Source File: AggregationFunction.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings({ "unchecked" }) public MAX(CriteriaBuilderImpl criteriaBuilder, Expression<N> expression) { super( criteriaBuilder, ( Class<N> ) expression.getJavaType(), NAME , expression); }
Example 15
Source File: AggregationFunction.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings({ "unchecked" }) public LEAST(CriteriaBuilderImpl criteriaBuilder, Expression<X> expression) { super( criteriaBuilder, ( Class<X> ) expression.getJavaType(), NAME , expression); }
Example 16
Source File: AggregationFunction.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings({ "unchecked" }) public GREATEST(CriteriaBuilderImpl criteriaBuilder, Expression<X> expression) { super( criteriaBuilder, ( Class<X> ) expression.getJavaType(), NAME , expression); }
Example 17
Source File: AbsFunction.java From lams with GNU General Public License v2.0 | 4 votes |
public AbsFunction(CriteriaBuilderImpl criteriaBuilder, Expression expression) { super( criteriaBuilder, expression.getJavaType(), NAME, expression ); }
Example 18
Source File: NullifExpression.java From lams with GNU General Public License v2.0 | 4 votes |
private static Class determineType(Class javaType, Expression primaryExpression) { return javaType != null ? javaType : primaryExpression.getJavaType(); }
Example 19
Source File: JpaCriteriaQueryBackend.java From katharsis-framework with Apache License 2.0 | 4 votes |
@Override public Class<?> getJavaElementType(Expression<?> currentCriteriaPath) { return currentCriteriaPath.getJavaType(); }
Example 20
Source File: BinaryArithmeticOperation.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Helper for determining the appropriate operation return type based on one of the operands as an expression. * * @param defaultType The default return type to use if we cannot determine the java type of 'expression' operand. * @param expression The operand. * * @return The appropriate return type. */ public static Class<? extends Number> determineReturnType( Class<? extends Number> defaultType, Expression<? extends Number> expression) { return expression == null || expression.getJavaType() == null ? defaultType : expression.getJavaType(); }