Search in sources :

Example 1 with SDOSetting

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

the class SDOTestCase method compareSequences.

/**
 * INTERNAL: Return whether the 2 sequences are equal. Element properties
 * and unstructured text will be compared - attributes are out of scope.
 * <p>
 * For shallow equal - only dataType=true objects are compared, DataObject
 * values are ignored but should be defaults. Note: A setting object should
 * handle its own isEqual() behavior
 */
public boolean compareSequences(SDOSequence aSequence, SDOSequence aSequenceCopy, boolean isDeep) {
    // sequence
    if (null == aSequence && null == aSequenceCopy) {
        return true;
    }
    // both sequences must be null
    if (null == aSequence || null == aSequenceCopy) {
        return false;
    }
    // value=null for shallow copies
    if (aSequence.size() != aSequenceCopy.size()) {
        return false;
    }
    // the settings inside the sequence must be new objects
    SDOSetting originalSetting = null;
    SDOSetting copySetting = null;
    List<? super Setting> originalSettingsList = aSequence.getSettings();
    List<? super Setting> copySettingsList = aSequenceCopy.getSettings();
    if (null == originalSettingsList || null == copySettingsList) {
        return false;
    }
    Property originalProperty = null;
    Property copyProperty = null;
    /**
     * For shallow equal when dataType is false we do not check this
     * setting, the value will be unset (default value) in the shallow copy.
     * orig v1=String v2=DataObject v3=String shallowcopy v1=String
     * v2=null(default) v3=String deepcopy v1=String v2=DataObject v3=String
     */
    for (int index = 0, size = aSequence.size(); index < size; index++) {
        originalSetting = (SDOSetting) originalSettingsList.get(index);
        copySetting = (SDOSetting) copySettingsList.get(index);
        originalProperty = originalSetting.getProperty();
        copyProperty = copySetting.getProperty();
        // both !null = valid state (check equality)
        if ((null == originalProperty && null != copyProperty) || (null != originalProperty && null == copyProperty)) {
            return false;
        }
        // handle both properties == null
        if (originalProperty != copyProperty) {
            return false;
        }
        Object originalValue = originalSetting.getValue();
        Object copyValue = copySetting.getValue();
        // check equality directly
        if (null == originalProperty || originalProperty.getType().isDataType()) {
            // if one of the values is null return false
            if (// 
            ((null == originalValue) && (null != copyValue)) || ((null != originalValue) && (null == copyValue))) {
                return false;
            }
            // we can also use !.equals
            if ((null != originalValue) && !originalValue.equals(copyValue)) {
                return false;
            }
        } else {
            // only compare DataObjects when in a deep equal
            if (isDeep) {
                if (null != originalValue && null != copyValue) {
                    // instead of a CCE
                    if (originalValue instanceof DataObject && copyValue instanceof DataObject) {
                        if (!equalityHelper.equal((DataObject) originalValue, (DataObject) copyValue)) {
                            return false;
                        }
                    } else {
                        return false;
                    }
                } else {
                    // both values must be null to be equal
                    if ((null == originalValue && null != copyValue) || (null == copyValue && null != originalValue)) {
                        return false;
                    }
                }
            } else {
            /**
             * For DataObjects in general anything that is deep equal is
             * also shallow equal - but not the reverse. In the case of
             * shallow equal on sequences. We can ignore the state of
             * the 2 complex objects. UC1: if aSequenceCopy setting was
             * from a shallowCopy then it will be unset. UC2: if
             * aSequenceCopy setting was from a deepCopy or a reversed
             * argument shallowCopy then it may be unset or set. We will
             * not check for a default value on either sequence setting.
             */
            }
        }
    }
    return true;
}
Also used : SDOSetting(org.eclipse.persistence.sdo.SDOSetting) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Example 2 with SDOSetting

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

the class ChangeSummaryRootLoggingOnModifyComplexAtCSLoadAndSaveTestCases method verifyAfterLoad.

