Search in sources :

Example 1 with SalesPerson

use of org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson in project eclipselink by eclipse-ee4j.

the class TransparentIndirectionAddOverflowBehaviourTest method verify.

/*
     * Checks to see that the names of the updated version and the origional are the same
     */
@Override
public void verify() {
    FieldOffice cachedOffice2 = (FieldOffice) getSession().readObject(this.clone2);
    SalesPerson cachedTransfer = (SalesPerson) getSession().readObject(this.transfer);
    Resource cachedResource = (Resource) getSession().readObject(this.resource);
    if (cachedOffice2.getSalespeople().contains(cachedTransfer)) {
        throw new TestErrorException("Failed to replicate Set behavior for double add when tracking changes");
    }
    if (!cachedOffice2.getResources().contains(cachedResource)) {
        throw new TestErrorException("Failed to replicate List behavior for double add when tracking changes");
    }
}
Also used : FieldOffice(org.eclipse.persistence.testing.models.relationshipmaintenance.FieldOffice) SalesPerson(org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson) Resource(org.eclipse.persistence.testing.models.relationshipmaintenance.Resource) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 2 with SalesPerson

use of org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson in project eclipselink by eclipse-ee4j.

the class TransparentIndirectionAddRemoveTest method testAddRemove.

public void testAddRemove() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    FieldOffice office = (FieldOffice) uow.readObject(FieldOffice.class, new ExpressionBuilder().get("location").get("city").equal("Toronto"));
    SalesPerson person = new SalesPerson();
    person.setName("Bob");
    person.setFieldOffice(office);
    office.getSalespeople().add(person);
    uow.commit();
    if (((IndirectContainer) office.getSalespeople()).isInstantiated()) {
        throwError("Sales people indirect collection should not be instantiated on add.");
    }
    if (!office.getSalespeople().contains(person)) {
        throwError("Person not added in clone.");
    }
    office = (FieldOffice) getSession().readObject(office);
    person = (SalesPerson) getSession().readObject(person);
    if (!office.getSalespeople().contains(person)) {
        throwError("Person not added in cache.");
    }
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    uow = getSession().acquireUnitOfWork();
    office = (FieldOffice) uow.readObject(office);
    person = (SalesPerson) uow.readObject(person);
    office.getSalespeople().remove(person);
    uow.commit();
    if (((IndirectContainer) office.getSalespeople()).isInstantiated()) {
        throwError("Sales people indirect collection should not be instantiated on remove.");
    }
    if (office.getSalespeople().contains(person)) {
        throwError("Person not removed in clone.");
    }
    office = (FieldOffice) getSession().readObject(office);
    person = (SalesPerson) getSession().readObject(person);
    if (office.getSalespeople().contains(person)) {
        throwError("Person not removed in cache.");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) FieldOffice(org.eclipse.persistence.testing.models.relationshipmaintenance.FieldOffice) SalesPerson(org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 3 with SalesPerson

use of org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson in project eclipselink by eclipse-ee4j.

the class TransparentIndirectionAddRemoveTest method testSetUnset.

public void testSetUnset() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    FieldOffice office = (FieldOffice) uow.readObject(FieldOffice.class, new ExpressionBuilder().get("location").get("city").equal("Toronto"));
    SalesPerson person = new SalesPerson();
    person.setName("Bob");
    person = (SalesPerson) uow.registerObject(person);
    person.setFieldOffice(office);
    uow.commit();
    if (((IndirectContainer) office.getSalespeople()).isInstantiated()) {
        throwError("Sales people indirect collection should not be instantiated on add.");
    }
    if (!office.getSalespeople().contains(person)) {
        throwError("Person not added in clone.");
    }
    office = (FieldOffice) getSession().readObject(office);
    person = (SalesPerson) getSession().readObject(person);
    if (!office.getSalespeople().contains(person)) {
        throwError("Person not added in cache.");
    }
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    uow = getSession().acquireUnitOfWork();
    office = (FieldOffice) uow.readObject(office);
    person = (SalesPerson) uow.readObject(person);
    person.setFieldOffice(null);
    uow.commit();
    if (((IndirectContainer) office.getSalespeople()).isInstantiated()) {
        throwError("Sales people indirect collection should not be instantiated on remove.");
    }
    if (office.getSalespeople().contains(person)) {
        throwError("Person not removed in clone.");
    }
    office = (FieldOffice) getSession().readObject(office);
    person = (SalesPerson) getSession().readObject(person);
    if (office.getSalespeople().contains(person)) {
        throwError("Person not removed in cache.");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) FieldOffice(org.eclipse.persistence.testing.models.relationshipmaintenance.FieldOffice) SalesPerson(org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 4 with SalesPerson

use of org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson in project eclipselink by eclipse-ee4j.

the class TransparentIndirectionResumeAddTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    FieldOffice office = new FieldOffice();
    SalesPerson person = new SalesPerson();
    person.setName("Bob");
    person.setFieldOffice(office);
    office.getSalespeople().add(person);
    uow.registerNewObject(office);
    uow.commitAndResume();
    person = new SalesPerson();
    person.setName("Joe");
    person.setFieldOffice(office);
    office.getSalespeople().add(person);
    if (!office.getSalespeople().contains(person)) {
        throwError("Person not added in clone.");
    }
    uow.commit();
    office = (FieldOffice) getSession().readObject(office);
    person = (SalesPerson) getSession().readObject(person);
    if (!office.getSalespeople().contains(person)) {
        throwError("Person not added in cache.");
    }
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    office = (FieldOffice) getSession().readObject(office);
    person = (SalesPerson) getSession().readObject(person);
    if (!office.getSalespeople().contains(person)) {
        throwError("Person not added in cache.");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) FieldOffice(org.eclipse.persistence.testing.models.relationshipmaintenance.FieldOffice) SalesPerson(org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson)

Example 5 with SalesPerson

use of org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson in project eclipselink by eclipse-ee4j.

the class SetReferencedObjectTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Iterator iterator = uow.readAllObjects(SalesPerson.class).iterator();
    this.sales = (SalesPerson) iterator.next();
    this.secondSales = (SalesPerson) iterator.next();
    while ((this.secondSales.getFieldOffice() == this.sales.getFieldOffice()) && iterator.hasNext()) {
        this.secondSales = (SalesPerson) iterator.next();
    }
    this.fieldOfficeClone = this.sales.getFieldOffice();
    this.sales.setFieldOffice(this.secondSales.getFieldOffice());
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) SalesPerson(org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson) Iterator(java.util.Iterator)

Aggregations

SalesPerson (org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson)6 FieldOffice (org.eclipse.persistence.testing.models.relationshipmaintenance.FieldOffice)5 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)4 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)2 IndirectContainer (org.eclipse.persistence.indirection.IndirectContainer)2 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)2 Resource (org.eclipse.persistence.testing.models.relationshipmaintenance.Resource)2 Iterator (java.util.Iterator)1