Search in sources :

Example 26 with ListWrapper

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

the class SDOSequenceTestCS method testRemoveAllComplexManyViaListWrapper.

public void testRemoveAllComplexManyViaListWrapper() {
    defineAndLoadRoot(false, false);
    SDOSequence aSequence = getSequence(root, "/", 5);
    int sequenceSizeBefore = aSequence.size();
    DataObject itemDO1 = (DataObject) root.get("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("item[2]");
    assertNotNull(itemDO1);
    assertNotNull(itemDO2);
    assertFalse(itemDO1 == itemDO2);
    // DataObject po = (DataObject)root.get(PO_SEQUENCE_PATH);
    ListWrapper existingList = (ListWrapper) root.get("item");
    int listSizeBefore = existingList.size();
    assertEquals(3, 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);
    assertEquals(0, existingList.size());
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Example 27 with ListWrapper

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

the class SDOSequenceTestXSD method testRemoveComplexManyViaListWrapperReference.

public void testRemoveComplexManyViaListWrapperReference() {
    defineAndLoadRoot(false, false);
    SDOSequence aSequence = getSequence(root, "/", 5);
    int sequenceSizeBefore = aSequence.size();
    DataObject itemDO1 = (DataObject) root.get("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("item[2]");
    assertNotNull(itemDO1);
    assertNotNull(itemDO2);
    assertFalse(itemDO1 == itemDO2);
    ListWrapper existingList = (ListWrapper) root.get("item");
    int listSizeBefore = existingList.size();
    assertEquals(3, 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);
    // delete po[1]/item[2] from setting
    existingList.remove(itemDO2);
    assertEquals(sequenceSizeBefore - 1, aSequence.size());
    // are we removed on the DataObject?
    DataObject item1ObjectFromAfterRemove = (DataObject) root.get("item[1]");
    // TODO: verify delete or dont delete after a sequence.remove
    assertTrue(item1ObjectFromAfterRemove == itemDO1);
    assertFalse(item1ObjectFromAfterRemove == itemDO2);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Example 28 with ListWrapper

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

the class SDOSequenceTestXSD method testAddComplexManyByDataObjectSetPropertyWithSingleItemOnExistingList.

public void testAddComplexManyByDataObjectSetPropertyWithSingleItemOnExistingList() {
    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 item3 = (DataObject) root.get("item[3]");
    assertNotNull(item3);
    Property itemProperty = po.getInstanceProperty("item");
    // add to sequence
    aSequence.add(indexToPlaceAtEnd, itemProperty, item3);
    // 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);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 29 with ListWrapper

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

the class SDOSequenceTestXSD method testAddAllComplexManyByListWrapperAddPropertyOnExistingList.

public void testAddAllComplexManyByListWrapperAddPropertyOnExistingList() {
    defineAndLoadRoot(false, false);
    SDOSequence aSequence = getSequence(root, "/", 5);
    // DataObject po = (DataObject)root.get(PO_SEQUENCE_PATH);
    int treeSizeBeforeAdd = preOrderTraversalDataObjectList(root).size();
    assertEquals(10, treeSizeBeforeAdd);
    assertEquals(5, aSequence.size());
    ListWrapper existingList = (ListWrapper) root.get("item");
    int listSizeBefore = existingList.size();
    assertEquals(3, listSizeBefore);
    int indexToPlaceAtEnd = aSequence.size();
    // object to add
    DataObject item3 = (DataObject) root.get("item[1]");
    assertNotNull(item3);
    Property itemProperty = root.getInstanceProperty("item");
    // add list of items to existing list
    List<DataObject> aListToAdd = new ArrayList<DataObject>();
    DataObject item4 = dataFactory.create(typeHelper.getType(URINAME, ITEM_TYPENAME));
    item4.set("itemID", 4);
    item4.set("name", "item4-DF");
    DataObject item5 = dataFactory.create(typeHelper.getType(URINAME, ITEM_TYPENAME));
    item5.set("itemID", 5);
    item5.set("name", "item5-DF");
    aListToAdd.add(item4);
    aListToAdd.add(item5);
    // add each to the end of the list
    for (Iterator<DataObject> i = aListToAdd.iterator(); i.hasNext(); ) {
        existingList.add(i.next());
    }
    // verify that the list has increased on the do
    int listSizeAfter = ((ListWrapper) root.get("item")).size();
    assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
    // verify that the sequence size has increased
    assertEquals(indexToPlaceAtEnd + aListToAdd.size(), aSequence.size());
    // get back new Setting value
    for (int i = 0; i < aListToAdd.size(); i++) {
        SDODataObject itemValue = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd + i);
        assertNotNull(itemValue);
        assertEquals(itemValue, aListToAdd.get(i));
        assertNotNull(aSequence.getProperty(indexToPlaceAtEnd + i));
    }
    // check increased size of sequence
    assertEquals(5 + aListToAdd.size(), aSequence.size());
    // verify that DataObject has changed
    int treeSizeAfterAdd = preOrderTraversalDataObjectList(root).size();
    assertEquals(treeSizeBeforeAdd + aListToAdd.size(), treeSizeAfterAdd);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 30 with ListWrapper

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

the class SDOSequenceTestXSD method test_PropertyReturnFrom_getProperty.

/**
 * Returns the property for the given entry index.
 * Returns <code>null</code> for mixed text entries.
 * @param index the index of the entry.
 */
public void test_PropertyReturnFrom_getProperty() {
    // int index) {
    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() - 1;
    // object to replace
    DataObject item2 = (DataObject) root.get("item[2]");
    assertNotNull(item2);
/*        // add the item to the current list
        ListWrapper existingList = (ListWrapper)aSequence.getValue(indexToPlaceAtEnd);
        assertNotNull(existingList);
        existingList.add(item2);

        boolean exceptionThrown = false;
        Property property1 = po.getInstanceProperty("item");
        Object property1Return = null;
        try {
            property1Return = aSequence.getProperty(indexToPlaceAtEnd);
        } catch (IndexOutOfBoundsException e) {
            exceptionThrown = true;
        } finally {
            assertFalse(exceptionThrown);
        }

        // verify property
        assertNotNull(property1Return);
        assertEquals(property1, property1Return);
*/
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Aggregations

ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)164 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)131 DataObject (commonj.sdo.DataObject)106 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)73 ArrayList (java.util.ArrayList)72 Property (commonj.sdo.Property)47 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)47 List (java.util.List)29 Iterator (java.util.Iterator)9 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)9 ChangeSummary (commonj.sdo.ChangeSummary)8 Type (commonj.sdo.Type)8 QName (javax.xml.namespace.QName)7 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)7 DefaultSchemaLocationResolver (org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver)7 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)7 SDOException (org.eclipse.persistence.exceptions.SDOException)6 Map (java.util.Map)5 Setting (org.eclipse.persistence.oxm.sequenced.Setting)4 SDOSetting (org.eclipse.persistence.sdo.SDOSetting)4