Search in sources :

Example 16 with ValueStore

use of org.eclipse.persistence.sdo.ValueStore in project eclipselink by eclipse-ee4j.

the class ChangeSummaryXSDWithCSonChildUndoTestCases method testMoveSalesPO1ItemsToDifferentCS_MultiOperation_DetachSetComplexSingleWithManyChildBelowRootAndUndo.

// move above cs
// move containing cs
// move within cs
/*
    // move between different CS
    public void testTC1MoveMoveSalesPO1ItemsToDifferentCS_MultiOperation_DetachSetComplexSingleWithManyChildBelowRootAndUndo() {
        // sequence (detach from cs1, set on cs2, detach cs2, (re)set on cs1) - or do undo after the first set on cs2
        // save original root for later comparison after undo
        DataObject originalRootDO = copyHelper.copy(rootObject);
        assertTrue(equalityHelper.equal(rootObject, originalRootDO));

        DataObject salesDO = rootObject.getDataObject("sales");
        DataObject salesPO1DO = salesDO.getDataObject("purchaseOrder[1]");
        DataObject salesPO2DO = salesDO.getDataObject("purchaseOrder[2]");

        DataObject salesPO1ItemsDO = salesPO1DO.getDataObject("items");
        DataObject salesPO2ItemsDO = salesPO2DO.getDataObject("items");

        DataObject salesPO1Item1DO = salesPO1ItemsDO.getDataObject("item[1]");
        DataObject salesPO1Item2DO = salesPO1ItemsDO.getDataObject("item[2]");
        //DataObject salesPO2Item1DO = salesPO2ItemsDO.getDataObject("item[1]");
        //DataObject salesPO2Item2DO = salesPO2ItemsDO.getDataObject("item[2]");

        DataObject salesPO1Item1ProductDO = salesPO1Item1DO.getDataObject("product");
        DataObject salesPO1Item2ProductDO = salesPO1Item2DO.getDataObject("product");
        //DataObject salesPO2Item1ProductDO = salesPO2Item1DO.getDataObject("product");
        //DataObject salesPO2Item2ProductDO = salesPO2Item2DO.getDataObject("product");

        DataObject salesPO1Item1ProductPrice1DO = salesPO1Item1ProductDO.getDataObject("price[1]");
        DataObject salesPO1Item1ProductPrice2DO = salesPO1Item1ProductDO.getDataObject("price[2]");
        DataObject salesPO1Item2ProductPrice1DO = salesPO1Item2ProductDO.getDataObject("price[1]");
        DataObject salesPO1Item2ProductPrice2DO = salesPO1Item2ProductDO.getDataObject("price[2]");
        //DataObject salesPO2Item1ProductPrice1DO = salesPO2Item1ProductDO.getDataObject("price[1]");
        //DataObject salesPO2Item1ProductPrice2DO = salesPO2Item1ProductDO.getDataObject("price[2]");
        //DataObject salesPO2Item2ProductPrice1DO = salesPO2Item2ProductDO.getDataObject("price[1]");
        //DataObject salesPO2Item2ProductPrice2DO = salesPO2Item2ProductDO.getDataObject("price[2]");

        //DataObject developmentDO = rootObject.getDataObject("development");
        DataObject stock1DO = rootObject.getDataObject("stock[1]");
        DataObject stock2DO = rootObject.getDataObject("stock[2]");
        DataObject stock3DO = rootObject.getDataObject("stock[3]");

        assertNull(salesDO.getChangeSummary());
        assertNotNull(salesPO1DO.getChangeSummary());
        assertNotNull(salesPO2DO.getChangeSummary());
        assertNotNull(salesPO1ItemsDO.getChangeSummary());
        assertNotNull(salesPO2ItemsDO.getChangeSummary());

        // preoperation setup
        // remove po2.items in prep for move (outside cs)
        salesPO2ItemsDO.detach();

        salesPO1CS.beginLogging();
        salesPO2CS.beginLogging();
        stock1CS.beginLogging();
        stock2CS.beginLogging();
        stock3CS.beginLogging();
    }
    */
