コード例 #1
0
  /**
   * Returns the given value converted into the type of the given property as determined via the
   * field bridge of the property.
   *
   * @param value the value to convert
   * @param entityType the type hosting the property
   * @param propertyPath the name of the property
   * @return the given value converted into the type of the given property
   */
  @Override
  public Object convertToPropertyType(String entityType, List<String> propertyPath, String value) {
    final Class<?> propertyType = getPrimitivePropertyType(entityType, propertyPath);
    if (propertyType == null) {
      // not a primitive, then it is an embedded entity, need to signal an invalid query
      throw log.getPredicatesOnCompleteEmbeddedEntitiesNotAllowedException(
          StringHelper.join(propertyPath, "."));
    }

    if (Date.class.isAssignableFrom(propertyType)) {
      try {
        return dateFormat.parse(value);
      } catch (ParseException e) {
        throw log.getInvalidDateLiteralException(value);
      }
    }

    if (Enum.class.isAssignableFrom(propertyType)) {
      try {
        return Enum.valueOf((Class<Enum>) propertyType, value);
      } catch (IllegalArgumentException e) {
        throw log.getInvalidEnumLiteralException(value, propertyType.getName());
      }
    }

    if (propertyType == String.class) {
      return value;
    }

    if (propertyType == Character.class || propertyType == char.class) {
      return value.charAt(0);
    }

    try {
      if (propertyType == Double.class || propertyType == double.class) {
        return Double.valueOf(value);
      }
      if (propertyType == Float.class || propertyType == float.class) {
        return Float.valueOf(value);
      }
      if (propertyType == Long.class || propertyType == long.class) {
        return Long.valueOf(value);
      }
      if (propertyType == Integer.class || propertyType == int.class) {
        return Integer.valueOf(value);
      }
      if (propertyType == Short.class || propertyType == short.class) {
        return Short.valueOf(value);
      }
      if (propertyType == Byte.class || propertyType == byte.class) {
        return Byte.valueOf(value);
      }
    } catch (NumberFormatException ex) {
      throw log.getInvalidNumericLiteralException(value);
    }

    if (propertyType == Boolean.class || propertyType == boolean.class) {
      if (value.equalsIgnoreCase("true")) {
        return true;
      } else if (value.equalsIgnoreCase("false")) {
        return false;
      } else {
        throw log.getInvalidBooleanLiteralException(value);
      }
    }

    return value;
  }
コード例 #2
0
 @Override
 public boolean hasEmbeddedProperty(String propertyName) {
   return propertyHelper.hasEmbeddedProperty(
       entityType, StringHelper.splitPropertyPath(propertyName));
 }