use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequence method remove.
private void remove(Setting setting) {
CoreMapping mapping = setting.getMapping();
if (null != mapping) {
Property property = null;
if (null == setting.getName()) {
XMLRoot xmlRoot = (XMLRoot) setting.getValue();
if (null != xmlRoot) {
property = dataObject.getInstanceProperty(xmlRoot.getLocalName());
valuesToSettings.remove(new Key(property, setting.getValue()));
}
} else {
property = dataObject.getInstanceProperty(mapping.getAttributeName());
valuesToSettings.remove(new Key(property, setting.getValue()));
}
if (property.isMany()) {
ListWrapper listWrapper = (ListWrapper) dataObject.getList(property);
listWrapper.remove(setting.getValue(), false, false);
} else {
dataObject.unset(property, false, false);
}
} else if (setting.getName() != null && setting.getName().equals(TEXT_XPATH)) {
// Handle "text()"
dataObject._setModified(true);
}
List<Setting> children = setting.getChildren();
if (null != children) {
int childrenSize = children.size();
for (int x = 0; x < childrenSize; x++) {
remove(children.get(x));
}
}
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDODataObjectCloneTestCases method testListClone.
public void testListClone() {
DataObject items = purchaseOrder.getDataObject("items");
ListWrapper lineItems = (ListWrapper) items.getList("item");
ListWrapper lineItemsClone = (ListWrapper) lineItems.clone();
assertFalse(lineItems == lineItemsClone);
assertFalse(lineItems.getCurrentElements() == lineItemsClone.getCurrentElements());
assertTrue(lineItems.size() == lineItemsClone.size());
assertTrue(lineItems.get(0) == lineItemsClone.get(0));
assertTrue(lineItems.get(1) == lineItemsClone.get(1));
}
use of org.eclipse.persistence.sdo.helper.ListWrapper 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);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method testRemoveAllEmptyComplexManyReferenceViaListWrapper.
public void testRemoveAllEmptyComplexManyReferenceViaListWrapper() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
int sequenceSizeBefore = aSequence.size();
DataObject itemDO1 = (DataObject) root.get(PO_SEQUENCE_PATH + "/item[1]");
// after removal the items list indexes on the dataObject will shift down, get item[2] for later comparison
DataObject itemDO2 = (DataObject) root.get(PO_SEQUENCE_PATH + "/item[2]");
assertNotNull(itemDO1);
assertNotNull(itemDO2);
assertFalse(itemDO1 == itemDO2);
DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
ListWrapper existingList = (ListWrapper) po.get("item");
int listSizeBefore = existingList.size();
assertEquals(2, listSizeBefore);
// get item from sequence
int item2SequenceIndex = getNthSequenceIndexFor(aSequence, "item", 2);
assertTrue(item2SequenceIndex > -1);
DataObject itemObjectFromSetting = (DataObject) aSequence.getValue(item2SequenceIndex);
assertNotNull(itemObjectFromSetting);
assertTrue(itemObjectFromSetting == itemDO2);
// create a list of items to remove
List<DataObject> listToRemove = new ArrayList<DataObject>();
// for(Iterator<DataObject> i = existingList.iterator(); i.hasNext();) {
// listToRemove.add(i.next());
// }
int sizeListToRemove = listToRemove.size();
// remove entire list
existingList.removeAll(listToRemove);
assertEquals(sequenceSizeBefore - sizeListToRemove, aSequence.size());
assertEquals(listSizeBefore - sizeListToRemove, existingList.size());
// are we removed on the DataObject?
// DataObject item1ObjectFromAfterRemove = (DataObject)root.get(PO_SEQUENCE_PATH + "/item[1]");
// TODO: verify delete or dont delete after a sequence.remove
// assertTrue(item1ObjectFromAfterRemove == itemDO1);
// assertFalse(item1ObjectFromAfterRemove == itemDO2);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method test_booleanReturnFrom_add_Property_Object_WhereValuePassedIsSingleItemInEmptyList.
/**
* Test setting a many property using a single item of a list instead of passing a
* ListWrapper as usual.
* The existing list will need to be null (not an empty ListWrapper)
*/
public void test_booleanReturnFrom_add_Property_Object_WhereValuePassedIsSingleItemInEmptyList() {
// Property property, Object value) {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(PO_TREE_SIZE, treeSizeBeforeAdd);
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
int listSizeBefore = ((ListWrapper) po.get("item")).size();
assertEquals(2, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
// object to add
DataObject item2 = (DataObject) root.get("item[2]");
assertNotNull(item2);
Property itemProperty = po.getInstanceProperty("item");
// add to sequence
aSequence.add(itemProperty, item2);
// get back new Setting value
// ListWrapper item2Value = (ListWrapper)aSequence.getValue(indexToPlaceAtEnd);
SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd);
assertNotNull(item2Value);
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence
assertEquals(PO_SEQUENCE_TREE_SIZE + 1, aSequence.size());
// verify that the list has increased
int listSizeAfter = ((ListWrapper) po.get("item")).size();
assertEquals(listSizeBefore + 1, listSizeAfter);
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd + 1, treeSizeAfterAdd);
}
Aggregations