@Override
protected void verifyAfterLoad(XMLDocument document) {
    super.verifyAfterLoad(document);
    ChangeSummary teamCS = document.getRootObject().getChangeSummary();
    assertNotNull(teamCS);
    DataObject manager = document.getRootObject().getDataObject("manager");
    assertNotNull(manager);
    assertTrue(teamCS.isLogging());
    assertTrue(teamCS.isLogging());
    assertFalse(teamCS.isCreated(manager));
    assertTrue(teamCS.isModified(manager));
    DataObject phone3 = manager.getDataObject("phone[3]");
    assertEquals("3456789", phone3.getString("number"));
    teamCS.isModified(phone3);
    List managersettings = teamCS.getOldValues(manager);
    // assertEquals(1, managersettings.size());
    SDOSetting nameSetting = (SDOSetting) teamCS.getOldValue(manager, manager.getInstanceProperty("name"));
    assertEquals("Old Name", nameSetting.getValue());
    List settings = teamCS.getOldValues(phone3);
    assertEquals(1, settings.size());
    SDOSetting firstSetting = (SDOSetting) settings.get(0);
    assertEquals("1111111", firstSetting.getValue());
// setting for number should have value 1111111
/*        DataObject address = manager.getDataObject("address");
        assertNotNull(address);
        ChangeSummary addressCS = address.getChangeSummary();

        List phones = manager.getList("phone");
        for (int i = 0; i < phones.size(); i++) {
            DataObject nextPhone = ((DataObject)phones.get(i));
            ChangeSummary phoneCS = nextPhone.getChangeSummary();
            // verify changesummary tree integrity
            assertEquals(teamCS, phoneCS);
            // we modified the address
            if (i == 2) {
                assertEquals("3456789",nextPhone.getString("number"));
                assertTrue(teamCS.isCreated(nextPhone));
            } else {
                assertFalse(teamCS.isCreated(nextPhone));
            }
        }

        // verify child change summaries are equal to their parent
        assertEquals(teamCS, addressCS);
        assertTrue(teamCS.isCreated(address));
        */
// verify logging status
// assertEquals(0, teamCS.getOldValues(address).size());
// DataObject addressDO = manager.getDataObject("address");
// assertTrue(teamCS.isModified(addressDO));
// modify stuff for write
// document.getRootObject();
}
Also used : DataObject(commonj.sdo.DataObject) SDOSetting(org.eclipse.persistence.sdo.SDOSetting) List(java.util.List) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) ChangeSummary(commonj.sdo.ChangeSummary)

Example 3 with SDOSetting

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

the class SDOMarshalListener method beforeMarshal.

