use of org.eclipse.persistence.mappings.foundation.AbstractTransformationMapping in project eclipselink by eclipse-ee4j.
the class ObjectBuilder method assignReturnValueToMapping.
/**
* INTERNAL:
* Assign values from objectRow to the object through the mapping.
* If not null changeSet must correspond to object. changeSet is updated with all of the field values in the row.
*/
protected void assignReturnValueToMapping(Object object, ReadObjectQuery query, AbstractRecord row, DatabaseField field, DatabaseMapping mapping, Collection handledMappings, ObjectChangeSet changeSet) {
if ((handledMappings != null) && handledMappings.contains(mapping)) {
return;
}
if (mapping.isAbstractDirectMapping()) {
if (changeSet != null && (!changeSet.isNew() || (query.getDescriptor() != null && query.getDescriptor().shouldUseFullChangeSetsForNewObjects()))) {
DirectToFieldChangeRecord changeRecord = (DirectToFieldChangeRecord) changeSet.getChangesForAttributeNamed(mapping.getAttributeName());
Object oldAttributeValue = null;
if (changeRecord == null) {
oldAttributeValue = mapping.getAttributeValueFromObject(object);
}
// use null cachekey to ensure we build directly into the attribute
Object attributeValue = mapping.readFromRowIntoObject(row, null, object, null, query, query.getSession(), true);
if (changeRecord == null) {
// Don't use ObjectChangeSet.updateChangeRecordForAttributeWithMappedObject to avoid unnecessary conversion - attributeValue is already converted.
changeRecord = (DirectToFieldChangeRecord) ((AbstractDirectMapping) mapping).internalBuildChangeRecord(attributeValue, oldAttributeValue, changeSet);
changeSet.addChange(changeRecord);
} else {
changeRecord.setNewValue(attributeValue);
}
} else {
mapping.readFromRowIntoObject(row, null, object, null, query, query.getSession(), true);
}
} else if (mapping.isAggregateObjectMapping()) {
((AggregateObjectMapping) mapping).readFromReturnRowIntoObject(row, object, query, handledMappings, changeSet);
} else if (mapping.isTransformationMapping()) {
((AbstractTransformationMapping) mapping).readFromReturnRowIntoObject(row, object, query, handledMappings, changeSet);
} else {
query.getSession().log(SessionLog.FINEST, SessionLog.QUERY, "field_for_unsupported_mapping_returned", field, this.descriptor);
}
}
use of org.eclipse.persistence.mappings.foundation.AbstractTransformationMapping in project eclipselink by eclipse-ee4j.
the class AggregateObjectMapping method readFromReturnRowIntoObject.
/**
* INTERNAL:
* Build an aggregate object from the specified return row and put it
* in the specified target object.
* Return row is merged into object after execution of insert or update call
* according to ReturningPolicy.
* If not null changeSet must correspond to targetObject. changeSet is updated with all of the field values in the row.
*/
public Object readFromReturnRowIntoObject(AbstractRecord row, Object targetObject, ReadObjectQuery query, Collection handledMappings, ObjectChangeSet changeSet) throws DatabaseException {
Object aggregate = getAttributeValueFromObject(targetObject);
ObjectChangeSet aggregateChangeSet = null;
if (aggregate == null) {
aggregate = readFromRowIntoObject(row, null, targetObject, null, query, query.getSession(), true);
} else {
if (changeSet != null && (!changeSet.isNew() || (query.getDescriptor() != null && query.getDescriptor().shouldUseFullChangeSetsForNewObjects()))) {
aggregateChangeSet = getReferenceDescriptor(aggregate, query.getSession()).getObjectBuilder().createObjectChangeSet(aggregate, (UnitOfWorkChangeSet) ((UnitOfWorkImpl) query.getSession()).getUnitOfWorkChangeSet(), true, query.getSession());
}
AbstractRecord aggregateRow = new DatabaseRecord();
int size = row.size();
List<DatabaseField> fields = row.getFields();
List values = row.getValues();
List<DatabaseField> aggregateFields = getReferenceFields();
for (int i = 0; i < size; i++) {
DatabaseField field = fields.get(i);
if (aggregateFields.contains(field)) {
aggregateRow.add(field, values.get(i));
}
}
getObjectBuilder(aggregate, query.getSession()).assignReturnRow(aggregate, query.getSession(), aggregateRow, aggregateChangeSet);
}
if (aggregate != null && isNullAllowed()) {
boolean allAttributesNull = true;
int nAggregateFields = this.fields.size();
for (int i = 0; (i < nAggregateFields) && allAttributesNull; i++) {
DatabaseField field = this.fields.elementAt(i);
if (row.containsKey(field)) {
allAttributesNull = row.get(field) == null;
} else {
Object fieldValue = valueFromObject(targetObject, field, query.getSession());
if (fieldValue == null) {
Object baseValue = getDescriptor().getObjectBuilder().getBaseValueForField(field, targetObject);
if (baseValue != null) {
DatabaseMapping baseMapping = getDescriptor().getObjectBuilder().getBaseMappingForField(field);
if (baseMapping.isForeignReferenceMapping()) {
ForeignReferenceMapping refMapping = (ForeignReferenceMapping) baseMapping;
if (refMapping.usesIndirection()) {
allAttributesNull = refMapping.getIndirectionPolicy().objectIsInstantiated(baseValue);
}
} else if (baseMapping.isTransformationMapping()) {
AbstractTransformationMapping transMapping = (AbstractTransformationMapping) baseMapping;
if (transMapping.usesIndirection()) {
allAttributesNull = transMapping.getIndirectionPolicy().objectIsInstantiated(baseValue);
}
}
}
} else {
allAttributesNull = false;
}
}
}
if (allAttributesNull) {
aggregate = null;
setAttributeValueInObject(targetObject, aggregate);
}
}
if (changeSet != null && (!changeSet.isNew() || (query.getDescriptor() != null && query.getDescriptor().shouldUseFullChangeSetsForNewObjects()))) {
AggregateChangeRecord record = (AggregateChangeRecord) changeSet.getChangesForAttributeNamed(getAttributeName());
if (aggregate == null) {
if (record != null) {
record.setChangedObject(null);
}
} else {
if (record == null) {
record = new AggregateChangeRecord(changeSet);
record.setAttribute(getAttributeName());
record.setMapping(this);
changeSet.addChange(record);
}
if (aggregateChangeSet == null) {
// the old aggregate value was null
aggregateChangeSet = getReferenceDescriptor(aggregate, query.getSession()).getObjectBuilder().createObjectChangeSet(aggregate, (UnitOfWorkChangeSet) ((UnitOfWorkImpl) query.getSession()).getUnitOfWorkChangeSet(), true, query.getSession());
}
record.setChangedObject(aggregateChangeSet);
}
}
if (handledMappings != null) {
handledMappings.add(this);
}
return aggregate;
}
Aggregations