Search in sources :

Example 1 with RelationalAssociationImplementation

use of org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalAssociationImplementation in project legend-pure by finos.

the class RelationalAssociationImplementationUnbind method run.

@Override
public void run(RelationalAssociationImplementation instance, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    ImportStub mappingImportStub = (ImportStub) instance._parentCoreInstance();
    RelationalPropertyMappingUnbind.cleanPropertyMappings(instance, modelRepository, processorSupport, mappingImportStub);
}
Also used : ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) ImportStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)

Example 2 with RelationalAssociationImplementation

use of org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalAssociationImplementation in project legend-pure by finos.

the class RelationalAssociationImplementationProcessor method process.

@Override
public void process(RelationalAssociationImplementation associationMapping, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
    Mapping parentMapping = (Mapping) ImportStub.withImportStubByPass(associationMapping._parentCoreInstance(), processorSupport);
    MapIterable<String, SetImplementation> classMappingIndex = org.finos.legend.pure.m2.dsl.mapping.Mapping.getClassMappingsByIdIncludeEmbedded(parentMapping, processorSupport);
    RichIterable<? extends PropertyMapping> propertyMappings = associationMapping._propertyMappings();
    for (PropertyMapping propertyMapping : propertyMappings) {
        RelationalPropertyMappingProcessor.processRelationalPropertyMapping(propertyMapping, matcher, state, repository, "", processorSupport, associationMapping, associationMapping);
        RichIterable<JoinTreeNode> joinTreeNodes = RelationalPropertyMappingProcessor.collectJoinTreeNodes(propertyMapping);
        if (joinTreeNodes.notEmpty()) {
            CoreInstance sourceSetImplementation = MappingValidator.validateId(associationMapping, propertyMapping, classMappingIndex, propertyMapping._sourceSetImplementationId(), "source", processorSupport);
            TableAlias mainTableAlias = findMainTableAlias(sourceSetImplementation, matcher, state, processorSupport);
            RelationalOperationElement mainTable = mainTableAlias != null ? mainTableAlias._relationalElement() : null;
            for (JoinTreeNode joinTreeNode : joinTreeNodes) {
                RelationalOperationElementProcessor.processAliasForJoinTreeNode(joinTreeNode, mainTable, processorSupport);
            }
        }
    }
    associationMapping._stores(associationMapping._propertyMappings().collect(STORE).toSet().without(null));
}
Also used : RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) TableAlias(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode) RootRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RootRelationalInstanceSetImplementation) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation) EmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation)

Example 3 with RelationalAssociationImplementation

use of org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalAssociationImplementation in project legend-engine by finos.

the class RelationalCompilerExtension method getExtraAssociationMappingProcessors.

@Override
public List<Function3<AssociationMapping, Mapping, CompileContext, AssociationImplementation>> getExtraAssociationMappingProcessors() {
    return Collections.singletonList((associationMapping, parentMapping, context) -> {
        if (associationMapping instanceof RelationalAssociationMapping) {
            RelationalAssociationMapping relationalAssociationImplementation = (RelationalAssociationMapping) associationMapping;
            RelationalAssociationImplementation base = new Root_meta_relational_mapping_RelationalAssociationImplementation_Impl("");
            final org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association pureAssociation = context.resolveAssociation(relationalAssociationImplementation.association, associationMapping.sourceInformation);
            MutableList<EmbeddedRelationalInstanceSetImplementation> embeddedRelationalPropertyMappings = Lists.mutable.empty();
            MutableList<Store> stores = ListIterate.collect(relationalAssociationImplementation.stores, context::resolveStore);
            // NOTE: we set the association before processing the property mappings, so we can resolve the correct property in the association
            // in the case where the user does not provide the class name of where the association property comes from
            base._association(pureAssociation);
            RichIterable<org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping> rpm = ListIterate.collect(relationalAssociationImplementation.propertyMappings, propertyMapping -> HelperRelationalBuilder.processAbstractRelationalPropertyMapping(propertyMapping, context, base, null, embeddedRelationalPropertyMappings, HelperMappingBuilder.getAllEnumerationMappings(parentMapping), Maps.mutable.empty()));
            base._stores(stores)._propertyMappings(rpm)._parent(parentMapping);
            parentMapping._classMappingsAddAll(embeddedRelationalPropertyMappings);
            return base;
        }
        return null;
    });
}
Also used : RelationalAssociationImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalAssociationImplementation) Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) EmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation) RelationalAssociationMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.RelationalAssociationMapping)

Example 4 with RelationalAssociationImplementation

use of org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalAssociationImplementation in project legend-pure by finos.

the class RelationalAssociationImplementationValidator method run.

@Override
public void run(RelationalAssociationImplementation associationMapping, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    Mapping parentMapping = (Mapping) ImportStub.withImportStubByPass(associationMapping._parentCoreInstance(), processorSupport);
    MapIterable<String, SetImplementation> classMappingIndex = org.finos.legend.pure.m2.dsl.mapping.Mapping.getClassMappingsByIdIncludeEmbedded(parentMapping, processorSupport);
    RichIterable<? extends PropertyMapping> propertyMappings = associationMapping._propertyMappings();
    for (PropertyMapping propertyMapping : propertyMappings) {
        RelationalInstanceSetImplementation sourceSetImplementation = (RelationalInstanceSetImplementation) MappingValidator.validateId(associationMapping, propertyMapping, classMappingIndex, propertyMapping._sourceSetImplementationId(), "source", processorSupport);
        RelationalInstanceSetImplementation targetSetImplementation = (RelationalInstanceSetImplementation) MappingValidator.validateId(associationMapping, propertyMapping, classMappingIndex, propertyMapping._targetSetImplementationId(), "target", processorSupport);
        JoinTreeNode joinTreeNode = propertyMapping instanceof RelationalPropertyMapping && ((RelationalPropertyMapping) propertyMapping)._relationalOperationElement() instanceof RelationalOperationElementWithJoin ? ((RelationalOperationElementWithJoin) ((RelationalPropertyMapping) propertyMapping)._relationalOperationElement())._joinTreeNode() : null;
        if (joinTreeNode == null) {
            throw new PureCompilationException(propertyMapping.getSourceInformation(), "Mapping Error: expected a join");
        }
        RelationalOperationElement sourceTable = findMainTable(sourceSetImplementation);
        RelationalOperationElement targetTable = findMainTable(targetSetImplementation);
        org.finos.legend.pure.m2.relational.serialization.grammar.v1.validator.JoinTreeNodeValidation.validateJoinTreeNode(joinTreeNode, sourceTable, targetTable, processorSupport);
    }
}
Also used : RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode) RootRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RootRelationalInstanceSetImplementation) RelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalInstanceSetImplementation) EmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation) RelationalOperationElementWithJoin(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) RootRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RootRelationalInstanceSetImplementation) RelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalInstanceSetImplementation) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation) EmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

EmbeddedRelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation)3 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)2 PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)2 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)2 RootRelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RootRelationalInstanceSetImplementation)2 RelationalOperationElement (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement)2 JoinTreeNode (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode)2 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 RelationalAssociationMapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.RelationalAssociationMapping)1 ImportStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)1 Store (org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store)1 RelationalAssociationImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalAssociationImplementation)1 RelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalInstanceSetImplementation)1 RelationalPropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping)1 RelationalOperationElementWithJoin (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin)1 TableAlias (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)1