Search in sources :

Example 16 with DefaultSchemaLocationResolver

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

the class SDODataGraphDataObjectBackPointerTest method testUnsetDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS.

public void testUnsetDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    String generatedSchema = ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // log(generatedSchema);
    // aDataObject.getType());
    dataGraph.createRootObject(URINAME, COMPANY_TYPENAME);
    DataObject aWrappedDO = dataGraph.getRootObject();
    assertNotNull(aWrappedDO);
    // TODO
    assertEquals(aWrappedDO.getType(), dataGraph.getType(URINAME, COMPANY_TYPENAME));
    DataObject dgDO = populateRootDataGraphDataObject(dataGraph.getRootObject(), types);
    ListWrapper pOrders = (ListWrapper) dgDO.getList(PO_PATH);
    int poSize = pOrders.size();
    assertEquals(1, poSize);
    // Delete DO
    DataObject detachedDO = (DataObject) pOrders.get(0);
    dgDO.unset(PO_PATH + "[1]");
    ListWrapper pOrdersDGList = (ListWrapper) dgDO.getList(PO_PATH);
    int poSizeDG = pOrdersDGList.size();
    assertEquals(poSize - 1, poSizeDG);
    assertEquals(null, detachedDO.getDataGraph());
    DataObject copyPOshipTo = (DataObject) detachedDO.get("shipTo");
    DataObject copyPObillTo = (DataObject) detachedDO.get("billTo");
    DataObject copyPOitem1 = (DataObject) detachedDO.get("item[1]");
    DataObject copyPOitem2 = (DataObject) detachedDO.get("item[2]");
    /*
        // Check dataGraph back pointers recursively (containment only)
        List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(detachedDO);
        assertNotNull(copyPreOrderList);
        assertEquals(5, copyPreOrderList.size());
        copyPreOrderList.contains(copyPOshipTo);
        copyPreOrderList.contains(copyPObillTo);
        copyPreOrderList.contains(copyPOitem1);
        copyPreOrderList.contains(copyPOitem2);
*/
    assertNull(copyPOshipTo.getDataGraph());
    assertNull(copyPObillTo.getDataGraph());
    /**
     * item property is unidirectional or containment=false - therefore not in the dataGraph.
     * However, if the item also has a containment=true reference to itself then it does reference the dataGraph
     */
    assertNull(copyPOitem1.getDataGraph());
    assertNull(copyPOitem2.getDataGraph());
    // Check that the CS is not set on all nodes including non-containment ones
    assertNull(copyPOitem1.getChangeSummary());
}
Also used : Type(commonj.sdo.Type) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) QName(javax.xml.namespace.QName) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper)

Example 17 with DefaultSchemaLocationResolver

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

the class SDODataGraphDataObjectBackPointerTest method testDeleteDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS.

public void testDeleteDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // log(generatedSchema);
    // aDataObject.getType());
    dataGraph.createRootObject(URINAME, COMPANY_TYPENAME);
    DataObject aWrappedDO = dataGraph.getRootObject();
    assertNotNull(aWrappedDO);
    // TODO
    assertEquals(aWrappedDO.getType(), dataGraph.getType(URINAME, COMPANY_TYPENAME));
    DataObject dgDO = populateRootDataGraphDataObject(dataGraph.getRootObject(), types);
    ListWrapper pOrders = (ListWrapper) dgDO.getList(PO_PATH);
    int poSize = pOrders.size();
    assertEquals(1, poSize);
    // save objects before they are split apart
    DataObject detachedDO = (DataObject) pOrders.get(0);
    DataObject copyPOshipTo = (DataObject) detachedDO.get("shipTo");
    DataObject copyPObillTo = (DataObject) detachedDO.get("billTo");
    DataObject copyPOitem1 = (DataObject) detachedDO.get("item[1]");
    DataObject copyPOitem2 = (DataObject) detachedDO.get("item[2]");
    // Delete DO
    detachedDO.delete();
    ListWrapper pOrdersDGList = (ListWrapper) dgDO.getList(PO_PATH);
    int poSizeDG = pOrdersDGList.size();
    assertEquals(poSize - 1, poSizeDG);
    assertEquals(null, detachedDO.getDataGraph());
    /*
        // Check dataGraph back pointers recursively (containment only)
        List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(detachedDO);
        assertNotNull(copyPreOrderList);
        assertEquals(5, copyPreOrderList.size());
        copyPreOrderList.contains(copyPOshipTo);
        copyPreOrderList.contains(copyPObillTo);
        copyPreOrderList.contains(copyPOitem1);
        copyPreOrderList.contains(copyPOitem2);
*/
    assertNull(copyPOshipTo.getDataGraph());
    assertNull(copyPObillTo.getDataGraph());
    /**
     * item property is unidirectional or containment=false - therefore not in the dataGraph.
     * However, if the item also has a containment=true reference to itself then it does reference the dataGraph
     */
    assertNull(copyPOitem1.getDataGraph());
    assertNull(copyPOitem2.getDataGraph());
    // Check that the CS is not set on all nodes including non-containment ones
    assertNull(copyPOitem1.getChangeSummary());
}
Also used : Type(commonj.sdo.Type) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) QName(javax.xml.namespace.QName) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper)

Example 18 with DefaultSchemaLocationResolver

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

the class SDODataGraphDataObjectBackPointerTest method testDetachDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS.

