Skip to content

Commit

Permalink
Instantiate dummy database if user passes string as element (#2411)
Browse files Browse the repository at this point in the history
  • Loading branch information
haroonsherjan authored Oct 27, 2023
1 parent ca47277 commit 0b21b21
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void buildEngineRuntime(EngineRuntime engineRuntime, Root_meta_cor
Root_meta_core_runtime_ConnectionStore connectionStore =
new Root_meta_core_runtime_ConnectionStore_Impl("")
._connection(connection)
._element(getElement(storePointer.path, storePointer.sourceInformation, context));
._element(getStore(storePointer.path, storePointer.sourceInformation, context));
pureRuntime._connectionStoresAdd(connectionStore);
});
});
Expand Down Expand Up @@ -155,7 +155,7 @@ public static void buildEngineRuntime(EngineRuntime engineRuntime, Root_meta_cor
connection.accept(new ConnectionSecondPassBuilder(context, pureConnection));
final Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("", null, context.pureModel.getClass("meta::core::runtime::ConnectionStore"))
._connection(pureConnection)
._element(getElement(storeConnections.store.path, storeConnections.store.sourceInformation, context));
._element(getStore(storeConnections.store.path, storeConnections.store.sourceInformation, context));

pureRuntime._connectionStoresAdd(connectionStore);
});
Expand Down Expand Up @@ -222,7 +222,7 @@ public static Root_meta_core_runtime_Runtime buildPureRuntime(Runtime runtime, C
connection.accept(new ConnectionSecondPassBuilder(context, pureConnection));
final Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("", null, context.pureModel.getClass("meta::core::runtime::ConnectionStore"))
._connection(pureConnection)
._element(getElement(connection.element, connection.sourceInformation, context));
._element(getStore(connection.element, connection.sourceInformation, context));
pureRuntime._connectionStoresAdd(connectionStore);
});
return pureRuntime;
Expand All @@ -238,23 +238,11 @@ else if (runtime instanceof RuntimePointer)
throw new UnsupportedOperationException();
}

public static Object getElement(String element, SourceInformation sourceInformation, CompileContext context)
public static Object getStore(String element, SourceInformation sourceInformation, CompileContext context)
{
return element.equals("ModelStore") ?
new Root_meta_external_store_model_ModelStore_Impl("", null, context.pureModel.getClass("meta::external::store::model::ModelStore"))
: resolveElementSafe(element, sourceInformation, context);
}

private static Object resolveElementSafe(String element, SourceInformation sourceInformation, CompileContext context)
{
try
{
return context.resolveStore(element, sourceInformation);
}
catch (EngineException e)
{
return element;
}
: context.resolveStore(element, sourceInformation);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import java.util.*;
import java.util.function.Consumer;

import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getElement;
import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getStore;

@Deprecated
public class MappingTestRunner
Expand Down Expand Up @@ -102,7 +102,7 @@ public void setupTestData()
CompileContext context = this.pureModel.getContext();
Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("")
._connection(conn.accept(connectionVisitor))
._element(getElement(conn.element, conn.elementSourceInformation, context));
._element(getStore(conn.element, conn.elementSourceInformation, context));
this.runtime._connectionStoresAdd(connectionStore);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.tuple.Tuples;
import org.eclipse.collections.impl.utility.ListIterate;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.ConnectionFirstPassBuilder;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
import org.finos.legend.engine.plan.execution.PlanExecutor;
Expand Down Expand Up @@ -57,7 +56,7 @@
import java.util.stream.Collectors;

import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperModelBuilder.getElementFullPath;
import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getElement;
import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getStore;

public class MappingTestRunner implements TestRunner
{
Expand Down Expand Up @@ -142,7 +141,7 @@ private TestResult executeMappingTest(MappingTest mappingTest, MappingTestRunne
Connection conn = connection.getOne();
Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("")
._connection(conn.accept(context.getConnectionVisitor()))
._element(getElement(conn.element, conn.elementSourceInformation, context.getPureModel().getContext()));
._element(getStore(conn.element, conn.elementSourceInformation, context.getPureModel().getContext()));
runtime._connectionStoresAdd(connectionStore);
});
handleGenerationOfPlan(connections.stream().map(Pair::getOne).collect(Collectors.toList()), runtime, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void addDatabaseConnectionProperties(Root_meta_external_store_rela
}
catch (RuntimeException e)
{
new Root_meta_relational_metamodel_Database_Impl(element)._name(element);
context.pureModel.storesIndex.putIfAbsent(element, new Root_meta_relational_metamodel_Database_Impl(element)._name(element));
}
}

Expand Down

0 comments on commit 0b21b21

Please sign in to comment.