@Override
public void beforeMarshal(Object obj) {
    if (obj instanceof SDOChangeSummary) {
        SDOChangeSummary changeSummary = ((SDOChangeSummary) obj);
        // CREATED - build a list of xpaths to write to the created attribute
        // this must be done dynamically because the xpath is relative to the marshalledObject
        // so it can't be calculated until we know what object is being marshalled
        List createdSet = changeSummary.getCreated();
        List xpaths = new ArrayList(createdSet.size());
        String rootElementName = this.marshalledObjectRootQName.getLocalPart();
        String rootNamespaceUri = this.marshalledObjectRootQName.getNamespaceURI();
        if (rootNamespaceUri != null && !rootNamespaceUri.equals(XMLConstants.EMPTY_STRING)) {
            org.eclipse.persistence.internal.oxm.NamespaceResolver resolver = getRootMarshalRecord().getNamespaceResolver();
            if (resolver != null) {
                String prefix = resolver.resolveNamespaceURI(this.marshalledObjectRootQName.getNamespaceURI());
                if (prefix != null) {
                    rootElementName = prefix + XMLConstants.COLON + rootElementName;
                }
            }
        }
        if ((createdSet != null) && (createdSet.size() > 0)) {
            Iterator anIterator = createdSet.iterator();
            SDODataObject nextCreatedDO = null;
            while (anIterator.hasNext()) {
                // get path to the changeSummaryRoot (may not be the root marshalled object - may be internal)
                nextCreatedDO = ((SDODataObject) anIterator.next());
                String nextPath = getPathFromAncestor(nextCreatedDO, (SDODataObject) marshalledObject, changeSummary);
                // Add sdoRef attribute...all modified objects written should have this
                if (nextPath == SDOConstants.EMPTY_STRING) {
                    // if this is the root, just put the root element
                    xpaths.add(SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + // 
                    SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName);
                } else {
                    xpaths.add(SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + // 
                    SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + nextPath);
                }
            }
        }
        changeSummary.setCreatedXPaths(xpaths);
        // Build xpathToCS
        String xpathMarshalledObjToCS = getPathFromAncestor(changeSummary.getRootObject(), (SDODataObject) marshalledObject, changeSummary);
        String xpathChangeSumProp = getXPathForProperty(changeSummary.getRootObject().getType().getChangeSummaryProperty());
        String xpathToCS = SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName;
        // check if the CS is at the local-cs-root or is in a child property
        if ((xpathMarshalledObjToCS != null) && !xpathMarshalledObjToCS.equals(SDOConstants.EMPTY_STRING)) {
            // SDO_XPATH_TO_ROOT)) {
            // CS is not on the root
            xpathToCS = xpathToCS + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + xpathMarshalledObjToCS;
        }
        xpathToCS = // 
        xpathToCS + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + xpathChangeSumProp + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT;
        // MODIFIED && DELETED
        List deletedXPaths = new ArrayList();
        Document document = XMLPlatformFactory.getInstance().getXMLPlatform().createDocument();
        Element csNode = null;
        List modifiedItems = changeSummary.getModified();
        int modifiedSize = modifiedItems.size();
        List newNodes = new ArrayList(modifiedSize);
        SDODataObject nextModifiedDO = null;
        // Iterate through CS modified items
        for (int i = 0; i < modifiedSize; i++) {
            nextModifiedDO = (SDODataObject) modifiedItems.get(i);
            String sdoPrefix = typeHelper.getPrefix(SDOConstants.SDO_URL);
            // List unsetPropNames = new ArrayList();
            String uri = getURI(nextModifiedDO);
            String qualifiedName = getQualifiedName(nextModifiedDO);
            String sdoRefPrefix = SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT;
            if (uri == null) {
                csNode = document.createElement(qualifiedName);
            } else {
                csNode = document.createElementNS(uri, qualifiedName);
            }
            String nextPath = getPathFromAncestor(nextModifiedDO, (SDODataObject) marshalledObject, changeSummary);
            // Add sdoRef attribute...all modified objects written should have this
            if (nextPath == SDOConstants.EMPTY_STRING) {
                // if this is the root, just put the root element
                csNode.setAttributeNS(SDOConstants.SDO_URL, // 
                sdoPrefix + // 
                SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + // 
                SDOConstants.CHANGESUMMARY_REF, sdoRefPrefix + rootElementName);
            } else {
                csNode.setAttributeNS(SDOConstants.SDO_URL, // 
                sdoPrefix + // 
                SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + // 
                SDOConstants.CHANGESUMMARY_REF, sdoRefPrefix + rootElementName + "/" + nextPath);
            }
            // Bug6346754 Add all namespaces if they are not yet declared above.
            Vector namespaces = nextModifiedDO.getType().getXmlDescriptor().getNonNullNamespaceResolver().getNamespaces();
            for (int j = 0; j < namespaces.size(); j++) {
                Namespace next = (Namespace) namespaces.get(j);
                if (declareNamespace(next.getNamespaceURI(), next.getPrefix(), changeSummary.getRootObject())) {
                    csNode.setAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, javax.xml.XMLConstants.XMLNS_ATTRIBUTE + XMLConstants.COLON + next.getPrefix(), next.getNamespaceURI());
                }
            }
            List nextDOSettings = changeSummary.getOldValues(nextModifiedDO);
            DOMRecord row = new DOMRecord(csNode);
            Session session = ((SDOXMLHelper) typeHelper.getHelperContext().getXMLHelper()).getXmlContext().getSession();
            row.setSession((AbstractSession) session);
            // Iterate through SDOSettings for the current modified Object
            SDOSetting nextSetting = null;
            for (int j = 0; j < nextDOSettings.size(); j++) {
                nextSetting = (SDOSetting) nextDOSettings.get(j);
                if (nextSetting.isSet()) {
                    if (!nextSetting.getProperty().getType().isDataType()) {
                        if (nextSetting.getProperty().isMany()) {
                            List values = (List) nextSetting.getValue();
                            for (int k = 0; k < values.size(); k++) {
                                doMarshal(// 
                                nextSetting.getProperty(), // 
                                (DataObject) values.get(k), changeSummary, csNode, nextModifiedDO, deletedXPaths, xpathToCS, sdoPrefix, rootElementName);
                            }
                        } else {
                            doMarshal(// 
                            nextSetting.getProperty(), // 
                            (DataObject) nextSetting.getValue(), changeSummary, csNode, nextModifiedDO, deletedXPaths, xpathToCS, sdoPrefix, rootElementName);
                        }
                    } else {
                        // This writes out simple values
                        Object value = nextSetting.getValue();
                        if (value == null) {
                            // Marshal out xsi:nil=true
                            marshalNilAttribute(nextSetting.getProperty(), row);
                        } else {
                            String xPath = getXPathForProperty(nextSetting.getProperty());
                            XMLField field = new XMLField(xPath);
                            field.setNamespaceResolver(typeHelper.getNamespaceResolver());
                            row.put(field, value);
                        }
                    }
                }
            }
            List unsetPropNames = changeSummary.getUnsetProps(nextModifiedDO);
            if (!unsetPropNames.isEmpty()) {
                XMLConversionManager xmlConversionManager = ((SDOXMLHelper) typeHelper.getHelperContext().getXMLHelper()).getXmlConversionManager();
                String unsetPropsString = xmlConversionManager.convertObject(unsetPropNames, String.class);
                csNode.setAttributeNS(SDOConstants.SDO_URL, // 
                sdoPrefix + // 
                SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + SDOConstants.CHANGESUMMARY_UNSET, unsetPropsString);
            }
            newNodes.add(csNode);
        }
        changeSummary.setDeletedXPaths(deletedXPaths);
        changeSummary.setModifiedDoms(newNodes);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) SDOSetting(org.eclipse.persistence.sdo.SDOSetting) DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Namespace(org.eclipse.persistence.internal.oxm.Namespace) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) Vector(java.util.Vector) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) Session(org.eclipse.persistence.sessions.Session) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 4 with SDOSetting

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

