Search in sources :

Example 1 with Employee

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.

the class ReportQueryConstructorExpressionTestSuite method testConstructorExpressionWithOtherAttributes.

public void testConstructorExpressionWithOtherAttributes() {
    ExpressionBuilder employees = new ExpressionBuilder();
    ReportQuery query = new ReportQuery(Employee.class, employees);
    query.addAttribute("firstName");
    query.addAttribute("lastName");
    List reportResults = (List) getServerSession("fieldaccess").executeQuery(query);
    ConstructorReportItem citem = new ConstructorReportItem("Employee");
    citem.setResultType(Employee.class);
    citem.addAttribute(employees.get("firstName"));
    citem.addAttribute(employees.get("lastName"));
    query.addConstructorReportItem(citem);
    Vector results = (Vector) getServerSession("fieldaccess").executeQuery(query);
    Iterator i = results.iterator();
    Iterator report = reportResults.iterator();
    while (i.hasNext()) {
        ReportQueryResult result1 = (ReportQueryResult) i.next();
        Employee emp = (Employee) result1.get("Employee");
        // Employee emp = (Employee)i.next();
        ReportQueryResult result2 = (ReportQueryResult) report.next();
        if (emp.getFirstName() != null) {
            assertTrue("Null first name in constructor query", result1.get("firstName") != null);
            assertTrue("Null first name", result2.get("firstName") != null);
            assertTrue("Wrong first name", emp.getFirstName().equals(result2.get("firstName")));
        }
        if (emp.getLastName() != null) {
            assertTrue("Null last name in constructor query", result1.get("lastName") != null);
            assertTrue("Null last name", result2.get("lastName") != null);
            assertTrue("Wrong last name", emp.getLastName().equals(result2.get("lastName")));
        }
    }
    assertTrue("Different result sizes", !(report.hasNext()));
}
Also used : Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) ConstructorReportItem(org.eclipse.persistence.queries.ConstructorReportItem) ReportQuery(org.eclipse.persistence.queries.ReportQuery) Iterator(java.util.Iterator) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector) ReportQueryResult(org.eclipse.persistence.queries.ReportQueryResult)

Example 2 with Employee

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.

the class ReportQueryConstructorExpressionTestSuite method testSimpleConstructorExpressionWithNamedQuery.

public void testSimpleConstructorExpressionWithNamedQuery() {
    ExpressionBuilder employees = new ExpressionBuilder();
    ReportQuery query = new ReportQuery(Employee.class, employees);
    query.addAttribute("firstName");
    query.addAttribute("lastName");
    EntityManager em = createEntityManager("fieldaccess");
    Vector reportResults = (Vector) getServerSession("fieldaccess").executeQuery(query);
    Vector results = (Vector) em.createNamedQuery("constuctFieldAccessEmployees").getResultList();
    Iterator i = results.iterator();
    Iterator report = reportResults.iterator();
    while (i.hasNext()) {
        Employee emp = (Employee) i.next();
        ReportQueryResult result = (ReportQueryResult) report.next();
        if (emp.getFirstName() != null) {
            assertTrue("Null first name", result.get("firstName") != null);
            assertTrue("Wrong first name", emp.getFirstName().equals(result.get("firstName")));
        }
        if (emp.getLastName() != null) {
            assertTrue("Null last name", result.get("lastName") != null);
            assertTrue("Wrong last name", emp.getLastName().equals(result.get("lastName")));
        }
    }
    assertTrue("Different result sizes", !(report.hasNext()));
}
Also used : EntityManager(jakarta.persistence.EntityManager) Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) ReportQuery(org.eclipse.persistence.queries.ReportQuery) Iterator(java.util.Iterator) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector) ReportQueryResult(org.eclipse.persistence.queries.ReportQueryResult)

Example 3 with Employee

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.

the class ReportQueryMultipleReturnTestSuite method testSimpleReturnObject.

