Search in sources :

Example 66 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class ResolverBuilder method visit.

@Override
public void visit(StateFieldPathExpression expression) {
    // so we can't resolve the type
    if (!expression.endsWithDot()) {
        // Check first to see if it's an enum type
        String path = expression.toActualText();
        IType type = queryContext.getTypeRepository().getEnumType(path);
        if (type != null) {
            resolver = buildEnumResolver(expression, type, path);
        } else {
            expression.getIdentificationVariable().accept(this);
            for (int index = expression.hasVirtualIdentificationVariable() ? 0 : 1, count = expression.pathSize(); index < count; index++) {
                path = expression.getPath(index);
                resolver = buildStateFieldResolver(expression.getPath(index));
            }
        }
    } else {
        resolver = buildNullResolver();
    }
}
Also used : IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 67 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class StateFieldResolver method resolveManagedType.

@Override
protected IManagedType resolveManagedType(IMapping mapping) {
    ITypeDeclaration typeDeclaration = mapping.getTypeDeclaration();
    IType type = typeDeclaration.getType();
    // it cannot be traversed
    if (getTypeHelper().isCollectionType(type)) {
        return null;
    }
    // Primitive types cannot have a managed type
    if (getTypeHelper().isPrimitiveType(type)) {
        return null;
    }
    // Retrieve the corresponding managed type for the mapping's type
    return getProvider().getManagedType(type);
}
Also used : ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 68 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class StateFieldPathExpressionStateObject method resolveManagedType.

@Override
protected IManagedType resolveManagedType() {
    IMapping mapping = getMapping();
    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();
    } else // IType for the Map can be used to retrieve the type of the key and value
    if (typeHelper.isMapType(type)) {
        return new MapManagedType(getManagedTypeProvider(), type);
    }
    // Retrieve the corresponding managed type for the mapping's type
    return getManagedTypeProvider().getManagedType(type);
}
Also used : TypeHelper(org.eclipse.persistence.jpa.jpql.tools.TypeHelper) ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) IMapping(org.eclipse.persistence.jpa.jpql.tools.spi.IMapping) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 69 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class CollectionValuedFieldResolver method resolveManagedType.

@Override
protected IManagedType resolveManagedType(IMapping mapping) {
    ITypeDeclaration typeDeclaration = mapping.getTypeDeclaration();
    IType type = typeDeclaration.getType();
    // Collection type cannot be traversed
    if (getTypeHelper().isCollectionType(type)) {
        ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();
        if (typeParameters.length == 0) {
            return null;
        }
        type = typeParameters[0].getType();
    } else // IType for the Map can be used to retrieve the type of the key and value
    if (getTypeHelper().isMapType(type)) {
        ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();
        if (typeParameters.length != 2) {
            return null;
        }
        type = typeParameters[1].getType();
    }
    // Retrieve the corresponding managed type for the mapping's type
    return getProvider().getManagedType(type);
}
Also used : ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 70 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class NumericResolver method buildType.

@Override
protected IType buildType() {
    List<IType> types = new ArrayList<>(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));
    return types.get(0);
}
Also used : TypeHelper(org.eclipse.persistence.jpa.jpql.tools.TypeHelper) NumericTypeComparator(org.eclipse.persistence.jpa.jpql.tools.NumericTypeComparator) ArrayList(java.util.ArrayList) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Aggregations

IType (org.eclipse.persistence.jpa.jpql.tools.spi.IType)137 Test (org.junit.Test)113 AbstractJPQLQueryHelper (org.eclipse.persistence.jpa.jpql.tools.AbstractJPQLQueryHelper)112 IQuery (org.eclipse.persistence.jpa.jpql.tools.spi.IQuery)112 JPQLCoreTest (org.eclipse.persistence.jpa.tests.jpql.JPQLCoreTest)103 BigInteger (java.math.BigInteger)16 TypeHelper (org.eclipse.persistence.jpa.jpql.tools.TypeHelper)8 ITypeDeclaration (org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration)7 Date (java.util.Date)6 ArrayList (java.util.ArrayList)3 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)2 AbstractDoubleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractDoubleEncapsulatedExpression)2 AbstractExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractExpression)2 AbstractPathExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression)2 AbstractSingleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression)2 AbstractTripleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractTripleEncapsulatedExpression)2 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)2 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)2 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)2 ArithmeticExpression (org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression)2