Search in sources :

Example 1 with DataGraph

use of commonj.sdo.DataGraph in project eclipselink by eclipse-ee4j.

the class SDODataGraphDataObjectBackPointerTest method testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithoutCS.

// This function will exercise the updateDataGraph() function on SDODataObject.updateContainment()
public void testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithoutCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // Create target
    DataObject aDataObjectTarget = createRootObject(types);
    DataGraph aDataGraphTarget = dataGraph;
    aDataGraphTarget.createRootObject(aDataObjectTarget.getType());
    DataObject targetRoot = aDataGraphTarget.getRootObject();
    // Check it
    assertNotNull(targetRoot);
    assertEquals(targetRoot.getType(), aDataGraphTarget.getType(URINAME, COMPANY_TYPENAME));
    ListWrapper pOrdersTarget = (ListWrapper) targetRoot.getList(PO_PATH);
    int poSize = pOrdersTarget.size();
    assertEquals(0, poSize);
    // Create source
    DataObject aDataObjectSource = createRootObject(types);
    DataGraph aDataGraphSource = new SDODataGraph(aHelperContext);
    aDataGraphSource.createRootObject(aDataObjectSource.getType());
    DataObject sourceRoot = aDataGraphSource.getRootObject();
    // Check it
    assertNotNull(sourceRoot);
    assertEquals(sourceRoot.getType(), aDataGraphSource.getType(URINAME, COMPANY_TYPENAME));
    ListWrapper pOrdersSource = (ListWrapper) aDataObjectSource.getList(PO_PATH);
    int poSizeSource = pOrdersSource.size();
    assertEquals(1, poSizeSource);
    // Clear the target CS so that we enter only the DataGraph recursive loop
    ((SDODataObject) targetRoot)._setChangeSummary(null);
    // Get source DO
    DataObject sourcePO = (DataObject) pOrdersSource.get(0);
    // DataGraph should be null before set
    assertNull(sourcePO.getDataGraph());
    // Move the root object from one null data graph to the other
    pOrdersTarget.add(sourcePO);
    // DataGraph should be not be null before set
    assertNotNull(sourcePO.getDataGraph());
    // Target dataGraph should be set on all children
    assertEquals(aDataGraphTarget, sourcePO.getDataGraph());
    DataObject copyPOshipTo = (DataObject) sourcePO.get("shipTo");
    DataObject copyPObillTo = (DataObject) sourcePO.get("billTo");
    DataObject copyPOitem1 = (DataObject) sourcePO.get("item[1]");
    DataObject copyPOitem2 = (DataObject) sourcePO.get("item[2]");
    // Check dataGraph back pointers recursively (containment only)
    List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(sourcePO);
    assertNotNull(copyPreOrderList);
    assertEquals(5, copyPreOrderList.size());
    copyPreOrderList.contains(copyPOshipTo);
    copyPreOrderList.contains(copyPObillTo);
    copyPreOrderList.contains(copyPOitem1);
    copyPreOrderList.contains(copyPOitem2);
    assertNotNull(copyPOshipTo.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOshipTo.getDataGraph());
    assertNotNull(copyPObillTo.getDataGraph());
    assertEquals(aDataGraphTarget, copyPObillTo.getDataGraph());
    // item property is unidirectional or containment=false - still in the dataGraph in this case
    assertNotNull(copyPOitem1.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOitem1.getDataGraph());
    assertNotNull(copyPOitem2.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOitem2.getDataGraph());
}
Also used : QName(javax.xml.namespace.QName) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) Type(commonj.sdo.Type) DataGraph(commonj.sdo.DataGraph) SDODataGraph(org.eclipse.persistence.sdo.SDODataGraph) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) SDODataGraph(org.eclipse.persistence.sdo.SDODataGraph) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 2 with DataGraph

use of commonj.sdo.DataGraph in project eclipselink by eclipse-ee4j.

the class SDODataObject method detachDeleteRecursivePrivate.

/**
 * INTERNAL:
 * Recursively walk the tree and set oldSettings for a detached/deleted object.
 * @param fromDelete
 * @param clearCS (true = clear the cs field) = !(is root of the detach/delete subtree the CS root?)
 * @param isRootOfRecursiveLoop (are we at the root of the detach/delete or inside the subtree)
 */
