Search in sources :

Example 36 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class QueryOptionTestSuite method buildReadOnlyTest.

/**
 * Test the read-only query option.
 */
public TestCase buildReadOnlyTest() {
    TestCase test = new TestCase() {

        @Override
        public void test() {
            UnitOfWork uow = getSession().acquireUnitOfWork();
            Employee employee = (Employee) uow.executeQuery("readOnlyQuery", Employee.class);
            if (employee != getSession().readObject(employee)) {
                throwError("Read-only option not used, employee registered in the unit of work.");
            }
        }
    };
    test.setName("ReadOnlyTest");
    test.setDescription("Test the read-only query option in named queries.");
    return test;
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) TestCase(org.eclipse.persistence.testing.framework.TestCase)

Example 37 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class MemoryQueryReturnNotConfirmedTest method setup.

@Override
public void setup() {
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    queryAll = (ReadAllQuery) getSession().getDescriptor(org.eclipse.persistence.testing.models.employee.domain.Employee.class).getQueryManager().getQuery("memoryQueryReturnNotConfirmedQuery");
    allEmployees = (Vector) getSession().executeQuery(queryAll);
    queryObject = new ReadObjectQuery(Employee.class);
    queryObject.setSelectionCriteria(new ExpressionBuilder().get("address").get("city").notEqual("Montreal"));
    employee = (Employee) getSession().executeQuery(queryObject);
    if (employee != null) {
        employee.getAddress();
    }
    // queryObject = new ReadObjectQuery(Employee.class);
    queryObject.setSelectionCriteria(new ExpressionBuilder().get("address").get("city").equal("Montreal"));
    employee = (Employee) getSession().executeQuery(queryObject);
    if (employee != null) {
        employee.getAddress();
    }
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 38 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class ReportQueryAndExistsSubQueryWithWhereClause method setup.

@Override
protected void setup() throws Exception {
    if (getSession().isRemoteSession()) {
        throwWarning("Report queries with objects are not supported on remote session.");
    }
    super.setup();
    reportQuery = new ReportQuery(Employee.class, new ExpressionBuilder());
    ExpressionBuilder builder = reportQuery.getExpressionBuilder();
    reportQuery.addAttribute("employee", builder);
    ReportQuery innerQuery = new ReportQuery(Employee.class, new ExpressionBuilder());
    innerQuery.addAttribute("areaCode", builder.anyOf("phoneNumbers").get("areaCode"));
    Expression innerExp = builder.anyOf("phoneNumbers").get("areaCode").like("613");
    innerQuery.setSelectionCriteria(innerExp);
    Expression exists = builder.exists(innerQuery);
    reportQuery.setSelectionCriteria(exists);
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Expression(org.eclipse.persistence.expressions.Expression) ReportQuery(org.eclipse.persistence.queries.ReportQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 39 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class AllChangeSetsTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Vector employees = uow.readAllObjects(Employee.class);
    // let's require at least 5 object
    if (employees.size() <= 4) {
        throw new TestProblemException("only " + employees.size() + " employees were read, need at least 5");
    }
    // Existing object has changed - should be counted
    Employee emp = (Employee) employees.firstElement();
    emp.setFirstName("Changed");
    changedObjectsCount++;
    Address add = emp.getAddress();
    if (emp.getAddress() != null) {
        // Existing object has changed - should be counted
        add.setCity("Changed");
        changedObjectsCount++;
    }
    // New object - should be counted
    Employee newEmp = new Employee();
    Employee newEmpClone = (Employee) uow.registerObject(newEmp);
    newEmpClone.setFirstName("New");
    changedObjectsCount++;
    Iterator it = emp.getPhoneNumbers().iterator();
    while (it.hasNext()) {
        PhoneNumber phone = (PhoneNumber) it.next();
        // to force reading the phone in and therefore registering in uow
        // Registered but not changed - should NOT be counted
        String code = phone.getAreaCode();
    }
    // forcedUpdate with false - should NOT be counted (doesn't affect cache)
    Employee emp1 = (Employee) employees.elementAt(1);
    uow.forceUpdateToVersionField(emp1, false);
    // forcedUpdate with true - should be counted
    Employee emp2 = (Employee) employees.elementAt(2);
    uow.forceUpdateToVersionField(emp2, true);
    changedObjectsCount++;
    uow.commit();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Address(org.eclipse.persistence.testing.models.employee.domain.Address) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) Iterator(java.util.Iterator) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) Vector(java.util.Vector)

Example 40 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class BuildCloneFromRowOneToOneTest method createNewManagerObject.

public Employee createNewManagerObject() {
    Employee employee = new org.eclipse.persistence.testing.models.employee.domain.Employee();
    employee.setFirstName("Markus" + System.currentTimeMillis());
    employee.setLastName("Markson");
    employee.setMale();
    employee.setSalary(35000);
    employee.setPeriod(employmentPeriodExample());
    return employee;
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

Aggregations

Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)220 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)79 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)52 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)40 Vector (java.util.Vector)34 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)32 SmallProject (org.eclipse.persistence.testing.models.employee.domain.SmallProject)29 Address (org.eclipse.persistence.testing.models.employee.domain.Address)24 PhoneNumber (org.eclipse.persistence.testing.models.employee.domain.PhoneNumber)22 Expression (org.eclipse.persistence.expressions.Expression)21 LargeProject (org.eclipse.persistence.testing.models.employee.domain.LargeProject)18 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)16 TestSuite (org.eclipse.persistence.testing.framework.TestSuite)15 PopulationManager (org.eclipse.persistence.tools.schemaframework.PopulationManager)15 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)14 Project (org.eclipse.persistence.testing.models.employee.domain.Project)14 EmployeePopulator (org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator)11 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)9 ValidationException (org.eclipse.persistence.exceptions.ValidationException)9 EmploymentPeriod (org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod)9