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