/*
        // detach above the CS and verify that CS is intact (Helena Yan)
        public void testDetachResetComplexSingleParentOfCSRootAndUndo() {
            // sequence (detach from above cs1 and reset)
            // save original root for later comparison after undo
            DataObject originalRootDO = copyHelper.copy(rootObject);
            assertTrue(equalityHelper.equal(rootObject, originalRootDO));

            DataObject salesDO = rootObject.getDataObject("sales");
            DataObject salesPO1DO = salesDO.getDataObject("purchaseOrder[1]");
            DataObject salesPO2DO = salesDO.getDataObject("purchaseOrder[2]");

            DataObject salesPO1ItemsDO = salesPO1DO.getDataObject("items");
            DataObject salesPO2ItemsDO = salesPO2DO.getDataObject("items");

            DataObject salesPO1Item1DO = salesPO1ItemsDO.getDataObject("item[1]");
            DataObject salesPO1Item2DO = salesPO1ItemsDO.getDataObject("item[2]");
            //DataObject salesPO2Item1DO = salesPO2ItemsDO.getDataObject("item[1]");
            //DataObject salesPO2Item2DO = salesPO2ItemsDO.getDataObject("item[2]");

            DataObject salesPO1Item1ProductDO = salesPO1Item1DO.getDataObject("product");
            DataObject salesPO1Item2ProductDO = salesPO1Item2DO.getDataObject("product");
            //DataObject salesPO2Item1ProductDO = salesPO2Item1DO.getDataObject("product");
            //DataObject salesPO2Item2ProductDO = salesPO2Item2DO.getDataObject("product");

            DataObject salesPO1Item1ProductPrice1DO = salesPO1Item1ProductDO.getDataObject("price[1]");
            DataObject salesPO1Item1ProductPrice2DO = salesPO1Item1ProductDO.getDataObject("price[2]");
            DataObject salesPO1Item2ProductPrice1DO = salesPO1Item2ProductDO.getDataObject("price[1]");
            DataObject salesPO1Item2ProductPrice2DO = salesPO1Item2ProductDO.getDataObject("price[2]");
            //DataObject salesPO2Item1ProductPrice1DO = salesPO2Item1ProductDO.getDataObject("price[1]");
            //DataObject salesPO2Item1ProductPrice2DO = salesPO2Item1ProductDO.getDataObject("price[2]");
            //DataObject salesPO2Item2ProductPrice1DO = salesPO2Item2ProductDO.getDataObject("price[1]");
            //DataObject salesPO2Item2ProductPrice2DO = salesPO2Item2ProductDO.getDataObject("price[2]");

            //DataObject developmentDO = rootObject.getDataObject("development");
            DataObject stock1DO = rootObject.getDataObject("stock[1]");
            DataObject stock2DO = rootObject.getDataObject("stock[2]");
            DataObject stock3DO = rootObject.getDataObject("stock[3]");

            assertNull(salesDO.getChangeSummary());
            assertNotNull(salesPO1DO.getChangeSummary());
            assertNotNull(salesPO2DO.getChangeSummary());
            assertNotNull(salesPO1ItemsDO.getChangeSummary());
            assertNotNull(salesPO2ItemsDO.getChangeSummary());

            // preoperation setup
            // remove po2.items in prep for move (outside cs)
            salesPO2ItemsDO.detach();

            salesPO1CS.beginLogging();
            salesPO2CS.beginLogging();
            stock1CS.beginLogging();
            stock2CS.beginLogging();
            stock3CS.beginLogging();

            // verify original VS is null and save a copy of current VS for object identity testing after undo
            assertValueStoresInitializedAfterLoggingOn(salesPO1DO);
            assertValueStoresInitializedAfterLoggingOn(salesPO2DO);
            assertValueStoresInitializedAfterLoggingOn(stock1DO);
            assertValueStoresInitializedAfterLoggingOn(stock2DO);
            assertValueStoresInitializedAfterLoggingOn(stock3DO);
            // save a copy of current VS for object identity testing after undo
            ValueStore aCurrentValueStoreAfterLoggingFirstOn = ((SDODataObject)salesPO1DO).getCurrentValueStore();

            // 2 operations
            salesPO1DO.unset("items");
            salesPO2DO.set("items", salesPO1ItemsDO);
            // or 1 operation
            //salesPO2DO.set("items", salesPO1ItemsDO);
            boolean wasDeleted = false;

            // verify CS is null on removed trees
            assertChangeSummaryStatusIfClearedIfCSIsAncestor(salesPO1ItemsDO, true);

            // check valueStores
            assertValueStoresCopiedAndSwappedAfterFirstModifyOperation(salesPO1DO, aCurrentValueStoreAfterLoggingFirstOn);

            assertNotNull(salesPO1Item1DO);
            assertNotNull(salesPO1Item2DO);

            assertModified(salesPO1DO, salesPO1CS);
            assertDetached(salesPO1ItemsDO, salesPO1CS); // 20070206 CS is not being deleted
            assertDetached(salesPO1Item1DO, salesPO1CS, wasDeleted);
            assertDetached(salesPO1Item2DO, salesPO1CS, wasDeleted);
            assertDetached(salesPO1Item1ProductDO, salesPO1CS, wasDeleted);
            assertDetached(salesPO1Item1ProductPrice1DO, salesPO1CS, wasDeleted);
            assertDetached(salesPO1Item1ProductPrice2DO, salesPO1CS, wasDeleted);
            assertDetached(salesPO1Item2ProductDO, salesPO1CS, wasDeleted);
            assertDetached(salesPO1Item2ProductPrice1DO, salesPO1CS, wasDeleted);
            assertDetached(salesPO1Item2ProductPrice2DO, salesPO1CS, wasDeleted);
            assertEquals(10, salesPO1CS.getChangedDataObjects().size());
            assertEquals(15, ((SDOChangeSummary)salesPO1CS).getOldContainer().size());//  from 14 (sales has 2 PO's not 1)
            assertEquals(15, ((SDOChangeSummary)salesPO1CS).getOldContainmentProperty().size());

            // set the items back  (in effect doing an undo)
            salesPO1DO.set("items", salesPO2ItemsDO);

            assertUndoChangesEqualToOriginal(salesPO1CS, rootObject, originalRootDO);

            // verify that property is reset
            assertTrue(salesPO2DO.isSet("items"));
            // get back items object
            DataObject itemsDOundone = salesPO1DO.getDataObject("items");
            // compare with original
            assertTrue(equalityHelper.equal(itemsDOundone, salesPO1ItemsDO));

            assertValueStoresReturnedToStartStateAfterUndoChanges(salesPO1DO, aCurrentValueStoreAfterLoggingFirstOn);
        }
    */
