Package org.eclipse.persistence.jpa.jpql.tools

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


    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

      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

   */
  @Override
  protected IType buildType() {

    IType type = getTypeDeclaration().getType();
    TypeHelper helper = getTypeHelper();

    // Integral types: int/Integer, long/Long => the result is a Long
    if (helper.isIntegralType(type)) {
      return helper.longType();
    }

    // Floating types: float/Float, double/Double => the result is a Double
    if (helper.isFloatingType(type)) {
      return helper.doubleType();
    }

    // BigInteger, the result is the same
    IType bigIntegerType = helper.bigInteger();

    if (type.equals(bigIntegerType)) {
      return bigIntegerType;
    }

    // BigDecimal, the result is the same
    IType bigDecimalType = helper.bigDecimal();

    if (type.equals(bigDecimalType)) {
      return bigDecimalType;
    }

    // Anything else is an invalid type
    return helper.objectType();
  }
View Full Code Here

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

   */
  @Override
  protected IType buildType() {

    List<IType> types = new ArrayList<IType>(resolvers.size());
    TypeHelper helper = getTypeHelper();
    IType unresolvableType = helper.unknownType();

    // Convert any primitive types into its Class type and any non-number into Object
    for (Resolver typeResolver : resolvers) {

      IType type = typeResolver.getType();

      // Only a resolvable type will be added to the list
      if (type != unresolvableType) {
        // Non-numeric type cannot be added
        if (!helper.isNumericType(type)) {
          type = helper.objectType();
        }
        types.add(type);
      }
    }

    if (types.isEmpty()) {
      return helper.unknownType();
    }

    // Comparing the types will result in putting the
    // result at the beginning of the list
    Collections.sort(types, new NumericTypeComparator(helper));
View Full Code Here

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

    TypeHelper helper = getTypeHelper();
    IType unknownType = helper.unknownType();
    IType type = null;

    for (int index = 0, count = resolvers.size(); index < count; index++) {
      IType anotherType = resolvers.get(index).getType();

      if (anotherType == unknownType) {
        continue;
      }

      if (type == null) {
        type = anotherType;
      }
      // Two types are not the same, then the type is Object
      else if (!type.equals(anotherType)) {
        return helper.objectType();
      }
    }

    if (type == null) {
      type = unknownType;
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
    if (typeHelper.isCollectionType(type)) {

      ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();

      if (typeParameters.length == 0) {
        return null;
      }

      type = typeParameters[0].getType();
    }
    // Wrap the Map into a virtual IManagedType so it can be returned and the
    // IType for the Map can be used to retrieve the type of the key and value
    else if (typeHelper.isMapType(type)) {
      return new MapManagedType(getManagedTypeProvider(), type);
    }

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

TOP

Related Classes of org.eclipse.persistence.jpa.jpql.tools.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.