Search in sources :

Example 1 with ALCTEmployee

use of org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee in project eclipselink by eclipse-ee4j.

the class ALCTEmployeeSystem method populate.

/**
 *    This method will instantiate all of the example instances and insert them into the database
 *    using the given session.
 */
@Override
public void populate(DatabaseSession session) {
    UnitOfWork unitOfWork = session.acquireUnitOfWork();
    ALCTEmployee emp = new ALCTEmployee();
    emp.setFirstName("ALCTEmp");
    emp.setLastName("NotRequired");
    ALCTEmploymentPeriod empPeriod = new ALCTEmploymentPeriod();
    empPeriod.setEndDate(Helper.dateFromYearMonthDate(2006, 12, 2));
    empPeriod.setStartDate(Helper.dateFromYearMonthDate(2004, 12, 2));
    emp.setPeriod(empPeriod);
    unitOfWork.registerObject(emp);
    unitOfWork.commit();
}
Also used : ALCTEmployee(org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) ALCTEmploymentPeriod(org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmploymentPeriod)

Example 2 with ALCTEmployee

use of org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee in project eclipselink by eclipse-ee4j.

the class AggregateAttributeChangeTrackingTest method test.

@Override
protected void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    ALCTEmployee emp = (ALCTEmployee) uow.readObject(ALCTEmployee.class);
    emp.getPeriod().setEndDate(new java.sql.Date(191099988948748948L));
    if (emp._persistence_getPropertyChangeListener() == null) {
        throw new TestErrorException("Attribute Level Change Tracking not active in aggregate");
    }
    if (!((AttributeChangeListener) emp._persistence_getPropertyChangeListener()).hasChanges()) {
        throw new TestErrorException("Attribute Level Change Tracking not active in aggregate");
    }
}
Also used : ALCTEmployee(org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 3 with ALCTEmployee

use of org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee in project eclipselink by eclipse-ee4j.

the class WeakReferenceTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork(ReferenceMode.WEAK);
    int size = uow.readAllObjects(ALCTEmployee.class).size();
    for (int i = 0; i < 200; ++i) {
        // force cacheKey cleanup
        uow.setShouldNewObjectsBeCached(true);
        ALCTEmployee emp = new ALCTEmployee();
        emp.setId(new BigDecimal(i));
        uow.registerObject(emp);
    }
    try {
        Long[] arr = new Long[10000000];
        for (int i = 0; i < 10000000; ++i) {
            arr[i] = (long) i;
        }
        System.gc();
        try {
            Thread.sleep(200);
        } catch (InterruptedException ex) {
        }
        System.gc();
    } catch (Error er) {
    // ignore
    }
    if (((UnitOfWorkImpl) uow).getCloneMapping().size() == size) {
        throw new TestErrorException("Did not release weak references.");
    }
}
Also used : ALCTEmployee(org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) BigDecimal(java.math.BigDecimal)

Example 4 with ALCTEmployee

use of org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee in project eclipselink by eclipse-ee4j.

the class ChangeTrackedWeakReferenceTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork(ReferenceMode.FORCE_WEAK);
    Collection collection = uow.readAllObjects(ALCTEmployee.class);
    for (Iterator iterator = collection.iterator(); iterator.hasNext(); ) {
        ((ALCTEmployee) iterator.next()).setFirstName("" + System.currentTimeMillis());
    }
    int size = collection.size();
    try {
        Long[] arr = new Long[100000];
        for (int i = 0; i < 100000; ++i) {
            arr[i] = (long) i;
        }
    } catch (Error er) {
    // ignore
    }
    if (((UnitOfWorkImpl) uow).getCloneMapping().size() != size) {
        throw new TestErrorException("Released Objects with changes on weak references.");
    }
}
Also used : ALCTEmployee(org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Iterator(java.util.Iterator) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) Collection(java.util.Collection) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)

Aggregations

UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)4 ALCTEmployee (org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmployee)4 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)3 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)2 BigDecimal (java.math.BigDecimal)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ALCTEmploymentPeriod (org.eclipse.persistence.testing.tests.unitofwork.changeflag.model.ALCTEmploymentPeriod)1