Search in sources :

Example 31 with IContextParameter

use of org.talend.core.model.process.IContextParameter in project tesb-studio-se by Talend.

the class ContextPartGenerator method generatePart.

public CharSequence generatePart(IContext designerContext) throws CodeGeneratorException {
    List<IContextParameter> listParameters = designerContext.getContextParameterList();
    if (listParameters == null) {
        return "";
    }
    CodeGeneratorArgument codeGenArgument = argumentBuilder.build();
    codeGenArgument.setContextName(designerContext.getName());
    List<IContextParameter> listParametersCopy = tranformEncryptedParams(listParameters);
    codeGenArgument.setNode(listParametersCopy);
    JetBean jetBean = JetUtil.createJetBean(codeGenArgument);
    jetBean.setTemplateRelativeUri(ECamelTemplate.CONTEXT.getTemplateURL());
    return JetUtil.jetGenerate(jetBean);
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 32 with IContextParameter

use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.

the class PostgresGenerationManagerTest method testBuildSqlSelect.

@Test
public void testBuildSqlSelect() {
    // without context
    String schema = "school";
    String main_table = "classInfo";
    String lookup_table = "scoreInfo";
    init(schema, main_table, lookup_table);
    PostgresGenerationManager manager = new PostgresGenerationManager();
    String query = manager.buildSqlSelect(component, "grade");
    assertNotNull(query);
    query = query.replaceAll("[\\s]", "");
    String expectedQuery = "\"SELECT" + "\\\"school\\\".\\\"classInfo\\\".\\\"id\\\",\\\"school\\\".\\\"classInfo\\\".\\\"name\\\",\\\"school\\\".\\\"classInfo\\\".\\\"classNum\\\",\\\"school\\\".\\\"scoreInfo\\\".\\\"score\\\"" + "FROM\\\"school\\\".\\\"classInfo\\\",\\\"school\\\".\\\"scoreInfo\\\"" + "WHERE\\\"school\\\".\\\"classInfo\\\".\\\"id\\\"=3\"";
    assertEquals(expectedQuery, query);
    // with context
    schema = "context.schema";
    main_table = "context.main_table";
    lookup_table = "context.lookup";
    init(schema, main_table, lookup_table);
    JobContext newContext = new JobContext("Default");
    List<IContextParameter> newParamList = new ArrayList<IContextParameter>();
    newContext.setContextParameterList(newParamList);
    JobContextParameter param = new JobContextParameter();
    param.setName("schema");
    newParamList.add(param);
    param = new JobContextParameter();
    param.setName("main_table");
    newParamList.add(param);
    param = new JobContextParameter();
    param.setName("lookup");
    newParamList.add(param);
    component.getProcess().getContextManager().setDefaultContext(newContext);
    query = manager.buildSqlSelect(component, "grade");
    query = query.replaceAll("[\\s]", "");
    expectedQuery = "\"SELECT\"+context.schema+\".\"+context.main_table+\".\\\"id\\\",\"+context.schema+\".\"+" + "context.main_table+\".\\\"name\\\",\"+context.schema+\".\"+context.main_table+\".\\\"classNum\\\",\"+" + "context.schema+\".\"+context.lookup+\".\\\"score\\\"FROM\"+context.schema+\".\"+" + "context.main_table+\",\"+context.schema+\".\"+context.lookup+\"WHERE\"+context.schema+\".\"+" + "context.main_table+\".\\\"id\\\"=3\"";
    assertEquals(expectedQuery, query);
}
Also used : JobContextParameter(org.talend.core.model.context.JobContextParameter) ArrayList(java.util.ArrayList) JobContext(org.talend.core.model.context.JobContext) IContextParameter(org.talend.core.model.process.IContextParameter) Test(org.junit.Test)

Aggregations

IContextParameter (org.talend.core.model.process.IContextParameter)32 ArrayList (java.util.ArrayList)14 IContext (org.talend.core.model.process.IContext)14 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)4 Point (org.eclipse.swt.graphics.Point)3 JobContextParameter (org.talend.core.model.context.JobContextParameter)3 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)3 IProcess (org.talend.core.model.process.IProcess)3 ContextItem (org.talend.core.model.properties.ContextItem)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 File (java.io.File)2 Properties (java.util.Properties)2 EList (org.eclipse.emf.common.util.EList)2 CCombo (org.eclipse.swt.custom.CCombo)2 TableViewerCreatorColumnNotModifiable (org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable)2 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)2