View | Details | Raw Unified | Return to bug 285889 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/persistence/internal/oxm/TreeObjectBuilder.java (-14 / +20 lines)
Lines 81-87 Link Here
81
    }
81
    }
82
82
83
    public void addTransformationMapping(AbstractTransformationMapping transformationMapping) {
83
    public void addTransformationMapping(AbstractTransformationMapping transformationMapping) {
84
        if (null == getTransformationMappings()) {
84
        if (null == this.transformationMappings) {
85
            this.transformationMappings = new ArrayList();
85
            this.transformationMappings = new ArrayList();
86
        }
86
        }
87
        transformationMappings.add(transformationMapping);
87
        transformationMappings.add(transformationMapping);
Lines 96-102 Link Here
96
    }
96
    }
97
97
98
    public void addContainerValue(ContainerValue containerValue) {
98
    public void addContainerValue(ContainerValue containerValue) {
99
        if (null == getContainerValues()) {
99
        if (null == this.containerValues) {
100
            this.containerValues = new ArrayList();
100
            this.containerValues = new ArrayList();
101
        }
101
        }
102
        this.containerValues.add(containerValue);
102
        this.containerValues.add(containerValue);
Lines 107-113 Link Here
107
    }
107
    }
108
108
109
    public void addNullCapableValue(NullCapableValue nullCapableValue) {
109
    public void addNullCapableValue(NullCapableValue nullCapableValue) {
110
        if (null == getNullCapableValues()) {
110
        if (null == this.nullCapableValues) {
111
            this.nullCapableValues = new ArrayList();
111
            this.nullCapableValues = new ArrayList();
112
        }
112
        }
113
        this.nullCapableValues.add(nullCapableValue);
113
        this.nullCapableValues.add(nullCapableValue);
Lines 172-177 Link Here
172
                    mappingNodeValue = new XMLFragmentCollectionMappingNodeValue((XMLFragmentCollectionMapping)xmlMapping);
172
                    mappingNodeValue = new XMLFragmentCollectionMappingNodeValue((XMLFragmentCollectionMapping)xmlMapping);
173
                } else if (xmlMapping instanceof XMLCollectionReferenceMapping) {
173
                } else if (xmlMapping instanceof XMLCollectionReferenceMapping) {
174
                    XMLCollectionReferenceMapping xmlColMapping = (XMLCollectionReferenceMapping)xmlMapping;
174
                    XMLCollectionReferenceMapping xmlColMapping = (XMLCollectionReferenceMapping)xmlMapping;
175
                    XMLField xmlColMappingField = (XMLField) xmlColMapping.getField();
176
                    XPathNode branchNode;
177
                    if(null == xmlColMappingField) {
178
                        addChild(XPathFragment.SELF_FRAGMENT, new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver());
179
                        branchNode = rootXPathNode;
180
                    } else {
181
                        branchNode = addChild(((XMLField) xmlColMapping.getField()).getXPathFragment(), new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver());
182
                    }
175
                    Iterator fieldIt = xmlColMapping.getFields().iterator();
183
                    Iterator fieldIt = xmlColMapping.getFields().iterator();
176
                    while (fieldIt.hasNext()) {
184
                    while (fieldIt.hasNext()) {
177
                        XMLField xmlFld = (XMLField)fieldIt.next();
185
                        XMLField xmlFld = (XMLField)fieldIt.next();
Lines 182-188 Link Here
182
                        if (mappingNodeValue.isNullCapableValue()) {
190
                        if (mappingNodeValue.isNullCapableValue()) {
183
                            addNullCapableValue((NullCapableValue)mappingNodeValue);
191
                            addNullCapableValue((NullCapableValue)mappingNodeValue);
184
                        }
192
                        }
185
                        addChild(xmlFld.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
193
                        branchNode.addChild(xmlFld.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
186
                    }
194
                    }
187
                    continue;
195
                    continue;
188
                } else if (xmlMapping instanceof XMLObjectReferenceMapping) {
196
                } else if (xmlMapping instanceof XMLObjectReferenceMapping) {
Lines 283-290 Link Here
283
        }
291
        }
284
    }
292
    }
285
293
286
    public void addChild(XPathFragment xPathFragment, NodeValue nodeValue, NamespaceResolver namespaceResolver) {
294
    public XPathNode addChild(XPathFragment xPathFragment, NodeValue nodeValue, NamespaceResolver namespaceResolver) {
287
        getRootXPathNode().addChild(xPathFragment, nodeValue, namespaceResolver);
295
        return getRootXPathNode().addChild(xPathFragment, nodeValue, namespaceResolver);
288
    }
296
    }
