use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class ChangeSummaryXSDwSeqTestCases method testDeepCopyObjectWithCSLoggingOnWithComboDeleteSingleCreateManyModifyRootChangesInTheDeepCopy.
// see #6026714: for fix for null complex type retains last sequence value during copy of a copy
public void testDeepCopyObjectWithCSLoggingOnWithComboDeleteSingleCreateManyModifyRootChangesInTheDeepCopy() {
List preOrderList = null;
int numberOfDataObjectsInSubTree = 0;
// unset isMany=true (to fill unsetPropsMap and createdList later when we (re)set it back)
SDODataObject shipTo = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_SHIPTO);
// use index 2 to avoid a swap later
SDODataObject phone2 = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_SHIPTO_PHONE2);
shipTo.unset("phone[2]");
// save size of tree before CS was turned on
preOrderList = preOrderTraversalDataObjectList((SDODataObject) rootObject, false);
numberOfDataObjectsInSubTree = preOrderList.size();
int numberOfNodesInRootBeforeCSon = 14;
assertEquals(numberOfNodesInRootBeforeCSon, numberOfDataObjectsInSubTree);
SDOProperty openRootProperty = new SDOProperty(aHelperContext);
openRootProperty.setName(OC_PROP1SimpleSingleNAME);
openRootProperty.setType(SDOConstants.SDO_STRING);
// aRootTypeOC.setOpen(true);
((SDOType) rootObject.getType()).setOpen(true);
rootObject.set(openRootProperty, OC_PROP1SimpleSingleVALUE);
// set an Open Content property and delete it
SDOProperty openRootPropertyToBeDeleted = new SDOProperty(aHelperContext);
openRootPropertyToBeDeleted.setName(OC_PROP2SimpleSingleNAME);
openRootPropertyToBeDeleted.setType(SDOConstants.SDO_STRING);
// aRootTypeOC.setOpen(true);
rootObject.set(openRootPropertyToBeDeleted, OC_PROP2SimpleSingleVALUE);
// verify logging is on
// turn on logging
cs.beginLogging();
assertTrue(cs.isLogging());
// do some changes
// delete an Open Content property
rootObject.unset(openRootPropertyToBeDeleted);
// ChangeSummary.Setting setting = cs.getOldValue(rootObject, openRootPropertyToBeDeleted);
// assertEquals("openTest", setting.getValue());
SDODataObject items = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_ITEMS);
// detach isMany=false (to fill deletedList and modifiedList)
// items.detach();
items.delete();
// (re)set isMany=true (to fill createdList, unsetPropsMap)
List phones = (List) shipTo.get("phone");
phones.add(phone2);
// get an oldSetting in order to enable caching to fill the oldSettings hash map in the cs
// Object oldValueItems = cs.getOldValue(rootObject, rootObject.getInstanceProperty("items")).getValue();
// assertNotNull(oldValueItems);
// assertNull(rootObject.get("items"));
// save fields lengths for later comparision
List<DataObject> changedObjects = cs.getChangedDataObjects();
int changedObjectsLength = changedObjects.size();
// int itemsOldValuesSize = cs.getOldValues(items).size();// invoke usage of the reverseDeletedMap
// take an object with CS on and deep copy it
SDODataObject copy = (SDODataObject) copyHelper.copy(rootObject);
// see #6026714: for fix for null complex type retains last sequence value during copy of a copy
// copy the copy - so we are sure that the copy has enough in the cs to do an undo of the 2nd level copy
SDODataObject copyOfCopy = (SDODataObject) copyHelper.copy(copy);
// SDODataObject copy = (SDODataObject)marshalUnmarshalObject(rootObject);
// verify that logging is still on
ChangeSummary cs2 = copy.getChangeSummary();
assertNotNull(cs2);
assertTrue(cs2.isLogging());
ChangeSummary cs3 = copyOfCopy.getChangeSummary();
assertNotNull(cs3);
assertTrue(cs3.isLogging());
// verify saved field lengths from above
assertEquals(changedObjectsLength, cs2.getChangedDataObjects().size());
// no cache entries yet = 0 oldValues
// assertEquals(itemsOldValuesSize, cs2.getOldValues(items).size());
// check shallow equality
assertEquals(rootObject.getInstanceProperties().size(), copy.getInstanceProperties().size());
boolean isEqual = equalityHelper.equalShallow(rootObject, copy);
assertTrue(isEqual);
// check deep equal is unaffected (we should have a copy of the copy for List items
// - ListWrapper.add(item) will remove the item from its original wrapper)
boolean copyEqualToOriginal = equalityHelper.equal(rootObject, copy);
assertTrue(copyEqualToOriginal);
assertTrue(equalityHelper.equalShallow(rootObject, copyOfCopy));
// check deep equal is unaffected (we should have a copy of the copy for List items
// - ListWrapper.add(item) will remove the item from its original wrapper)
assertTrue(equalityHelper.equal(rootObject, copyOfCopy));
// verify that all objects referenced in the copy changeSummary are from the copy not the original
// verify createdList
// verify deepCopies
// verify deletedList
// verify modifiedList
// verify oldContainer
// verify oldContainmentProperty
// verify originalElements
// verify originalValueStores
Map originalValueStores = ((SDOChangeSummary) cs).getOriginalValueStores();
Map originalValueStoresCopy = ((SDOChangeSummary) cs2).getOriginalValueStores();
// verify originally deleted items is referencing a copy and a copy of its valuestore
// verify reverseDeletedMap
// verify rootDataObject
assertEquals(copy, cs2.getRootObject());
// verify unsetPropsMap
SDODataObject items2 = (SDODataObject) copy.get(PROPERTY_NAME_PO_ITEMS);
// check new phone copy
SDODataObject phone2c = (SDODataObject) copy.get(PROPERTY_NAME_PO_SHIPTO_PHONE2);
assertNotNull(phone2);
// get original new phone
SDODataObject phone2o = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_SHIPTO_PHONE2);
assertNotNull(phone2);
assertFalse(phone2o == phone2c);
assertFalse(phone2o._getCurrentValueStore() == phone2c._getCurrentValueStore());
// check new phone copy (in oldSettings) is == to currentValueStore phone (both are the same deepcopies of the original)
List createdListCopy = ((SDOChangeSummary) cs2).getCreated();
assertNotNull(createdListCopy);
assertEquals(1, createdListCopy.size());
SDODataObject phone2cInCreatedList = (SDODataObject) createdListCopy.get(0);
assertNotNull(phone2cInCreatedList);
assertNotNull(phone2cInCreatedList);
// test cs.createList iterator makes deep copies
assertTrue(phone2c == phone2cInCreatedList);
assertTrue(phone2c._getCurrentValueStore() == phone2cInCreatedList._getCurrentValueStore());
// get an oldSetting in order to enable caching to fill the hash map in the cs
// Object oldValueItems2 = cs2.getOldValue(copy, copy.getInstanceProperty("items"));
// verify that we have oldSettings in the new copy
// assertNotNull(oldValueItems2);
// assertNotNull(((SDOSetting)oldValueItems2).getValue());
// assertNull(copy.get("items"));
// deleted objects are 9
// verify that we have transferred the logged changes during the copy (we dont have to worry about nested changesummaries)
assertEquals(changedObjectsLength, cs2.getChangedDataObjects().size());
preOrderList = preOrderTraversalDataObjectList(copy, false);
numberOfDataObjectsInSubTree = preOrderList.size();
// assume that for logging=true copies we should have oldContainer, oldContProperties
// 16 - 10
assertEquals(6, numberOfDataObjectsInSubTree);
assertEquals(//
((SDOChangeSummary) cs).getOldContainer().size(), copy.getChangeSummary().getOldContainer().size());
assertEquals(//
((SDOChangeSummary) cs).getOldContainmentProperty().size(), copy.getChangeSummary().getOldContainmentProperty().size());
// no oldSetting for simple object
// verify oc props that were deleted are in oldSettings
// (Property)copy.getOpenContentPropertiesMap().get(OC_PROP2SimpleSingleNAME);
Property oc2cProp = openRootPropertyToBeDeleted;
assertNotNull(oc2cProp);
Object oc2cSetting = cs2.getOldValue(copy, oc2cProp);
assertNotNull(oc2cSetting);
String oc2cValue = (String) ((SDOSetting) oc2cSetting).getValue();
assertNotNull(oc2cValue);
assertEquals(OC_PROP2SimpleSingleVALUE, oc2cValue);
// verify unsetOC map
List<Property> ocUnsetList = ((SDOChangeSummary) cs2).getUnsetOCProperties(copy);
assertNotNull(ocUnsetList);
Property oc2cProp_ocUnsetMap = ocUnsetList.get(0);
assertNotNull(oc2cProp_ocUnsetMap);
// verify that we are pointing to the same global property
assertEquals(oc2cProp_ocUnsetMap, openRootPropertyToBeDeleted);
String oc2cValue_ocUnsetMap = oc2cProp_ocUnsetMap.getName();
assertNotNull(oc2cValue_ocUnsetMap);
assertSame(openRootPropertyToBeDeleted.getName(), oc2cValue_ocUnsetMap);
// verify oldContainer <key, value> are both deep copies
// we an old setting first
// DataObject anOldContainerValue = cs2.getOldContainer(items2);
// assertTrue(copy == anOldContainerValue);
// perform an undo on the copy and compare to the undone original (not the undone copy)
cs2.undoChanges();
// verify that original was unaffected by undo on copy
items = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_ITEMS);
assertNull(items);
// get back "items" that has been reset
items2 = (SDODataObject) copy.get(PROPERTY_NAME_PO_ITEMS);
assertNotNull(items2);
assertEquals(0, cs2.getChangedDataObjects().size());
preOrderList = preOrderTraversalDataObjectList(copy, false);
numberOfDataObjectsInSubTree = preOrderList.size();
// assume that for logging=true copies we should have oldContainer, oldContProperties
assertEquals(14, numberOfDataObjectsInSubTree);
// undo changes on original
cs.undoChanges();
assertEquals(0, cs.getChangedDataObjects().size());
// the items:do in the original and copy should not be the same object (different valueStores)
// verify that original was unaffected by undo on copy
items = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_ITEMS);
assertFalse(items == items2);
assertFalse(items._getCurrentValueStore() == items2._getCurrentValueStore());
assertEquals(0, cs2.getChangedDataObjects().size());
preOrderList = preOrderTraversalDataObjectList(copy, false);
numberOfDataObjectsInSubTree = preOrderList.size();
// assume that for logging=true copies we should have oldContainer, oldContProperties
// 16 - 10
assertEquals(14, numberOfDataObjectsInSubTree);
// verify deep objects item[*] are distince between original and copy
SDODataObject item1o = (SDODataObject) items.get("item[1]");
SDODataObject item1c = (SDODataObject) items2.get("item[1]");
assertNotNull(item1o);
assertNotNull(item1c);
assertFalse(item1o == item1c);
assertFalse(item1o._getCurrentValueStore() == item1c._getCurrentValueStore());
// verify listwrappers hashes are the same between two equal objects in the cs
// verify simple Many integrity
ListWrapper origComments = (ListWrapper) rootObject.get("items/item[1]/comment");
assertNotNull(origComments);
assertEquals(2, origComments.size());
ListWrapper copyComments = (ListWrapper) copy.get("items/item[1]/comment");
assertNotNull(copyComments);
assertEquals(2, copyComments.size());
// writeXML(copy);
// check shallow equality
assertTrue(equalityHelper.equalShallow(rootObject, copy));
// check deep equal is unaffected (we should have a copy of the copy for List items
// - ListWrapper.add(item) will remove the item from its original wrapper)
assertTrue(equalityHelper.equal(rootObject, copy));
// verify equality and undo the copyOfCopy to ensure that the csCopyOfCopy has enough info to do an undo
copyOfCopy.getChangeSummary().undoChanges();
assertTrue(equalityHelper.equalShallow(rootObject, copyOfCopy));
// check deep equal is unaffected (we should have a copy of the copy for List items
// - ListWrapper.add(item) will remove the item from its original wrapper)
assertTrue(equalityHelper.equal(rootObject, copyOfCopy));
assertTrue(equalityHelper.equal(copy, copyOfCopy));
// Verify CS undo of oc props
// verify oc props that are copied
Object oc1cProp = copy.get(OC_PROP1SimpleSingleNAME);
assertNotNull(oc1cProp);
assertEquals(OC_PROP1SimpleSingleVALUE, oc1cProp);
// verify that deleted oc props were returned being set after an undo - use saved Property object (outside of this object)
Object oc2cPropUndo = rootObject.get(openRootPropertyToBeDeleted);
assertNotNull(oc2cPropUndo);
assertEquals(oc2cPropUndo, OC_PROP2SimpleSingleVALUE);
// test undo for oc - not implemented yet see #5928954
// verify that deleted oc props were returned being set after an undo - do not used saved Property object -use getPath
oc2cPropUndo = rootObject.get(openRootPropertyToBeDeleted.getName());
assertNotNull(oc2cPropUndo);
assertEquals(oc2cPropUndo, OC_PROP2SimpleSingleVALUE);
// verify oc Property is in valueStore
String openRootPropertyToBeDeletedAfterUndo = (String) //
((SDODataObject) rootObject)._getCurrentValueStore().getOpenContentProperty(openRootPropertyToBeDeleted);
assertNotNull(openRootPropertyToBeDeletedAfterUndo);
assertEquals(openRootPropertyToBeDeletedAfterUndo, OC_PROP2SimpleSingleVALUE);
// exercise printstring
cs.toString();
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDODataGraphDataObjectBackPointerTest method testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithoutCS.
// This function will exercise the updateDataGraph() function on SDODataObject.updateContainment()
public void testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithoutCS() {
DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
registerTypes();
List<Type> types = getTypesToGenerateFrom();
((SDOXSDHelper) xsdHelper).generate(types, resolver);
// Create target
DataObject aDataObjectTarget = createRootObject(types);
DataGraph aDataGraphTarget = dataGraph;
aDataGraphTarget.createRootObject(aDataObjectTarget.getType());
DataObject targetRoot = aDataGraphTarget.getRootObject();
// Check it
assertNotNull(targetRoot);
assertEquals(targetRoot.getType(), aDataGraphTarget.getType(URINAME, COMPANY_TYPENAME));
ListWrapper pOrdersTarget = (ListWrapper) targetRoot.getList(PO_PATH);
int poSize = pOrdersTarget.size();
assertEquals(0, poSize);
// Create source
DataObject aDataObjectSource = createRootObject(types);
DataGraph aDataGraphSource = new SDODataGraph(aHelperContext);
aDataGraphSource.createRootObject(aDataObjectSource.getType());
DataObject sourceRoot = aDataGraphSource.getRootObject();
// Check it
assertNotNull(sourceRoot);
assertEquals(sourceRoot.getType(), aDataGraphSource.getType(URINAME, COMPANY_TYPENAME));
ListWrapper pOrdersSource = (ListWrapper) aDataObjectSource.getList(PO_PATH);
int poSizeSource = pOrdersSource.size();
assertEquals(1, poSizeSource);
// Clear the target CS so that we enter only the DataGraph recursive loop
((SDODataObject) targetRoot)._setChangeSummary(null);
// Get source DO
DataObject sourcePO = (DataObject) pOrdersSource.get(0);
// DataGraph should be null before set
assertNull(sourcePO.getDataGraph());
// Move the root object from one null data graph to the other
pOrdersTarget.add(sourcePO);
// DataGraph should be not be null before set
assertNotNull(sourcePO.getDataGraph());
// Target dataGraph should be set on all children
assertEquals(aDataGraphTarget, sourcePO.getDataGraph());
DataObject copyPOshipTo = (DataObject) sourcePO.get("shipTo");
DataObject copyPObillTo = (DataObject) sourcePO.get("billTo");
DataObject copyPOitem1 = (DataObject) sourcePO.get("item[1]");
DataObject copyPOitem2 = (DataObject) sourcePO.get("item[2]");
// Check dataGraph back pointers recursively (containment only)
List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(sourcePO);
assertNotNull(copyPreOrderList);
assertEquals(5, copyPreOrderList.size());
copyPreOrderList.contains(copyPOshipTo);
copyPreOrderList.contains(copyPObillTo);
copyPreOrderList.contains(copyPOitem1);
copyPreOrderList.contains(copyPOitem2);
assertNotNull(copyPOshipTo.getDataGraph());
assertEquals(aDataGraphTarget, copyPOshipTo.getDataGraph());
assertNotNull(copyPObillTo.getDataGraph());
assertEquals(aDataGraphTarget, copyPObillTo.getDataGraph());
// item property is unidirectional or containment=false - still in the dataGraph in this case
assertNotNull(copyPOitem1.getDataGraph());
assertEquals(aDataGraphTarget, copyPOitem1.getDataGraph());
assertNotNull(copyPOitem2.getDataGraph());
assertEquals(aDataGraphTarget, copyPOitem2.getDataGraph());
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDODataObjectListWrapperTest method testGetListNullProperty.
public void testGetListNullProperty() {
Property p = null;
try {
ListWrapper aList = (ListWrapper) aRoot.getList(p);
} catch (SDOException e) {
assertEquals(SDOException.CANNOT_PERFORM_OPERATION_ON_NULL_ARGUMENT, e.getErrorCode());
return;
}
fail("A CANNOT_PERFORM_OPERATION_ON_NULL_ARGUMENT exception should have occurred");
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDODataObjectListWrapperTest method testListWrapperAddAll.
// boolean addAll(Collection items)
public void testListWrapperAddAll() {
// Setup step:
// log("SDODataObjectListWrapperTest.testListWrapperAddAll()");
// create a List of new items
List aNewList = new ArrayList();
// create item from existing
SDODataObject anItem1 = (SDODataObject) copyHelper.copy(((SDODataObject) aRoot.get("items/item[2]")));
// modify object
anItem1.set(anItem1.getInstanceProperty("partNum"), "926-ZA");
SDODataObject anItem2 = (SDODataObject) copyHelper.copy(((SDODataObject) aRoot.get("items/item[2]")));
// modify object
anItem2.set(anItem1.getInstanceProperty("partNum"), "926-ZB");
SDODataObject anItem3 = (SDODataObject) copyHelper.copy(((SDODataObject) aRoot.get("items/item[2]")));
// modify object
anItem3.set(anItem1.getInstanceProperty("partNum"), "926-ZC");
// add items to list (to be added to the ListWrapper)
aNewList.add(anItem1);
aNewList.add(anItem2);
aNewList.add(anItem3);
// get containment node
ListWrapper aList = (ListWrapper) aRoot.getList("items/item");
// Test step:
assertTrue(aList.addAll(aNewList));
// Validate step: (the 3 existing objects should have been clear()ed with the new ones added)
assertTrue(aList.size() == (aNewList.size() + 2));
SDODataObject additionalDO = (SDODataObject) aRoot.get("items/item[5]");
assertNotNull(additionalDO);
// assertTrue(additionalDO.getProperty("partNum").getName().equals("926-ZC"));
assertTrue(additionalDO.equals(anItem3));
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDODataObjectListWrapperTest method testListWrapperAddAllWithEmptyCollection.
// boolean addAll(Collection items)
public void testListWrapperAddAllWithEmptyCollection() {
// Setup step:
// log("SDODataObjectListWrapperTest.testListWrapperAddAllWithEmptyCollection()");
// create a List of new items
List aNewList = new ArrayList();
// get containment node
ListWrapper aList = (ListWrapper) aRoot.getList("items/item");
// Test step:
int originalSize = aList.size();
assertFalse(aList.addAll(aNewList));
// Validate step:
assertTrue(aList.size() == originalSize);
}
Aggregations