Search in sources :

Example 26 with SDOChangeSummary

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

the class SDODataObjectGetPathTest method testGetPathFromAncestorDeletedFromChildToRootLoggingOff.

// if logging is off we get null path because we need a changeSummary to compute containers
public void testGetPathFromAncestorDeletedFromChildToRootLoggingOff() {
    SDODataObject anItem = (SDODataObject) aRoot5.get("items/item[2]");
    // get changeSummary
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    assertFalse(aCS.isLogging());
    // delete source object, useXPathFormat
    anItem.delete();
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(anItem, aRoot5, aRoot5.getChangeSummary());
    assertNull(aPath);
// get path to root
// String aPathAcrossCS = anItem.getPathFromAncestor(aCS, aRoot5, false);
// assertNotNull(aPathAcrossCS);
// assertEquals(aPathAcrossCS, "items/item[2]");
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 27 with SDOChangeSummary

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

the class SDODataObjectGetPathTest method testGetPathFromAncestorDeletedFromContainedToParentLoggingOn.

// these deleted tests are not supported yet for XPath
// TODO: we must store the index (2) position when deleting inside a ListWrapper
public void testGetPathFromAncestorDeletedFromContainedToParentLoggingOn() {
    SDODataObject target = (SDODataObject) aRoot5.get("items");
    SDODataObject aSibling = (SDODataObject) aRoot5.get("items/item[2]");
    // start logging
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    aCS.beginLogging();
    // delete source object
    aSibling.delete();
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(aSibling, target, target.getChangeSummary());
    assertNotNull(aPath);
    // TODO: no storage of deleted indexed postition - defaults to size() = start of list for now
    // see SDODataObject: index = ((SDODataObject)parent).getList(aChild).size();
    assertEquals("ns0:item[2]", aPath);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 28 with SDOChangeSummary

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

the class SDODataObjectGetPathTest method testGetPathFromAncestorDeletedFromChildToAncestorInsideListWrapperLoggingOn.

// test index=0 from item inside deleted listWrapper
public void testGetPathFromAncestorDeletedFromChildToAncestorInsideListWrapperLoggingOn() {
    SDODataObject anItem = (SDODataObject) aRoot5.get("items/item[2]");
    // start logging
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    aCS.beginLogging();
    assertTrue(aCS.isLogging());
    // delete source object
    // SDODataObject deletedObject = ((SDODataObject)aRoot5.get("items"));
    // detach();
    anItem.delete();
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(anItem, aRoot5, aRoot5.getChangeSummary());
    assertNotNull(aPath);
    // TODO: no storage of deleted indexed postition - defaults to size() = start of list for now
    // see SDODataObject: index = ((SDODataObject)parent).getList(aChild).size();
    // assertEquals("items/item[2]", aPath);
    assertEquals("ns0:items/ns0:item[2]", aPath);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 29 with SDOChangeSummary

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

the class SDODataObjectGetPathTest method testGetPathFromAncestorDeletedFromRootToSiblingLoggingOff.

public void testGetPathFromAncestorDeletedFromRootToSiblingLoggingOff() {
    SDODataObject anItem = (SDODataObject) aRoot5.get("items/item[2]");
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(aRoot5, anItem, aRoot5.getChangeSummary());
    // get changeSummary
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    assertFalse(aCS.isLogging());
    // delete source object
    aRoot5.delete();
    assertEquals(SDOConstants.SDO_XPATH_INVALID_PATH, aPath);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 30 with SDOChangeSummary

use of org.eclipse.persistence.sdo.SDOChangeSummary 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)

Aggregations

SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)123 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)109 DataObject (commonj.sdo.DataObject)91 ChangeSummary (commonj.sdo.ChangeSummary)66 List (java.util.List)63 ArrayList (java.util.ArrayList)56 SDOSetting (org.eclipse.persistence.sdo.SDOSetting)37 Property (commonj.sdo.Property)25 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)25 ValueStore (org.eclipse.persistence.sdo.ValueStore)17 SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)16 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)16 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)9 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)9 SDOType (org.eclipse.persistence.sdo.SDOType)7 Sequence (commonj.sdo.Sequence)6 Iterator (java.util.Iterator)6 Map (java.util.Map)6 HashSet (java.util.HashSet)2 Set (java.util.Set)2