289
297
290
    public AbstractRecord buildRow(AbstractRecord record, Object object, org.eclipse.persistence.internal.sessions.AbstractSession session) {
298
    public AbstractRecord buildRow(AbstractRecord record, Object object, org.eclipse.persistence.internal.sessions.AbstractSession session) {
Lines 315-325 Link Here
315
        boolean hasValue = false;
323
        boolean hasValue = false;
316
        NamespaceResolver namespaceResolver = ((XMLDescriptor)this.getDescriptor()).getNamespaceResolver();
324
        NamespaceResolver namespaceResolver = ((XMLDescriptor)this.getDescriptor()).getNamespaceResolver();
317
325
318
        List attributeChildren = rootXPathNode.getAttributeChildren();
326
        List<XPathNode> attributeChildren = rootXPathNode.getAttributeChildren();
319
        if (null != attributeChildren) {
327
        if (null != attributeChildren) {
320
            for (int x = 0, attributeChildrenSize=attributeChildren.size(); x < attributeChildrenSize; x++) {
328
            for (int x = 0, attributeChildrenSize=attributeChildren.size(); x < attributeChildrenSize; x++) {
321
                XPathNode attributeNode = (XPathNode)rootXPathNode.getAttributeChildren().get(x);
329
                hasValue = attributeChildren.get(x).marshal(marshalRecord, object, session, namespaceResolver, null, ObjectMarshalContext.getInstance()) || hasValue;
322
                hasValue = attributeNode.marshal(marshalRecord, object, session, namespaceResolver, null, ObjectMarshalContext.getInstance()) || hasValue;
323
            }
330
            }
324
        }
331
        }
325
332
Lines 327-337 Link Here
327
            hasValue = rootXPathNode.getAnyAttributeNode().marshal(marshalRecord, object, session, namespaceResolver, null, ObjectMarshalContext.getInstance()) || hasValue;
334
            hasValue = rootXPathNode.getAnyAttributeNode().marshal(marshalRecord, object, session, namespaceResolver, null, ObjectMarshalContext.getInstance()) || hasValue;
328
        }
335
        }
329
336
330
        List selfChildren = rootXPathNode.getSelfChildren();
337
        List<XPathNode> selfChildren = rootXPathNode.getSelfChildren();
331
        if (null != selfChildren) {
338
        if (null != selfChildren) {
332
            for (int x = 0, selfChildrenSize=selfChildren.size(); x < selfChildrenSize; x++) {
339
            for (int x = 0, selfChildrenSize=selfChildren.size(); x < selfChildrenSize; x++) {
333
                XPathNode childNode = (XPathNode)selfChildren.get(x);
340
                selfChildren.get(x).marshalSelfAttributes(marshalRecord, object, session, namespaceResolver, marshalRecord.getMarshaller());
334
                childNode.marshalSelfAttributes(marshalRecord, object, session, namespaceResolver, marshalRecord.getMarshaller());
335
            }
341
            }
336
        }
342
        }
337
343
Lines 375-379 Link Here
375
    public AbstractRecord createRecord(int size, AbstractSession session) {
381
    public AbstractRecord createRecord(int size, AbstractSession session) {
376
        return createRecord(session);
382
        return createRecord(session);
377
    }
383
    }
378
        
