use of org.eclipse.persistence.oxm.record.XMLEntry in project eclipselink by eclipse-ee4j.
the class XPathEngine method create.
public void create(List<Field> xmlFields, Node contextNode, List<XMLEntry> values, Field lastUpdatedField, DocumentPreservationPolicy docPresPolicy, CoreAbstractSession session) {
List itemsToWrite = new ArrayList();
for (int i = 0, size = values.size(); i < size; i++) {
XMLEntry nextEntry = values.get(i);
itemsToWrite.add(nextEntry.getValue());
if (i == (values.size() - 1) || values.get(i + 1).getXMLField() != nextEntry.getXMLField()) {
create(nextEntry.getXMLField(), contextNode, itemsToWrite, lastUpdatedField, docPresPolicy, session);
itemsToWrite = new ArrayList();
lastUpdatedField = nextEntry.getXMLField();
}
}
}
use of org.eclipse.persistence.oxm.record.XMLEntry in project eclipselink by eclipse-ee4j.
the class UnmarshalXPathEngine method addXMLEntry.
private void addXMLEntry(Node entryNode, XML_FIELD xmlField, List<XMLEntry> entries) {
XMLEntry entry = new XMLEntry();
entry.setValue(entryNode);
entry.setXMLField(xmlField);
entries.add(entry);
}
use of org.eclipse.persistence.oxm.record.XMLEntry in project eclipselink by eclipse-ee4j.
the class XMLChoiceCollectionMapping method writeFromObjectIntoRow.
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) throws DescriptorException {
if (this.isReadOnly()) {
return;
}
Object attributeValue = getAttributeValueFromObject(object);
List<XMLEntry> nestedRows = new ArrayList<>();
XMLRecord record = (XMLRecord) row;
// First determine which Field is associated with each value:
if (null != attributeValue) {
ContainerPolicy cp = getContainerPolicy();
Object iterator = cp.iteratorFor(attributeValue);
if (null != iterator) {
while (cp.hasNext(iterator)) {
Object value = cp.next(iterator, session);
value = convertObjectValueToDataValue(value, session, record.getMarshaller());
NodeValue associatedNodeValue = null;
XMLField associatedField = null;
Object fieldValue = value;
if (value instanceof XMLRoot) {
XMLRoot rootValue = (XMLRoot) value;
String localName = rootValue.getLocalName();
String namespaceUri = rootValue.getNamespaceURI();
fieldValue = rootValue.getObject();
associatedField = getFieldForName(localName, namespaceUri);
if (associatedField == null) {
associatedField = getClassToFieldMappings().get(fieldValue.getClass());
}
} else {
associatedField = getClassToFieldMappings().get(value.getClass());
}
if (associatedField == null) {
// this may be a reference mapping
List<XMLField> sourceFields = classToSourceFieldsMappings.get(value.getClass());
if (sourceFields != null && sourceFields.size() > 0) {
DatabaseMapping xmlMapping = (DatabaseMapping) this.choiceElementMappings.get(sourceFields.get(0));
for (XMLField next : sourceFields) {
fieldValue = ((XMLCollectionReferenceMapping) xmlMapping).buildFieldValue(value, next, session);
XMLEntry entry = new XMLEntry();
entry.setValue(fieldValue);
entry.setXMLField(next);
nestedRows.add(entry);
}
}
} else {
DatabaseMapping xmlMapping = (DatabaseMapping) this.choiceElementMappings.get(associatedField);
if (xmlMapping.isAbstractCompositeCollectionMapping()) {
fieldValue = ((XMLCompositeCollectionMapping) xmlMapping).buildCompositeRow(fieldValue, session, row, writeType);
}
XMLEntry entry = new XMLEntry();
entry.setValue(fieldValue);
entry.setXMLField(associatedField);
nestedRows.add(entry);
}
}
}
}
row.put(getFields(), nestedRows);
}
use of org.eclipse.persistence.oxm.record.XMLEntry in project eclipselink by eclipse-ee4j.
the class XMLChoiceCollectionMapping method valueFromRow.
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
List<XMLEntry> values = ((DOMRecord) row).getValuesIndicatingNoEntry(this.getFields());
Object container = getContainerPolicy().containerInstance(values.size());
for (XMLEntry next : values) {
Field valueField = next.getXMLField();
DatabaseMapping nextMapping = (DatabaseMapping) this.choiceElementMappings.get(valueField);
if (nextMapping.isAbstractCompositeCollectionMapping()) {
XMLCompositeCollectionMapping xmlMapping = (XMLCompositeCollectionMapping) nextMapping;
Object value = xmlMapping.buildObjectFromNestedRow((AbstractRecord) next.getValue(), joinManager, sourceQuery, executionSession, isTargetProtected);
value = convertDataValueToObjectValue(value, executionSession, ((XMLRecord) row).getUnmarshaller());
getContainerPolicy().addInto(value, container, executionSession);
} else if (nextMapping instanceof XMLCompositeDirectCollectionMapping) {
XMLCompositeDirectCollectionMapping xmlMapping = (XMLCompositeDirectCollectionMapping) nextMapping;
Object value = next.getValue();
value = convertDataValueToObjectValue(value, executionSession, ((XMLRecord) row).getUnmarshaller());
getContainerPolicy().addInto(value, container, executionSession);
}
}
ArrayList<XMLMapping> processedMappings = new ArrayList<>();
for (XMLMapping mapping : choiceElementMappings.values()) {
if (((DatabaseMapping) mapping).isObjectReferenceMapping() && ((DatabaseMapping) mapping).isCollectionMapping() && !(processedMappings.contains(mapping))) {
((XMLCollectionReferenceMapping) mapping).readFromRowIntoObject(row, joinManager, ((XMLRecord) row).getCurrentObject(), cacheKey, sourceQuery, executionSession, isTargetProtected, container);
processedMappings.add(mapping);
}
}
return container;
}
use of org.eclipse.persistence.oxm.record.XMLEntry in project eclipselink by eclipse-ee4j.
the class XPathEngine method replaceCollection.
public List<XMLEntry> replaceCollection(List<Field> xmlFields, List<XMLEntry> values, Node contextNode, DocumentPreservationPolicy docPresPolicy, Field lastUpdatedField, CoreAbstractSession session) {
List<XMLEntry> oldNodes = unmarshalXPathEngine.selectNodes(contextNode, xmlFields, getNamespaceResolverForField(xmlFields.get(0)));
if (oldNodes == null || oldNodes.size() == 0) {
return oldNodes;
}
Iterator<XMLEntry> oldValues = oldNodes.iterator();
// Remove all the old values, and then call create to add them back in.
while (oldValues.hasNext()) {
XMLEntry entry = oldValues.next();
Node nextNode = (Node) entry.getValue();
Node parent = nextNode.getParentNode();
parent.removeChild(nextNode);
while (parent != contextNode) {
if (parent.getChildNodes().getLength() == 0) {
nextNode = parent;
parent = nextNode.getParentNode();
parent.removeChild(nextNode);
} else {
break;
}
}
}
create(xmlFields, contextNode, values, lastUpdatedField, xmlBinderPolicy, session);
return oldNodes;
}
Aggregations