Search in sources :

Example 11 with IndirectContainer

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

the class IndirectContainerTestDatabase method testUOWRemoveSalesRep.

/**
 */
public void testUOWRemoveSalesRep() {
    UnitOfWork uow = this.getSession().acquireUnitOfWork();
    AbstractOrder key = this.buildOrderShell();
    key.id = originalID;
    AbstractOrder orderFromDB = (AbstractOrder) uow.readObject(key);
    AbstractSalesRep salesRep = (AbstractSalesRep) orderFromDB.getSalesRepStream().nextElement();
    orderFromDB.removeSalesRep(salesRep);
    uow.commit();
    this.getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    orderFromDB = (AbstractOrder) this.getSession().readObject(key);
    assertTrue("The sales reps should NOT be populated.", !((IndirectContainer) orderFromDB.getSalesRepContainer()).isInstantiated());
    assertEquals("The number of sales reps is incorrect.", this.buildTestOrder1().getNumberOfSalesReps() - 1, orderFromDB.getNumberOfSalesReps());
    assertTrue("Removed sales rep still present.", !orderFromDB.containsSalesRep(salesRep));
}
Also used : AbstractSalesRep(org.eclipse.persistence.testing.models.transparentindirection.AbstractSalesRep) AbstractOrder(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 12 with IndirectContainer

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

the class IndirectContainerTestDatabase method testUOWUnchanged.

/**
 */
public void testUOWUnchanged() {
    UnitOfWork uow = this.getSession().acquireUnitOfWork();
    AbstractOrder key = this.buildOrderShell();
    key.id = originalID;
    AbstractOrder orderFromDB = (AbstractOrder) uow.readObject(key);
    assertTrue("The sales reps should NOT be populated.", !((IndirectContainer) orderFromDB.getSalesRepContainer()).isInstantiated());
    assertTrue("The order lines should NOT be populated.", !((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    assertTrue("The contacts should NOT be populated.", !((IndirectContainer) orderFromDB.getContactContainer()).isInstantiated());
    uow.commit();
    assertTrue("The sales reps should NOT be populated.", !((IndirectContainer) orderFromDB.getSalesRepContainer()).isInstantiated());
    assertEquals("The number of sales reps is incorrect.", this.buildTestOrder1().getNumberOfSalesReps(), orderFromDB.getNumberOfSalesReps());
    assertTrue("The sales reps should be populated.", ((IndirectContainer) orderFromDB.getSalesRepContainer()).isInstantiated());
    assertTrue("The contacts should NOT be populated.", !((IndirectContainer) orderFromDB.getContactContainer()).isInstantiated());
    assertEquals("The number of contacts is incorrect.", this.buildTestOrder1().getNumberOfContacts(), orderFromDB.getNumberOfContacts());
    assertTrue("The contacts should be populated.", ((IndirectContainer) orderFromDB.getContactContainer()).isInstantiated());
    assertTrue("The order lines should NOT be populated.", !((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    assertEquals("The number of order lines is incorrect.", this.buildTestOrder1().getNumberOfLines(), orderFromDB.getNumberOfLines());
    assertTrue("The order lines should be populated.", ((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    assertEquals("The number of contacts2 is incorrect.", this.buildTestOrder1().getNumberOfContacts2(), orderFromDB.getNumberOfContacts2());
    assertEquals("The number of sales reps 2 is incorrect.", this.buildTestOrder1().getNumberOfSalesReps2(), orderFromDB.getNumberOfSalesReps2());
    assertTrue("The total should NOT be instantiated yet.", !(orderFromDB.total.isInstantiated()));
    assertEquals("The total is incorrect.", this.buildTestOrder1().getTotal(), orderFromDB.getTotal());
    assertTrue("The total should be instantiated.", orderFromDB.total.isInstantiated());
    assertEquals("The total 2 is incorrect.", this.buildTestOrder1().total2, orderFromDB.total2);
}
Also used : AbstractOrder(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 13 with IndirectContainer

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

the class IndirectContainerTestDatabase method testRefreshNewObject.

/**
 */
public void testRefreshNewObject() {
    AbstractOrder originalOrder = this.buildTestOrder2();
    this.writeNewOrder(originalOrder);
    // re-read the object to get the clone if necessary
    originalOrder = (AbstractOrder) this.getSession().readObject(originalOrder);
    AbstractOrderLine orderLine = (AbstractOrderLine) ((AbstractOrderLine) originalOrder.getLineStream().nextElement()).clone();
    orderLine.itemName = "munged";
    this.getBackdoorSession().executeNonSelectingSQL("update ORDLINE set ITEM_NAME = '" + orderLine.itemName + "' where ID = " + orderLine.id);
    AbstractOrder orderFromDB = (AbstractOrder) this.getSession().refreshObject(originalOrder);
    assertTrue("The order lines should NOT be populated.", !((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    assertTrue("New order line not found.", orderFromDB.containsLine(orderLine));
    assertTrue("The order lines should be populated.", ((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    // there were problems with TransformationMappings, so make sure they work too
    assertTrue("The total should NOT be instantiated yet.", !(orderFromDB.total.isInstantiated()));
    assertEquals("The total is incorrect.", this.buildTestOrder2().getTotal(), orderFromDB.getTotal());
    assertTrue("The total should be instantiated.", orderFromDB.total.isInstantiated());
    assertEquals("The total 2 is incorrect.", this.buildTestOrder2().total2, orderFromDB.total2);
}
Also used : AbstractOrderLine(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine) AbstractOrder(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 14 with IndirectContainer

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

the class IndirectContainerTestDatabase method testUOWRemoveLine.

/**
 */
public void testUOWRemoveLine() {
    UnitOfWork uow = this.getSession().acquireUnitOfWork();
    AbstractOrder key = this.buildOrderShell();
    key.id = originalID;
    AbstractOrder orderFromDB = (AbstractOrder) uow.readObject(key);
    AbstractOrderLine orderLine = (AbstractOrderLine) orderFromDB.getLineStream().nextElement();
    orderFromDB.removeLine(orderLine);
    uow.commit();
    this.getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    orderFromDB = (AbstractOrder) this.getSession().readObject(key);
    assertTrue("The order lines should NOT be populated.", !((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    assertEquals("The number of order lines is incorrect.", this.buildTestOrder1().getNumberOfLines() - 1, orderFromDB.getNumberOfLines());
    assertTrue("Removed order line still present.", !orderFromDB.containsLine(orderLine));
}
Also used : AbstractOrderLine(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine) AbstractOrder(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

Example 15 with IndirectContainer

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

the class IndirectContainerTestDatabase method testUOWAddLine.

/**
 */
public void testUOWAddLine() {
    UnitOfWork uow = this.getSession().acquireUnitOfWork();
    AbstractOrder key = this.buildOrderShell();
    key.id = originalID;
    AbstractOrder orderFromDB = (AbstractOrder) uow.readObject(key);
    AbstractOrderLine orderLine = this.buildTestOrderLine1();
    orderFromDB.addLine(orderLine);
    uow.commit();
    this.getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    orderFromDB = (AbstractOrder) this.getSession().readObject(key);
    assertTrue("The order lines should NOT be populated.", !((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    assertEquals("The number of order lines is incorrect.", this.buildTestOrder1().getNumberOfLines() + 1, orderFromDB.getNumberOfLines());
    assertTrue("New order line not found.", orderFromDB.containsLine(orderLine));
}
Also used : AbstractOrderLine(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine) AbstractOrder(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder) IndirectContainer(org.eclipse.persistence.indirection.IndirectContainer)

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