Search in sources :

Example 6 with IndirectContainer

use of org.eclipse.persistence.indirection.IndirectContainer in project eclipselink by eclipse-ee4j.

the class ContainerIndirectionPolicy method getOriginalIndirectionObject.

/**
 * INTERNAL:
 *    Return the original indirection object for a unit of work indirection object.
 */
@Override
public Object getOriginalIndirectionObject(Object unitOfWorkIndirectionObject, AbstractSession session) {
    IndirectContainer container = (IndirectContainer) unitOfWorkIndirectionObject;
    if (container.getValueHolder() instanceof UnitOfWorkValueHolder) {
        ValueHolderInterface<?> valueHolder = ((UnitOfWorkValueHolder<?>) container.getValueHolder()).getWrappedValueHolder();
        if ((valueHolder == null) && session.isRemoteUnitOfWork()) {
            RemoteSessionController controller = ((RemoteUnitOfWork) session).getParentSessionController();
            valueHolder = controller.getRemoteValueHolders().get(((UnitOfWorkValueHolder<?>) container.getValueHolder()).getWrappedValueHolderRemoteID());
        }
        return buildContainer(valueHolder);
    } else {
        return container;
    }
}
Also used : RemoteUnitOfWork(org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork) RemoteSessionController(org.eclipse.persistence.internal.sessions.remote.RemoteSessionController) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 7 with IndirectContainer

use of org.eclipse.persistence.indirection.IndirectContainer in project eclipselink by eclipse-ee4j.

the class ContainerIndirectionPolicy method backupCloneAttribute.

/**
 * INTERNAL:
 *    Return a backup clone of the attribute.
 */
@Override
public Object backupCloneAttribute(Object attributeValue, Object clone, Object backup, UnitOfWorkImpl unitOfWork) {
    IndirectContainer container = (IndirectContainer) attributeValue;
    ValueHolderInterface valueHolder = container.getValueHolder();
    ValueHolderInterface<?> newValueHolder = (ValueHolderInterface<?>) super.backupCloneAttribute(valueHolder, clone, backup, unitOfWork);
    return buildContainer(newValueHolder);
}
Also used : ValueHolderInterface(org.eclipse.persistence.indirection.ValueHolderInterface) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 8 with IndirectContainer

use of org.eclipse.persistence.indirection.IndirectContainer in project eclipselink by eclipse-ee4j.

the class ContainerIndirectionPolicy method setRealAttributeValueInObject.

/**
 * INTERNAL:
 *    Set the value of the appropriate attribute of target to attributeValue.
 * In this case, place the value inside the target's ValueHolder.
 */
@Override
public void setRealAttributeValueInObject(Object target, Object attributeValue) {
    IndirectContainer container = (IndirectContainer) this.getMapping().getAttributeValueFromObject(target);
    container.getValueHolder().setValue(attributeValue);
    this.getMapping().setAttributeValueInObject(target, container);
}
Also used : IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 9 with IndirectContainer

use of org.eclipse.persistence.indirection.IndirectContainer 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 10 with IndirectContainer

use of org.eclipse.persistence.indirection.IndirectContainer 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)

Aggregations

IndirectContainer (org.eclipse.persistence.indirection.IndirectContainer)20 AbstractOrder (org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder)9 ValueHolderInterface (org.eclipse.persistence.indirection.ValueHolderInterface)5 AbstractOrderLine (org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)3 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)2 Server (org.eclipse.persistence.sessions.server.Server)2 FieldOffice (org.eclipse.persistence.testing.models.relationshipmaintenance.FieldOffice)2 SalesPerson (org.eclipse.persistence.testing.models.relationshipmaintenance.SalesPerson)2 AbstractSalesRep (org.eclipse.persistence.testing.models.transparentindirection.AbstractSalesRep)2 EntityManager (jakarta.persistence.EntityManager)1 Collection (java.util.Collection)1 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)1 QueryBasedValueHolder (org.eclipse.persistence.internal.indirection.QueryBasedValueHolder)1 RemoteSessionController (org.eclipse.persistence.internal.sessions.remote.RemoteSessionController)1 RemoteUnitOfWork (org.eclipse.persistence.internal.sessions.remote.RemoteUnitOfWork)1 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)1 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)1