Search in sources :

Example 1 with DirectMapMapping

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

the class MappingAccessor method setIndirectionPolicy.

/**
 * INTERNAL:
 * Set the correct indirection policy on a collection mapping. Method
 * assume that the reference class has been set on the mapping before
 * calling this method.
 */
protected void setIndirectionPolicy(ContainerMapping mapping, String mapKey, boolean usesIndirection) {
    MetadataClass rawClass = getRawClass();
    boolean containerPolicySet = false;
    if (usesIndirection && (mapping instanceof ForeignReferenceMapping)) {
        containerPolicySet = true;
        CollectionMapping collectionMapping = (CollectionMapping) mapping;
        if (rawClass.isClass(Map.class)) {
            if (collectionMapping.isDirectMapMapping()) {
                ((DirectMapMapping) mapping).useTransparentMap();
            } else {
                collectionMapping.useTransparentMap(mapKey);
            }
        } else if (rawClass.isClass(List.class)) {
            collectionMapping.useTransparentList();
        } else if (rawClass.isClass(Collection.class)) {
            collectionMapping.useTransparentCollection();
        } else if (rawClass.isClass(Set.class)) {
            collectionMapping.useTransparentSet();
        } else {
            getLogger().logWarningMessage(MetadataLogger.WARNING_INVALID_COLLECTION_USED_ON_LAZY_RELATION, getJavaClass(), getAnnotatedElement(), rawClass);
            processIndirection((ForeignReferenceMapping) mapping);
            containerPolicySet = false;
        }
    } else {
        if (mapping instanceof CollectionMapping) {
            ((CollectionMapping) mapping).dontUseIndirection();
        }
    }
    if (!containerPolicySet) {
        if (rawClass.isClass(Map.class)) {
            if (mapping instanceof DirectMapMapping) {
                ((DirectMapMapping) mapping).useMapClass(java.util.Hashtable.class);
            } else {
                mapping.useMapClass(java.util.Hashtable.class, mapKey);
            }
        } else if (rawClass.isClass(Set.class)) {
            // This will cause it to use a CollectionContainerPolicy type
            mapping.useCollectionClass(java.util.HashSet.class);
        } else if (rawClass.isClass(List.class)) {
            // This will cause a ListContainerPolicy type to be used or
            // OrderedListContainerPolicy if ordering is specified.
            mapping.useCollectionClass(java.util.Vector.class);
        } else if (rawClass.isClass(Collection.class)) {
            // Force CollectionContainerPolicy type to be used with a
            // collection implementation.
            mapping.setContainerPolicy(new CollectionContainerPolicy(java.util.Vector.class));
        } else {
            // Use the supplied collection class type if its not an interface
            if (mapKey == null || mapKey.equals("")) {
                if (rawClass.isList()) {
                    mapping.useListClassName(rawClass.getName());
                } else {
                    mapping.useCollectionClassName(rawClass.getName());
                }
            } else {
                mapping.useMapClassName(rawClass.getName(), mapKey);
            }
        }
    }
}
Also used : ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) Set(java.util.Set) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 2 with DirectMapMapping

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

the class ConverterAccessor method process.

/**
 * INTERNAL:
 * Process this converter for the given mapping.
 */
public void process(DatabaseMapping mapping, boolean isForMapKey, String attributeName, boolean disableConversion) {
    ConverterClass converterClass = new ConverterClass(getJavaClassName(), isForMapKey, fieldClassification.getName(), disableConversion);
    converterClass.setSession(getProject().getSession());
    if (mapping.isDirectMapMapping() && isForMapKey) {
        ((DirectMapMapping) mapping).setKeyConverter(converterClass);
    } else if (mapping.isDirectCollectionMapping()) {
        ((DirectCollectionMapping) mapping).setValueConverter(converterClass);
    } else if (mapping.isDirectToFieldMapping()) {
        ((AbstractDirectMapping) mapping).setConverter(converterClass);
    } else if (mapping.isAggregateObjectMapping()) {
        ((AggregateObjectMapping) mapping).addConverter(converterClass, attributeName);
    } else if (mapping.isAggregateCollectionMapping()) {
        ((AggregateCollectionMapping) mapping).addConverter(converterClass, attributeName);
    }
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) ConverterClass(org.eclipse.persistence.mappings.converters.ConverterClass) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 3 with DirectMapMapping

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

the class DirectCollectionAccessor method processDirectMapMapping.

/**
 * INTERNAL:
 */
