Search in sources :

Example 11 with IType

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

the class SumFunctionResolver method buildType.

@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();
}
Also used : TypeHelper(org.eclipse.persistence.jpa.jpql.tools.TypeHelper) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 12 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(CollectionValuedPathExpression 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);
                if (index + 1 < count) {
                    resolver = buildStateFieldResolver(path);
                } else {
                    resolver = buildCollectionValuedFieldResolver(path);
                }
            }
        }
    } else {
        resolver = buildNullResolver();
    }
}
Also used : IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 13 with IType

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

the class CollectionValuedFieldResolver method buildType.

@Override
protected IType buildType() {
    ITypeDeclaration typeDeclaration = getTypeDeclaration();
    IType type = typeDeclaration.getType();
    // For a collection type, return the first type parameter
    if (getTypeHelper().isCollectionType(type)) {
        ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();
        if (typeParameters.length > 0) {
            type = typeParameters[0].getType();
        }
    } else // For a map type, by default the value is the actual type to return
    if (getTypeHelper().isMapType(type)) {
        ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();
        if (typeParameters.length == 2) {
            type = typeParameters[1].getType();
        }
    }
    // only deals with the primitive wrapper type
    return getTypeHelper().convertPrimitive(type);
}
Also used : ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 14 with IType

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

the class CollectionEquivalentResolver method buildType.

@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;
        } else // Two types are not the same, then the type is Object
        if (!type.equals(anotherType)) {
            return helper.objectType();
        }
    }
    if (type == null) {
        type = unknownType;
    }
    return type;
}
Also used : TypeHelper(org.eclipse.persistence.jpa.jpql.tools.TypeHelper) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 15 with IType

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

the class AbstractContentAssistExtensionTest method test_enumConstants_07.

@Test
public final void test_enumConstants_07() throws Exception {
    String jpqlQuery = "SELECT e FROM Employee e WHERE CASE e.status WHEN jpql.query.EnumType.";
    int position = jpqlQuery.length();
    IType type = getPersistenceUnit().getTypeRepository().getType(EnumType.class.getName());
    List<String> proposals = new ArrayList<>();
    CollectionTools.addAll(proposals, type.getEnumConstants());
    testHasOnlyTheseProposals(jpqlQuery, position, proposals);
}
Also used : EnumType(jpql.query.EnumType) ArrayList(java.util.ArrayList) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType) Test(org.junit.Test)

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