Search in sources :

Example 1 with MappedKeyMapContainerPolicy

use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy in project eclipselink by eclipse-ee4j.

the class EntityGraphImpl method addKeySubgraph.

@Override
public <X> Subgraph<X> addKeySubgraph(String attributeName, Class<X> type) {
    if (!this.isMutable) {
        throw new IllegalStateException(ExceptionLocalization.buildMessage("immutable_entitygraph"));
    }
    AttributeNodeImpl node = null;
    if (this.attributeNodes != null) {
        node = this.attributeNodes.get(attributeName);
    }
    if (node == null) {
        node = new AttributeNodeImpl<X>(attributeName);
        addAttributeNodeImpl(node);
    }
    AttributeGroup localGroup = null;
    DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeName);
    if (mapping == null) {
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage("metamodel_managed_type_attribute_not_present", new Object[] { this.descriptor.getJavaClassName(), attributeName }));
    }
    if (!mapping.getContainerPolicy().isMappedKeyMapPolicy() && !((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).isMapKeyAttribute()) {
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage("attribute_is_not_map_with_managed_key", new Object[] { attributeName, descriptor.getJavaClassName() }));
    }
    localGroup = new AttributeGroup(attributeName, type, true);
    ClassDescriptor targetDesc = mapping.getContainerPolicy().getDescriptorForMapKey();
    if (type != null && targetDesc.hasInheritance()) {
        targetDesc = targetDesc.getInheritancePolicy().getDescriptor(type);
        if (targetDesc == null) {
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage("type_unkown_for_this_attribute", new Object[] { type.getName(), attributeName }));
        }
    }
    EntityGraphImpl entityGraph = new EntityGraphImpl(localGroup, targetDesc, attributeName);
    node.addKeySubgraph(entityGraph);
    // order is important here, must add entity graph to node list before adding to group or it will appear in node list twice.
    this.attributeGroup.addAttributeKey(attributeName, localGroup);
    return entityGraph;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 2 with MappedKeyMapContainerPolicy

use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy 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 3 with MappedKeyMapContainerPolicy

use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy in project eclipselink by eclipse-ee4j.

the class TestUpdateEntityAggregateMapMapping method setup.

@Override
public void setup() {
    AggregateCollectionMapping mapping = (AggregateCollectionMapping) getSession().getProject().getDescriptor(EntityAggregateMapHolder.class).getMappingForAttributeName("entityToAggregateMap");
    keyMapping = (ForeignReferenceMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    oldKeyPrivateOwnedValue = keyMapping.isPrivateOwned();
    keyMapping.setIsPrivateOwned(usePrivateOwned);
    super.setup();
}
Also used : AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)

Example 4 with MappedKeyMapContainerPolicy

use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy in project eclipselink by eclipse-ee4j.

the class TestUpdateEntityEntityMapMapping method setup.

@Override
public void setup() {
    mapping = (ManyToManyMapping) getSession().getProject().getDescriptor(EntityEntityMapHolder.class).getMappingForAttributeName("entityToEntityMap");
    oldPrivateOwnedValue = mapping.isPrivateOwned();
    mapping.setIsPrivateOwned(usePrivateOwned);
    keyMapping = (ForeignReferenceMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    oldKeyPrivateOwnedValue = keyMapping.isPrivateOwned();
    keyMapping.setIsPrivateOwned(usePrivateOwned);
    UnitOfWork uow = getSession().acquireUnitOfWork();
    holder = new EntityEntityMapHolder();
    EntityMapValue value = new EntityMapValue();
    value.setId(1);
    EntityMapKey key = new EntityMapKey();
    key.setId(11);
    key.setData("data1");
    holder.addEntityToEntityMapItem(key, value);
    uow.registerObject(key);
    EntityMapValue value2 = new EntityMapValue();
    value2.setId(2);
    key = new EntityMapKey();
    key.setId(22);
    holder.addEntityToEntityMapItem(key, value2);
    uow.registerObject(holder);
    uow.registerObject(key);
    uow.registerObject(value);
    uow.registerObject(value2);
    uow.commit();
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) EntityMapValue(org.eclipse.persistence.testing.models.collections.map.EntityMapValue) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy) EntityEntityMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntityMapHolder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 5 with MappedKeyMapContainerPolicy

use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy 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

MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)25 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)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 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)5 DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)4 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)3 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)3 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 List (java.util.List)1 Expression (org.eclipse.persistence.expressions.Expression)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)1 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)1 AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)1 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)1 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)1