use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.
the class XMLCompositeDirectCollectionMapping method valueFromRow.
/**
* INTERNAL:
* Build the nested collection from the database row.
*/
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
ContainerPolicy cp = this.getContainerPolicy();
DOMRecord domRecord = (DOMRecord) row;
Object fieldValue = domRecord.getValues(this.getField(), this.getNullPolicy());
if (fieldValue == null) {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
return container != null ? container : cp.containerInstance();
} else {
return cp.containerInstance();
}
}
Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue);
if (fieldValues == null) {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
return container != null ? container : cp.containerInstance();
} else {
return cp.containerInstance();
}
}
Object result = null;
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
result = container != null ? container : cp.containerInstance();
} else {
result = cp.containerInstance(fieldValues.size());
}
for (Enumeration stream = fieldValues.elements(); stream.hasMoreElements(); ) {
Object element = stream.nextElement();
element = convertDataValueToObjectValue(element, executionSession, ((XMLRecord) row).getUnmarshaller());
if (element != null && element.getClass() == ClassConstants.STRING) {
if (isCollapsingStringValues) {
element = XMLConversionManager.getDefaultXMLManager().collapseStringValue((String) element);
} else if (isNormalizingStringValues) {
element = XMLConversionManager.getDefaultXMLManager().normalizeStringValue((String) element);
}
}
cp.addInto(element, result, sourceQuery.getSession());
}
return result;
}
use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.
the class XMLCompositeDirectCollectionMapping method writeFromObjectIntoRow.
/**
* INTERNAL:
*/
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) {
if (this.isReadOnly()) {
return;
}
Object attributeValue = this.getAttributeValueFromObject(object);
if (attributeValue == null) {
row.put(this.getField(), null);
return;
}
ContainerPolicy cp = this.getContainerPolicy();
Vector elements = new Vector(cp.sizeFor(attributeValue));
Object iter = cp.iteratorFor(attributeValue);
if (null != iter) {
while (cp.hasNext(iter)) {
Object element = cp.next(iter, session);
element = convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller());
if (element != null) {
elements.addElement(element);
} else if (!usesSingleNode()) {
AbstractNullPolicy nullPolicy = getNullPolicy();
if (nullPolicy == null) {
elements.addElement(null);
} else {
if (nullPolicy.getMarshalNullRepresentation() == XMLNullRepresentationType.XSI_NIL) {
elements.addElement(XMLRecord.NIL);
} else if (nullPolicy.getMarshalNullRepresentation() == XMLNullRepresentationType.ABSENT_NODE) {
// Do nothing
} else {
elements.addElement(XMLConstants.EMPTY_STRING);
}
}
}
}
}
Object fieldValue = null;
if (!elements.isEmpty()) {
fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session);
}
row.put(this.getField(), fieldValue);
}
use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.
the class XMLCompositeObjectMapping method valueFromRow.
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
Object fieldValue = row.get(this.getField());
// BUG#2667762 there could be whitespace in the row instead of null
if ((fieldValue == null) || (fieldValue instanceof String)) {
return null;
}
XMLRecord nestedRow = (XMLRecord) this.getDescriptor().buildNestedRowFromFieldValue(fieldValue);
// Check the policy to see if this DOM record represents null
if (getNullPolicy().valueIsNull((Element) nestedRow.getDOM())) {
return null;
}
return valueFromRow(fieldValue, nestedRow, joinManager, sourceQuery, executionSession, isTargetProtected);
}
use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.
the class XMLCompositeObjectMapping method readFromRowIntoObject.
@Override
public Object readFromRowIntoObject(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object targetObject, CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException {
Object fieldValue = databaseRow.getIndicatingNoEntry(getField());
// Check for absent nodes based on policy flag
if ((null == fieldValue) || fieldValue instanceof String) {
if (getNullPolicy().getIsSetPerformedForAbsentNode()) {
setAttributeValueInObject(targetObject, null);
} else {
return null;
}
return null;
}
// }
// Empty or xsi:nil nodes (non-absent) will arrive here along with populated nodes
XMLRecord nestedRow = (XMLRecord) this.getDescriptor().buildNestedRowFromFieldValue(fieldValue);
// Check the policy to see if this DOM empty/xsi:nil or filled record represents null
if (getNullPolicy().valueIsNull((Element) nestedRow.getDOM())) {
setAttributeValueInObject(targetObject, null);
return null;
}
Object attributeValue = valueFromRow(fieldValue, nestedRow, joinManager, sourceQuery, executionSession, isTargetProtected);
setAttributeValueInObject(targetObject, attributeValue);
if (null != getContainerAccessor()) {
if (this.inverseReferenceMapping.getContainerPolicy() == null) {
getContainerAccessor().setAttributeValueInObject(attributeValue, targetObject);
} else {
Object backpointerContainer = getContainerAccessor().getAttributeValueFromObject(attributeValue);
if (backpointerContainer == null) {
backpointerContainer = this.inverseReferenceMapping.getContainerPolicy().containerInstance();
getContainerAccessor().setAttributeValueInObject(attributeValue, backpointerContainer);
}
this.inverseReferenceMapping.getContainerPolicy().addInto(targetObject, backpointerContainer, executionSession);
}
}
return attributeValue;
}
use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.
the class XMLBinaryDataMapping method valueFromRow.
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) {
// PERF: Direct variable access.
Object value = row.get(this.field);
if (value == null) {
return value;
}
Object fieldValue = null;
XMLUnmarshaller unmarshaller = ((XMLRecord) row).getUnmarshaller();
if (value instanceof String) {
if (this.isSwaRef() && (unmarshaller.getAttachmentUnmarshaller() != null)) {
if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler((String) value);
} else {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray((String) value);
}
} else if (!this.isSwaRef()) {
// should be base64
byte[] bytes = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(value);
fieldValue = bytes;
}
} else if (value instanceof byte[] || value instanceof Byte[]) {
fieldValue = value;
} else {
// this was an element, so do the XOP/SWAREF/Inline binary cases for an element
XMLRecord record = (XMLRecord) value;
if (getNullPolicy().valueIsNull((Element) record.getDOM())) {
return null;
}
record.setSession(executionSession);
if ((unmarshaller.getAttachmentUnmarshaller() != null) && unmarshaller.getAttachmentUnmarshaller().isXOPPackage() && !this.isSwaRef() && !this.shouldInlineBinaryData()) {
// look for the include element:
String xpath = XMLConstants.EMPTY_STRING;
// need a prefix for XOP
String prefix = null;
NamespaceResolver descriptorResolver = ((XMLDescriptor) getDescriptor()).getNamespaceResolver();
// 20061023: handle NPE on null NSR
if (descriptorResolver != null) {
prefix = descriptorResolver.resolveNamespaceURI(XMLConstants.XOP_URL);
}
if (prefix == null) {
prefix = XMLConstants.XOP_PREFIX;
}
NamespaceResolver tempResolver = new NamespaceResolver();
tempResolver.put(prefix, XMLConstants.XOP_URL);
xpath = prefix + include;
XMLField field = new XMLField(xpath);
field.setNamespaceResolver(tempResolver);
String includeValue = (String) record.get(field);
if (includeValue != null) {
if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray(includeValue);
} else {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(includeValue);
}
} else {
// If we didn't find the Include element, check for inline
fieldValue = record.get(XMLConstants.TEXT);
// should be a base64 string
fieldValue = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(fieldValue);
}
} else if ((unmarshaller.getAttachmentUnmarshaller() != null) && isSwaRef()) {
String refValue = (String) record.get(XMLConstants.TEXT);
if (refValue != null) {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(refValue);
}
} else {
fieldValue = record.get(XMLConstants.TEXT);
// should be a base64 string
if (fieldValue != null) {
fieldValue = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(fieldValue);
} else {
fieldValue = new byte[0];
}
}
}
Object attributeValue = convertDataValueToObjectValue(fieldValue, executionSession, unmarshaller);
attributeValue = XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(attributeValue, getAttributeClassification(), executionSession, null);
return attributeValue;
}
Aggregations