private void detachDeleteRecursivePrivate(boolean fromDelete, boolean clearCS, boolean isRootOfRecursiveLoop) {
    // Store flag for (is root of the detach/delete subtree the CS root?) before we modify it when this object has no container
    boolean subTreeRootHasCStoClear = clearCS;
    if (null == getContainer()) {
        clearCS = false;
    }
    if (isRootOfRecursiveLoop || fromDelete) {
        if (null != getContainer()) {
            getContainer()._setModified(true);
            _setContainer(null);
            _setContainmentPropertyName(null);
        }
    }
    _setDeleted(true);
    /**
     * Order here is important - the dataGraph pointer should be cleared preorder before we enter the recursive loop to clear child DO's
     */
    DataGraph previousDataGraph = getDataGraph();
    // Remove back pointer to containing DataGraph
    setDataGraph(null);
    List instancePropertiesList = getInstanceProperties();
    for (int i = 0, psize = instancePropertiesList.size(); i < psize; i++) {
        SDOProperty nextProperty = (SDOProperty) instancePropertiesList.get(i);
        Object oldValue = get(nextProperty);
        if (!nextProperty.getType().isChangeSummaryType()) {
            // Non-containment nodes have changeSummary and dataGraph pointers if they were in a dataGraph
            if (nextProperty.isContainment() || isContainedByDataGraph(previousDataGraph, nextProperty)) {
                if (nextProperty.isMany()) {
                    Object manyItem;
                    for (int j = 0, lsize = ((List) oldValue).size(); j < lsize; j++) {
                        manyItem = ((List) oldValue).get(j);
                        detachDeleteRecursivePrivateHelper((SDODataObject) manyItem, fromDelete, clearCS);
                    }
                } else {
                    detachDeleteRecursivePrivateHelper((SDODataObject) oldValue, fromDelete, clearCS);
                }
            }
            if (fromDelete && !nextProperty.isReadOnly()) {
                unset(nextProperty, fromDelete);
            }
        }
    }
    /**
     * Bug # 6202793
     * We delete the changeSummary field in the following use cases
     * in addition to when the clearCS field was passed in as or transformed to true.
     * Case 0: detach subtree root from root (with cs) = false
     * Case 1: detach subtree internal from root (with cs) = false
     * Case 2: delete subtree root from root (with cs) = false
     * Case 3: delete subtree internal from root (with cs) = true
     * Case 4: detach subtree root from root (without cs) = false
     * Case 5: detach subtree internal from root (without cs) = false
     * Case 6: delete subtree root from root (without cs) = true
     * Case 7: delete subtree internal from root (without cs) = true
     */
    if (clearCS || subTreeRootHasCStoClear) {
        _setChangeSummary(null);
    }
}
Also used : DataGraph(commonj.sdo.DataGraph) ArrayList(java.util.ArrayList) List(java.util.List) DataObject(commonj.sdo.DataObject) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject)

Example 3 with DataGraph

use of commonj.sdo.DataGraph in project eclipselink by eclipse-ee4j.

the class SDODataGraphDataObjectBackPointerTest method testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithCS.

// This function will exercise the updateChangeSummaryAndDataGraph() function on SDODataObject.updateContainment()
public void testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // Create target
    DataObject aDataObjectTarget = createRootObject(types);
    DataGraph aDataGraphTarget = dataGraph;
    aDataGraphTarget.createRootObject(aDataObjectTarget.getType());
    DataObject targetRoot = aDataGraphTarget.getRootObject();
    // Check it
    assertNotNull(targetRoot);
    assertEquals(targetRoot.getType(), aDataGraphTarget.getType(URINAME, COMPANY_TYPENAME));
    ListWrapper pOrdersTarget = (ListWrapper) targetRoot.getList(PO_PATH);
    int poSize = pOrdersTarget.size();
    assertEquals(0, poSize);
    // Add a porder (null DG source)
    // Create source
    DataObject aDataObjectSource = createRootObject(types);
    DataGraph aDataGraphSource = new SDODataGraph(aHelperContext);
    aDataGraphSource.createRootObject(aDataObjectSource.getType());
    DataObject sourceRoot = aDataGraphSource.getRootObject();
    // Check it
    assertNotNull(sourceRoot);
    assertEquals(sourceRoot.getType(), aDataGraphSource.getType(URINAME, COMPANY_TYPENAME));
    ListWrapper pOrdersSource = (ListWrapper) aDataObjectSource.getList(PO_PATH);
    int poSizeSource = pOrdersSource.size();
    assertEquals(1, poSizeSource);
    // Get source DO
    DataObject sourcePO = (DataObject) pOrdersSource.get(0);
    // DataGraph should be null before set
    assertNull(sourcePO.getDataGraph());
    // Move the root object from one null data graph to the other
    pOrdersTarget.add(sourcePO);
    // DataGraph should be not be null before set
    assertNotNull(sourcePO.getDataGraph());
    // Target dataGraph should be set on all children
    assertEquals(aDataGraphTarget, sourcePO.getDataGraph());
    DataObject copyPOshipTo = (DataObject) sourcePO.get("shipTo");
    DataObject copyPObillTo = (DataObject) sourcePO.get("billTo");
    DataObject copyPOitem1 = (DataObject) sourcePO.get("item[1]");
    DataObject copyPOitem2 = (DataObject) sourcePO.get("item[2]");
    // Check dataGraph back pointers recursively (containment only)
    List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(sourcePO);
    assertNotNull(copyPreOrderList);
    assertEquals(5, copyPreOrderList.size());
    copyPreOrderList.contains(copyPOshipTo);
    copyPreOrderList.contains(copyPObillTo);
    copyPreOrderList.contains(copyPOitem1);
    copyPreOrderList.contains(copyPOitem2);
    assertNotNull(copyPOshipTo.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOshipTo.getDataGraph());
    assertNotNull(copyPObillTo.getDataGraph());
    assertEquals(aDataGraphTarget, copyPObillTo.getDataGraph());
    // item property is unidirectional or containment=false - still in the dataGraph in this case
    assertNotNull(copyPOitem1.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOitem1.getDataGraph());
    assertNotNull(copyPOitem2.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOitem2.getDataGraph());
}
Also used : QName(javax.xml.namespace.QName) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) Type(commonj.sdo.Type) DataGraph(commonj.sdo.DataGraph) SDODataGraph(org.eclipse.persistence.sdo.SDODataGraph) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) SDODataGraph(org.eclipse.persistence.sdo.SDODataGraph)

Aggregations

DataGraph (commonj.sdo.DataGraph)3 DataObject (commonj.sdo.DataObject)3 Type (commonj.sdo.Type)2 QName (javax.xml.namespace.QName)2 SDODataGraph (org.eclipse.persistence.sdo.SDODataGraph)2 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)2 DefaultSchemaLocationResolver (org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver)2 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)2 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)1