use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping in project legend-engine by finos.
the class HelperRelationalBuilder method processRelationalPropertyMapping.
private static PropertyMapping processRelationalPropertyMapping(RelationalPropertyMapping propertyMapping, CompileContext context, PropertyMappingsImplementation immediateParent, InstanceSetImplementation topParent, MutableList<EmbeddedRelationalInstanceSetImplementation> embeddedRelationalPropertyMappings, RichIterable<EnumerationMapping<Object>> allEnumerationMappings, MutableMap<String, TableAlias> aliasMap) {
org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping rpm = new Root_meta_relational_mapping_RelationalPropertyMapping_Impl("");
Property property = resolvePropertyForRelationalPropertyMapping(propertyMapping, immediateParent, context);
if (propertyMapping.bindingTransformer != null) {
return buildSemiStructuredPropertyMapping(property, propertyMapping, immediateParent, (RootRelationalInstanceSetImplementation) topParent, embeddedRelationalPropertyMappings, aliasMap, context);
}
org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping res = rpm._property(property)._localMappingProperty(propertyMapping.localMappingProperty != null)._relationalOperationElement(processRelationalOperationElement(propertyMapping.relationalOperation, context, aliasMap, FastList.newList()))._sourceSetImplementationId(HelperRelationalBuilder.getPropertyMappingSourceId(propertyMapping, immediateParent, property, context))._targetSetImplementationId(HelperRelationalBuilder.getPropertyMappingTargetId(propertyMapping, immediateParent, property, context))._owner(immediateParent);
rpm.setSourceInformation(SourceInformationHelper.toM3SourceInformation(propertyMapping.sourceInformation));
if (propertyMapping.enumMappingId != null) {
EnumerationMapping<Object> eMap = allEnumerationMappings.select(e -> e._name().equals(propertyMapping.enumMappingId)).getFirst();
Assert.assertTrue(eMap != null, () -> "Can't find enumeration mapping '" + propertyMapping.enumMappingId + "'");
res = res._transformer(eMap);
}
return res;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping in project legend-engine by finos.
the class HelperRelationalBuilder method collectJoinTreeNodesFromPropertyMapping.
private static void collectJoinTreeNodesFromPropertyMapping(List<org.eclipse.collections.api.tuple.Pair<String, JoinTreeNode>> targetCollection, PropertyMapping propertyMapping) {
if (propertyMapping instanceof org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) {
RelationalOperationElement relationalOperationElement = ((org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) propertyMapping)._relationalOperationElement();
HelperRelationalBuilder.collectJoinTreeNodes(targetCollection, propertyMapping._property()._name(), relationalOperationElement);
}
if (propertyMapping instanceof OtherwiseEmbeddedRelationalInstanceSetImplementation) {
PropertyMapping relationalOperationElement = ((OtherwiseEmbeddedRelationalInstanceSetImplementation) propertyMapping)._otherwisePropertyMapping();
collectJoinTreeNodesFromPropertyMapping(targetCollection, relationalOperationElement);
}
if (propertyMapping instanceof PropertyMappingsImplementation) {
RichIterable<? extends PropertyMapping> propertyMappings = ((PropertyMappingsImplementation) propertyMapping)._propertyMappings();
for (PropertyMapping subMapping : propertyMappings) {
collectJoinTreeNodesFromPropertyMapping(targetCollection, subMapping);
}
}
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping 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.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping in project legend-engine by finos.
the class RelationalParseTreeWalker method visitInlineEmbeddedPropertyMapping.
private PropertyMapping visitInlineEmbeddedPropertyMapping(RelationalParserGrammar.InlineEmbeddedPropertyMappingContext ctx, PropertyPointer propertyPointer, String targetId) {
InlineEmbeddedPropertyMapping inlineEmbeddedPropertyMapping = new InlineEmbeddedPropertyMapping();
inlineEmbeddedPropertyMapping.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
inlineEmbeddedPropertyMapping.id = targetId;
inlineEmbeddedPropertyMapping.target = targetId;
inlineEmbeddedPropertyMapping.property = propertyPointer;
inlineEmbeddedPropertyMapping.setImplementationId = PureGrammarParserUtility.fromIdentifier(ctx.identifier());
return inlineEmbeddedPropertyMapping;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping in project legend-engine by finos.
the class RelationalGrammarComposerExtension method getExtraClassMappingComposers.
@Override
public List<Function2<ClassMapping, PureGrammarComposerContext, String>> getExtraClassMappingComposers() {
return Lists.mutable.with((classMapping, context) -> {
if (classMapping instanceof RootRelationalClassMapping) {
RelationalGrammarComposerContext ctx = RelationalGrammarComposerContext.Builder.newInstance(context).build();
RootRelationalClassMapping rootRelationalClassMapping = (RootRelationalClassMapping) classMapping;
StringBuilder builder = new StringBuilder();
builder.append(": Relational\n");
builder.append(getTabString()).append("{\n");
if (rootRelationalClassMapping.filter != null) {
appendTabString(builder, 2).append(HelperRelationalGrammarComposer.renderFilterMapping(rootRelationalClassMapping.filter)).append("\n");
}
builder.append(rootRelationalClassMapping.distinct ? (getTabString(2) + "~distinct\n") : "");
if (!rootRelationalClassMapping.groupBy.isEmpty()) {
appendTabString(builder, 2).append("~groupBy\n");
appendTabString(builder, 2).append("(\n");
builder.append(LazyIterate.collect(rootRelationalClassMapping.groupBy, op -> getTabString(3) + HelperRelationalGrammarComposer.renderRelationalOperationElement(op, ctx)).makeString(",\n"));
builder.append("\n");
appendTabString(builder, 2).append(")\n");
}
if (!rootRelationalClassMapping.primaryKey.isEmpty()) {
appendTabString(builder, 2).append("~primaryKey\n");
appendTabString(builder, 2).append("(\n");
builder.append(LazyIterate.collect(rootRelationalClassMapping.primaryKey, op -> getTabString(3) + HelperRelationalGrammarComposer.renderRelationalOperationElement(op, ctx)).makeString(",\n"));
builder.append("\n");
appendTabString(builder, 2).append(")\n");
}
if (rootRelationalClassMapping.mainTable != null) {
TablePtr tablePtr = rootRelationalClassMapping.mainTable;
appendTabString(builder, 2).append("~mainTable ");
builder.append("[").append(tablePtr.getDb()).append("]");
builder.append((tablePtr.schema != null && !tablePtr.schema.equals("default")) ? (tablePtr.schema + "." + tablePtr.table) : tablePtr.table);
builder.append("\n");
}
if (!rootRelationalClassMapping.propertyMappings.isEmpty()) {
RelationalGrammarComposerContext indentedContext = RelationalGrammarComposerContext.Builder.newInstance(ctx).withIndentation(4).build();
builder.append(LazyIterate.collect(rootRelationalClassMapping.propertyMappings, propertyMapping -> HelperRelationalGrammarComposer.renderAbstractRelationalPropertyMapping(propertyMapping, indentedContext, false)).makeString(",\n"));
builder.append("\n");
}
appendTabString(builder).append("}");
return builder.toString();
}
return null;
});
}
Aggregations