Search in sources :

Example 16 with SDOSequence

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

the class SDOSequenceTestXSD method test_SequenceReturnFrom_SDODataObject_getSequence_Property_type_single_many.

/**
 * Returns the value of the specified <code>Sequence</code> property.
 * @param property the property to get.
 * @see #get(Property)
 * @deprecated in 2.1.0.
 */
@Deprecated
public void test_SequenceReturnFrom_SDODataObject_getSequence_Property_type_single_many() {
    defineAndLoadRoot(false, false);
    assertNotNull(root);
    // get property index of porder
    Property aPOProperty = root.getInstanceProperty(PO_PATH);
    // Expect a failure for a single many property
    SDOSequence aSequence = null;
    boolean exceptionThrown = false;
    int errorCode = -1;
    try {
        aSequence = (SDOSequence) root.getSequence(aPOProperty);
    } catch (SDOException e) {
        exceptionThrown = true;
        errorCode = e.getErrorCode();
    } finally {
        assertTrue(exceptionThrown);
        assertNull(aSequence);
        assertEquals(45022, errorCode);
    }
}
Also used : SDOException(org.eclipse.persistence.exceptions.SDOException) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Example 17 with SDOSequence

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

the class SDOSequenceTestXSD method test_getValue_whereIndexIsOutOfBounds.

public void test_getValue_whereIndexIsOutOfBounds() {
    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.getValue(-1);
        } catch (IndexOutOfBoundsException e) {
            exceptionThrown = true;
        } finally {
            assertTrue(exceptionThrown);
        }
*/
}
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 18 with SDOSequence

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

the class SDOSequenceTestXSD method testAddSimpleManyByDataObjectSetPropertyWithListOnExistingList.

public void testAddSimpleManyByDataObjectSetPropertyWithListOnExistingList() {
    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("comment")).size();
    assertEquals(PO_COMMENT_LIST_SIZE, listSizeBefore);
    int indexToPlaceAtEnd = aSequence.size();
    Property commentProperty = po.getInstanceProperty("comment");
    // add list of items to sequence
    List<String> aListToAdd = new ArrayList<String>();
    aListToAdd.add("comment 2");
    aListToAdd.add("comment 3");
    aSequence.add(indexToPlaceAtEnd, commentProperty, aListToAdd);
    // get back new Setting value
    String comment2Value = (String) aSequence.getValue(indexToPlaceAtEnd);
    assertNotNull(comment2Value);
    assertEquals(comment2Value, aListToAdd.get(0));
    assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
    // check increased size of sequence for simple type
    assertEquals(PO_SEQUENCE_TREE_SIZE + aListToAdd.size(), aSequence.size());
    // verify that the list has increased
    int listSizeAfter = ((ListWrapper) po.get("comment")).size();
    assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
    // verify that DataObject has changed but not the # of dataObjects
    int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
    assertEquals(treeSizeBeforeAdd + 0, 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 19 with SDOSequence

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

the class SDOSequenceTestXSD method testAddComplexManyByListWrapperAddPropertyOnExistingList.

public void testAddComplexManyByListWrapperAddPropertyOnExistingList() {
    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);
    for (Iterator<DataObject> i = aListToAdd.iterator(); i.hasNext(); ) {
        // add to the end of the list
        existingList.add(i.next());
    }
    // 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 20 with SDOSequence

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

the class SDOSequenceTestCS method test_booleanReturnFrom_add_int_Object.

/**
 * Adds a new entry with the specified property index and value
 * to the end of the entries.
 * @param propertyIndex the index of the entry's property.
 * @param value the value for the entry.
 */
public void test_booleanReturnFrom_add_int_Object() {
    // int propertyIndex, 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);
    // get "item" property index
    int propIndex = 0;
    for (Iterator i = po.getInstanceProperties().iterator(); i.hasNext(); ) {
        Property aProperty = (Property) i.next();
        if (aProperty != null && aProperty.getName().equals("item")) {
            break;
        } else {
            propIndex++;
        }
    }
    // add to sequence
    aSequence.add(propIndex, 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_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) Iterator(java.util.Iterator) 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)

Aggregations

SDOSequence (org.eclipse.persistence.sdo.SDOSequence)211 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)178 DataObject (commonj.sdo.DataObject)176 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)93 Property (commonj.sdo.Property)75 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)73 ArrayList (java.util.ArrayList)46 SDOException (org.eclipse.persistence.exceptions.SDOException)37 Sequence (commonj.sdo.Sequence)15 List (java.util.List)10 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)8 Iterator (java.util.Iterator)7 ChangeSummary (commonj.sdo.ChangeSummary)6 SDOType (org.eclipse.persistence.sdo.SDOType)4 Map (java.util.Map)2 TypeHelper (commonj.sdo.helper.TypeHelper)1 HashMap (java.util.HashMap)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)1 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)1