Search in sources :

Example 1 with AggregateObjectMapping

use of org.eclipse.persistence.mappings.AggregateObjectMapping in project jmix by jmix-framework.

the class EmbeddedAttributesMappingProcessor method process.

@Override
public void process(MappingProcessorContext context) {
    DatabaseMapping mapping = context.getMapping();
    if (mapping instanceof AggregateObjectMapping) {
        MetaClass metaClass = metadata.getClass(mapping.getDescriptor().getJavaClass());
        MetaProperty metaProperty = metaClass.getProperty(mapping.getAttributeName());
        EmbeddedParameters embeddedParameters = metaProperty.getAnnotatedElement().getAnnotation(EmbeddedParameters.class);
        if (embeddedParameters != null && !embeddedParameters.nullAllowed()) {
            ((AggregateObjectMapping) mapping).setIsNullAllowed(false);
        }
    }
}
Also used : EmbeddedParameters(io.jmix.core.entity.annotation.EmbeddedParameters) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) MetaClass(io.jmix.core.metamodel.model.MetaClass) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 2 with AggregateObjectMapping

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

the class MappingAccessor method processEmbeddableMapKeyClass.

/**
 * INTERNAL:
 */
protected AggregateObjectMapping processEmbeddableMapKeyClass(MappedKeyMapAccessor mappedKeyMapAccessor) {
    AggregateObjectMapping keyMapping = new AggregateObjectMapping();
    MetadataClass mapKeyClass = mappedKeyMapAccessor.getMapKeyClass();
    keyMapping.setReferenceClassName(mapKeyClass.getName());
    // The embeddable accessor must be processed by now. If it is not then
    // we are in trouble since by the time we get here, we are too late in
    // the cycle to process embeddable classes and their accessors. See
    // MetadataProject processStage3(), processEmbeddableMappingAccessors.
    // At this stage all class accessors (embeddable, entity and mapped
    // superclass) have to have been processed to gather all their
    // relational and embedded mappings.
    EmbeddableAccessor mapKeyAccessor = getProject().getEmbeddableAccessor(mapKeyClass);
    // Ensure the reference descriptor is marked as an embeddable collection.
    mapKeyAccessor.getDescriptor().setIsEmbeddable();
    // Process the attribute overrides for this may key embeddable.
    processAttributeOverrides(mappedKeyMapAccessor.getMapKeyAttributeOverrides(), keyMapping, mapKeyAccessor.getDescriptor());
    // Process the association overrides for this may key embeddable.
    processAssociationOverrides(mappedKeyMapAccessor.getMapKeyAssociationOverrides(), keyMapping, mapKeyAccessor.getDescriptor());
    // Process a convert key or jpa converter for the map key if specified.
    processConverts(getMapKeyConverts(mappedKeyMapAccessor.getMapKeyConverts()), keyMapping, mappedKeyMapAccessor.getMapKeyClass(), true);
    keyMapping.setDescriptor(getDescriptor().getClassDescriptor());
    return keyMapping;
}
Also used : AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) EmbeddableAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor)

Example 3 with AggregateObjectMapping

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

the class EmbeddedAccessor method process.

/**
 * INTERNAL:
 * Process an embedded.
 */
@Override
public void process() {
    // Build and aggregate object mapping and add it to the descriptor.
    AggregateMapping mapping = getOwningDescriptor().getClassDescriptor().newAggregateMapping();
    setMapping(mapping);
    mapping.setReferenceClassName(getReferenceClassName());
    mapping.setAttributeName(getAttributeName());
    // Will check for PROPERTY access
    setAccessorMethods(mapping);
    // EIS and ORDT mappings may not be aggregate object mappings.
    if (mapping.isAggregateObjectMapping()) {
        AggregateObjectMapping aggregateMapping = (AggregateObjectMapping) mapping;
        aggregateMapping.setIsNullAllowed(true);
        // Process attribute overrides.
        processAttributeOverrides(m_attributeOverrides, aggregateMapping, getReferenceDescriptor());
        // Process association overrides.
        processAssociationOverrides(m_associationOverrides, aggregateMapping, getReferenceDescriptor());
        // Process converts.
        processConverts(getConverts(m_converts), aggregateMapping, getReferenceClass(), false);
    } else if (mapping.isAbstractCompositeObjectMapping()) {
        ((AbstractCompositeObjectMapping) mapping).setField(getDatabaseField(getDescriptor().getPrimaryTable(), MetadataLogger.COLUMN));
    }
    // Process a @ReturnInsert and @ReturnUpdate (to log a warning message)
    processReturnInsertAndUpdate();
}
Also used : AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) AggregateMapping(org.eclipse.persistence.mappings.AggregateMapping)