// move between different CS
public void testMoveSalesPO1ItemsToDifferentCS_MultiOperation_DetachSetComplexSingleWithManyChildBelowRootAndUndo() {
    // sequence (detach from cs1, set on cs2, detach cs2, (re)set on cs1) - or do undo after the first set on cs2
    // save original root for later comparison after undo
    DataObject originalRootDO = copyHelper.copy(rootObject);
    assertTrue(equalityHelper.equal(rootObject, originalRootDO));
    DataObject salesDO = rootObject.getDataObject("sales");
    DataObject salesPO1DO = salesDO.getDataObject("purchaseOrder[1]");
    DataObject salesPO2DO = salesDO.getDataObject("purchaseOrder[2]");
    DataObject salesPO1ItemsDO = salesPO1DO.getDataObject("items");
    DataObject salesPO2ItemsDO = salesPO2DO.getDataObject("items");
    DataObject salesPO1Item1DO = salesPO1ItemsDO.getDataObject("item[1]");
    DataObject salesPO1Item2DO = salesPO1ItemsDO.getDataObject("item[2]");
    DataObject salesPO2Item1DO = salesPO2ItemsDO.getDataObject("item[1]");
    DataObject salesPO2Item2DO = salesPO2ItemsDO.getDataObject("item[2]");
    DataObject salesPO1Item1ProductDO = salesPO1Item1DO.getDataObject("product");
    DataObject salesPO1Item2ProductDO = salesPO1Item2DO.getDataObject("product");
    DataObject salesPO2Item1ProductDO = salesPO2Item1DO.getDataObject("product");
    DataObject salesPO2Item2ProductDO = salesPO2Item2DO.getDataObject("product");
    DataObject salesPO1Item1ProductPrice1DO = salesPO1Item1ProductDO.getDataObject("price[1]");
    DataObject salesPO1Item1ProductPrice2DO = salesPO1Item1ProductDO.getDataObject("price[2]");
    DataObject salesPO1Item2ProductPrice1DO = salesPO1Item2ProductDO.getDataObject("price[1]");
    DataObject salesPO1Item2ProductPrice2DO = salesPO1Item2ProductDO.getDataObject("price[2]");
    DataObject salesPO2Item1ProductPrice1DO = salesPO2Item1ProductDO.getDataObject("price[1]");
    DataObject salesPO2Item1ProductPrice2DO = salesPO2Item1ProductDO.getDataObject("price[2]");
    DataObject salesPO2Item2ProductPrice1DO = salesPO2Item2ProductDO.getDataObject("price[1]");
    DataObject salesPO2Item2ProductPrice2DO = salesPO2Item2ProductDO.getDataObject("price[2]");
    // DataObject developmentDO = rootObject.getDataObject("development");
    DataObject stock1DO = rootObject.getDataObject("stock[1]");
    DataObject stock2DO = rootObject.getDataObject("stock[2]");
    DataObject stock3DO = rootObject.getDataObject("stock[3]");
    assertNull(salesDO.getChangeSummary());
    assertNotNull(salesPO1DO.getChangeSummary());
    assertNotNull(salesPO2DO.getChangeSummary());
    assertNotNull(salesPO1ItemsDO.getChangeSummary());
    assertNotNull(salesPO2ItemsDO.getChangeSummary());
    List<DataObject> preOrderList = preOrderTraversalDataObjectList((SDODataObject) rootObject, false);
    assertEquals(62, preOrderList.size());
    // preoperation setup
    // remove po2.items in prep for move (outside cs)
    salesPO2ItemsDO.detach();
    preOrderList = preOrderTraversalDataObjectList((SDODataObject) rootObject, false);
    // 9 nodes removed
    assertEquals(53, preOrderList.size());
    salesPO1CS.beginLogging();
    salesPO2CS.beginLogging();
    stock1CS.beginLogging();
    stock2CS.beginLogging();
    stock3CS.beginLogging();
    // verify original VS is null and save a copy of current VS for object identity testing after undo
    assertValueStoresInitializedAfterLoggingOn(salesPO1DO);
    assertValueStoresInitializedAfterLoggingOn(salesPO2DO);
    assertValueStoresInitializedAfterLoggingOn(stock1DO);
    assertValueStoresInitializedAfterLoggingOn(stock2DO);
    assertValueStoresInitializedAfterLoggingOn(stock3DO);
    // save a copy of current VS for object identity testing after undo
    ValueStore aCurrentValueStoreAfterLoggingFirstOn = ((SDODataObject) salesPO1DO)._getCurrentValueStore();
    // 2 operations
    salesPO1DO.unset("items");
    // salesPO2DO.set("items", salesPO1ItemsDO);
    // or 1 operation
    // salesPO2DO.set("items", salesPO1ItemsDO);
    boolean wasDeleted = false;
    // verify CS is not null on removed sub trees
    // false);
    assertChangeSummaryStatusIfClearedIfCSIsAncestor(salesPO1ItemsDO, true);
    // check valueStores
    assertValueStoresCopiedAndSwappedAfterFirstModifyOperation(salesPO1DO, aCurrentValueStoreAfterLoggingFirstOn);
    assertNotNull(salesPO1Item1DO);
    assertNotNull(salesPO1Item2DO);
    // we have oldSettings on the original container
    assertModified(salesPO1DO, salesPO1CS);
    assertDetached(salesPO1ItemsDO, salesPO1CS);
    assertDetached(salesPO1Item1DO, salesPO1CS, wasDeleted);
    assertDetached(salesPO1Item2DO, salesPO1CS, wasDeleted);
    assertDetached(salesPO1Item1ProductDO, salesPO1CS, wasDeleted);
    assertDetached(salesPO1Item1ProductPrice1DO, salesPO1CS, wasDeleted);
    assertDetached(salesPO1Item1ProductPrice2DO, salesPO1CS, wasDeleted);
    assertDetached(salesPO1Item2ProductDO, salesPO1CS, wasDeleted);
    assertDetached(salesPO1Item2ProductPrice1DO, salesPO1CS, wasDeleted);
    assertDetached(salesPO1Item2ProductPrice2DO, salesPO1CS, wasDeleted);
    assertEquals(10, salesPO1CS.getChangedDataObjects().size());
    // from 14 (sales has 2 PO's not 1)
    assertEquals(16, ((SDOChangeSummary) salesPO1CS).getOldContainer().size());
    assertEquals(16, ((SDOChangeSummary) salesPO1CS).getOldContainmentProperty().size());
    // writeXML(rootObject, URINAME, TYPENAME, System.out);
    // move the items to the other cs
    salesPO2DO.set("items", salesPO1ItemsDO);
    // assertUndoChangesEqualToOriginal(salesPO1CS, rootObject, originalRootDO);
    // we have oldSettings (null ones) on the new container
    assertModified(salesPO2DO, salesPO2CS);
    assertCreated(salesPO1ItemsDO, salesPO2CS);
    assertUnchanged(salesPO1Item1DO, salesPO2CS);
    assertUnchanged(salesPO1Item2DO, salesPO2CS);
    assertUnchanged(salesPO1Item1ProductDO, salesPO2CS);
    assertUnchanged(salesPO1Item1ProductPrice1DO, salesPO2CS);
    assertUnchanged(salesPO1Item1ProductPrice2DO, salesPO2CS);
    assertUnchanged(salesPO1Item2ProductDO, salesPO2CS);
    assertUnchanged(salesPO1Item2ProductPrice1DO, salesPO2CS);
    assertUnchanged(salesPO1Item2ProductPrice2DO, salesPO2CS);
    assertEquals(2, salesPO2CS.getChangedDataObjects().size());
    // from 14 (sales has 2 PO's not 1)
    assertEquals(6, ((SDOChangeSummary) salesPO2CS).getOldContainer().size());
    assertEquals(6, ((SDOChangeSummary) salesPO2CS).getOldContainmentProperty().size());
    // verify that property is set on new container
    assertTrue(salesPO2DO.isSet("items"));
    // get back items object
    DataObject itemsDOundone = salesPO2DO.getDataObject("items");
    // compare with original
    // assertTrue(equalityHelper.equal(itemsDOundone, salesPO2ItemsDO));
    assertFalse(equalityHelper.equal(itemsDOundone, salesPO2ItemsDO));
// assertValueStoresReturnedToStartStateAfterUndoChanges(salesPO1DO, aCurrentValueStoreAfterLoggingFirstOn);
// writeXML(rootObject, URINAME, TYPENAME, System.out);
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) ValueStore(org.eclipse.persistence.sdo.ValueStore) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 17 with ValueStore