public void testDetachDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    String generatedSchema = ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // log(generatedSchema);
    // aDataObject.getType());
    dataGraph.createRootObject(URINAME, COMPANY_TYPENAME);
    DataObject aWrappedDO = dataGraph.getRootObject();
    assertNotNull(aWrappedDO);
    // TODO
    assertEquals(aWrappedDO.getType(), dataGraph.getType(URINAME, COMPANY_TYPENAME));
    DataObject dgDO = populateRootDataGraphDataObject(dataGraph.getRootObject(), types);
    ListWrapper pOrders = (ListWrapper) dgDO.getList(PO_PATH);
    int poSize = pOrders.size();
    assertEquals(1, poSize);
    // Detach DO
    DataObject detachedDO = (DataObject) pOrders.get(0);
    detachedDO.detach();
    ListWrapper pOrdersDGList = (ListWrapper) dgDO.getList(PO_PATH);
    int poSizeDG = pOrdersDGList.size();
    assertEquals(poSize - 1, poSizeDG);
    assertEquals(null, detachedDO.getDataGraph());
    DataObject copyPOshipTo = (DataObject) detachedDO.get("shipTo");
    DataObject copyPObillTo = (DataObject) detachedDO.get("billTo");
    DataObject copyPOitem1 = (DataObject) detachedDO.get("item[1]");
    DataObject copyPOitem2 = (DataObject) detachedDO.get("item[2]");
    /*
        // Check dataGraph back pointers recursively (containment only)
        List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(detachedDO);
        assertNotNull(copyPreOrderList);
        assertEquals(5, copyPreOrderList.size());
        copyPreOrderList.contains(copyPOshipTo);
        copyPreOrderList.contains(copyPObillTo);
        copyPreOrderList.contains(copyPOitem1);
        copyPreOrderList.contains(copyPOitem2);
*/
    assertNull(copyPOshipTo.getDataGraph());
    assertNull(copyPObillTo.getDataGraph());
    /**
     * item property is unidirectional or containment=false - therefore not in the dataGraph.
     * However, if the item also has a containment=true reference to itself then it does reference the dataGraph
     */
    assertNull(copyPOitem1.getDataGraph());
    assertNull(copyPOitem2.getDataGraph());
    // Check that the CS is not set on all nodes including non-containment ones
    assertNull(copyPOitem1.getChangeSummary());
}
Also used : Type(commonj.sdo.Type) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) QName(javax.xml.namespace.QName) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper)

Example 19 with DefaultSchemaLocationResolver

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

the class SDODataGraphDataObjectBackPointerTest method testAddDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS.

public void testAddDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // log(generatedSchema);
    DataObject aDataObject = createRootObject(types);
    dataGraph.createRootObject(aDataObject.getType());
    DataObject aWrappedDO = dataGraph.getRootObject();
    assertNotNull(aWrappedDO);
    assertEquals(aWrappedDO.getType(), dataGraph.getType(URINAME, COMPANY_TYPENAME));
    DataObject dgDO = dataGraph.getRootObject();
    ListWrapper pOrders = (ListWrapper) aDataObject.getList(PO_PATH);
    int poSize = pOrders.size();
    assertEquals(1, poSize);
    // Create detached DO
    DataObject copyPO = (DataObject) pOrders.get(0);
    // Create a new ListWrapper and set it on the DG DO
    List<DataObject> aList = new ArrayList<DataObject>();
    aList.add(copyPO);
    // Add DO to DG-DO - there is no existing elements
    dgDO.set("porder", aList);
    ListWrapper pOrdersDGList = (ListWrapper) dgDO.getList(PO_PATH);
    int poSizeDG = pOrdersDGList.size();
    // or
    // pOrdersDGList.add(copyPO);
    assertEquals(poSize, poSizeDG);
    assertEquals(dataGraph, copyPO.getDataGraph());
    DataObject copyPOshipTo = (DataObject) copyPO.get("shipTo");
    DataObject copyPObillTo = (DataObject) copyPO.get("billTo");
    DataObject copyPOitem1 = (DataObject) copyPO.get("item[1]");
    DataObject copyPOitem2 = (DataObject) copyPO.get("item[2]");
    // Check dataGraph back pointers recursively (containment only)
    List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(copyPO);
    assertNotNull(copyPreOrderList);
    assertEquals(5, copyPreOrderList.size());
    copyPreOrderList.contains(copyPOshipTo);
    copyPreOrderList.contains(copyPObillTo);
    copyPreOrderList.contains(copyPOitem1);
    copyPreOrderList.contains(copyPOitem2);
    // for(DataObject aDO : copyPreOrderList) {
    // assertEquals(dataGraph, aDO.getDataGraph()); // Check containment=true|false nodes
    // }
    assertNotNull(copyPOshipTo.getDataGraph());
    assertNotNull(copyPObillTo.getDataGraph());
    // item property is unidirectional or containment=false - still in the dataGraph in this case
    assertNotNull(copyPOitem1.getDataGraph());
    assertNotNull(copyPOitem2.getDataGraph());
    // Check that the CS is set on all nodes including non-containment ones
    assertNotNull(copyPOitem1.getChangeSummary());
}
Also used : Type(commonj.sdo.Type) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper)

Aggregations

DefaultSchemaLocationResolver (org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver)19 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)19 Type (commonj.sdo.Type)11 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)11 DataObject (commonj.sdo.DataObject)7 StringReader (java.io.StringReader)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 QName (javax.xml.namespace.QName)7 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)7 Document (org.w3c.dom.Document)7 InputSource (org.xml.sax.InputSource)7 SDOType (org.eclipse.persistence.sdo.SDOType)4 InputStream (java.io.InputStream)3 DataGraph (commonj.sdo.DataGraph)2 FileInputStream (java.io.FileInputStream)2 SDODataGraph (org.eclipse.persistence.sdo.SDODataGraph)2 Property (commonj.sdo.Property)1 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)1