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;
}
}
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);
}
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);
}
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.");
}
}
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.");
}
}
Aggregations