384
379
}
385
}
(-)src/org/eclipse/persistence/internal/oxm/XMLCollectionReferenceMappingMarshalNodeValue.java (+160 lines)
Line 0 Link Here
1
package org.eclipse.persistence.internal.oxm;
2
3
import java.util.List;
4
import javax.xml.namespace.QName;
5
6
import org.eclipse.persistence.internal.oxm.record.MarshalContext;
7
import org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext;
8
import org.eclipse.persistence.internal.queries.ContainerPolicy;
9
import org.eclipse.persistence.internal.sessions.AbstractSession;
10
import org.eclipse.persistence.oxm.NamespaceResolver;
11
import org.eclipse.persistence.oxm.XMLDescriptor;
12
import org.eclipse.persistence.oxm.XMLField;
13
import org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping;
14
import org.eclipse.persistence.oxm.record.MarshalRecord;
15
16
public class XMLCollectionReferenceMappingMarshalNodeValue extends MappingNodeValue implements ContainerValue {
17
18
    private XMLCollectionReferenceMapping xmlCollectionReferenceMapping;
19
    private XPathNode branchNode;
20
21
    public XMLCollectionReferenceMappingMarshalNodeValue(XMLCollectionReferenceMapping xmlCollectionReferenceMapping) {
22
        this.xmlCollectionReferenceMapping = xmlCollectionReferenceMapping;
23
        branchNode = new XPathNode();
24
        NamespaceResolver namespaceResolver = ((XMLDescriptor) xmlCollectionReferenceMapping.getDescriptor()).getNamespaceResolver();
25
        List fkFields = xmlCollectionReferenceMapping.getFields();
26
        for(int x=0, fkFieldsSize=fkFields.size(); x<fkFieldsSize; x++) {
27
            XMLField fkField = (XMLField) fkFields.get(x);
28
            branchNode.addChild(fkField.getXPathFragment(), new XMLCollectionReferenceMappingFKMarshalNodeValue(xmlCollectionReferenceMapping, fkField), namespaceResolver);
29
        }
30
    }
31
32
    public Object getContainerInstance() {
33
        return getContainerPolicy().containerInstance();
34
    }
35
36
    public ContainerPolicy getContainerPolicy() {
37
        return xmlCollectionReferenceMapping.getContainerPolicy();
38
    }
39
40
    @Override
41
    public XMLCollectionReferenceMapping getMapping() {
42
        return xmlCollectionReferenceMapping;
43
    }
44
45
    public boolean getReuseContainer() {
46
        return xmlCollectionReferenceMapping.getReuseContainer();
47
    }
48
49
    public void setContainerInstance(Object object, Object containerInstance) {
50
        xmlCollectionReferenceMapping.setAttributeValueInObject(object, containerInstance);
51
    }
52
53
    @Override
54
    public boolean marshal(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, AbstractSession session, NamespaceResolver namespaceResolver) {
55
        if (xmlCollectionReferenceMapping.isReadOnly()) {
56
            return false;
57
        }
58
59
        Object collection = xmlCollectionReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(object);
60
        if (null == collection) {
61
            return false;
62
        }
63
        ContainerPolicy cp = getContainerPolicy();
64
        Object iterator = cp.iteratorFor(collection);
65
        if (cp.hasNext(iterator)) {
66
            XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
67
            marshalRecord.closeStartGroupingElements(groupingFragment);
68
        } else {
69
            return false;
70
        }
71
        if(xPathFragment != XPathFragment.SELF_FRAGMENT) {
72
            marshalRecord.openStartElement(xPathFragment, namespaceResolver);
73
        }
74
        while (cp.hasNext(iterator)) {
75
            Object objectValue = cp.next(iterator, session);
76
            marshalSingleValue(xPathFragment, marshalRecord, object, objectValue, session, namespaceResolver, ObjectMarshalContext.getInstance());
77
        }
78
        if(xPathFragment != XPathFragment.SELF_FRAGMENT) {
79
            marshalRecord.endElement(xPathFragment, namespaceResolver);
80
        }
81
        return true;
82
    }
83
84
    @Override
85
    public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
86
        if (xmlCollectionReferenceMapping.usesSingleNode()) {
87
            XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
88
            if (xPathFragment.isAttribute()) {
89
                marshalRecord.attribute(xPathFragment, namespaceResolver, (String) value);
90
                marshalRecord.closeStartGroupingElements(groupingFragment);
91
            } else {
92
                marshalRecord.closeStartGroupingElements(groupingFragment);
93
                marshalRecord.characters((String) value);
94
            }
95
        } else {
96
            for (int x = 0, size = marshalContext.getNonAttributeChildrenSize(branchNode); x < size; x++) {
97
                XPathNode xPathNode = (XPathNode)marshalContext.getNonAttributeChild(x, branchNode);
98
                xPathNode.marshal((MarshalRecord)marshalRecord, value, session, namespaceResolver, marshalRecord.getMarshaller(), marshalContext.getMarshalContext(x));
99
            }
100
            
101
        }
102
        return true;
103
    }
104
105
    @Override
106
    public boolean isMarshalNodeValue() {
107
        return true;
108
    }
109
110
    @Override
111
    public boolean isUnmarshalNodeValue() {
112
        return false;
113
    }