use of org.eclipse.persistence.sdo.ValueStore in project eclipselink by eclipse-ee4j.

the class ChangeSummaryXSDTestCases method testDeleteItemsAndUndo.

public void testDeleteItemsAndUndo() {
    // save original root for later comparison after undo
    DataObject originalRootDO = copyHelper.copy(rootObject);
    assertTrue(equalityHelper.equal(rootObject, originalRootDO));
    DataObject itemsDO = rootObject.getDataObject("items");
    DataObject item1DO = rootObject.getDataObject("items/item[1]");
    DataObject item2DO = rootObject.getDataObject("items/item[2]");
    DataObject item1ProductDO = item1DO.getDataObject("product");
    DataObject item1ProductPrice1DO = item1ProductDO.getDataObject("price[1]");
    DataObject item1ProductPrice2DO = item1ProductDO.getDataObject("price[2]");
    DataObject item2ProductDO = item2DO.getDataObject("product");
    DataObject item2ProductPrice1DO = item2ProductDO.getDataObject("price[1]");
    DataObject item2ProductPrice2DO = item2ProductDO.getDataObject("price[2]");
    cs.beginLogging();
    // verify original VS is null and save a copy of current VS for object identity testing after undo
    ValueStore aCurrentValueStore = ((SDODataObject) rootObject)._getCurrentValueStore();
    assertNotNull(aCurrentValueStore);
    ValueStore anOriginalValueStore = (ValueStore) ((SDOChangeSummary) cs).getOriginalValueStores().get(rootObject);
    assertNull(anOriginalValueStore);
    itemsDO.delete();
    // check valueStores
    assertNotNull(aCurrentValueStore);
    ValueStore anOriginalValueStoreAfterOperation = (ValueStore) ((SDOChangeSummary) cs).getOriginalValueStores().get(rootObject);
    ValueStore aCurrentValueStoreAfterOperation = ((SDODataObject) rootObject)._getCurrentValueStore();
    assertNotNull(anOriginalValueStoreAfterOperation);
    assertNotNull(aCurrentValueStoreAfterOperation);
    assertTrue(anOriginalValueStoreAfterOperation == aCurrentValueStore);
    assertNotNull(item1DO);
    assertNotNull(item2DO);
    assertModified(rootObject, cs);
    assertDeleted(itemsDO, cs);
    assertDeleted(item1DO, cs);
    assertDeleted(item2DO, cs);
    assertDeleted(item1ProductDO, cs);
    assertDeleted(item1ProductPrice1DO, cs);
    assertDeleted(item1ProductPrice2DO, cs);
    assertDeleted(item2ProductDO, cs);
    assertDeleted(item2ProductPrice1DO, cs);
    assertDeleted(item2ProductPrice2DO, cs);
    assertEquals(10, cs.getChangedDataObjects().size());
    // from 9
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
    // from 9
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
    assertUndoChangesEqualToOriginal(cs, rootObject, originalRootDO);
    // verify that property is reset
    assertTrue(rootObject.isSet("items"));
    // get back items object
    DataObject itemsDOundone = rootObject.getDataObject("items");
    ValueStore anOriginalValueStoreAfterUndo = (ValueStore) ((SDOChangeSummary) cs).getOriginalValueStores().get(rootObject);
    ValueStore aCurrentValueStoreAfterUndo = ((SDODataObject) rootObject)._getCurrentValueStore();
    assertNull(anOriginalValueStoreAfterUndo);
    assertNotNull(aCurrentValueStoreAfterUndo);
    // we return the original value store back to the current VS
    assertTrue(aCurrentValueStoreAfterUndo == aCurrentValueStore);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ValueStore(org.eclipse.persistence.sdo.ValueStore) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 18 with ValueStore

use of org.eclipse.persistence.sdo.ValueStore in project eclipselink by eclipse-ee4j.

the class ChangeSummaryXSDWithCSonRootUndoTestCases method testDeleteItemsResetAndUndo_SingleOperation_DeleteComplexSingleWithManyChildBelowRootResetAndUndo.

public void testDeleteItemsResetAndUndo_SingleOperation_DeleteComplexSingleWithManyChildBelowRootResetAndUndo() {
    // save original root for later comparison after undo
    DataObject originalRootDO = copyHelper.copy(rootObject);
    assertTrue(equalityHelper.equal(rootObject, originalRootDO));
    DataObject itemsDO = rootObject.getDataObject("items");
    DataObject item1DO = rootObject.getDataObject("items/item[1]");
    DataObject item2DO = rootObject.getDataObject("items/item[2]");
    DataObject item1ProductDO = item1DO.getDataObject("product");
    DataObject item1ProductPrice1DO = item1ProductDO.getDataObject("price[1]");
    DataObject item1ProductPrice2DO = item1ProductDO.getDataObject("price[2]");
    DataObject item2ProductDO = item2DO.getDataObject("product");
    DataObject item2ProductPrice1DO = item2ProductDO.getDataObject("price[1]");
    DataObject item2ProductPrice2DO = item2ProductDO.getDataObject("price[2]");
    cs.beginLogging();
    // verify original VS is null and save a copy of current VS for object identity testing after undo
    assertValueStoresInitializedAfterLoggingOn(rootObject);
    // save a copy of current VS for object identity testing after undo
    ValueStore aCurrentValueStoreAfterLoggingFirstOn = ((SDODataObject) rootObject)._getCurrentValueStore();
    assertNotNull(itemsDO.getChangeSummary());
    itemsDO.delete();
    boolean wasDeleted = true;
    // verify CS is null on removed trees
    assertChangeSummaryStatusIfClearedIfCSIsAncestor(itemsDO, true);
    // check valueStores
    assertValueStoresCopiedAndSwappedAfterFirstModifyOperation(rootObject, aCurrentValueStoreAfterLoggingFirstOn);
    assertNotNull(item1DO);
    assertNotNull(item2DO);
    assertModified(rootObject, cs);
    assertDeleted(itemsDO, cs, wasDeleted);
    assertDeleted(item1DO, cs, wasDeleted);
    assertDeleted(item2DO, cs, wasDeleted);
    assertDeleted(item1ProductDO, cs, wasDeleted);
    assertDeleted(item1ProductPrice1DO, cs, wasDeleted);
    assertDeleted(item1ProductPrice2DO, cs, wasDeleted);
    assertDeleted(item2ProductDO, cs, wasDeleted);
    assertDeleted(item2ProductPrice1DO, cs, wasDeleted);
    assertDeleted(item2ProductPrice2DO, cs, wasDeleted);
    assertEquals(10, cs.getChangedDataObjects().size());
    // from 9
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
    // from 9
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
    assertUndoChangesEqualToOriginal(cs, rootObject, originalRootDO);
    // verify that property is reset
    assertTrue(rootObject.isSet("items"));
    // get back items object
    DataObject itemsDOundone = rootObject.getDataObject("items");
    // compare with original
    assertTrue(equalityHelper.equal(itemsDOundone, itemsDO));
    assertValueStoresReturnedToStartStateAfterUndoChanges(rootObject, aCurrentValueStoreAfterLoggingFirstOn);
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) ValueStore(org.eclipse.persistence.sdo.ValueStore) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 19 with ValueStore

use of org.eclipse.persistence.sdo.ValueStore in project eclipselink by eclipse-ee4j.

the class SDOCopyHelper method copyChangeSummary.

/**
 * INTERNAL:
 * Implement ChangeSummary deep copy
 *      Note: a copy with a CS requires the DefautlValueStore implementation
 *      because of changes outside the ValueStore interface for the dataObject field
 * DeepCopy the original changeSummary into the copy dataObject.
 * All deleted keys in originalValueStore, deletedMap, deepCopies are the same original object.
 * We require the following relationships in order to build copies of originals and copies of copies of originals.
 *     origDOtoCopyDOMap
 *         original object (deleted + current) - in original DO : copy of original object - in copy DO
 *     copyDOtoCopyOfDOMap
 *
 *     Assumptions:
 *        Property objects instances are copied only by reference - metadata is the same in the copy.
 *        Deleted objects never exist in the currentValueStore (and are therefore not in the doMap).
 *        Created and modified objects are always in the currentValueStore (and are in the doMap).
 *
 * @param anOriginalCS
 * @param aCopyCS
 * @param origDOCS1toCopyDOCS2Map (map of original do's (CS1) to their copy do's in (CS2))
 */
private // 
void copyChangeSummary(// 
ChangeSummary anOriginalCS, // 
ChangeSummary aCopyCS, Map origDOCS1toCopyDOCS2Map) {
    // cast interfaces to concrete classes in one place
    SDOChangeSummary originalCS = (SDOChangeSummary) anOriginalCS;
    SDOChangeSummary copyCS = (SDOChangeSummary) aCopyCS;
    // handled by copy constructor
    // map of copy of original ListWrapper (CS2) to its new copy of a copy (CS2) - link ValueStores to Elements
    HashMap copyListWrapperCS2toCopyOfListCS2Map = new HashMap();
    // in the absence of a ListWrapper.getProperty() we keep a map
    HashMap propertyToOriginalListMap = new HashMap();
    /**
     * In 3 parts we add deleted objects to the global doMap and copy modified, created nodes
     */
    // fields that need re-referencing from original to copy
    DataObject anOriginalObject = null;
    DataObject aCopyOfOriginalObject = null;
    // iterate deleted objects
    for (Iterator anIterator = originalCS.getDeleted().iterator(); anIterator.hasNext(); ) {
        anOriginalObject = (DataObject) anIterator.next();
        aCopyOfOriginalObject = copy(anOriginalObject, null);
        // fix deletedList
        copyCS.getDeleted().add(aCopyOfOriginalObject);
        // Assumption check do map before a possible re-add - reset()
        if (null == origDOCS1toCopyDOCS2Map.get(anOriginalObject)) {
            // add temp map of original  : copy of original
            origDOCS1toCopyDOCS2Map.put(anOriginalObject, aCopyOfOriginalObject);
        }
    }
    // iterate created objects
    for (Iterator aIterator = originalCS.getCreated().iterator(); aIterator.hasNext(); ) {
        copyCS.getCreated().add(origDOCS1toCopyDOCS2Map.get(aIterator.next()));
    }
    // add modified objects
    for (Iterator anIterator = originalCS.getModified().iterator(); anIterator.hasNext(); ) {
        copyCS.getModified().add(origDOCS1toCopyDOCS2Map.get(anIterator.next()));
    }
    /**
     * Fix originalValueStores by deep copying the original dataObject:key and the original valueStore:value
     * key is original deleted object in [deepCopies] - value is copy of the ValueStore
     */
    ValueStore aVSCopy = null;
    ValueStore aVSOriginal = null;
    for (Iterator anIterator = originalCS.getOriginalValueStores().keySet().iterator(); anIterator.hasNext(); ) {
        anOriginalObject = (DataObject) anIterator.next();
        // deep copy to get corresponding copy DataObject (deleted objects were added to doMap)
        aCopyOfOriginalObject = (DataObject) origDOCS1toCopyDOCS2Map.get(anOriginalObject);
        /**
         * Recursively shallow-copy elements (by iterating the ovs map and iterating the properties of each item)
         * Fix the dataObject pointer
         */
        aVSCopy = createValueStore();
        aVSOriginal = (ValueStore) originalCS.getOriginalValueStores().get(anOriginalObject);
        // changes made to the copy VS must not affect the original -hence the dataObject field must be a copy of the original
        aVSCopy.initialize(aCopyOfOriginalObject);
        Object aVSPropertyItem = null;
        // get the # of non-opencontent properties for the object holding the CS - do not use DVS.getTypePropertyValues()
        for (int size = anOriginalObject.getType().getDeclaredProperties().size(), i = 0; i < size; i++) {
            aVSPropertyItem = aVSOriginal.getDeclaredProperty(i);
            // only iterate set properties
            if (aVSOriginal.isSetDeclaredProperty(i)) {
                // shallow copy the object values
                // handle single case
                SDOProperty currentProperty = (SDOProperty) anOriginalObject.getType().getDeclaredProperties().get(i);
                if (currentProperty.isMany()) {
                    propertyToOriginalListMap.put(aVSPropertyItem, currentProperty);
                    // handle many case - handled by originalElements
                    // container DO must be in our reference map
                    SDODataObject copyContainer = (SDODataObject) origDOCS1toCopyDOCS2Map.get(anOriginalObject);
                    ListWrapper aCopyOfListCopy = (ListWrapper) ((DataObject) copyContainer).getList(currentProperty);
                    // add reference of new copy of original List keyed on original List
                    copyListWrapperCS2toCopyOfListCS2Map.put((anOriginalObject).getList(currentProperty), aCopyOfListCopy);
                    aVSCopy.setDeclaredProperty(i, aCopyOfListCopy);
                } else {
                    // COMPLEX SINGLE
                    if (!currentProperty.getType().isDataType()) {
                        // are we using the cast to DataObject as a sort of instance check that would throw a CCE?
                        aVSCopy.setDeclaredProperty(i, origDOCS1toCopyDOCS2Map.get(aVSPropertyItem));
                    } else {
                        // skip changeSummary property
                        if (!currentProperty.getType().isChangeSummaryType()) {
                            // simple singles set
                            aVSCopy.setDeclaredProperty(i, aVSPropertyItem);
                        }
                    }
                }
            }
        }
        // create list of unset and current open content properties
        List ocPropertiesList = new ArrayList();
        ocPropertiesList.addAll(originalCS.getUnsetOCProperties(anOriginalObject));
        // add existing properties
        ocPropertiesList.addAll(((SDODataObject) anOriginalObject)._getOpenContentProperties());
        ocPropertiesList.addAll(((SDODataObject) anOriginalObject)._getOpenContentPropertiesAttributes());
        // iterate existing open content properties
        for (Iterator i = ocPropertiesList.iterator(); i.hasNext(); ) {
            SDOProperty ocProperty = (SDOProperty) i.next();
            if (aVSOriginal.isSetOpenContentProperty(ocProperty)) {
                // get oc value
                Object anOCPropertyItem = aVSOriginal.getOpenContentProperty(ocProperty);
                // get oc copy - shallow copy the object values
                if (ocProperty.isMany()) {
                    // handle many case - handled by originalElements
                    // container DO must be in our reference map
                    SDODataObject copyContainer = (SDODataObject) origDOCS1toCopyDOCS2Map.get(anOriginalObject);
                    ListWrapper aCopyOfListCopy = (ListWrapper) ((DataObject) copyContainer).getList(ocProperty);
                    // add reference of new copy of original List keyed on original List
                    copyListWrapperCS2toCopyOfListCS2Map.put((anOriginalObject).getList(ocProperty), aCopyOfListCopy);
                    aVSCopy.setOpenContentProperty(ocProperty, aCopyOfListCopy);
                } else {
                    // handle complex single case
                    if (!ocProperty.getType().isDataType()) {
                        aVSCopy.setOpenContentProperty(ocProperty, origDOCS1toCopyDOCS2Map.get(aVSPropertyItem));
                    } else {
                        // simple singles set
                        aVSCopy.setOpenContentProperty(ocProperty, anOCPropertyItem);
                    }
                }
            }
        }
        // set the copy map entry keyed on copy with value a deep copy of the copy
        copyCS.getOriginalValueStores().put(aCopyOfOriginalObject, aVSCopy);
    }
    // end originalValueStore iteration
    /**
     * Fix originalElements by deep copying the original dataObject:key and the original List:value
     * key is original deleted object in [deepCopies] - value is copy of the elements
     * The instances of ListWrapper inside the valueStores must be the same ones used in the originalElements
     */
    ListWrapper anOriginalListKey = null;
    ListWrapper aCopyListWrapper = null;
    List aCopyList = null;
    for (Iterator anIterator = originalCS.getOriginalElements().keySet().iterator(); anIterator.hasNext(); ) {
        anOriginalListKey = (ListWrapper) anIterator.next();
        // create a new ListWrapper
        SDOProperty aProperty = (SDOProperty) propertyToOriginalListMap.get(anOriginalListKey);
        aCopyListWrapper = (ListWrapper) copyListWrapperCS2toCopyOfListCS2Map.get(anOriginalListKey);
        aCopyList = new ArrayList();
        /**
         * For each key:ListWrapper
         *     - shallow copy all the items in the currentElements list
         *     - replace the dataObject with its copy of the copy
         *     - leave the property as is
         * For each value:ArrayList
         *     - replace all values with their copy
         */
        Object aListItem = null;
        Object aListItemCopy = null;
        for (Iterator anItemIterator = anOriginalListKey.iterator(); anItemIterator.hasNext(); ) {
            aListItem = anItemIterator.next();
            // for simple many types we use the original in the copy
            if (!aProperty.getType().isDataType()) {
                // get the copy of the original (in the current valuestore) - we need do not make a copy of this copy
                // we should have a copy of the copy for List items - ListWrapper.add(item) will remove the item from its original wrapper
                aListItemCopy = origDOCS1toCopyDOCS2Map.get(aListItem);
            } else {
                aListItemCopy = aListItem;
            }
            aCopyList.add(aListItemCopy);
        }
        // add element list directly to the ListWrapper and bypass the cs element copy and containment updates
        aCopyListWrapper.setCurrentElements(aCopyList);
        List listValueCopy = new ArrayList();
        // fix ArrayList value
        List listValue = (List) originalCS.getOriginalElements().get(anOriginalListKey);
        aListItem = null;
        aListItemCopy = null;
        for (Iterator aListIterator = listValue.iterator(); aListIterator.hasNext(); ) {
            aListItem = aListIterator.next();
            // for simple many types we use the original in the copy
            if (!aProperty.getType().isDataType()) {
                aListItemCopy = origDOCS1toCopyDOCS2Map.get(aListItem);
            } else {
                aListItemCopy = aListItem;
            }
            // don't add nulls to the listWrapper so an undoChanges will encounter an NPE later
            if (aListItemCopy != null) {
                listValueCopy.add(aListItemCopy);
            }
        }
        // set the copy map entry keyed on copy with value a deep copy of the copy
        copyCS.getOriginalElements().put(aCopyListWrapper, listValueCopy);
    }
    // end originalist Iteration
    /**
     * fields that are already set when logging is turned on but need to be fixed (deleted objects need references)
     */
    Map oldContainersMap = originalCS.getOldContainers();
    Map copyContainersMap = copyCS.getOldContainers();
    DataObject oldContainerKey = null;
    DataObject copyContainerKey = null;
    // convert any existing entries in the Map - should normally be 0 - unless any OC properties were unset
    for (Iterator anIterator = oldContainersMap.keySet().iterator(); anIterator.hasNext(); ) {
        oldContainerKey = (DataObject) anIterator.next();
        // get corresponding copy
        copyContainerKey = (SDODataObject) origDOCS1toCopyDOCS2Map.get(oldContainerKey);
        // check existing copyContainers for existing objects - should be 0 - add all objects when pauseLogging() used
        DataObject oldContainerValue = null;
        if (null == copyContainersMap.get(copyContainerKey)) {
            oldContainerValue = (DataObject) oldContainersMap.get(oldContainerKey);
            // set copy key:value pair on copy map directly
            copyContainersMap.put(copyContainerKey, origDOCS1toCopyDOCS2Map.get(oldContainerValue));
        }
    }
    Map oldContainmentPropertyMap = originalCS.getOldContainmentProperty();
    Map copyContainmentPropertyMap = copyCS.getOldContainmentProperty();
    DataObject oldContainmentPropertyKey = null;
    DataObject copyContainmentPropertyKey = null;
    // convert any existing entries in the Map - should normally be 0 - unless any OC properties were unset
    for (Iterator iterContProp = oldContainmentPropertyMap.keySet().iterator(); iterContProp.hasNext(); ) {
        oldContainmentPropertyKey = (DataObject) iterContProp.next();
        // get corresponding copy
        copyContainmentPropertyKey = (SDODataObject) origDOCS1toCopyDOCS2Map.get(oldContainmentPropertyKey);
        // check existing copyContainers for existing objects - should be 0 - add all objects when pauseLogging() used
        if (null == copyContainmentPropertyMap.get(copyContainmentPropertyKey)) {
            // set copy key:value pair on copy map directly
            copyContainmentPropertyMap.put(copyContainmentPropertyKey, oldContainmentPropertyMap.get(oldContainmentPropertyKey));
        }
    }
    Map oldUnsetOCPropertyMap = originalCS.getUnsetOCPropertiesMap();
    SDODataObject oldOCPropertyContainer = null;
    // convert any existing entries in the Map - should normally be 0
    for (Iterator iterContainer = oldUnsetOCPropertyMap.keySet().iterator(); iterContainer.hasNext(); ) {
        // DataObject will be non-Null
        oldOCPropertyContainer = (SDODataObject) iterContainer.next();
        // check existing copyContainers for existing objects - should be 0 - add all objects when pauseLogging() used
        for (Iterator iterUnset = ((List) oldUnsetOCPropertyMap.get(oldOCPropertyContainer)).iterator(); iterUnset.hasNext(); ) {
            // set/create new list on copy Map with corresponding copy of container
            copyCS.setUnsetOCProperty((SDODataObject) // 
            origDOCS1toCopyDOCS2Map.get(oldOCPropertyContainer), (Property) iterUnset.next());
        }
    }
    // iterate the map of <DataObject, Sequence>
    for (Iterator aMapIterator = originalCS.getOriginalSequences().keySet().iterator(); aMapIterator.hasNext(); ) {
        SDODataObject sequenceDataObjectKey = (SDODataObject) aMapIterator.next();
        SDOSequence originalSequence = (SDOSequence) originalCS.getOriginalSequences().get(sequenceDataObjectKey);
        // create a new Sequence with a pointer to the copy of the original DataObject backpointer
        // assume that all dataObject backpointers are containment objects.
        SDODataObject copyOriginalSequenceDataObject = (SDODataObject) origDOCS1toCopyDOCS2Map.get(originalSequence.getDataObject());
        SDOSequence copySequence = new SDOSequence(copyOriginalSequenceDataObject);
        replicateAndRereferenceSequenceCopyPrivate(originalSequence, copySequence, originalSequence.getDataObject(), copyOriginalSequenceDataObject, origDOCS1toCopyDOCS2Map, originalCS);
        // set the copy map entry keyed on copy with value a deep copy of the copy
        copyCS.getOriginalSequences().put(copyOriginalSequenceDataObject, copySequence);
    }
/**
 * fields to ignore
 *        // aHelperContext    SDOHelperContext  (id=42)
 *        // dataGraph    null
 *        // logging    true
 *        // loggingMapping    true
 *        // unsetPropsMap    HashMap<K,V>  (id=117)
 *        // createdXPaths    null
 *        // deletedXPaths    null
 *        // modifiedDoms    null
 */
/**
 * fields to ignore that are on-demand
 *     oldSettings    HashMap<K,V>  (id=110)
 * reverseDeletedMap    HashMap<K,V>  (id=116)
 * oldSequences    HashMap<K,V>  (id=88)
 */
}
Also used : DefaultValueStore(org.eclipse.persistence.sdo.DefaultValueStore) ValueStore(org.eclipse.persistence.sdo.ValueStore) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) Iterator(java.util.Iterator) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) HashMap(java.util.HashMap) Map(java.util.Map) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 20 with ValueStore

