Search in sources :

Example 41 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_outofbounds.

public void test_voidReturnFrom_add_int_Property_Object_outofbounds() {
    // 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 itemProperty = po.getInstanceProperty("item");
    // add to sequence
    try {
        aSequence.add(-1, itemProperty, item2);
    } catch (Exception e) {
    }
    boolean exceptionThrown = false;
    // get back new Setting value
    ListWrapper item2Value = null;
    try {
        item2Value = (ListWrapper) aSequence.getValue(indexToPlaceAtEnd);
    } catch (SDOException e) {
        assertEquals(SDOException.INVALID_INDEX, e.getErrorCode());
        exceptionThrown = true;
    }
    assertNull(item2Value);
    assertTrue(exceptionThrown);
/*        assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
        // check increased size of sequence didnt happen
        assertEquals(PO_SEQUENCE_SIZE, aSequence.size());

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

        // verify that DataObject has not changed
        int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
        assertEquals(treeSizeBeforeAdd, treeSizeAfterAdd);
*/
}
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)

Example 42 with ListWrapper

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

the class SDOCopyHelperDeepCopyTest method testUC0312DeepCopy1_nBidirectionalPropInsideCopyTreeCopiedContTreeSameAsCopyTree2ndNodeIsMany.

// bidirectional property target is cached during containment iteration
public void testUC0312DeepCopy1_nBidirectionalPropInsideCopyTreeCopiedContTreeSameAsCopyTree2ndNodeIsMany() {
    // set containment so that the bidirectional target is cached
    rootWorkm.setContainment(true);
    // create copy of the root
    SDODataObject copy = (SDODataObject) ((SDOCopyHelper) copyHelper).copy(rootUC4m, getChangeSummary());
    // verify that container is null
    assertNull(copy.getContainer());
    // get bidirectional node from the copy root (direction 1)
    ListWrapper bidirCopyViaCopyRoot = (ListWrapper) // 
    copy.get("rootHome/homeAddress/addressWork");
    assertNotNull(bidirCopyViaCopyRoot);
    // get bidirectional start node via opposite property
    SDODataObject bidirCopyStart = (SDODataObject) // 
    copy.get("rootHome/homeAddress");
    assertNotNull(bidirCopyStart);
    // verify changeSummary is set on opposites
    // ChangeSummary aCS2 = bidirCopyStart.getChangeSummary();
    // assertNotNull(aCS2);
    // get property containing opposite property link (inside copy tree)
    SDOProperty bidirCopyOppositeStartProp = // 
    bidirCopyStart.getType().getProperty("addressWork");
    assertNotNull(bidirCopyOppositeStartProp);
    // Spec 8.4 "Properties that are bi-directional require type.dataType=false"
    assertFalse(bidirCopyOppositeStartProp.getType().isDataType());
    // get bidir property inside copy tree
    SDOProperty oppositeEndProp = ((SDODataObject) // 
    copy.get("rootHome/homeAddress")).getType().getProperty(// .getOpposite();
    "addressWork");
    assertNotNull(oppositeEndProp);
    // Spec 8.4 "Properties that are bi-directional require type.dataType=false"
    assertFalse(oppositeEndProp.getType().isDataType());
    // get opposite DO (direction 2)
    SDODataObject bidirCopyViaOppositeDO = (SDODataObject) // 
    copy.get("rootWork/workAddress");
    // assertNotNull(bidirCopyViaOppositeDO);
    // verify changeSummary is set on opposites
    // ChangeSummary aCS1 = bidirCopyViaOppositeDO.getChangeSummary();
    // assertNotNull(aCS1);
    // Constraint C3 - Spec 3.9.4
    // verify there are no object pointers between source and copy (all objects are instance independent)
    // ie: a' != a  - or there are no references to "root" from "copy"
    assertNotSame(// 
    rootUC4m.get("rootHome/homeAddress"), copy.get("rootHome/homeAddress"));
    // verify isMany objects are distinct
    ListWrapper do1 = (ListWrapper) rootUC4m.get("rootWork");
    ListWrapper do2 = (ListWrapper) copy.get("rootWork");
    // verify we are not just getting back empty lists for a null object lookup
    assertTrue(do1.size() > 0);
    assertTrue(do2.size() > 0);
    // verify lists are different (shallow check)
    assertNotSame(do1, do2);
    // verify list elements are different (deep check)
    assertNotNull(do1.get(0));
    assertNotNull(do2.get(0));
    assertFalse(do1.get(0) == do2.get(0));
    // assertNotSame((SDODataObject)rootUC4m.get(//
    // "rootHome/homeAddress/addressWork"),//
    // (SDODataObject)copy.get("//" +//
    // "rootHome/homeAddress/addressWork"));
    // Spec 8.4 "Properties that are bi-directional require that no more than one end has containment=true"
    assertFalse(areBothBidirectionalOppositePropertiesContainmentTrue(bidirCopyOppositeStartProp, bidirCopyOppositeStartProp.getOpposite()));
}
Also used : ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 43 with ListWrapper

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

