Search in sources :

Example 31 with Employee

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

the class MultipleUnitOfWorkTest method changeFirstUnitOfWorkWorkingCopy.

protected void changeFirstUnitOfWorkWorkingCopy() {
    Employee employee = (Employee) this.firstUnitOfWorkWorkingCopy;
    // Transformation
    employee.setNormalHours(new java.sql.Time[3]);
    employee.setStartTime(Helper.timeFromHourMinuteSecond(2, 2, 2));
    employee.setEndTime(Helper.timeFromHourMinuteSecond(2, 2, 2));
    // Aggregate
    employee.setPeriod(new org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod(Helper.dateFromYearMonthDate(1903, 3, 3), Helper.dateFromYearMonthDate(1904, 4, 4)));
    // One to many private
    employee.setPhoneNumbers(new Vector());
    employee.addPhoneNumber(new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber("home", "514", "2263374"));
    employee.addPhoneNumber(new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber("office", "509", "8224599"));
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Vector(java.util.Vector)

Example 32 with Employee

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

the class NestedUOWWithNewObjectRegisteredTwiceTest method test.

@Override
public void test() {
    Employee empRO = (Employee) getSession().readObject(Employee.class, new ExpressionBuilder().get("firstName").equal(firstName));
    // start transaction T0
    UnitOfWork uowT0 = getSession().acquireUnitOfWork();
    Employee empT0 = (Employee) uowT0.registerObject(empRO);
    // create phone number and commit in a nested unit of work
    UnitOfWork uowT01 = uowT0.acquireUnitOfWork();
    Employee empT01 = (Employee) uowT01.registerObject(empT0);
    PhoneNumber pN = (PhoneNumber) uowT01.registerObject(new PhoneNumber());
    pN.setAreaCode(areaCode);
    empT01.addPhoneNumber(pN);
    uowT01.commit();
    // the phone number is a new object in uowT0
    PhoneNumber pNT0 = (PhoneNumber) empT0.getPhoneNumbers().get(0);
    // start another nested unit of work
    UnitOfWork uowT02 = uowT0.acquireUnitOfWork();
    uowT02.setShouldNewObjectsBeCached(true);
    // load empT0 from the parent cache and clone and register it
    Employee empT02 = (Employee) uowT02.registerObject(empT0);
    // get detail via relation.  this will trigger the value holder and clone and register phone number in uowT02
    pNT02REL = (PhoneNumber) empT02.getPhoneNumbers().get(0);
    // get detail via registration.  this should return the same clone as referenced by pNT02REL
    pNT02REG = (PhoneNumber) uowT02.registerObject(pNT0);
    uowT0.commit();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 33 with Employee

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

the class NewObjectIdentityTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    origPerson = new Employee();
    Employee person = (Employee) uow.registerObject(origPerson);
    person.setFirstName("Anthony");
    person.setLastName("Anthony");
    ((UnitOfWorkImpl) uow).issueSQLbeforeCompletion();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            ReadAllQuery query = new ReadAllQuery(Employee.class);
            query.setSelectionCriteria(query.getExpressionBuilder().get("firstName").equal("Anthony").and(query.getExpressionBuilder().get("lastName").equal("Anthony")));
            readPerson = (Employee) ((Vector) getSession().executeQuery(query)).firstElement();
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
    try {
        Thread.sleep(3000);
    } catch (InterruptedException ex) {
    }
    ((UnitOfWorkImpl) uow).mergeClonesAfterCompletion();
    try {
        thread.join();
    } catch (InterruptedException ex) {
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) Vector(java.util.Vector)

Example 34 with Employee

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

the class NoValidationWithInitIdentityMaps method testNoneCheckDatabase.

public void testNoneCheckDatabase() {
    Employee employeeFromCache = (Employee) getSession().readObject(Employee.class);
    // initialize Identity map to verify toplink will perform an existence check
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    getSession().getDescriptor(Employee.class).setExistenceChecking("Check database");
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Employee newObject = (Employee) uow.newInstance(Employee.class);
    this.objectToBeWritten = newObject;
    uow.dontPerformValidation();
    newObject.setManager(employeeFromCache);
    uow.commit();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

Example 35 with Employee

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

the class NoValidationWithInitIdentityMaps method testNoneAssumeExistence.

public void testNoneAssumeExistence() {
    Employee employeeFromCache = (Employee) getSession().readObject(Employee.class);
    // initialize Identity map to verify toplink will perform an existence check
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    getSession().getDescriptor(Employee.class).setExistenceChecking("Assume existence");
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Employee newObject = (Employee) uow.newInstance(Employee.class);
    this.objectToBeWritten = newObject;
    uow.dontPerformValidation();
    newObject.setManager(employeeFromCache);
    uow.commit();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) 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