Search in sources :

Example 1 with UnidirectionalOneToManyMapping

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

the class MapCollectionsProject method buildEntityEntityU1MMapHolderDescriptor.

protected void buildEntityEntityU1MMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(EntityEntityU1MMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("ENT_ENT_U1M_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("ENT_ENT_U1M_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("ENT_ENT_U1M_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("ENT_ENT_U1M_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    UnidirectionalOneToManyMapping mapMapping = new UnidirectionalOneToManyMapping();
    mapMapping.setAttributeName("entityToEntityMap");
    mapMapping.setReferenceClass(EntityMapValue.class);
    mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    mapMapping.setGetMethodName("getEntityToEntityMap");
    mapMapping.setSetMethodName("setEntityToEntityMap");
    mapMapping.addTargetForeignKeyFieldName("ENT_MAP_VALUE.HOLDER_ID", "ENT_ENT_U1M_MAP_HOLDER.ID");
    org.eclipse.persistence.mappings.OneToOneMapping keyMapping = new org.eclipse.persistence.mappings.OneToOneMapping();
    keyMapping.setReferenceClass(EntityMapKey.class);
    keyMapping.addForeignKeyFieldName("ENT_MAP_VALUE.KEY_ID", "ENT_MAP_KEY.ID");
    keyMapping.dontUseIndirection();
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(mapMapping);
    mapMapping.setContainerPolicy(policy);
    descriptor.addMapping(mapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy) UnidirectionalOneToManyMapping(org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 2 with UnidirectionalOneToManyMapping

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

the class MapCollectionsProject method buildDirectEntityU1MMapHolderDescriptor.

protected void buildDirectEntityU1MMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(DirectEntityU1MMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("DIR_ENT_U1M_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("DIR_ENT_U1M_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("DIR_ENT_U1M_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("DIR_ENT_U1M_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    UnidirectionalOneToManyMapping mapMapping = new UnidirectionalOneToManyMapping();
    mapMapping.setAttributeName("directToEntityMap");
    mapMapping.setReferenceClass(EntityMapValue.class);
    mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    mapMapping.setGetMethodName("getDirectToEntityMap");
    mapMapping.setSetMethodName("setDirectToEntityMap");
    mapMapping.addTargetForeignKeyFieldName("ENT_MAP_VALUE.HOLDER_ID", "DIR_ENT_U1M_MAP_HOLDER.ID");
    org.eclipse.persistence.mappings.DirectToFieldMapping keyMapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
    keyMapping.setFieldName("ENT_MAP_VALUE.MAP_KEY");
    keyMapping.setAttributeClassification(Integer.class);
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(mapMapping);
    mapMapping.setContainerPolicy(policy);
    descriptor.addMapping(mapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) 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) UnidirectionalOneToManyMapping(org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)

Example 3 with UnidirectionalOneToManyMapping

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

the class MapCollectionsProject method buildAggregateEntityU1MMapHolderDescriptor.

protected void buildAggregateEntityU1MMapHolderDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(AggregateEntityU1MMapHolder.class);
    Vector vector = new Vector();
    vector.addElement("AGG_ENT_U1M_MAP_HOLDER");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("AGG_ENT_U1M_MAP_HOLDER.ID");
    // SECTION: PROPERTIES
    descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
    descriptor.setExistenceChecking("Check cache");
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberName("AGG_ENT_U1M_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_ENT_U1M_MAP_HOLDER.ID");
    descriptor.addMapping(directtofieldmapping);
    UnidirectionalOneToManyMapping mapMapping = new UnidirectionalOneToManyMapping();
    mapMapping.setAttributeName("aggregateToEntityMap");
    mapMapping.setReferenceClass(EntityMapValue.class);
    mapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
    mapMapping.setGetMethodName("getAggregateToEntityMap");
    mapMapping.setSetMethodName("setAggregateToEntityMap");
    mapMapping.addTargetForeignKeyFieldName("ENT_MAP_VALUE.HOLDER_ID", "AGG_ENT_U1M_MAP_HOLDER.ID");
    AggregateObjectMapping keyMapping = new AggregateObjectMapping();
    keyMapping.setReferenceClass(AggregateMapKey.class);
    keyMapping.addFieldNameTranslation("ENT_MAP_VALUE.MAP_KEY_1", "key->DIRECT");
    keyMapping.setDescriptor(descriptor);
    MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
    policy.setKeyMapping(keyMapping);
    policy.setValueMapping(mapMapping);
    mapMapping.setContainerPolicy(policy);
    descriptor.addMapping(mapMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) 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) UnidirectionalOneToManyMapping(org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)

Example 4 with UnidirectionalOneToManyMapping

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

the class OneToManyAccessor method processUnidirectionalOneToManyMapping.

/**
 * INTERNAL:
 * Process an unidirectional one to many mapping for this accessor since
 * join columns were specified and no mapped by value.
 */
protected void processUnidirectionalOneToManyMapping() {
    // Create a 1-M unidirectional mapping and process common collection
    // mapping metadata first followed by specific metadata.
    UnidirectionalOneToManyMapping mapping = new UnidirectionalOneToManyMapping();
    process(mapping);
    // Process the JoinColumn metadata.
    processUnidirectionalOneToManyTargetForeignKeyRelationship(mapping, getJoinColumns(getJoinColumns(), getOwningDescriptor()), getOwningDescriptor());
}
Also used : UnidirectionalOneToManyMapping(org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)

Example 5 with UnidirectionalOneToManyMapping

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

the class OneToManyAccessor method processAssociationOverride.

/**
 * INTERNAL:
 * Process an association override for either an embedded object mapping,
 * or a map mapping (element-collection, 1-M and M-M) containing an
 * embeddable object as the value or key.
 */
@Override
protected void processAssociationOverride(AssociationOverrideMetadata associationOverride, EmbeddableMapping embeddableMapping, MetadataDescriptor owningDescriptor) {
    if (getMapping().isUnidirectionalOneToManyMapping()) {
        // Create an override mapping and process the join columns to it.
        UnidirectionalOneToManyMapping overrideMapping = new UnidirectionalOneToManyMapping();
        overrideMapping.setAttributeName(getAttributeName());
        processUnidirectionalOneToManyTargetForeignKeyRelationship(overrideMapping, associationOverride.getJoinColumns(), owningDescriptor);
        // The override mapping will have the correct source, sourceRelation,
        // target and targetRelation keys. Along with the correct relation table.
        embeddableMapping.addOverrideUnidirectionalOneToManyMapping(overrideMapping);
        // Set the override mapping which will have the correct metadata
        // set. This is the metadata any non-owning relationship accessor
        // referring to this accessor will need.
        setOverrideMapping(overrideMapping);
    } else {
        super.processAssociationOverride(associationOverride, embeddableMapping, owningDescriptor);
    }
}
Also used : UnidirectionalOneToManyMapping(org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)

Aggregations

UnidirectionalOneToManyMapping (org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)5 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)3 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)3 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)3 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)3 AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)1 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)1