114
115
    private static class XMLCollectionReferenceMappingFKMarshalNodeValue extends MappingNodeValue {
116
117
        private XMLCollectionReferenceMapping xmlCollectionReferenceMapping;
118
        private XMLField xmlField;
119
120
        public XMLCollectionReferenceMappingFKMarshalNodeValue(XMLCollectionReferenceMapping xmlCollectionReferenceMapping, XMLField xmlField) {
121
            this.xmlCollectionReferenceMapping = xmlCollectionReferenceMapping;
122
            this.xmlField = xmlField;
123
        }
124
125
        @Override
126
        public boolean marshal(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, AbstractSession session, NamespaceResolver namespaceResolver) {
127
            XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
128
            marshalRecord.closeStartGroupingElements(groupingFragment);
129
            return marshalSingleValue(xPathFragment, marshalRecord, null, object, session, namespaceResolver, ObjectMarshalContext.getInstance());
130
        }
131
132
        @Override
133
        public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
134
            Object fieldValue = xmlCollectionReferenceMapping.buildFieldValue(value, xmlField, session);
135
            if (fieldValue == null) {
136
                return false;
137
            }
138
            QName schemaType = getSchemaType(xmlField, fieldValue, session);
139
            String stringValue = getValueToWrite(schemaType, fieldValue, (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(), namespaceResolver);
140
            if (stringValue != null) {
141
                if (xPathFragment.isAttribute()) {
142
                    marshalRecord.attribute(xPathFragment, namespaceResolver, stringValue);
143
                    marshalRecord.closeStartElement();
144
                } else {
145
                    marshalRecord.closeStartElement();
146
                    marshalRecord.characters(stringValue);
147
                }
148
                return true;
149
            }
150
            return false;
151
        }
152
153
        @Override
154
        public XMLCollectionReferenceMapping getMapping() {
155
            return xmlCollectionReferenceMapping;
156
        }
157
158
    }
159
160
}
(-)src/org/eclipse/persistence/internal/oxm/XMLCollectionReferenceMappingNodeValue.java (-1 / +11 lines)
Lines 262-265 Link Here
262
        return getMapping().getReuseContainer();
262
        return getMapping().getReuseContainer();
263
    }
263
    }
264
264
265
}
265
    @Override
266
    public boolean isMarshalNodeValue() {
267
        return false;
268
    }
269
270
    @Override
271
    public boolean isUnmarshalNodeValue() {
272
        return true;
273
    }
274
275
}
(-)src/org/eclipse/persistence/internal/oxm/XPathNode.java (-6 / +7 lines)
Lines 109-123 Link Here
109
        this.parent = parent;
109
        this.parent = parent;
110
    }
110
    }
111
111
112
    public List getAttributeChildren() {
112
    public List<XPathNode> getAttributeChildren() {
113
        return this.attributeChildren;
113
        return this.attributeChildren;
114
    }
114
    }
115
115
116
    public List getNonAttributeChildren() {
116
    public List<XPathNode> getNonAttributeChildren() {
117
        return this.nonAttributeChildren;
117
        return this.nonAttributeChildren;
118
    }
118
    }
119
119
120
    public List getSelfChildren() {
120
    public List<XPathNode> getSelfChildren() {
121
        return this.selfChildren;
121
        return this.selfChildren;
122
    }
122
    }
123
123
Lines 183-189 Link Here
183
        }
183
        }
184
    }
184
    }
185
185
186
    public void addChild(XPathFragment anXPathFragment, NodeValue aNodeValue, NamespaceResolver namespaceResolver) {
186
    public XPathNode addChild(XPathFragment anXPathFragment, NodeValue aNodeValue, NamespaceResolver namespaceResolver) {
187
        if (null != anXPathFragment && anXPathFragment.nameIsText()) {
187
        if (null != anXPathFragment && anXPathFragment.nameIsText()) {
188
            if (aNodeValue.isOwningNode(anXPathFragment)) {
188
            if (aNodeValue.isOwningNode(anXPathFragment)) {
189
                XPathNode textXPathNode = new XPathNode();
189
                XPathNode textXPathNode = new XPathNode();
Lines 200-206 Link Here
200
                    nonAttributeChildren = new ArrayList();
200
                    nonAttributeChildren = new ArrayList();
201
                }
201
                }
202
                nonAttributeChildren.add(textXPathNode);
202
                nonAttributeChildren.add(textXPathNode);
203
                return;
203
                return textXPathNode;
204
            }
204
            }
205
        }
205
        }
206
206
Lines 255-261 Link Here
255
                }
255
                }
256
                setAnyNode(xPathNode);
256
                setAnyNode(xPathNode);
257
            }
257
            }
258
            return;
258
            return xPathNode;
259
        }
259
        }
