Search in sources :

Example 1 with TransparentIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy 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)

Example 2 with TransparentIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class TransparentIndirectionPolicyInstanceTest method setup.

@Override
protected void setup() {
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    descriptorToModify = project.getDescriptors().get(Employee.class);
    for (Enumeration<DatabaseMapping> mappingsEnum = (descriptorToModify.getMappings()).elements(); mappingsEnum.hasMoreElements(); ) {
        mappingToModify = mappingsEnum.nextElement();
        if (mappingToModify.isForeignReferenceMapping()) {
            ((ForeignReferenceMapping) mappingToModify).setIndirectionPolicy(new TransparentIndirectionPolicy());
        }
    }
}
Also used : ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 3 with TransparentIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class UseTransparentMapOnCollectionMapping method setup.

@Override
protected void setup() {
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    descriptorToModify = project.getDescriptors().get(Employee.class);
    policy = new TransparentIndirectionPolicy();
    mapPolicy = new MapContainerPolicy();
    for (Enumeration<DatabaseMapping> mappingsEnum = (descriptorToModify.getMappings()).elements(); mappingsEnum.hasMoreElements(); ) {
        mappingToModify = mappingsEnum.nextElement();
        if (mappingToModify.isForeignReferenceMapping()) {
            if (mappingToModify.isCollectionMapping()) {
                CollectionMapping collectionMapping = (CollectionMapping) mappingToModify;
                collectionMapping.setContainerPolicy(mapPolicy);
                mapPolicy.setKeyName("testMethod");
                collectionMapping.getContainerPolicy().setContainerClass(Vector.class);
                ((ForeignReferenceMapping) mappingToModify).setIndirectionPolicy(policy);
            }
        }
    }
}
Also used : ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) MapContainerPolicy(org.eclipse.persistence.internal.queries.MapContainerPolicy) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Example 4 with TransparentIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class DirectMapMapping method useTransparentMap.

/**
 * PUBLIC:
 * Configure the mapping to use an instance of the specified container class
 * to hold the target objects.
 * <p>The container class must implement (directly or indirectly) the Map interface.
 * <p>Note: Do not use both useMapClass(Class concreteClass), useTransparentMap().  The last use of one of the two methods will override the previous one.
 */
public void useTransparentMap() {
    setIndirectionPolicy(new TransparentIndirectionPolicy());
    useMapClass(ClassConstants.IndirectMap_Class);
}
Also used : TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)

Example 5 with TransparentIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy 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

TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)25 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)16 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)15 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)15 UnidirectionalOneToManyMapping (org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)6 AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)5 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)5 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)5 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)5 IntegrityChecker (org.eclipse.persistence.exceptions.IntegrityChecker)3 DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)3 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)3 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)3 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)2 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 Expression (org.eclipse.persistence.expressions.Expression)1 IndirectMap (org.eclipse.persistence.indirection.IndirectMap)1 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)1 BasicIndirectionPolicy (org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy)1