Search in sources :

Example 1 with IType

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

the class NumericTypeComparator method compare.

@Override
public int compare(IType type1, IType type2) {
    // Same type
    if (type1.equals(type2)) {
        return 0;
    }
    // Object type
    IType type = typeHelper.objectType();
    if (type1.equals(type))
        return -1;
    if (type2.equals(type))
        return 1;
    // Double
    type = typeHelper.doubleType();
    if (type1.equals(type))
        return -1;
    if (type2.equals(type))
        return 1;
    // Float
    type = typeHelper.floatType();
    if (type1.equals(type))
        return -1;
    if (type2.equals(type))
        return 1;
    // BigDecimal
    type = typeHelper.bigDecimal();
    if (type1.equals(type))
        return -1;
    if (type2.equals(type))
        return 1;
    // BigInteger
    type = typeHelper.bigInteger();
    if (type1.equals(type))
        return -1;
    if (type2.equals(type))
        return 1;
    // Long
    type = typeHelper.longType();
    if (type1.equals(type))
        return -1;
    if (type2.equals(type))
        return 1;
    // Integer
    type = typeHelper.integerType();
    if (type1.equals(type))
        return -1;
    if (type2.equals(type))
        return 1;
    return 1;
}
Also used : IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 2 with IType

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

the class EclipseLinkJPQLQueryHelperTest method test_ResultType_Func_3.

@Test
public void test_ResultType_Func_3() throws Exception {
    // SELECT FUNC('age', e.empId, e.name) FROM Employee e
    IQuery namedQuery = namedQuery("Employee", "employee.func3");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of FUNC('toString', e.name) should have been found", type);
    assertEquals("The wrong type for FUNC('toString', e.name) was retrieved", getType(namedQuery, Object.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)

Example 3 with IType

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

the class EclipseLinkJPQLQueryHelperTest method test_ResultType_Func_1.

@Test
public void test_ResultType_Func_1() throws Exception {
    // SELECT FUNC('toString', e.name) FROM Employee e
    IQuery namedQuery = namedQuery("Employee", "employee.func1");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of FUNC('toString', e.name) should have been found", type);
    assertEquals("The wrong type for FUNC('toString', e.name) was retrieved", getType(namedQuery, Object.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)

Example 4 with IType

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

the class EclipseLinkJPQLQueryHelperTest method test_ResultType_Func_2.

@Test
public void test_ResultType_Func_2() throws Exception {
    // SELECT FUNC('age', e.empId, e.salary) FROM Employee e
    IQuery namedQuery = namedQuery("Employee", "employee.func2");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of FUNC('age', e.empId, e.salary) should have been found", type);
    assertEquals("The wrong type for FUNC('age', e.empId, e.salary) was retrieved", getType(namedQuery, Object.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)

Example 5 with IType

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

the class EclipseLinkJPQLQueryHelperTest2_4 method test_ParameterType_FromSubquery_1.

@Test
public void test_ParameterType_FromSubquery_1() throws Exception {
    // Select e3.salary from Employee e, (Select count(e2), e2.department from Employee e2 group by e2.department) e3 where e3.department = :dept
    IQuery namedQuery = namedQuery("Employee", "employee.fromSubquery1");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getParameterType(":dept");
    assertNotNull("The type of :dept should have been found", type);
    assertEquals("The type for :dept was incorrectly calculated", getType(namedQuery, String.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)

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