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