Search in sources :

Example 41 with IQuery

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

the class AbstractJPQLQueryHelperTest method test_ResultType_30.

@Test
public final void test_ResultType_30() throws Exception {
    // SELECT CASE WHEN e.name = 'Pascal' THEN jpql.query.EnumType.FIRST_NAME
    // WHEN e.name = 'JPQL'   THEN jpql.query.EnumType.LAST_NAME
    // ELSE jpql.query.EnumType.NAME
    // END
    // FROM Employee e
    IQuery namedQuery = namedQuery("Employee", "employee.enum");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of the case should have been found", type);
    assertEquals("The wrong type for 2 - 2.2F was retrieved", helper.getTypeRepository().getType("jpql.query.EnumType"), 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 42 with IQuery

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

the class AbstractJPQLQueryHelperTest method test_ParameterType_05.

@Test
public final void test_ParameterType_05() throws Exception {
    // select count(c) FROM Customer c JOIN c.aliases a GROUP BY a.alias HAVING a.alias = SUBSTRING(:string1, :int1, :int2)
    IQuery namedQuery = namedQuery("Customer", "customer.substring");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getParameterType(":int1");
    assertNotNull("The type of :int1 should have been found", type);
    assertEquals("The wrong type for :int1 was retrieved", getType(namedQuery, Integer.class), type);
}
Also used : BigInteger(java.math.BigInteger) 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 43 with IQuery

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

the class AbstractJPQLQueryHelperTest method test_ResultType_70.

@Test
public final void test_ResultType_70() throws Exception {
    // SELECT SUM(o.totalPrice) FROM Order o
    IQuery namedQuery = namedQuery("Order", "order.sum1");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of SUM(o.totalPrice) should have been found", type);
    assertEquals("The wrong type for SUM(o.totalPrice) 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 44 with IQuery

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

the class AbstractJPQLQueryHelperTest method test_ResultType_09.

@Test
public final void test_ResultType_09() throws Exception {
    // SELECT CASE WHEN e.name = 'Java Persistence Query Language' THEN 'Java Persistence Query Language'
    // WHEN 1 + 2 THEN SUBSTRING(e.name, 0, 2)
    // ELSE e.name
    // END
    // FROM Employee e
    IQuery namedQuery = namedQuery("Employee", "employee.case1");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of CASE(...) should have been found", type);
    assertEquals("The wrong type for CASE(...) was retrieved", 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) JPQLCoreTest(org.eclipse.persistence.jpa.tests.jpql.JPQLCoreTest)

Example 45 with IQuery

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

the class AbstractJPQLQueryHelperTest method test_ParameterType_09.

@Test
public final void test_ParameterType_09() throws Exception {
    // select o from Dept o where o.dname in (:dname1, :dname2, :dname3)
    IQuery namedQuery = namedQuery("Dept", "dept.dname");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getParameterType(":dname1");
    assertNotNull("The type of :dname1 should have been found", type);
    assertEquals("The wrong type for :newdate was retrieved", 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) JPQLCoreTest(org.eclipse.persistence.jpa.tests.jpql.JPQLCoreTest)

Aggregations

IQuery (org.eclipse.persistence.jpa.jpql.tools.spi.IQuery)120 AbstractJPQLQueryHelper (org.eclipse.persistence.jpa.jpql.tools.AbstractJPQLQueryHelper)112 IType (org.eclipse.persistence.jpa.jpql.tools.spi.IType)112 Test (org.junit.Test)112 JPQLCoreTest (org.eclipse.persistence.jpa.tests.jpql.JPQLCoreTest)103 BigInteger (java.math.BigInteger)16 Date (java.util.Date)7 IEntity (org.eclipse.persistence.jpa.jpql.tools.spi.IEntity)6 NamedQueries (jakarta.persistence.NamedQueries)1 NamedQuery (jakarta.persistence.NamedQuery)1 Annotation (java.lang.annotation.Annotation)1 BigDecimal (java.math.BigDecimal)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1 JavaQuery (org.eclipse.persistence.jpa.tests.jpql.tools.spi.java.JavaQuery)1