Search in sources :

Example 51 with IQuery

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

the class AbstractJPQLQueryHelperTest method test_ParameterType_07.

@Test
public final void test_ParameterType_07() throws Exception {
    // select c.firstName FROM Customer c Group By c.firstName HAVING c.firstName = concat(:fname, :lname)
    IQuery namedQuery = namedQuery("Customer", "customer.name");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getParameterType(":lname");
    assertNotNull("The type of :lname should have been found", type);
    assertEquals("The wrong type for :lname 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 52 with IQuery

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

the class AbstractJPQLQueryHelperTest method test_ResultType_26.

@Test
public final void test_ResultType_26() throws Exception {
    // SELECT AVG(e.salary) / 2E2 FROM Employee e
    IQuery namedQuery = namedQuery("Employee", "employee.division2");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The type of AVG(salary) / 2E2 should have been found", type);
    assertEquals("The wrong type for AVG(salary) / 2E2 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 53 with IQuery

use of org.eclipse.persistence.jpa.jpql.tools.spi.IQuery 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 54 with IQuery

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

the class JavaEntity method buildQueries.

protected Map<String, IQuery> buildQueries() {
    Map<String, IQuery> queries = new HashMap<>();
    try {
        Class<?> type = getType().getType();
        Annotation[] annotations = type.getAnnotations();
        NamedQueries namedQueries = getAnnotation(annotations, NamedQueries.class);
        if (namedQueries != null) {
            for (NamedQuery namedQuery : namedQueries.value()) {
                IQuery query = buildQuery(namedQuery);
                queries.put(namedQuery.name(), query);
            }
        } else {
            NamedQuery namedQuery = getAnnotation(annotations, NamedQuery.class);
            if (namedQuery != null) {
                IQuery query = buildQuery(namedQuery);
                queries.put(namedQuery.name(), query);
            }
        }
    } catch (Exception e) {
    // Ignore
    }
    return queries;
}
Also used : IQuery(org.eclipse.persistence.jpa.jpql.tools.spi.IQuery) HashMap(java.util.HashMap) NamedQueries(jakarta.persistence.NamedQueries) NamedQuery(jakarta.persistence.NamedQuery) Annotation(java.lang.annotation.Annotation)

Example 55 with IQuery

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

the class DefaultJPQLQueryHelperTest2_1 method namedQuery.

@Override
protected IQuery namedQuery(String entityName, String queryName) throws Exception {
    IEntity entity = entity(entityName);
    IQuery namedQuery = entity.getNamedQuery(queryName);
    assertNotNull("The named query " + queryName + " could not be found on " + entityName, namedQuery);
    return namedQuery;
}
Also used : IQuery(org.eclipse.persistence.jpa.jpql.tools.spi.IQuery) IEntity(org.eclipse.persistence.jpa.jpql.tools.spi.IEntity)

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