Search in sources :

Example 96 with SDODataObject

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

the class SDOTypeHelperAppInfoTestCases method testAppInfoElements.

/**
 * Tests setting appinfo elements on a Type and Property via
 * dataObject.set(Property, Object) API.
 *
 * Positive test.
 */
public void testAppInfoElements() {
    List<Element> aieList = new ArrayList<Element>();
    aieList.add(aiElement);
    List<Element> aiePropList = new ArrayList<Element>();
    aiePropList.add(aiElementProp);
    // create the data object
    SDODataObject dataObject = (SDODataObject) dataFactory.create(sdoTypeType);
    dataObject.set(NAME, MYDO);
    dataObject.set(URI, MYURI);
    dataObject.set(SDOConstants.APPINFO_PROPERTY, aieList);
    // create a property
    SDODataObject prop = (SDODataObject) dataObject.createDataObject(PROPERTY);
    prop.set(NAME, MYPROP);
    prop.set(TYPE, SDOConstants.SDO_STRING);
    prop.set(SDOConstants.APPINFO_PROPERTY, aiePropList);
    // create the type
    SDOType newType = (SDOType) typeHelper.define(dataObject);
    // ======
    // DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    // List<Object> types = new ArrayList<Object>();
    // types.add(newType);
    // String generatedSchema = ((SDOXSDHelper)xsdHelper).generate(types, resolver);
    // System.out.println(generatedSchema);
    // ======
    // validate that AppInfoElements were handled correctly on Type and Property
    // Type
    assertNotNull("Type [newType] is null", newType);
    assertTrue("Type does not have AppInfoElements set as expected", newType.getAppInfoElements() != null);
    assertTrue("Expected AppInfoElements list of size [1] on Type, but was [" + newType.getAppInfoElements().size() + "]", newType.getAppInfoElements().size() == 1);
    String val = ((Element) newType.getAppInfoElements().get(0)).getAttribute(SDOConstants.APPINFO_SOURCE_ATTRIBUTE);
    assertNotNull("AppInfoElement source on Type is empty/null", val != null && val.length() > 0);
    assertTrue("Expected AppInfoElement source [" + TYPE_APP_INFO + "] on Type but was [" + val + "]", val.equals(TYPE_APP_INFO));
    String appInfoString = xsdHelper.getAppinfo(newType, TYPE_APP_INFO);
    assertEquals("Expected getAppInfo() to return [" + TYPE_APP_INFO_STRING + "] but was [" + appInfoString + "]", TYPE_APP_INFO_STRING, appInfoString);
    // Property
    SDOProperty myProp = newType.getProperty(MYPROP);
    assertNotNull("Property [myProperty] is null", myProp);
    assertTrue("Property does not have AppInfoElements set as expected", myProp.getAppInfoElements() != null);
    assertTrue("Expected AppInfoElements list of size [1] on Property, but was [" + myProp.getAppInfoElements().size() + "]", myProp.getAppInfoElements().size() == 1);
    val = ((Element) myProp.getAppInfoElements().get(0)).getAttribute(SDOConstants.APPINFO_SOURCE_ATTRIBUTE);
    assertNotNull("AppInfoElement source on Property is empty/null", val != null && val.length() > 0);
    assertTrue("Expected AppInfoElement source [" + PROPERTY_APP_INFO + "] on Property but was [" + val + "]", val.equals(PROPERTY_APP_INFO));
    appInfoString = xsdHelper.getAppinfo(myProp, PROPERTY_APP_INFO);
    assertEquals("Expected getAppInfo() to return [" + PROPERTY_APP_INFO_STRING + "] but was [" + appInfoString + "]", PROPERTY_APP_INFO_STRING, appInfoString);
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) SDOType(org.eclipse.persistence.sdo.SDOType) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 97 with SDODataObject

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

the class ChangeSummaryVolumetricsTest method setUp.

@Override
public void setUp() {
    super.setUp();
    SDOType changeSummaryType = (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);
    SDOType dataObjectType = (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.DATAOBJECT);
    DataObject rootTypeDO = defineType(URINAME, TYPENAME);
    rootType = (SDOType) typeHelper.define(rootTypeDO);
    rootContainingPropertyB = setUpProperty("propertyA-B", true, dataObjectType, rootType);
    rootContainingPropertyC = setUpProperty("propertyA-C", true, dataObjectType, rootType);
    rootChangeSummaryProperty = setUpProperty("changeSummaryA", false, changeSummaryType, null);
    root = (SDODataObject) dataFactory.create(rootType);
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) SDOType(org.eclipse.persistence.sdo.SDOType)

Example 98 with SDODataObject

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

the class ChangeSummaryVolumetricsTest method buildDeepTree.

/*
     * root
     *   -> B
     *        -> CS-B
     *        -> D (String)
     *   -> C
     *        -> CS-C
     */
