use of org.eclipse.persistence.oxm.record.XMLRecord 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.XMLRecord 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.XMLRecord in project eclipselink by eclipse-ee4j.
the class XMLVariableXPathCollectionMapping method writeFromObjectIntoRow.
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) throws DescriptorException {
if (this.isReadOnly()) {
return;
}
Object attributeValue = this.getAttributeValueFromObject(object);
ContainerPolicy cp = this.getContainerPolicy();
Object iter = cp.iteratorFor(attributeValue);
if (null != iter) {
while (cp.hasNext(iter)) {
Object element = cp.next(iter, session);
// convert the value - if necessary
element = convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller());
if (element != null) {
XMLField variableField = new XMLField();
XMLRecord xmlRow = (XMLRecord) row;
// variableField.setXPathFragment(getXPathFragmentForValue(element,(XMLRecord)row));
variableField.setXPathFragment(getXPathFragmentForValue(element, xmlRow.getNamespaceResolver(), xmlRow.isNamespaceAware(), xmlRow.getNamespaceSeparator()));
row.put(variableField, buildCompositeRow(variableField, element, session, row, writeType));
}
}
}
}
use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.
the class EISOneToManyMapping method valueFromRow.
/**
* INTERNAL:
* Return the value of the reference attribute or a value holder.
* Check whether the mapping's attribute should be optimized through batch and joining.
*/
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
if (this.descriptor.getCachePolicy().isProtectedIsolation()) {
if (this.isCacheable && isTargetProtected && cacheKey != null) {
// cachekey will be null when isolating to uow
// used cached collection
Object cached = cacheKey.getObject();
if (cached != null) {
if (wasCacheUsed != null) {
wasCacheUsed[0] = Boolean.TRUE;
}
// the indirection object is responsible for cloning the value.
return getAttributeValueFromObject(cached);
}
} else if (!this.isCacheable && !isTargetProtected && cacheKey != null) {
return this.indirectionPolicy.buildIndirectObject(new ValueHolder<>(null));
}
}
if (((EISDescriptor) this.getDescriptor()).isXMLFormat()) {
((XMLRecord) row).setSession(executionSession);
}
ReadQuery targetQuery = getSelectionQuery();
if (!this.isForeignKeyRelationship) {
// if the source query is cascading then the target query must use the same settings
if (targetQuery.isObjectLevelReadQuery() && (sourceQuery.shouldCascadeAllParts() || (sourceQuery.shouldCascadePrivateParts() && isPrivateOwned()) || (sourceQuery.shouldCascadeByMapping() && this.cascadeRefresh))) {
targetQuery = (ObjectLevelReadQuery) targetQuery.clone();
((ObjectLevelReadQuery) targetQuery).setShouldRefreshIdentityMapResult(sourceQuery.shouldRefreshIdentityMapResult());
targetQuery.setCascadePolicy(sourceQuery.getCascadePolicy());
// CR #4365
targetQuery.setQueryId(sourceQuery.getQueryId());
// For queries that have turned caching off, such as aggregate collection, leave it off.
if (targetQuery.shouldMaintainCache()) {
targetQuery.setShouldMaintainCache(sourceQuery.shouldMaintainCache());
}
}
return getIndirectionPolicy().valueFromQuery(targetQuery, row, sourceQuery.getSession());
} else {
if (getIndirectionPolicy().usesIndirection()) {
EISOneToManyQueryBasedValueHolder valueholder = new EISOneToManyQueryBasedValueHolder(this, targetQuery, row, sourceQuery.getSession());
return getIndirectionPolicy().buildIndirectObject(valueholder);
} else {
Vector<AbstractRecord> subRows = getForeignKeyRows(row, executionSession);
if (subRows == null) {
return null;
}
ContainerPolicy cp = this.getContainerPolicy();
Object results = cp.containerInstance(subRows.size());
for (int i = 0; i < subRows.size(); i++) {
XMLRecord subRow = (XMLRecord) subRows.elementAt(i);
subRow.setSession(executionSession);
Object object = getIndirectionPolicy().valueFromQuery(targetQuery, subRow, sourceQuery.getSession());
if (object instanceof Collection) {
java.util.Iterator<?> iter = ((Collection<?>) object).iterator();
while (iter.hasNext()) {
cp.addInto(iter.next(), results, executionSession);
}
} else if (object instanceof java.util.Map) {
java.util.Iterator<?> iter = ((java.util.Map<?, ?>) object).values().iterator();
while (iter.hasNext()) {
cp.addInto(iter.next(), results, executionSession);
}
} else {
cp.addInto(object, results, executionSession);
}
}
if (cp.sizeFor(results) == 0) {
return null;
}
return results;
}
}
}
use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.
the class XMLInteraction method createInputDOM.
/**
* Create a DOM for this interaction.
* Convert the database row or arguments into an XML DOM tree.
*/
public Element createInputDOM(EISAccessor accessor) {
Element dom = null;
// or the modify row.
if ((getInputRow() != null) && (!hasArguments())) {
if (getInputResultPath().length() == 0) {
if (getInputRow() instanceof XMLRecord) {
dom = (Element) ((XMLRecord) getInputRow()).getDOM();
// Rename the root element if specified to be different.
if (!dom.getTagName().equals(getInputRootElementName())) {
XMLRecord parameterRow = createXMLRecord(getInputRootElementName());
parameterRow.put("/" + getInputRootElementName(), getInputRow());
dom = (Element) parameterRow.getDOM();
}
} else {
XMLRecord parameterRow = createXMLRecord(getInputRootElementName());
for (int index = 0; index < getInputRow().size(); index++) {
parameterRow.put(getInputRow().getFields().elementAt(index), getInputRow().getValues().elementAt(index));
}
dom = (Element) parameterRow.getDOM();
}
} else {
XMLRecord parameterRow = createXMLRecord(getInputRootElementName());
parameterRow.put(getInputResultPath(), getInputRow());
dom = (Element) parameterRow.getDOM();
}
} else {
XMLRecord parameterRow = createXMLRecord(getInputRootElementName());
for (int index = 0; index < getArgumentNames().size(); index++) {
String parameterName = getArgumentNames().get(index);
Object parameter = getParameters().get(index);
// If no arguments were passed to the call execution find the paramter from the row.
if ((parameter == null) && (getInputRow() != null)) {
parameter = getInputRow().get(parameterName);
}
parameterRow.put(parameterName, parameter);
}
dom = (Element) parameterRow.getDOM();
}
return dom;
}
Aggregations