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);
}
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));
}
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;
});
}
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);
}
}
Aggregations