Package org.eclipse.persistence.jpa.jpql

Examples of org.eclipse.persistence.jpa.jpql.TypeHelper


  private void validateUpdateItemTypes(UpdateItem expression, IType type) {

    if (expression.hasNewValue()) {

      Expression newValue = expression.getNewValue();
      TypeHelper typeHelper = getTypeHelper();
      boolean nullValue = isNullValue(newValue);

      // A NULL value is ignored, except if the type is a primitive, null cannot be
      // assigned to a mapping of primitive type
      if (nullValue) {
        if (typeHelper.isPrimitiveType(type)) {
          addProblem(expression, UpdateItem_NullNotAssignableToPrimitive);
        }
        return;
      }

      IType newValueType = getType(newValue);

      if (!newValueType.isResolvable() ||
         typeHelper.isDateType(type)    && typeHelper.isDateType(newValueType) ||
         typeHelper.isNumericType(type) && typeHelper.isNumericType(newValueType)) {

        return;
      }

      // The new value's type can't be assigned to the item's type
View Full Code Here


    if (types1.length != types1.length) {
      return false;
    }

    TypeHelper typeHelper = getTypeHelper();

    for (int index = types1.length; --index >= 0; ) {

      // Convert a primitive to its Object type
      IType type1 = typeHelper.convertPrimitive(types1[index].getType());
      IType type2 = typeHelper.convertPrimitive(types2[index]);

      if (!type1.isAssignableTo(type2)) {
        return false;
      }
    }
View Full Code Here

    // 1. The types are the same
    // 2. The type cannot be determined, pretend they are equivalent,
    //    another rule will validate it
    // 3. One is assignable to the other one
    TypeHelper typeHelper = getTypeHelper();

    return (type1 == type2) ||
           !type1.isResolvable() ||
           !type2.isResolvable() ||
            typeHelper.isNumericType(type1) && typeHelper.isNumericType(type2) ||
            typeHelper.isDateType(type1)    && typeHelper.isDateType(type2)    ||
            type1.isAssignableTo(type2) ||
            type2.isAssignableTo(type1);
  }
View Full Code Here

    // another rule will validate it
    if (!type1.isResolvable() || !type2.isResolvable()) {
      return true;
    }

    TypeHelper typeHelper = getTypeHelper();

    if (type1 == type2) {
      return typeHelper.isNumericType(type1) ||
      typeHelper.isStringType(type1||
      typeHelper.isDateType(type1);
    }
    else {
      return typeHelper.isNumericType(type1) && typeHelper.isNumericType(type2) ||
             typeHelper.isStringType(type1&& typeHelper.isStringType(type2||
             typeHelper.isDateType(type1)    && typeHelper.isDateType(type2);
    }
  }
View Full Code Here

   */
  private boolean isIntegralType(Expression expression) {

    if (isNumericType(expression)) {

      TypeHelper typeHelper = getTypeHelper();
      IType type = getType(expression);

      if (type != typeHelper.unknownType()) {
        return typeHelper.isIntegralType(type);
      }
    }

    return false;
  }
View Full Code Here

      return VERSION;
    }

    // Default
    IType type = getType();
    TypeHelper typeHelper = getTypeRepository().getTypeHelper();

    // M:M
    if (typeHelper.isCollectionType(type) ||
        typeHelper.isMapType(type)) {

      return ONE_TO_MANY;
    }

    // 1:1
View Full Code Here

      return false;
    }

    // Make sure both types are not primitives since isAssignableFrom() does not work.
    // For instance long and Long can't be compared but they are valid for JPQL query
    TypeHelper typeHelper = typeRepository.getTypeHelper();
    IType thisType = typeHelper.convertPrimitive(this);
    otherType = typeHelper.convertPrimitive(otherType);

    Class<?> thisClass  = ((JavaType) thisType) .type;
    Class<?> otherClass = ((JavaType) otherType).type;

    return otherClass.isAssignableFrom(thisClass);
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public TypeHelper getTypeHelper() {
    if (typeHelper == null) {
      typeHelper = new TypeHelper(this);
    }
    return typeHelper;
  }
View Full Code Here

    if (mapping == null) {
      return null;
    }

    TypeHelper typeHelper = getTypeHelper();
    ITypeDeclaration typeDeclaration = mapping.getTypeDeclaration();
    IType type = typeDeclaration.getType();

    // Collection type cannot be traversed
    // Example: SELECT e.employees. FROM Employee e where employees is a collection,
    // it cannot be traversed
    if (typeHelper.isCollectionType(type)) {
      return null;
    }

    // Primitive types cannot have a managed type
    if (typeHelper.isPrimitiveType(type)) {
      return null;
    }

    // Retrieve the corresponding managed type for the mapping's type
    return getManagedTypeProvider().getManagedType(type);
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  protected IType resolveType() {

    TypeHelper typeHelper = getTypeHelper();
    ITypeDeclaration typeDeclaration = getTypeDeclaration();
    IType type = typeDeclaration.getType();

    // For a collection type, return the first type parameter
    if (typeHelper.isCollectionType(type)) {

      ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();

      if (typeParameters.length > 0) {
        type = typeParameters[0].getType();
      }
    }
    // For a map type, by default the value is the actual type to return
    else if (typeHelper.isMapType(type)) {

      ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();

      if (typeParameters.length == 2) {
        type = typeParameters[1].getType();
      }
    }

    // A collection-valued path expression should not reference a primitive,
    // however, in an invalid query, this could potentially happen and the API
    // only deals with the primitive wrapper type
    return typeHelper.convertPrimitive(type);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.jpa.jpql.TypeHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.