public void testSimpleReturnObject() {
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.returnWithoutReportQueryResult();
    reportQuery.setReferenceClass(Employee.class);
    ExpressionBuilder empbuilder = new ExpressionBuilder();
    reportQuery.addAttribute("manager", empbuilder.get("manager"));
    reportQuery.setSelectionCriteria(empbuilder.get("salary").greaterThan(1));
    List result = (List) getServerSession("fieldaccess").executeQuery(reportQuery);
    Object resultItem = result.get(0);
    assertTrue("Failed to return Employees correctly, Not An Employee", Employee.class.isAssignableFrom(resultItem.getClass()));
}
Also used : Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) ReportQuery(org.eclipse.persistence.queries.ReportQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 4 with Employee

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.

the class ReportQueryMultipleReturnTestSuite method testReturnUnrelatedObjectAndDirectToField.

public void testReturnUnrelatedObjectAndDirectToField() {
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.returnWithoutReportQueryResult();
    reportQuery.setReferenceClass(Employee.class);
    ExpressionBuilder empbuilder = new ExpressionBuilder();
    ExpressionBuilder addBuilder = new ExpressionBuilder(Address.class);
    reportQuery.addAttribute("salary", empbuilder.get("salary"));
    reportQuery.addAttribute("manager", empbuilder.get("manager"));
    reportQuery.addAttribute("adress.city", addBuilder.get("city"));
    reportQuery.setSelectionCriteria(empbuilder.get("salary").greaterThan(1));
    List result = (List) getServerSession("fieldaccess").executeQuery(reportQuery);
    Object innerResult = result.get(0);
    assertTrue("Failed to return Employees correctly, Not an Object Array", Object[].class.isAssignableFrom(innerResult.getClass()));
    Object resultItem = ((Object[]) innerResult)[0];
    assertTrue("Failed to return Employees correctly, Not A Number", Number.class.isAssignableFrom(resultItem.getClass()));
    assertTrue("Failed to return Employees correctly, Not Correct Result", ((Number) resultItem).intValue() > 1);
    resultItem = ((Object[]) innerResult)[1];
    assertTrue("Failed to return Employees correctly, Not An Employee", Employee.class.isAssignableFrom(resultItem.getClass()));
    resultItem = ((Object[]) innerResult)[2];
    assertTrue("Failed to return Employees correctly, Not a City", String.class.isAssignableFrom(resultItem.getClass()));
}
Also used : Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) ReportQuery(org.eclipse.persistence.queries.ReportQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 5 with Employee

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.

the class FetchGroupTrackerWeavingTests method verifyCheckFetchedForSetWithFetchGroup_OneToMany.

@Test
public void verifyCheckFetchedForSetWithFetchGroup_OneToMany() {
    Employee emp = new Employee();
    TestFetchGroup fg = new TestFetchGroup();
    ((FetchGroupTracker) emp)._persistence_setFetchGroup(fg);
    assertNull(this.checkAttribute);
    assertNull(this.checkForSetAttribute);
    emp.setPhoneNumbers(new ArrayList<PhoneNumber>());
    assertNull(this.checkAttribute);
    assertNotNull(this.checkForSetAttribute);
    assertEquals("phoneNumbers", this.checkForSetAttribute);
}
Also used : FetchGroupTracker(org.eclipse.persistence.queries.FetchGroupTracker) Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) PhoneNumber(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PhoneNumber) Test(org.junit.Test)

Aggregations

Employee (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee)183 EntityManager (jakarta.persistence.EntityManager)159 Query (jakarta.persistence.Query)82 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)80 Test (org.junit.Test)74 FetchGroup (org.eclipse.persistence.queries.FetchGroup)65 PhoneNumber (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PhoneNumber)60 EntityFetchGroup (org.eclipse.persistence.internal.queries.EntityFetchGroup)26 List (java.util.List)24 Address (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Address)22 TypedQuery (jakarta.persistence.TypedQuery)21 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)21 ArrayList (java.util.ArrayList)19 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)18 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)18 FetchGroupTracker (org.eclipse.persistence.queries.FetchGroupTracker)17 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)16 EntityExistsException (jakarta.persistence.EntityExistsException)14 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)13 PersistenceException (jakarta.persistence.PersistenceException)13