protected void buildDeepTree() {
    SDOType changeSummaryType = (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);
    SDOType dataObjectType = (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.DATAOBJECT);
    DataObject type_BDO = defineType("B_uri", "B");
    DataObject propertyBDO = addProperty(type_BDO, "propertyB", dataObjectType);
    propertyBDO.set("containment", true);
    type_B = (SDOType) typeHelper.define(type_BDO);
    propertyB = (SDOProperty) type_B.getDeclaredPropertiesMap().get("propertyB");
    changeSummaryPropertyB = setUpProperty("changeSummaryB", false, changeSummaryType, type_B);
    DataObject type_CDO = defineType("C_uri", "C");
    DataObject propertyCDO = addProperty(type_CDO, "propertyC", dataObjectType);
    propertyBDO.set("containment", true);
    type_C = (SDOType) typeHelper.define(type_CDO);
    propertyC = (SDOProperty) type_C.getDeclaredPropertiesMap().get("propertyC");
    changeSummaryPropertyC = setUpProperty("changeSummaryC", false, changeSummaryType, type_C);
    typeB_children = new SDOType[NUM_B_LEVELS];
    propertyB_children = new SDOProperty[NUM_B_LEVELS];
    dataObjectB_children = new SDODataObject[NUM_B_LEVELS];
    dataObjectB = root.createDataObject(rootContainingPropertyB, type_B);
    dataObjectC = root.createDataObject(rootContainingPropertyC, type_C);
    // setup object array
    for (int i = 0; i < NUM_B_LEVELS; i++) {
        DataObject typeB_childreniDO = defineType("D_uri" + i, "D" + i);
        DataObject propDo = addProperty(typeB_childreniDO, "propertyD" + i, dataObjectType);
        propDo.set("containment", true);
        typeB_children[i] = (SDOType) typeHelper.define(typeB_childreniDO);
        propertyB_children[i] = (SDOProperty) typeB_children[i].getDeclaredPropertiesMap().get("propertyD" + i);
    }
    dataObjectB_children[0] = dataObjectB.createDataObject(propertyB, typeB_children[0]);
    for (int i = 1; i < NUM_B_LEVELS; i++) {
        dataObjectB_children[i] = dataObjectB_children[i - 1].createDataObject(propertyB_children[i - 1], typeB_children[i]);
    }
// dataObjectD = (SDODataObject)dataObjectB.createDataObject(propertyB, type_D);
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) SDOType(org.eclipse.persistence.sdo.SDOType)

Example 99 with SDODataObject

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

the class ChangeSummaryBeginLoggingEndLoggingIsLoggingTest method testOldContainerContainmentPropertyOldSettingListAfterBeginLogging.

/**
 * recursively check if old containers and old containment properties are set properly;
 * @param o    the DataObject to be checked
 */
private void testOldContainerContainmentPropertyOldSettingListAfterBeginLogging(SDODataObject o) {
    /*
         * 20060710
         * This testcase has been modified because the getOld* functions have moved to their
         * changeSummary counterparts and may not directly return the actual instance variable
         * when not in deleted | modified state
         */
    SDODataObject anOldContainer = o.getChangeSummary().getOldContainer(o);
    SDODataObject aContainer = o.getContainer();
    if (o.getChangeSummary().isModified(o) || o.getChangeSummary().isDeleted(o)) {
        assertEquals(anOldContainer, aContainer);
        if (aContainer != null) {
            Property pp = o.getContainer().getInstanceProperty(o._getContainmentPropertyName());
            assertEquals(o.getChangeSummary().getOldContainmentProperty(o), pp);
        }
    }
    assertNotNull(o.getChangeSummary().getOldValues(o));
    assertTrue(o.getChangeSummary().getOldValues(o).isEmpty());
    List properties = o.getInstanceProperties();
    Iterator iterProperties = properties.iterator();
    while (iterProperties.hasNext()) {
        Property p = (Property) iterProperties.next();
        Object v = o.get(p);
        if (v instanceof SDODataObject) {
            testOldContainerContainmentPropertyOldSettingListAfterBeginLogging(((SDODataObject) v));
        }
    }
}
Also used : Iterator(java.util.Iterator) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) Property(commonj.sdo.Property) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 100 with SDODataObject

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

the class ChangeSummaryCreatedModifiedDeletedTests method testIsCreatedAfterUseDataFactory.

public void testIsCreatedAfterUseDataFactory() {
    rootType.addDeclaredProperty(rootChangeSummaryProperty);
    root = (SDODataObject) dataFactory.create(rootType);
    changeSummaryA = root.getChangeSummary();
    buildTreeWithoutChildChangeSummaries();
    changeSummaryA.beginLogging();
    assertUnchanged(root, changeSummaryA);
    assertUnchanged(dataObjectB, changeSummaryA);
    assertUnchanged(dataObjectC, changeSummaryA);
    assertUnchanged(dataObjectD, changeSummaryA);
    SDOType type_E = new SDOType("EURI", "E");
    SDODataObject dataObjectE = (SDODataObject) dataFactory.create(type_E);
    dataObjectC.set(propertyC, dataObjectE);
    assertUnchanged(root, changeSummaryA);
    assertUnchanged(dataObjectB, changeSummaryA);
    assertModified(dataObjectC, changeSummaryA);
    assertUnchanged(dataObjectD, changeSummaryA);
    assertCreated(dataObjectE, changeSummaryA);
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Aggregations

SDODataObject (org.eclipse.persistence.sdo.SDODataObject)301 DataObject (commonj.sdo.DataObject)118 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)99 ArrayList (java.util.ArrayList)79 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)76 SDOType (org.eclipse.persistence.sdo.SDOType)70 List (java.util.List)65 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)64 Property (commonj.sdo.Property)52 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)51 ValueStore (org.eclipse.persistence.sdo.ValueStore)22 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)21 ChangeSummary (commonj.sdo.ChangeSummary)20 SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)20 Iterator (java.util.Iterator)18 Type (commonj.sdo.Type)9 XMLDocument (commonj.sdo.helper.XMLDocument)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)5 Map (java.util.Map)5