Search in sources :

Example 6 with AbstractDirectMapping

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);
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) QueryKeyExpression(org.eclipse.persistence.internal.expressions.QueryKeyExpression) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) Expression(org.eclipse.persistence.expressions.Expression) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 7 with AbstractDirectMapping

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);
    }
}
Also used : AbstractTransformationMapping(org.eclipse.persistence.mappings.foundation.AbstractTransformationMapping) AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) InvalidObject(org.eclipse.persistence.internal.helper.InvalidObject) DirectToFieldChangeRecord(org.eclipse.persistence.internal.sessions.DirectToFieldChangeRecord)

Example 8 with AbstractDirectMapping

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);
        }
    }
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) Iterator(java.util.Iterator)

Example 9 with AbstractDirectMapping

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);
            }
        }
    }
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping)

Example 10 with AbstractDirectMapping

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;
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping)

Aggregations

AbstractDirectMapping (org.eclipse.persistence.mappings.foundation.AbstractDirectMapping)20 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)6 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)6 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)3 Converter (org.eclipse.persistence.mappings.converters.Converter)3 Iterator (java.util.Iterator)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)2 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)2 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)2 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)2 SerializedObjectConverter (org.eclipse.persistence.mappings.converters.SerializedObjectConverter)2 TypeConversionConverter (org.eclipse.persistence.mappings.converters.TypeConversionConverter)2 XMLField (org.eclipse.persistence.oxm.XMLField)2 IOException (java.io.IOException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1