the class ChangeSummaryXSDTestCases 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);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOSetting(org.eclipse.persistence.sdo.SDOSetting) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) ArrayList(java.util.ArrayList) List(java.util.List) ChangeSummary(commonj.sdo.ChangeSummary) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary)

Example 44 with ListWrapper

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

the class ChangeSummaryXSDQuoteDataTestCases method testUndoWithAdditionalModifications.

/**
 * Tests isModified and isDeleted states of two data objects and their
 * parent after:
 *   1) the data objects are detached from the parent
 *   2) one data object is re-attached to the parent in the same position in
 *   the original list
 */
public void testUndoWithAdditionalModifications() throws Exception {
    ListWrapper items = (ListWrapper) quoteDataDO.get("lineItem");
    ListWrapper relatedQuoteItems = (ListWrapper) quoteDataDO.get("relatedQuoteItem");
    cs.beginLogging();
    DataObject item = (DataObject) items.get(0);
    DataObject rqItem = (DataObject) relatedQuoteItems.get(0);
    // sanity check
    assertFalse(cs.isModified(quoteDataDO));
    assertFalse(cs.isDeleted(item));
    assertFalse(cs.isDeleted(rqItem));
    // detach item and rqItem from quoteDataDO
    item.detach();
    rqItem.detach();
    // re-add item back to the same position in quoteDataDO (undo detach)
    items.add(0, item);
    // after the undo op, item is not deleted, but the parent has been modified (rqItem was detached)
    assertTrue(cs.isModified(quoteDataDO));
    assertFalse(cs.isDeleted(item));
}
Also used : DataObject(commonj.sdo.DataObject) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper)

Example 45 with ListWrapper

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

the class ChangeSummaryXSDQuoteDataTestCases method testMultipleUndo.

/**
 * Tests isModified and isDeleted states of two data objects and their
 * parent after:
 *   1) the data objects are detached from the parent
 *   2) one data object is re-attached to the parent in the same position in
 *   the original list
 */
public void testMultipleUndo() throws Exception {
    ListWrapper items = (ListWrapper) quoteDataDO.get("lineItem");
    ListWrapper relatedQuoteItems = (ListWrapper) quoteDataDO.get("relatedQuoteItem");
    cs.beginLogging();
    DataObject item = (DataObject) items.get(0);
    DataObject rqItem = (DataObject) relatedQuoteItems.get(0);
    // sanity check
    assertFalse(cs.isModified(quoteDataDO));
    assertFalse(cs.isDeleted(item));
    assertFalse(cs.isDeleted(rqItem));
    // detach item and rqItem from quoteDataDO
    item.detach();
    rqItem.detach();
    // re-add item back to the same position in quoteDataDO (undo detach)
    items.add(0, item);
    // after the undo op, item is not deleted, but the parent has been modified (rqItem was detached)
    assertTrue(cs.isModified(quoteDataDO));
    assertFalse(cs.isDeleted(item));
    // re-add rqItem back to the same position in quoteDataDO (undo detach)
    relatedQuoteItems.add(0, rqItem);
    // after the undo op, rqItem is not deleted, and the parent is modified
    assertFalse(cs.isModified(quoteDataDO));
    assertFalse(cs.isDeleted(rqItem));
}
Also used : DataObject(commonj.sdo.DataObject) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper)

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