use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectBuilder method createPrimaryKeyExpression.
/**
* Creates and stores primary key expression.
*/
public void createPrimaryKeyExpression(AbstractSession session) {
Expression expression = null;
Expression builder = new ExpressionBuilder();
Expression subExp1;
Expression subExp2;
Expression subExpression;
List<DatabaseField> primaryKeyFields = this.descriptor.getPrimaryKeyFields();
if (null != primaryKeyFields) {
for (int index = 0; index < primaryKeyFields.size(); index++) {
DatabaseField primaryKeyField = primaryKeyFields.get(index);
String fieldClassificationClassName = null;
if (this.getBaseMappingForField(primaryKeyField) instanceof AbstractDirectMapping) {
fieldClassificationClassName = ((AbstractDirectMapping) this.getBaseMappingForField(primaryKeyField)).getFieldClassificationClassName();
}
subExpression = ((DatasourcePlatform) session.getDatasourcePlatform()).createExpressionFor(primaryKeyField, builder, fieldClassificationClassName);
if (expression == null) {
expression = subExpression;
} else {
expression = expression.and(subExpression);
}
}
}
setPrimaryKeyExpression(expression);
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping 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.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectTypeConverter method initializeFieldClassification.
/**
* INTERNAL:
* Set the field classification through searching the fields map.
*/
public void initializeFieldClassification(Session session) throws DescriptorException {
if (getFieldToAttributeValues().isEmpty()) {
return;
}
Class<?> type = null;
Iterator fieldValuesEnum = getFieldToAttributeValues().keySet().iterator();
while (fieldValuesEnum.hasNext() && (type == null)) {
Object value = fieldValuesEnum.next();
if (value != Helper.NULL_VALUE) {
type = value.getClass();
}
}
setFieldClassification(type);
// CR#... Mapping must also have the field classification.
if (getMapping().isDirectToFieldMapping()) {
AbstractDirectMapping directMapping = (AbstractDirectMapping) getMapping();
// Allow user to specify field type to override computed value. (i.e. blob, nchar)
if (directMapping.getFieldClassification() == null) {
directMapping.setFieldClassification(type);
}
}
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class UUIDConverter method initialize.
/**
* Initialize mapping for JDBC data type.
*
* @param mapping field database mapping
* @param session current database session
*/
@Override
public void initialize(DatabaseMapping mapping, Session session) {
if (mapping.isDirectToFieldMapping()) {
if (((AbstractDirectMapping) mapping).getFieldClassification() == null) {
final AbstractDirectMapping directMapping = AbstractDirectMapping.class.cast(mapping);
final Class<?> attributeClassification = mapping.getAttributeClassification();
if (attributeClassification.isInstance(UUID.class)) {
directMapping.setFieldClassification(UUID.class);
}
}
}
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class EntityTypeFromDescriptor method buildMyEntityDescriptor.
private RelationalDescriptor buildMyEntityDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(MyEntity.class);
descriptor.setTableName(TABLE_NAME);
descriptor.addPrimaryKeyFieldName("ID");
AbstractDirectMapping mapping = (AbstractDirectMapping) descriptor.addDirectMapping("id", "ID");
mapping.setAttributeClassification(int.class);
mapping = (AbstractDirectMapping) descriptor.addDirectMapping("name", "NAME");
mapping.setAttributeClassification(String.class);
return descriptor;
}
Aggregations