use of org.eclipse.persistence.sdo.ValueStore in project eclipselink by eclipse-ee4j.

the class ChangeSummaryXSDWithCSonRootUndoTestCases method testDeleteItemsResetAndUndo_MultiOperation_DeleteComplexSingleWithManyChildBelowRootResetAndUndo.

public void testDeleteItemsResetAndUndo_MultiOperation_DeleteComplexSingleWithManyChildBelowRootResetAndUndo() {
    // save original root for later comparison after undo
    DataObject originalRootDO = copyHelper.copy(rootObject);
    assertTrue(equalityHelper.equal(rootObject, originalRootDO));
    DataObject itemsDO = rootObject.getDataObject("items");
    DataObject item1DO = rootObject.getDataObject("items/item[1]");
    DataObject item2DO = rootObject.getDataObject("items/item[2]");
    DataObject item1ProductDO = item1DO.getDataObject("product");
    DataObject item1ProductPrice1DO = item1ProductDO.getDataObject("price[1]");
    DataObject item1ProductPrice2DO = item1ProductDO.getDataObject("price[2]");
    DataObject item2ProductDO = item2DO.getDataObject("product");
    DataObject item2ProductPrice1DO = item2ProductDO.getDataObject("price[1]");
    DataObject item2ProductPrice2DO = item2ProductDO.getDataObject("price[2]");
    cs.beginLogging();
    // verify original VS is null and save a copy of current VS for object identity testing after undo
    assertValueStoresInitializedAfterLoggingOn(rootObject);
    // save a copy of current VS for object identity testing after undo
    ValueStore aCurrentValueStoreAfterLoggingFirstOn = ((SDODataObject) rootObject)._getCurrentValueStore();
    assertNotNull(itemsDO.getChangeSummary());
    itemsDO.delete();
    boolean wasDeleted = true;
    // verify CS is null on removed trees
    assertChangeSummaryStatusIfClearedIfCSIsAncestor(itemsDO, true);
    // check valueStores
    assertValueStoresCopiedAndSwappedAfterFirstModifyOperation(rootObject, aCurrentValueStoreAfterLoggingFirstOn);
    assertNotNull(item1DO);
    assertNotNull(item2DO);
    assertModified(rootObject, cs);
    assertDeleted(itemsDO, cs, wasDeleted);
    assertDeleted(item1DO, cs, wasDeleted);
    assertDeleted(item2DO, cs, wasDeleted);
    assertDeleted(item1ProductDO, cs, wasDeleted);
    assertDeleted(item1ProductPrice1DO, cs, wasDeleted);
    assertDeleted(item1ProductPrice2DO, cs, wasDeleted);
    assertDeleted(item2ProductDO, cs, wasDeleted);
    assertDeleted(item2ProductPrice1DO, cs, wasDeleted);
    assertDeleted(item2ProductPrice2DO, cs, wasDeleted);
    assertEquals(10, cs.getChangedDataObjects().size());
    // from 9
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
    // from 9
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
    // set the items back  (in effect doing an undo)
    rootObject.set("items", itemsDO);
    assertUndoChangesEqualToOriginal(cs, rootObject, originalRootDO);
    // verify that property is reset
    assertTrue(rootObject.isSet("items"));
    // get back items object
    DataObject itemsDOundone = rootObject.getDataObject("items");
    // compare with original
    assertTrue(equalityHelper.equal(itemsDOundone, itemsDO));
    assertValueStoresReturnedToStartStateAfterUndoChanges(rootObject, aCurrentValueStoreAfterLoggingFirstOn);
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) ValueStore(org.eclipse.persistence.sdo.ValueStore) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Aggregations

SDODataObject (org.eclipse.persistence.sdo.SDODataObject)22 ValueStore (org.eclipse.persistence.sdo.ValueStore)22 DataObject (commonj.sdo.DataObject)17 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)17 Property (commonj.sdo.Property)3 DefaultValueStore (org.eclipse.persistence.sdo.DefaultValueStore)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)1 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)1