Search in sources :

Example 36 with ListWrapper

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

the class SDOSequenceTestXSD method testRemoveComplexManyReferenceViaListWrapperReference.

public void testRemoveComplexManyReferenceViaListWrapperReference() {
    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);
    // 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(PO_SEQUENCE_PATH + "/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 37 with ListWrapper

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

the class SDOSequenceTestCS method testClearSimpleManyByListWrapper.

/*
    public void testRemoveSimpleManyBySequence() {
        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());

        ListWrapper existingList = (ListWrapper)po.get("comment");
        int listSizeBefore = existingList.size();
        assertEquals(PO_COMMENT_LIST_SIZE, listSizeBefore);

        int indexToPlaceAtEnd = aSequence.size();

        Property aProperty = po.getInstanceProperty("comment");

        // add list of items to existing list
        //List<String> aListToAdd = new ArrayList<String>();
        //aListToAdd.add("comment 2");
        //aListToAdd.add("comment 3");

        // remove entire list of comments
        for(int i=0; i<listSizeBefore; i++) {
            //int indexOfSetting = aSequence.getIndex(aProperty, existingList.get(i));
            int indexOfSetting = getNthSequenceIndexFor(aSequence, aProperty.getName());
            // get original setting
            SDOSetting aSetting = (SDOSetting)aSequence.getSettings().get(indexOfSetting);

            aSequence.remove(indexOfSetting);

            assertFalse(aSetting == aSequence.getSettings().get(indexOfSetting));
        }

        // verify that the list has decreased on the do
        int listSizeAfter = ((ListWrapper)po.get("comment")).size();
        assertEquals(0, listSizeAfter);

        // verify that the sequence size has decreased
        assertEquals(indexToPlaceAtEnd - listSizeBefore, aSequence.size());

        // verify that the sequence hash corresponding to the index to be removed is gone
        // check decreased size of sequence
        assertEquals(PO_SEQUENCE_TREE_SIZE - listSizeBefore, aSequence.size());

        // verify that DataObject has not changed for simple types
        int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
        assertEquals(treeSizeBeforeAdd, treeSizeAfterAdd);
    }
    */
public void testClearSimpleManyByListWrapper() {
    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());
    ListWrapper existingList = (ListWrapper) po.get("comment");
    int listSizeBefore = existingList.size();
    assertEquals(PO_COMMENT_LIST_SIZE, listSizeBefore);
    int indexToPlaceAtEnd = aSequence.size();
    Property itemProperty = po.getInstanceProperty("comment");
    // add list of items to existing list
    List<String> aListToAdd = new ArrayList<String>();
    aListToAdd.add("comment 2");
    aListToAdd.add("comment 3");
    existingList.clear();
    // verify that the list has decreased on the do
    int listSizeAfter = ((ListWrapper) po.get("comment")).size();
    assertEquals(0, listSizeAfter);
    // verify that the sequence size has decreased
    assertEquals(indexToPlaceAtEnd - listSizeBefore, aSequence.size());
    // check decreased size of sequence
    assertEquals(PO_SEQUENCE_TREE_SIZE - listSizeBefore, aSequence.size());
    // verify that DataObject has not changed for simple types
    int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
    assertEquals(treeSizeBeforeAdd, 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)

Example 38 with ListWrapper

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

the class SDOSequenceTestCS method testAddAllComplexManyNonContainmentByListWrapperAddAllPropertyOnExistingList.

public void testAddAllComplexManyNonContainmentByListWrapperAddAllPropertyOnExistingList() {
    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());
    ListWrapper existingList = (ListWrapper) po.get("item");
    int listSizeBefore = existingList.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 list of items to existing list
    List<DataObject> aListToAdd = new ArrayList<DataObject>();
    aListToAdd.add(item3);
    // add to the end of the list
    existingList.addAll(aListToAdd);
    // verify that the list has increased on the do
    int listSizeAfter = ((ListWrapper) po.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
    SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd + aListToAdd.size() - 1);
    assertNotNull(item2Value);
    assertEquals(item2Value, aListToAdd.get(0));
    assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
    // check increased size of sequence
    assertEquals(PO_SEQUENCE_TREE_SIZE + aListToAdd.size(), aSequence.size());
    // verify that DataObject has changed
    int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).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 39 with ListWrapper

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

the class SDOSequenceTestCS method testAddComplexManyByListWrapperAddAllPropertyOnExistingList.

public void testAddComplexManyByListWrapperAddAllPropertyOnExistingList() {
    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());
    ListWrapper existingList = (ListWrapper) po.get("item");
    int listSizeBefore = existingList.size();
    assertEquals(2, listSizeBefore);
    int indexToPlaceAtEnd = aSequence.size();
    // object to add
    DataObject item3 = (DataObject) root.get("item[1]");
    assertNotNull(item3);
    Property itemProperty = po.getInstanceProperty("item");
    // add list of items to existing list
    List<DataObject> aListToAdd = new ArrayList<DataObject>();
    aListToAdd.add(item3);
    aListToAdd.add(item3);
    // add to the end of the list
    existingList.addAll(aListToAdd);
    // verify that the list has increased on the do
    int listSizeAfter = ((ListWrapper) po.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
    SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd + aListToAdd.size() - 1);
    assertNotNull(item2Value);
    assertEquals(item2Value, aListToAdd.get(0));
    assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
    // check increased size of sequence
    assertEquals(PO_SEQUENCE_TREE_SIZE + aListToAdd.size(), aSequence.size());
    // verify that DataObject has changed
    int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).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 40 with ListWrapper

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

the class SDOSequenceTestCS method testRemoveIndexFirstDuplicateComplexManyReferenceViaSequence.

/**
 * Unable to test removal of an index of a duplicated list because the updateContainment code now does not allow duplicate
 * containment dataobjects
 */
public void testRemoveIndexFirstDuplicateComplexManyReferenceViaSequence() {
    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
    for (int i = 0; i < listSizeBefore; i++) {
        aSequence.remove(5);
    }
    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);
}
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)

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