the class ChangeSummaryCreatedModifiedDeletedTests method testOldSettingsAfterInternalDeleteOfLevel2of4AfterLoggingOn.

// verify recursive delete sets isSet properly
public void testOldSettingsAfterInternalDeleteOfLevel2of4AfterLoggingOn() {
    buildTreeWith4LevelsOfProperties();
    changeSummaryB = dataObjectB.getChangeSummary();
    changeSummaryB.beginLogging();
    assertNotNull(dataObjectD.getChangeSummary());
    dataObjectD.delete();
    // verify CS is null on removed trees
    assertChangeSummaryStatusIfClearedIfCSIsAncestor(dataObjectD, true);
    assertUnchanged(root, changeSummaryB);
    assertModified(dataObjectB, changeSummaryB);
    assertUnchanged(dataObjectC, changeSummaryB);
    // both d and child e are deleted (recursively)
    assertDeleted(dataObjectD, changeSummaryB);
    assertDeleted(dataObjectE, changeSummaryB);
    assertEquals(1, changeSummaryB.getOldValues(dataObjectB).size());
    assertTrue(changeSummaryB.getOldValue(dataObjectB, propertyB).isSet());
    DataObject deepCopyD = (DataObject) changeSummaryB.getDeepCopies().get(dataObjectD);
    assertTrue(changeSummaryB.getOldValue(dataObjectB, propertyB).getValue().equals(deepCopyD));
    assertTrue(changeSummaryB.getOldContainer(dataObjectD).equals(dataObjectB));
    assertTrue(changeSummaryB.getOldContainmentProperty(dataObjectD).equals(propertyB));
    // assertEquals(1, dataObjectD.getOldSettings().size());
    // assertEquals(1, changeSummaryB.dataObjectD.getOldSettings().size());
    SDOSetting aSetting = (SDOSetting) changeSummaryB.getOldValue(dataObjectD, propertyD);
    assertTrue(aSetting.isSet());
    DataObject deepCopyE = (DataObject) changeSummaryB.getDeepCopies().get(dataObjectE);
    assertTrue(aSetting.getValue().equals(deepCopyE));
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) SDOSetting(org.eclipse.persistence.sdo.SDOSetting)

Example 5 with SDOSetting

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

the class ChangeSummaryChildLoggingOnModifyComplexAtCSLoadAndSaveTestCases method verifyAfterLoad.

@Override
protected void verifyAfterLoad(XMLDocument document) {
    super.verifyAfterLoad(document);
    ChangeSummary teamCS = document.getRootObject().getChangeSummary();
    assertNull(teamCS);
    DataObject manager = document.getRootObject().getDataObject("manager");
    assertNotNull(manager);
    ChangeSummary managerCS = manager.getChangeSummary();
    assertNotNull(managerCS);
    DataObject address = manager.getDataObject("address");
    ChangeSummary addressCS = address.getChangeSummary();
    assertNotNull(addressCS);
    assertTrue(managerCS.isLogging());
    assertTrue(managerCS.isLogging());
    assertEquals(addressCS, managerCS);
    assertFalse(managerCS.isCreated(manager));
    assertTrue(managerCS.isModified(manager));
    DataObject phone3 = manager.getDataObject("phone[3]");
    assertEquals("3456789", phone3.getString("number"));
    managerCS.isModified(phone3);
    List managersettings = managerCS.getOldValues(manager);
    // assertEquals(1, managersettings.size());
    SDOSetting nameSetting = (SDOSetting) managerCS.getOldValue(manager, manager.getInstanceProperty("name"));
    assertEquals("Old Name", nameSetting.getValue());
    List settings = managerCS.getOldValues(phone3);
    assertEquals(1, settings.size());
    SDOSetting firstSetting = (SDOSetting) settings.get(0);
    assertEquals("1111111", firstSetting.getValue());
    assertTrue(firstSetting.isSet());
}
Also used : DataObject(commonj.sdo.DataObject) SDOSetting(org.eclipse.persistence.sdo.SDOSetting) List(java.util.List) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) ChangeSummary(commonj.sdo.ChangeSummary)

Aggregations

DataObject (commonj.sdo.DataObject)5 SDOSetting (org.eclipse.persistence.sdo.SDOSetting)5 List (java.util.List)3 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)3 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)3 ChangeSummary (commonj.sdo.ChangeSummary)2 Property (commonj.sdo.Property)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 Namespace (org.eclipse.persistence.internal.oxm.Namespace)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 DOMRecord (org.eclipse.persistence.oxm.record.DOMRecord)1 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)1 Session (org.eclipse.persistence.sessions.Session)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1