Search in sources :

Example 6 with Employee

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

the class InsertTest method test.

@Override
public void test() {
    Employee employee = new Employee();
    java.math.BigDecimal id = new java.math.BigDecimal(7777);
    java.util.Vector primaryKeys = new java.util.Vector();
    employee.setId(id);
    employee.setFirstName("Joe");
    employee.setLastName("Blow");
    primaryKeys.addElement(id);
    cache.put(primaryKeys, employee, null, 0);
    this.employee = employee;
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

Example 7 with Employee

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

the class TriggerValueHoldersSelfReferencingOneToOneTest method test.

/**
 * Test case.
 * Verify that {@code ConcurrentModificationException} is not thrown from {@code IdentityMapManager}
 * during 2nd queries execution when objects are already in the cache.
 */
@Override
public void test() {
    // We query for both Employees here because it is impossible to tell which order
    // keys will be returned from the identity map in
    // This bug only occurs when the first key returned is non-conforming and
    // a future key must be looked up
    ExpressionBuilder emp = new ExpressionBuilder();
    Expression queryExp = emp.get("manager").get("firstName").equal("Bob");
    ReadObjectQuery query = new ReadObjectQuery(Employee.class, queryExp);
    query.conformResultsInUnitOfWork();
    query.getInMemoryQueryIndirectionPolicy().triggerIndirection();
    Employee bob = (Employee) uow.executeQuery(query);
    assertNotNull(bob);
    assertEquals("Bob", bob.getManager().getFirstName());
    emp = new ExpressionBuilder();
    queryExp = emp.get("manager").get("firstName").equal("John");
    query = new ReadObjectQuery(Employee.class, queryExp);
    query.conformResultsInUnitOfWork();
    query.getInMemoryQueryIndirectionPolicy().triggerIndirection();
    Employee john = (Employee) uow.executeQuery(query);
    assertNotNull(john);
    assertEquals("John", john.getManager().getFirstName());
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Expression(org.eclipse.persistence.expressions.Expression) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 8 with Employee

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

the class UnitOfWorkConformReadObjectWithCriteriaTest method test.

@Override
public void test() {
    for (Employee sampleEmployee : this.employees) {
        Employee sampleManager = (Employee) sampleEmployee.getManager();
        // execute the conforming query
        Vector args = new Vector();
        args.add(sampleEmployee.getManager().getId());
        args.add(sampleEmployee.getLastName());
        Employee employeeResult = (Employee) uow.executeQuery(this.queryToExecute, args);
        assertNotNull("Employee should not be null", employeeResult);
        Employee managerResult = (Employee) employeeResult.getManager();
        assertNotNull("Manager should not be null", managerResult);
        assertEquals("The returned Employee should have the same id as the sample Employee", sampleEmployee.getId(), employeeResult.getId());
        assertEquals("The manager of the returned Employee should have the same id as the manager of the sample Employee", sampleManager.getId(), managerResult.getId());
    }
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Vector(java.util.Vector)

Example 9 with Employee

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

the class UnitOfWorkConformReadObjectWithCriteriaTest method setup.

@Override
public void setup() {
    this.employees = getSession().readAllObjects(Employee.class, new ExpressionBuilder().get("manager").notNull());
    for (Employee employee : employees) {
        assertNotNull(employee);
        assertNotNull(employee.getManager());
    }
    // Set up conforming query to execute
    ExpressionBuilder builder = new ExpressionBuilder();
    this.queryToExecute = new ReadObjectQuery(Employee.class, builder);
    Expression expression = builder.get("lastName").equal(builder.getParameter("employeeLastName"));
    expression = expression.and(builder.get("manager").get("id").equal(builder.getParameter("managerId")));
    this.queryToExecute.setSelectionCriteria(expression);
    this.queryToExecute.conformResultsInUnitOfWork();
    this.queryToExecute.addArgument("managerId", BigDecimal.class);
    this.queryToExecute.addArgument("employeeLastName", String.class);
    // start the test with an empty cache
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    // use the same uow for conforming queries
    this.uow = getSession().acquireUnitOfWork();
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Expression(org.eclipse.persistence.expressions.Expression) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 10 with Employee

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

the class ScrollableCursorJoiningVerificationTest method test.

@Override
public void test() {
    if (getSession().getPlatform().isHANA() || getSession().getPlatform().isSQLServer()) {
        throw new TestWarningException("ScrollableCursor is not supported on this platform");
    }
    // non-cursored results
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    ReadAllQuery nonCursoredQuery = new ReadAllQuery(Employee.class);
    nonCursoredQuery.dontCheckCache();
    nonCursoredQuery.addJoinedAttribute(nonCursoredQuery.getExpressionBuilder().anyOfAllowingNone("phoneNumbers"));
    nonCursoredQuery.addOrdering(nonCursoredQuery.getExpressionBuilder().get("id"));
    nonCursoredResults = (List) getSession().executeQuery(nonCursoredQuery);
    // forward cursored results
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    forwardCursoredResults = new ArrayList<Employee>();
    ReadAllQuery cursoredQuery = new ReadAllQuery(Employee.class);
    nonCursoredQuery.dontCheckCache();
    cursoredQuery.useScrollableCursor();
    cursoredQuery.addJoinedAttribute(cursoredQuery.getExpressionBuilder().anyOfAllowingNone("phoneNumbers"));
    cursoredQuery.addOrdering(cursoredQuery.getExpressionBuilder().get("id"));
    ScrollableCursor cursor = (ScrollableCursor) getSession().executeQuery(cursoredQuery);
    while (cursor.hasNext()) {
        Employee result = (Employee) cursor.next();
        forwardCursoredResults.add(result);
    }
    // reverse cursored results - use the same cursor
    reverseCursoredResults = new ArrayList();
    while (cursor.hasPrevious()) {
        Employee result = (Employee) cursor.previous();
        reverseCursoredResults.add(result);
    }
    cursor.close();
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ScrollableCursor(org.eclipse.persistence.queries.ScrollableCursor) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ArrayList(java.util.ArrayList) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

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