Search in sources :

Example 96 with ListWrapper

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

the class SDOSequenceTestCS method testAddComplexManyByDataObjectSetPropertyWithListOnExistingList.

public void testAddComplexManyByDataObjectSetPropertyWithListOnExistingList() {
    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[1]");
    assertNotNull(item3);
    Property itemProperty = po.getInstanceProperty("item");
    // add list of items to sequence
    List<DataObject> aListToAdd = new ArrayList<DataObject>();
    aListToAdd.add(item3);
    aSequence.add(indexToPlaceAtEnd, itemProperty, aListToAdd);
    // get back new Setting value
    SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd);
    assertNotNull(item2Value);
    assertEquals(item2Value, aListToAdd.get(0));
    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 + aListToAdd.size(), 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) 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 97 with ListWrapper

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

the class SDOSequenceTestCS method testRemoveIndexFirstDuplicateComplexManyReferenceViaListWrapper.

public void testRemoveIndexFirstDuplicateComplexManyReferenceViaListWrapper() {
    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++) {
        existingList.remove(0);
    }
    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)

Example 98 with ListWrapper

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

the class SDOSequenceTestCS 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 99 with ListWrapper

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

the class SDOSequenceTestCS method test_setValue_manyComplex_invalidIndexThrowsException.

public void test_setValue_manyComplex_invalidIndexThrowsException() {
    // int index, String propertyName, 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() - 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;
        try {
            aSequence.setValue(indexToPlaceAtEnd + 1, existingList);
        } catch (IndexOutOfBoundsException e) {
            exceptionThrown = true;
        } finally {
            assertTrue(exceptionThrown);
        }

        // get back modified Setting value
        ListWrapper item2Value = (ListWrapper)aSequence.getValue(indexToPlaceAtEnd);
        assertNotNull(item2Value);
        assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
        // check no increase in size of sequence
        assertEquals(PO_SEQUENCE_SIZE, aSequence.size());

        // verify that the list has increased
        int listSizeAfter = ((ListWrapper)po.get("item")).size();
        assertEquals(listSizeBefore + 1, listSizeAfter);

        // verify that DataObject has changed in size
        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) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Example 100 with ListWrapper

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

the class SDOSequenceTestCS method test_voidReturnFrom_add_int_Property_Object_propertyIsAttribute.

public void test_voidReturnFrom_add_int_Property_Object_propertyIsAttribute() {
    // int index, Property property, Object value) {
    defineAndLoadRoot(false, false);
    // detach shipTo
    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 orderDateProperty = po.getInstanceProperty("orderDate");
    // add to sequence
    try {
        aSequence.add(indexToPlaceAtEnd, orderDateProperty, "1999-10-19");
    } catch (Exception e) {
    }
    // get back new Setting value
    ListWrapper item2Value = null;
    try {
        item2Value = (ListWrapper) aSequence.getValue(indexToPlaceAtEnd);
    } catch (SDOException e) {
        assertEquals(SDOException.INVALID_INDEX, e.getErrorCode());
    }
    assertNull(item2Value);
}
Also used : SDOException(org.eclipse.persistence.exceptions.SDOException) 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) SDOException(org.eclipse.persistence.exceptions.SDOException)

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