Search in sources :

Example 1 with MapKeyMapping

use of org.eclipse.persistence.mappings.foundation.MapKeyMapping in project eclipselink by eclipse-ee4j.

the class MapAttributeImpl method getOwningPKTypeWhenMapKeyAnnotationMissingOrDefaulted.

/**
 * INTERNAL:
 * Default to the PK of the owning descriptor when no MapKey or MapKey:name attribute is specified.
 * Prerequisites: policy on the mapping is of type MappedKeyMapPolicy
 */
private Class<?> getOwningPKTypeWhenMapKeyAnnotationMissingOrDefaulted(MappedKeyMapContainerPolicy policy) {
    Class<?> javaClass = null;
    ;
    MapKeyMapping mapKeyMapping = policy.getKeyMapping();
    ClassDescriptor descriptor = ((DatabaseMapping) mapKeyMapping).getDescriptor();
    // If the reference descriptor is null then we are on a direct mapping
    if (null != descriptor) {
        javaClass = ((DatabaseMapping) mapKeyMapping).getAttributeClassification();
        if (null == javaClass) {
            // Default to the PK of the owning descriptor when no MapKey or MapKey:name attribute is specified
            if (descriptor.getCMPPolicy() != null) {
                javaClass = descriptor.getCMPPolicy().getPKClass();
            }
        }
    }
    return javaClass;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) MapKeyMapping(org.eclipse.persistence.mappings.foundation.MapKeyMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 2 with MapKeyMapping

use of org.eclipse.persistence.mappings.foundation.MapKeyMapping in project eclipselink by eclipse-ee4j.

the class MappingAccessor method processMapKeyClass.

/**
 * INTERNAL:
 * Process a map key class for the given map key map accessor.
 */
protected void processMapKeyClass(ContainerMapping mapping, MappedKeyMapAccessor mappedKeyMapAccessor) {
    MapKeyMapping keyMapping;
    MetadataClass mapKeyClass = mappedKeyMapAccessor.getMapKeyClass();
    if (getProject().hasEntity(mapKeyClass)) {
        keyMapping = processEntityMapKeyClass(mappedKeyMapAccessor);
    } else if (getProject().hasEmbeddable(mapKeyClass)) {
        keyMapping = processEmbeddableMapKeyClass(mappedKeyMapAccessor);
    } else {
        keyMapping = processDirectMapKeyClass(mappedKeyMapAccessor);
    }
    Class<?> containerClass;
    if (mapping instanceof ForeignReferenceMapping) {
        if (usesIndirection()) {
            containerClass = ClassConstants.IndirectMap_Class;
            ((ForeignReferenceMapping) mapping).setIndirectionPolicy(new TransparentIndirectionPolicy());
        } else {
            containerClass = java.util.Hashtable.class;
            ((ForeignReferenceMapping) mapping).dontUseIndirection();
        }
    } else {
        containerClass = java.util.Hashtable.class;
    }
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(containerClass);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping((MapComponentMapping) mapping);
    mapping.setContainerPolicy(policy);
}
Also used : ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) MapKeyMapping(org.eclipse.persistence.mappings.foundation.MapKeyMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)

Aggregations

MapKeyMapping (org.eclipse.persistence.mappings.foundation.MapKeyMapping)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)1 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)1 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)1