260
        boolean isSelfFragment = XPathFragment.SELF_FRAGMENT.equals(anXPathFragment);
260
        boolean isSelfFragment = XPathFragment.SELF_FRAGMENT.equals(anXPathFragment);
261
261
Lines 289-294 Link Here
289
            XPathFragment nextFragment = anXPathFragment.getNextFragment();
289
            XPathFragment nextFragment = anXPathFragment.getNextFragment();
290
            xPathNode.addChild(nextFragment, aNodeValue, namespaceResolver);
290
            xPathNode.addChild(nextFragment, aNodeValue, namespaceResolver);
291
        }
291
        }
292
        return xPathNode;
292
    }
293
    }
293
294
294
    public boolean marshal(MarshalRecord marshalRecord, Object object, AbstractSession session, NamespaceResolver namespaceResolver, XMLMarshaller marshaller, MarshalContext marshalContext) {
295
    public boolean marshal(MarshalRecord marshalRecord, Object object, AbstractSession session, NamespaceResolver namespaceResolver, XMLMarshaller marshaller, MarshalContext marshalContext) {
(-)src/org/eclipse/persistence/oxm/mappings/XMLCollectionReferenceMapping.java (+30 lines)
Lines 24-29 Link Here
24
import org.eclipse.persistence.exceptions.DatabaseException;
24
import org.eclipse.persistence.exceptions.DatabaseException;
25
import org.eclipse.persistence.exceptions.DescriptorException;
25
import org.eclipse.persistence.exceptions.DescriptorException;
26
import org.eclipse.persistence.internal.descriptors.ObjectBuilder;
26
import org.eclipse.persistence.internal.descriptors.ObjectBuilder;
27
import org.eclipse.persistence.internal.helper.DatabaseField;
27
import org.eclipse.persistence.internal.helper.NonSynchronizedVector;
28
import org.eclipse.persistence.internal.helper.NonSynchronizedVector;
28
import org.eclipse.persistence.internal.oxm.Reference;
29
import org.eclipse.persistence.internal.oxm.Reference;
29
import org.eclipse.persistence.internal.oxm.ReferenceResolver;
30
import org.eclipse.persistence.internal.oxm.ReferenceResolver;
Lines 62-67 Link Here
62
public class XMLCollectionReferenceMapping extends XMLObjectReferenceMapping implements ContainerMapping {
63
public class XMLCollectionReferenceMapping extends XMLObjectReferenceMapping implements ContainerMapping {
63
    protected ContainerPolicy containerPolicy; // type of container used to hold the aggregate objects
64
    protected ContainerPolicy containerPolicy; // type of container used to hold the aggregate objects
64
    private static final String SPACE = " ";
65
    private static final String SPACE = " ";
66
    private DatabaseField field;
65
    private boolean usesSingleNode;
67
    private boolean usesSingleNode;
66
    private boolean reuseContainer;
68
    private boolean reuseContainer;
67
69
Lines 77-82 Link Here
77
        this.usesSingleNode = false;
79
        this.usesSingleNode = false;
78
    }
80
    }
79
81
82
    public DatabaseField getField() {
83
        return field;
84
    }
85
86
    public void setField(DatabaseField field) {
87
        this.field = field;
88
    }
89
90
    
91
    /**
92
     * Get the XPath String
93
     * @return String the XPath String associated with this Mapping
94
     */
95
    public String getXPath() {
96
        return getField().getName();
97
    }
98
99
    /**
100
     * Set the Mapping field name attribute to the given XPath String
101
     * @param xpathString String
102
     */
103
    public void setXPath(String xpathString) {
104
        this.setField(new XMLField(xpathString));
105
    }
106
80
    /**    
107
    /**    
81
     * INTERNAL:
108
     * INTERNAL:
82
     * Retrieve the target object's primary key value that is mapped to a given
109
     * Retrieve the target object's primary key value that is mapped to a given
Lines 166-171 Link Here
166
     */
193
     */
167
    public void initialize(AbstractSession session) throws DescriptorException {
194
    public void initialize(AbstractSession session) throws DescriptorException {
168
        super.initialize(session);
195
        super.initialize(session);
196
        if(null != getField()) {
197
            setField(getDescriptor().buildField(getField()));
198
        }
169
        ContainerPolicy cp = getContainerPolicy();
199
        ContainerPolicy cp = getContainerPolicy();
170
        if (cp != null) {
200
        if (cp != null) {
171
            if (cp.getContainerClass() == null) {
201
            if (cp.getContainerClass() == null) {

Return to bug 285889