protected void processDirectMapMapping() {
    // Initialize and process common direct collection metadata. This must
    // be done before any field processing since field processing requires
    // that the collection table be processed before hand.
    DirectMapMapping mapping = new DirectMapMapping();
    process(mapping);
    // Process the container and indirection policies.
    processContainerPolicyAndIndirection(mapping);
    // Process the key column (we must process this field before the
    // call to processConverter, since it may set a field classification)
    mapping.setDirectKeyField(getDatabaseField(getReferenceDatabaseTable(), MetadataLogger.MAP_KEY_COLUMN));
    // in the processContainerPolicyAndIndirection call above.
    if (isBasicMap()) {
        // mapping to ensure we do the right conversions.
        if (hasAttributeType() || getAccessibleObject().isGenericCollectionType()) {
            mapping.setDirectKeyFieldClassificationName(getJavaClassName(getMapKeyReferenceClass()));
        }
        // Process a converter for the key column of this mapping.
        processMappingKeyConverter(mapping, getKeyConverter(), null, getMapKeyReferenceClass(), getMapKeyReferenceClassWithGenerics());
    }
    // Process the value column (we must process this field before the call
    // to processConverter, since it may set a field classification)
    mapping.setDirectField(getDatabaseField(getReferenceDatabaseTable(), MetadataLogger.VALUE_COLUMN));
    // mapping to ensure we do the right conversions.
    if (hasAttributeType() || getAccessibleObject().isGenericCollectionType()) {
        mapping.setDirectFieldClassificationName(getJavaClassName(getReferenceClass()));
    }
    // Process a converter for value column of this mapping.
    processMappingValueConverter(mapping, getValueConverter(), getConverts(), getReferenceClass(), getReferenceClassWithGenerics());
}
Also used : DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 4 with DirectMapMapping

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

the class ConverterClass method initialize.

/**
 * INTERNAL:
 */
@Override
public void initialize(DatabaseMapping mapping, Session session) {
    // Ensure the mapping has the correct field classification set.
    if (mapping.isDirectToFieldMapping()) {
        DirectToFieldMapping m = (DirectToFieldMapping) mapping;
        if (disableConversion) {
            m.setConverter(null);
        } else {
            m.setConverter(this);
            m.setFieldClassification(fieldClassification);
            m.setFieldClassificationClassName(fieldClassificationName);
        }
    } else if (mapping.isDirectMapMapping() && isForMapKey) {
        DirectMapMapping m = (DirectMapMapping) mapping;
        if (disableConversion) {
            m.setKeyConverter(null);
        } else {
            m.setKeyConverter(this);
            m.setDirectKeyFieldClassification(fieldClassification);
            m.setDirectKeyFieldClassificationName(fieldClassificationName);
        }
    } else if (mapping.isDirectCollectionMapping()) {
        DirectCollectionMapping m = (DirectCollectionMapping) mapping;
        if (disableConversion) {
            m.setValueConverter(null);
        } else {
            m.setValueConverter(this);
            m.setDirectFieldClassification(fieldClassification);
            m.setDirectFieldClassificationName(fieldClassificationName);
        }
    } else {
    // TODO: what else could it be???
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping)

Example 5 with DirectMapMapping

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

the class MapCollectionsProject method buildAggregateDirectMapHolderDescriptor.

protected void buildAggregateDirectMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(AggregateDirectMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("AGG_DIR_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("AGG_DIR_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("AGG_DIR_MAP_HOLDER_ID");
    descriptor.setSequenceNumberFieldName("ID");
    // SECTION: DIRECTTOFIELDMAPPING
    org.eclipse.persistence.mappings.DirectToFieldMapping directtofieldmapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
    directtofieldmapping.setAttributeName("id");
    directtofieldmapping.setIsReadOnly(false);
    directtofieldmapping.setGetMethodName("getId");
    directtofieldmapping.setSetMethodName("setId");
    directtofieldmapping.setFieldName("AGG_DIR_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    DirectMapMapping directMapMapping = new DirectMapMapping();
    directMapMapping.setAttributeName("aggregateToDirectMap");
    directMapMapping.setGetMethodName("getAggregateToDirectMap");
    directMapMapping.setSetMethodName("setAggregateToDirectMap");
    directMapMapping.setReferenceTableName("AGG_DIR_MAP_REL");
    directMapMapping.setDirectFieldName("AGG_DIR_MAP_REL.MAP_VALUE");
    directMapMapping.addReferenceKeyFieldName("AGG_DIR_MAP_REL.HOLDER_ID", "AGG_DIR_MAP_HOLDER.ID");
    directMapMapping.setDirectFieldClassification(Integer.class);
    directMapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    AggregateObjectMapping keyMapping = new AggregateObjectMapping();
    keyMapping.setReferenceClass(AggregateMapKey.class);
    keyMapping.addFieldNameTranslation("AGG_DIR_MAP_REL.MAP_KEY", "key->DIRECT");
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(directMapMapping);
    directMapMapping.setContainerPolicy(policy);
    descriptor.addMapping(directMapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)

Aggregations

DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)16 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)6 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)5 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)4 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)4 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)4 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)3 AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)2 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)2 JoinTable (com.blazebit.persistence.spi.JoinTable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Vector (java.util.Vector)1