Search in sources :

Example 1 with JoinTreeNode

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode in project legend-pure by finos.

the class RelationalOperationElementProcessor method processJoinTreeNode.

static void processJoinTreeNode(JoinTreeNode joinTreeNode, CoreInstance implementation, Matcher matcher, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) {
    String joinName = joinTreeNode._joinName();
    Database database = (Database) ImportStub.withImportStubByPass(joinTreeNode._databaseCoreInstance(), processorSupport);
    if (database == null) {
        throw new PureCompilationException(joinTreeNode.getSourceInformation(), "The system can't figure out which database to use.");
    }
    PostProcessor.processElement(matcher, database, state, processorSupport);
    CoreInstance joinType = joinTreeNode._joinTypeCoreInstance();
    if (joinType != null) {
        StringCoreInstance joinTypeString = (StringCoreInstance) joinType;
        String type = "INNER".equals(joinTypeString.getValue()) ? "INNER" : "LEFT_OUTER";
        Enumeration joinTypeEnumeration = (Enumeration) processorSupport.package_getByUserPath(M2RelationalPaths.JoinType);
        Enum joinTypeEnumInstance = (Enum) org.finos.legend.pure.m3.navigation.enumeration.Enumeration.findEnum(joinTypeEnumeration, type);
        if (joinTypeEnumInstance == null) {
            throw new PureCompilationException(joinTreeNode.getSourceInformation(), "The enum value '" + type + "' can't be found in the enumeration " + PackageableElement.getUserPathForPackageableElement(joinTypeEnumeration, "::"));
        }
        joinTreeNode._joinTypeCoreInstance(joinTypeEnumInstance);
    }
    Join join = findJoin(joinTreeNode, database, joinName, processorSupport);
    joinTreeNode._join(join);
    PropertyMappingsImplementation owner = joinTreeNode._setMappingOwner();
    if (owner == null && implementation != null) {
        joinTreeNode._setMappingOwner((PropertyMappingsImplementation) implementation);
    }
    for (TreeNode child : joinTreeNode._childrenData()) {
        processJoinTreeNode((JoinTreeNode) child, implementation, matcher, state, repository, processorSupport);
    }
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) Enumeration(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration) TreeNode(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.TreeNode) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode) Database(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Join(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join) RelationalOperationElementWithJoin(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) PropertyMappingsImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with JoinTreeNode

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode in project legend-pure by finos.

the class RelationalOperationElementProcessor method processColumnExpr.

static void processColumnExpr(RelationalOperationElement impl, CoreInstance implementation, CoreInstance mappingOwner, MutableSet<TableAlias> tableAliases, Matcher matcher, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) throws PureCompilationException {
    if (impl instanceof TableAliasColumn) {
        processTableAliasColumn((TableAliasColumn) impl, mappingOwner, tableAliases, processorSupport);
    } else if (impl instanceof DynaFunction) {
        processDynaFunction((DynaFunction) impl, implementation, mappingOwner, tableAliases, matcher, state, repository, processorSupport);
    } else if (impl instanceof RelationalOperationElementWithJoin) {
        RelationalOperationElement relationalOperationElement = ((RelationalOperationElementWithJoin) impl)._relationalOperationElement();
        if (relationalOperationElement != null) {
            if (relationalOperationElement instanceof DynaFunction) {
                processDynaFunction((DynaFunction) relationalOperationElement, implementation, mappingOwner, tableAliases, matcher, state, repository, processorSupport);
            } else if (relationalOperationElement instanceof TableAliasColumn) {
                processTableAliasColumn((TableAliasColumn) relationalOperationElement, mappingOwner, tableAliases, processorSupport);
            }
        }
        JoinTreeNode joinTreeNode = ((RelationalOperationElementWithJoin) impl)._joinTreeNode();
        if (joinTreeNode != null) {
            processJoinTreeNode(joinTreeNode, mappingOwner, matcher, state, repository, processorSupport);
            tableAliases.clear();
        }
    } else if (impl instanceof Literal) {
    // Do nothing
    } else {
        throw new PureCompilationException(impl.getSourceInformation(), "Not Supported Yet! " + impl);
    }
}
Also used : RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) Literal(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Literal) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode) TableAliasColumn(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn) DynaFunction(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.DynaFunction) RelationalOperationElementWithJoin(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 3 with JoinTreeNode

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode in project legend-pure by finos.

the class RelationalPropertyMappingProcessor method collectJoinTreeNodes.

private static void collectJoinTreeNodes(Collection<? super JoinTreeNode> targetCollection, PropertyMapping propertyMapping) {
    if (propertyMapping instanceof RelationalPropertyMapping) {
        RelationalOperationElement relationalOperationElement = ((RelationalPropertyMapping) propertyMapping)._relationalOperationElement();
        RelationalOperationElementProcessor.collectJoinTreeNodes(targetCollection, relationalOperationElement);
    }
    if (propertyMapping instanceof OtherwiseEmbeddedRelationalInstanceSetImplementation) {
        PropertyMapping relationalOperationElement = ((OtherwiseEmbeddedRelationalInstanceSetImplementation) propertyMapping)._otherwisePropertyMapping();
        collectJoinTreeNodes(targetCollection, relationalOperationElement);
    }
    if (propertyMapping instanceof PropertyMappingsImplementation) {
        RichIterable<? extends PropertyMapping> propertyMappings = ((PropertyMappingsImplementation) propertyMapping)._propertyMappings();
        for (PropertyMapping subMapping : propertyMappings) {
            collectJoinTreeNodes(targetCollection, subMapping);
        }
    }
}
Also used : RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) OtherwiseEmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.OtherwiseEmbeddedRelationalInstanceSetImplementation) RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) PropertyMappingsImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation)

Example 4 with JoinTreeNode

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode 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 5 with JoinTreeNode

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode in project legend-pure by finos.

the class RelationalMappingSpecificationProcessing method populateFilterMappingReferenceUsages.

static void populateFilterMappingReferenceUsages(RelationalMappingSpecification implementation, ModelRepository repository, ProcessorSupport processorSupport) {
    FilterMapping filterMapping = implementation != null ? implementation._filter() : null;
    if (filterMapping != null) {
        Database database = (Database) ImportStub.withImportStubByPass(filterMapping._databaseCoreInstance(), processorSupport);
        ReferenceUsage.addReferenceUsage(database, filterMapping, M2RelationalProperties.database, 0, repository, processorSupport, filterMapping._databaseCoreInstance().getSourceInformation());
        JoinTreeNode joinTreeNode = filterMapping._joinTreeNode();
        if (joinTreeNode != null) {
            RelationalOperationElementProcessor.populateJoinTreeNodeReferenceUsages(joinTreeNode, repository, processorSupport);
        }
    }
}
Also used : Database(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) FilterMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.FilterMapping) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode)

Aggregations

JoinTreeNode (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode)18 RelationalOperationElement (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement)14 RelationalOperationElementWithJoin (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin)12 Join (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join)9 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)8 TableAlias (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias)6 TreeNode (org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.TreeNode)5 PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)5 Database (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database)5 PropertyMappingsImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation)4 RootRelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RootRelationalInstanceSetImplementation)4 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)4 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)3 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)3 EmbeddedRelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation)3 OtherwiseEmbeddedRelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.OtherwiseEmbeddedRelationalInstanceSetImplementation)3 RelationalPropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping)3 TableAliasColumn (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn)3 Enum (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum)2 FilterMapping (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.FilterMapping)2