Example 4 with AggregateObjectMapping

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

the class ALCTEmployeeProject method buildEmployeeDescriptor.

public ClassDescriptor buildEmployeeDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(ALCTEmployee.class);
    descriptor.addTableName("ALCTEMPLOYEE");
    descriptor.addPrimaryKeyFieldName("ALCTEMPLOYEE.EMP_ID");
    // Descriptor Properties.
    descriptor.useSoftCacheWeakIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteSoftCacheWeakIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("ALCTEMPLOYEE.EMP_ID");
    descriptor.setSequenceNumberName("EMP_SEQ");
    VersionLockingPolicy lockingPolicy = new VersionLockingPolicy();
    lockingPolicy.setWriteLockFieldName("ALCTEMPLOYEE.VERSION");
    descriptor.setOptimisticLockingPolicy(lockingPolicy);
    descriptor.setAlias("ALCTEmployee");
    // Change Tracking
    descriptor.setObjectChangePolicy(new AttributeChangeTrackingPolicy());
    // Cache Invalidation Policy
    // Query Manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    descriptor.getQueryManager().setQueryTimeout(0);
    // Named Queries.
    // Event Manager.
    // Mappings.
    DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setFieldName("ALCTEMPLOYEE.F_NAME");
    firstNameMapping.setNullValue("");
    descriptor.addMapping(firstNameMapping);
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("ALCTEMPLOYEE.EMP_ID");
    descriptor.addMapping(idMapping);
    DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
    lastNameMapping.setAttributeName("lastName");
    lastNameMapping.setFieldName("ALCTEMPLOYEE.L_NAME");
    lastNameMapping.setNullValue("");
    descriptor.addMapping(lastNameMapping);
    DirectToFieldMapping genderMapping = new DirectToFieldMapping();
    genderMapping.setAttributeName("gender");
    genderMapping.setFieldName("ALCTEMPLOYEE.GENDER");
    ObjectTypeConverter genderMappingConverter = new ObjectTypeConverter();
    genderMappingConverter.addConversionValue("F", "Female");
    genderMappingConverter.addConversionValue("M", "Male");
    genderMapping.setConverter(genderMappingConverter);
    descriptor.addMapping(genderMapping);
    AggregateObjectMapping periodMapping = new AggregateObjectMapping();
    periodMapping.setAttributeName("period");
    periodMapping.setReferenceClass(ALCTEmploymentPeriod.class);
    periodMapping.setIsNullAllowed(true);
    periodMapping.addFieldNameTranslation("ALCTEMPLOYEE.END_DATE", "endDate->DIRECT");
    periodMapping.addFieldNameTranslation("ALCTEMPLOYEE.START_DATE", "startDate->DIRECT");
    descriptor.addMapping(periodMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) VersionLockingPolicy(org.eclipse.persistence.descriptors.VersionLockingPolicy) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) AttributeChangeTrackingPolicy(org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy)

Example 5 with AggregateObjectMapping

use of org.eclipse.persistence.mappings.AggregateObjectMapping 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

AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)21 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)10 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)8 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)5 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)5 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)5 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)5 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)4 ArrayList (java.util.ArrayList)3 Vector (java.util.Vector)3 VersionLockingPolicy (org.eclipse.persistence.descriptors.VersionLockingPolicy)2 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)2 Association (org.eclipse.persistence.mappings.Association)2 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)2 UnidirectionalOneToManyMapping (org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)2 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)2 Test (org.junit.Test)2 EmbeddedParameters (com.haulmont.cuba.core.entity.annotation.EmbeddedParameters)1 EmbeddedParameters (io.jmix.core.entity.annotation.EmbeddedParameters)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1