Java Code Examples for com.mysema.query.types.path.PathBuilder#getNumber()
The following examples show how to use
com.mysema.query.types.path.PathBuilder#getNumber() .
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: QuerydslUtils.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * Return where clause expression for number properties by casting it to * string before check its value. * <p/> * Querydsl Expr: * {@code entityPath.fieldName.stringValue() eq searchStr * Database operation: * {@code str(entity.fieldName) = searchStr * <p/> * Like operation is case sensitive. * * @param entityPath Full path to entity and associations. For example: * {@code Pet} , {@code Pet.owner} * @param fieldName Property name in the given entity path. For example: * {@code weight} in {@code Pet} entity, {@code age} in * {@code Pet.owner} entity. * @param searchStr the value to find, may be null * @return PredicateOperation */ @SuppressWarnings("unchecked") public static <T, N extends java.lang.Number & java.lang.Comparable<?>> BooleanExpression createNumberExpressionEqual( PathBuilder<T> entityPath, String fieldName, Class<N> fieldType, TypeDescriptor descriptor, String searchStr, ConversionService conversionService) { if (StringUtils.isEmpty(searchStr)) { return null; } NumberPath<N> numberExpression = entityPath.getNumber(fieldName, fieldType); TypeDescriptor strDesc = STRING_TYPE_DESCRIPTOR; if (conversionService != null) { try { return numberExpression.eq((N) conversionService.convert( searchStr, strDesc, descriptor)); } catch (ConversionException ex) { return numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } } else { return numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } }
Example 2
Source File: QuerydslUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public <T, N extends Number & Comparable<?>> BooleanExpression createNumberExpressionEqual( PathBuilder<T> entityPath, String fieldName, Class<N> fieldType, TypeDescriptor descriptor, String searchStr) { if (StringUtils.isEmpty(searchStr)) { return null; } NumberPath<N> numberExpression = entityPath.getNumber(fieldName, fieldType); TypeDescriptor strDesc = STRING_TYPE_DESCRIPTOR; if (conversionService != null) { try { return numberExpression.eq((N) conversionService.convert( searchStr, strDesc, descriptor)); } catch (ConversionException ex) { return numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } } else { return numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } }
Example 3
Source File: QuerydslUtils.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * Return an expression for {@code entityPath.fieldName} (for Numerics) with * the {@code operator} or "equal" by default. * <p/> * Expr: {@code entityPath.fieldName eq searchObj} * * @param entityPath * @param fieldName * @param searchObj * @param operator * @param fieldType * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T> BooleanExpression createNumericExpression( PathBuilder<T> entityPath, String fieldName, Object searchObj, String operator, Class<?> fieldType) { NumberPath numberExpression = null; if (BigDecimal.class.isAssignableFrom(fieldType)) { numberExpression = entityPath.getNumber(fieldName, (Class<BigDecimal>) fieldType); } else if (BigInteger.class.isAssignableFrom(fieldType)) { numberExpression = entityPath.getNumber(fieldName, (Class<BigInteger>) fieldType); } else if (Byte.class.isAssignableFrom(fieldType)) { numberExpression = entityPath.getNumber(fieldName, (Class<Byte>) fieldType); } else if (Double.class.isAssignableFrom(fieldType) || double.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Double>) fieldType); } else if (Float.class.isAssignableFrom(fieldType) || float.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Float>) fieldType); } else if (Integer.class.isAssignableFrom(fieldType) || int.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Integer>) fieldType); } else if (Long.class.isAssignableFrom(fieldType) || long.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Long>) fieldType); } else if (Short.class.isAssignableFrom(fieldType) || short.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Short>) fieldType); } if (numberExpression != null) { Number value = NumberUtils.createNumber((String) searchObj); if (StringUtils.equalsIgnoreCase(operator, OPERATOR_GOE)) { return numberExpression.goe(value); } else if (StringUtils.equalsIgnoreCase(operator, "gt")) { return numberExpression.gt(value); } else if (StringUtils.equalsIgnoreCase(operator, "like")) { return numberExpression.like((String) searchObj); } else if (StringUtils.equalsIgnoreCase(operator, OPERATOR_LOE)) { return numberExpression.loe(value); } else if (StringUtils.equalsIgnoreCase(operator, "lt")) { return numberExpression.lt(value); } } return entityPath.get(fieldName).eq(searchObj); }
Example 4
Source File: QuerydslUtils.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * Return where clause expression for number properties by casting it to * string before check its value. * <p/> * Querydsl Expr: * {@code entityPath.fieldName.stringValue() like ('%' + searchStr + '%')} * Database operation: * {@code str(entity.fieldName) like ('%' + searchStr + '%')} * <p/> * Like operation is case sensitive. * * @param entityPath Full path to entity and associations. For example: * {@code Pet} , {@code Pet.owner} * @param fieldName Property name in the given entity path. For example: * {@code weight} in {@code Pet} entity, {@code age} in * {@code Pet.owner} entity. * @param searchStr the value to find, may be null * @return PredicateOperation */ public static <T, N extends java.lang.Number & java.lang.Comparable<?>> BooleanExpression createNumberExpression( PathBuilder<T> entityPath, String fieldName, Class<N> fieldType, TypeDescriptor descriptor, String searchStr, ConversionService conversionService) { if (StringUtils.isBlank(searchStr)) { return null; } NumberPath<N> numberExpression = entityPath.getNumber(fieldName, fieldType); BooleanExpression expression = null; if (conversionService != null) { try { Object number = conversionService.convert(searchStr, STRING_TYPE_DESCRIPTOR, descriptor); if (number == null) { expression = numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } else { String toSearch = number.toString(); if (number instanceof BigDecimal && ((BigDecimal) number).scale() > 1) { // For bigDecimal trim 0 in decimal part toSearch = StringUtils.stripEnd(toSearch, "0"); if (StringUtils.endsWith(toSearch, ".")) { // prevent "#." strings toSearch = toSearch.concat("0"); } } expression = numberExpression.stringValue().like( "%".concat(toSearch).concat("%")); } } catch (ConversionException e) { expression = numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } } else { expression = numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } return expression; }
Example 5
Source File: QuerydslUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public <T> BooleanExpression createNumericExpression( PathBuilder<T> entityPath, String fieldName, Object searchObj, String operator, Class<?> fieldType) { NumberPath numberExpression = null; if (BigDecimal.class.isAssignableFrom(fieldType)) { numberExpression = entityPath.getNumber(fieldName, (Class<BigDecimal>) fieldType); } else if (BigInteger.class.isAssignableFrom(fieldType)) { numberExpression = entityPath.getNumber(fieldName, (Class<BigInteger>) fieldType); } else if (Byte.class.isAssignableFrom(fieldType)) { numberExpression = entityPath.getNumber(fieldName, (Class<Byte>) fieldType); } else if (Double.class.isAssignableFrom(fieldType) || double.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Double>) fieldType); } else if (Float.class.isAssignableFrom(fieldType) || float.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Float>) fieldType); } else if (Integer.class.isAssignableFrom(fieldType) || int.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Integer>) fieldType); } else if (Long.class.isAssignableFrom(fieldType) || long.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Long>) fieldType); } else if (Short.class.isAssignableFrom(fieldType) || short.class == fieldType) { numberExpression = entityPath.getNumber(fieldName, (Class<Short>) fieldType); } if (numberExpression != null) { Number value = NumberUtils.createNumber((String) searchObj); if (StringUtils.equalsIgnoreCase(operator, OPERATOR_GOE)) { return numberExpression.goe(value); } else if (StringUtils.equalsIgnoreCase(operator, "gt")) { return numberExpression.gt(value); } else if (StringUtils.equalsIgnoreCase(operator, "like")) { return numberExpression.like((String) searchObj); } else if (StringUtils.equalsIgnoreCase(operator, OPERATOR_LOE)) { return numberExpression.loe(value); } else if (StringUtils.equalsIgnoreCase(operator, "lt")) { return numberExpression.lt(value); } } return entityPath.get(fieldName).eq(searchObj); }
Example 6
Source File: QuerydslUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ @Override public <T, N extends Number & Comparable<?>> BooleanExpression createNumberExpression( PathBuilder<T> entityPath, String fieldName, Class<N> fieldType, TypeDescriptor descriptor, String searchStr) { if (StringUtils.isBlank(searchStr)) { return null; } NumberPath<N> numberExpression = entityPath.getNumber(fieldName, fieldType); BooleanExpression expression = null; if (conversionService != null) { try { Object number = conversionService.convert(searchStr, STRING_TYPE_DESCRIPTOR, descriptor); if (number == null) { expression = numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } else { String toSearch = number.toString(); if (number instanceof BigDecimal && ((BigDecimal) number).scale() > 1) { // For bigDecimal trim 0 in decimal part toSearch = StringUtils.stripEnd(toSearch, "0"); if (StringUtils.endsWith(toSearch, ".")) { // prevent "#." strings toSearch = toSearch.concat("0"); } } expression = numberExpression.stringValue().like( "%".concat(toSearch).concat("%")); } } catch (ConversionException e) { expression = numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } } else { expression = numberExpression.stringValue().like( "%".concat(searchStr).concat("%")); } return expression; }