Search in sources :

Example 1 with AbstractOrderLine

use of org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine in project eclipselink by eclipse-ee4j.

the class IndirectContainerTestDatabase method testRefreshObject.

/**
 */
public void testRefreshObject() {
    AbstractOrder key = this.buildOrderShell();
    key.id = originalID;
    AbstractOrder orderFromDB = (AbstractOrder) this.getSession().readObject(key);
    assertTrue("The order lines should NOT be populated.", !((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    AbstractOrderLine orderLine = (AbstractOrderLine) orderFromDB.getLineStream().nextElement();
    assertTrue("The order lines should be populated.", ((IndirectContainer) orderFromDB.getLineContainer()).isInstantiated());
    // there were problems with TransformationMappings, so make sure they work too
    AbstractOrder expected = this.buildTestOrder1();
    assertTrue("The total should NOT be instantiated yet.", !(orderFromDB.total.isInstantiated()));
    assertEquals("The total is incorrect.", expected.getTotal(), orderFromDB.getTotal());
    assertTrue("The total should be instantiated.", orderFromDB.total.isInstantiated());
    assertEquals("The total 2 is incorrect.", expected.total2, orderFromDB.total2);
    orderLine = (AbstractOrderLine) orderLine.clone();
    orderLine.itemName = "munged";
    this.getBackdoorSession().executeNonSelectingSQL("update ORDLINE set ITEM_NAME = '" + orderLine.itemName + "' where ID = " + orderLine.id);
    orderFromDB = (AbstractOrder) this.getSession().refreshObject(orderFromDB);
    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.", expected.getTotal(), orderFromDB.getTotal());
    assertTrue("The total should be instantiated.", orderFromDB.total.isInstantiated());
    assertEquals("The total 2 is incorrect.", expected.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 2 with AbstractOrderLine

use of org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine 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 3 with AbstractOrderLine

use of org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine 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 4 with AbstractOrderLine

use of org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine in project eclipselink by eclipse-ee4j.

the class IndirectMapTestDatabase method testKeysAndValues.

public void testKeysAndValues() {
    AbstractOrder key = this.buildOrderShell();
    key.id = originalID;
    MappedOrder orderFromDB = (MappedOrder) getSession().readObject(key);
    AbstractSalesRep tempSalesRep = (AbstractSalesRep) ((MappedOrder) this.buildTestOrder1()).salesReps.values().iterator().next();
    assertEquals("Invalid sales rep key/value pair.", tempSalesRep.name, ((AbstractSalesRep) orderFromDB.salesReps.get(tempSalesRep.getKey())).name);
    AbstractOrderLine tempLine = (AbstractOrderLine) ((MappedOrder) this.buildTestOrder1()).lines.values().iterator().next();
    assertEquals("Invalid order line key/value pair.", tempLine.itemName, ((AbstractOrderLine) orderFromDB.lines.get(tempLine.getKey())).itemName);
}
Also used : AbstractSalesRep(org.eclipse.persistence.testing.models.transparentindirection.AbstractSalesRep) AbstractOrderLine(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine) MappedOrder(org.eclipse.persistence.testing.models.transparentindirection.MappedOrder) AbstractOrder(org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder)

Example 5 with AbstractOrderLine

use of org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine 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

AbstractOrder (org.eclipse.persistence.testing.models.transparentindirection.AbstractOrder)5 AbstractOrderLine (org.eclipse.persistence.testing.models.transparentindirection.AbstractOrderLine)5 IndirectContainer (org.eclipse.persistence.indirection.IndirectContainer)4 AbstractSalesRep (org.eclipse.persistence.testing.models.transparentindirection.AbstractSalesRep)1 MappedOrder (org.eclipse.persistence.testing.models.transparentindirection.MappedOrder)1