Search in sources :

Example 61 with IType

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

the class AbstractJPQLQueryHelperTest method test_ResultType_61.

@Test
public final void test_ResultType_61() throws Exception {
    // SELECT e.salary / 1000D n From Employee e
    IQuery namedQuery = namedQuery("Employee", "employee.resultVariable3");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of e.salary / 1000D n as n should have been found", type);
    assertEquals("The wrong type for e.salary / 1000D n as n was retrieved", getType(namedQuery, Double.class), type);
}
Also used : IQuery(org.eclipse.persistence.jpa.jpql.tools.spi.IQuery) AbstractJPQLQueryHelper(org.eclipse.persistence.jpa.jpql.tools.AbstractJPQLQueryHelper) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType) Test(org.junit.Test) JPQLCoreTest(org.eclipse.persistence.jpa.tests.jpql.JPQLCoreTest)

Example 62 with IType

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

the class JavaTypeRepository method getEnumType.

@Override
public IType getEnumType(String enumTypeName) {
    // Get the position of the last dot so we can remove the constant
    int lastDotIndex = enumTypeName.lastIndexOf(".");
    if (lastDotIndex == -1) {
        return null;
    }
    // Retrieve the fully qualified enum type name
    String typeName = enumTypeName.substring(0, lastDotIndex);
    // Attempt to load the enum type
    IType type = loadTypeImp(typeName);
    return type.isEnum() ? type : null;
}
Also used : IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 63 with IType

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

the class JavaTypeDeclaration method buildTypeDeclaration.

protected JavaTypeDeclaration buildTypeDeclaration(Object genericType) {
    // <T1, ..., Tn>
    if (genericType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) genericType;
        return buildTypeDeclaration(parameterizedType.getRawType());
    }
    // <T>
    if (genericType instanceof TypeVariable) {
        TypeVariable<?> typeVariable = (TypeVariable<?>) genericType;
        for (Type type : typeVariable.getBounds()) {
            return buildTypeDeclaration(type);
        }
        return buildTypeDeclaration(Object.class);
    }
    // ?
    if (genericType instanceof WildcardType) {
        WildcardType wildcardType = (WildcardType) genericType;
        for (Type type : wildcardType.getUpperBounds()) {
            return buildTypeDeclaration(type);
        }
        return buildTypeDeclaration(Object.class);
    }
    // T[]
    if (genericType instanceof GenericArrayType) {
        GenericArrayType genericArrayType = (GenericArrayType) genericType;
        String arrayTypeName = buildArrayTypeName(genericArrayType.toString());
        IType arrayType = typeRepository.getType(arrayTypeName);
        return new JavaTypeDeclaration(typeRepository, arrayType, genericArrayType.getGenericComponentType(), true);
    }
    return buildTypeDeclaration((Class<?>) genericType);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType) WildcardType(java.lang.reflect.WildcardType) WildcardType(java.lang.reflect.WildcardType) TypeVariable(java.lang.reflect.TypeVariable) GenericArrayType(java.lang.reflect.GenericArrayType) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 64 with IType

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

the class AbstractMapping method calculateMappingType.

/**
 * Calculates the type of the mapping represented by this external form.
 *
 * @param annotations The {@link Annotation Annotations} that are present on the member
 * @return The mapping type, which is one of the constants defined in
 * {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMappingType IMappingType} when the provider is generic JPA
 */
protected int calculateMappingType(Annotation[] annotations) {
    if (hasAnnotation(annotations, ElementCollection.class)) {
        return ELEMENT_COLLECTION;
    }
    if (hasAnnotation(annotations, Embedded.class)) {
        return EMBEDDED;
    }
    if (hasAnnotation(annotations, EmbeddedId.class)) {
        return EMBEDDED_ID;
    }
    if (hasAnnotation(annotations, Id.class)) {
        return ID;
    }
    if (hasAnnotation(annotations, ManyToMany.class)) {
        return MANY_TO_MANY;
    }
    if (hasAnnotation(annotations, ManyToOne.class)) {
        return MANY_TO_ONE;
    }
    if (hasAnnotation(annotations, OneToMany.class)) {
        return ONE_TO_MANY;
    }
    if (hasAnnotation(annotations, OneToOne.class)) {
        return ONE_TO_ONE;
    }
    if (hasAnnotation(annotations, Transient.class)) {
        return TRANSIENT;
    }
    if (hasAnnotation(annotations, Version.class)) {
        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
    if (parent.getProvider().getEntity(type) != null) {
        return ONE_TO_ONE;
    }
    // Embedded
    if (parent.getProvider().getEmbeddable(type) != null) {
        return EMBEDDED;
    }
    // Basic
    return BASIC;
}
Also used : TypeHelper(org.eclipse.persistence.jpa.jpql.tools.TypeHelper) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 65 with IType

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

the class JavaConstructor method buildTypeDeclaration.

protected ITypeDeclaration buildTypeDeclaration(Class<?> javaType, Type genericType) {
    ITypeRepository typeRepository = getTypeRepository();
    IType type = typeRepository.getType(javaType);
    return new JavaTypeDeclaration(typeRepository, type, genericType, javaType.isArray());
}
Also used : ITypeRepository(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeRepository) 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