Search in sources :

Example 11 with SDOChangeSummary

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

the class ChangeSummaryXSDwSeqTestCases method testDetachAndResetYardToSamePlaceUsingFullCSUndoChangesFunction.

// same as above but using a real undoChanges() instead of a re(set)
// see bug# 5882923
// See SDO-225 Feb-15 2007 issue (option A - nothing in the cs, option B - track unset/reset)
public void testDetachAndResetYardToSamePlaceUsingFullCSUndoChangesFunction() {
    DataObject shipToDO = rootObject.getDataObject("shipTo");
    // Property containmentProp = shipToDO.getInstanceProperty("yard");
    DataObject yardDO = shipToDO.getDataObject("yard");
    Object length = yardDO.get("length");
    List yardDOSettings = setupDetachForResetOrUndoOfYardToSamePlace(shipToDO, yardDO, length);
    // originalValueStore of shipTo will already be copied in the modifiy part of the detach of its child above
    // this set will trigger a 2nd copy of the ValueStore - we will ignore it.
    // Case: Move/Reset
    // a detach of a child modifies its parent - trigering a copy of parent's ValueStore
    // a set on the parent will trigger another copy - but we will skip this one as we already
    // have a copy of the original.
    // Issue: if we reset the child back the same place (in effect doing our own undo)
    // do we optimize this and remove the copy - for now a real undoChanges() will do the same
    // shipToDO.set("yard", yardDO);
    cs.undoChanges();
    assertFalse(cs.isDeleted(yardDO));
    // if we add new logic
    assertFalse(cs.isModified(shipToDO));
    // assertTrue(cs.isModified(shipToDO)); // see bug# 5882923 - we should clear the setting here
    assertFalse(cs.isModified(yardDO));
    // if we add new logic
    assertEquals(0, cs.getChangedDataObjects().size());
    // assertEquals(1, cs.getChangedDataObjects().size());//just shipTo
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
    List shipToSettings = cs.getOldValues(shipToDO);
    // 20070214: modified from 1
    assertEquals(0, shipToSettings.size());
    yardDOSettings = cs.getOldValues(yardDO);
    // see cs.getOldValues() does not return and empty List when yardDO is !modified and !deleted (but !created as well) - (re)set
    // was 3 before we implemented undoChanges()
    assertEquals(0, yardDOSettings.size());
    // see cs.getOldValue() does not return null when yardDO is !modified and !deleted (but !created as well) - (re)set
    ChangeSummary.Setting lengthSetting = cs.getOldValue(yardDO, yardDO.getInstanceProperty("length"));
    // assertNotNull(lengthSetting);
    assertNull(lengthSetting);
// assertEquals(length, lengthSetting.getValue());
// writeXML(rootObject);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) ChangeSummary(commonj.sdo.ChangeSummary) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary)

Example 12 with SDOChangeSummary

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

the class ChangeSummaryXSDwSeqTestCases 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 13 with SDOChangeSummary

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

the class ChangeSummaryXSDwSeqTestCases method testDeleteItems.

public void testDeleteItems() {
    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();
    itemsDO.delete();
    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());
// writeXML(rootObject);// null objectValue in org.eclipse.persistence.internal.oxm.XMLAnyCollectionMappingNodeValue.marshal(XMLAnyCollectionMappingNodeValue.java:92)
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary)

Example 14 with SDOChangeSummary

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

the class ChangeSummaryXSDwSeqTestCases method testCSonRootDeleteComplexManyBelowRoot.

// test deletion inside a list - see detach() isMany section
// Test Scenarios:
// - many delete
public void testCSonRootDeleteComplexManyBelowRoot() {
    // testDeleteItem2() {
    DataObject itemsDO = rootObject.getDataObject("items");
    DataObject item1DO = rootObject.getDataObject("items/item[1]");
    DataObject item2DO = rootObject.getDataObject("items/item[2]");
    DataObject item2ProductDO = item2DO.getDataObject("product");
    DataObject item2ProductPrice1DO = item2ProductDO.getDataObject("price[1]");
    DataObject item2ProductPrice2DO = item2ProductDO.getDataObject("price[2]");
    cs.beginLogging();
    item2DO.delete();
    assertModified(itemsDO, cs);
    assertDeleted(item2DO, cs);
    assertDeleted(item2ProductDO, cs);
    assertDeleted(item2ProductPrice1DO, cs);
    assertDeleted(item2ProductPrice2DO, cs);
    assertEquals(5, cs.getChangedDataObjects().size());
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
    assertEquals(1, cs.getOldValues(itemsDO).size());
    ChangeSummary.Setting containmentSetting = (ChangeSummary.Setting) cs.getOldValues(itemsDO).get(0);
    assertEquals("item", containmentSetting.getProperty().getName());
    assertTrue(containmentSetting.getValue() instanceof List);
    assertEquals(2, ((List) containmentSetting.getValue()).size());
    assertEquals(true, containmentSetting.isSet());
// writeXML(rootObject);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOSetting(org.eclipse.persistence.sdo.SDOSetting) ArrayList(java.util.ArrayList) List(java.util.List) ChangeSummary(commonj.sdo.ChangeSummary) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary)

Example 15 with SDOChangeSummary

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

the class ChangeSummaryXSDwSeqTestCases method testDetachAndReSetPrice1BackToSameIndex.

// Verify that an unset followed by a (re)set of the same subtree returns tree to original state
// See SDO-225 Feb-15 2007 issue (option A - nothing in the cs, option B - track unset/reset)
public void testDetachAndReSetPrice1BackToSameIndex() {
    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();
    item2ProductPrice1DO.detach();
    assertModified(item2ProductDO, cs);
    assertDetached(item2ProductPrice1DO, cs);
    assertEquals(2, cs.getChangedDataObjects().size());
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
    List aSettingList = cs.getOldValues(item2ProductDO);
    assertTrue(aSettingList.size() > 0);
    ChangeSummary.Setting containmentSetting = (ChangeSummary.Setting) aSettingList.get(0);
    assertEquals("price", containmentSetting.getProperty().getName());
    assertTrue(containmentSetting.getValue() instanceof List);
    assertEquals(2, ((List) containmentSetting.getValue()).size());
    assertEquals(true, containmentSetting.isSet());
    // UNDO - reattach subtree
    ((ListWrapper) item2ProductDO.get("price")).add(0, item2ProductPrice1DO);
    assertFalse(cs.isDeleted(item2ProductPrice1DO));
    // assertUnchanged(cs.isModified(item2ProductDO)); //if we add new logic
    assertFalse(cs.isModified(item2ProductDO));
    assertFalse(cs.isModified(item2ProductPrice1DO));
    assertEquals(0, cs.getChangedDataObjects().size());
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
    assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
// writeXML(rootObject);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOSetting(org.eclipse.persistence.sdo.SDOSetting) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) ArrayList(java.util.ArrayList) List(java.util.List) ChangeSummary(commonj.sdo.ChangeSummary) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary)

Aggregations

SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)123 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)109 DataObject (commonj.sdo.DataObject)91 ChangeSummary (commonj.sdo.ChangeSummary)66 List (java.util.List)63 ArrayList (java.util.ArrayList)56 SDOSetting (org.eclipse.persistence.sdo.SDOSetting)37 Property (commonj.sdo.Property)25 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)25 ValueStore (org.eclipse.persistence.sdo.ValueStore)17 SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)16 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)16 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)9 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)9 SDOType (org.eclipse.persistence.sdo.SDOType)7 Sequence (commonj.sdo.Sequence)6 Iterator (java.util.Iterator)6 Map (java.util.Map)6 HashSet (java.util.HashSet)2 Set (java.util.Set)2