Search in sources :

Example 6 with JobContextParameter

use of org.talend.core.model.context.JobContextParameter 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

JobContextParameter (org.talend.core.model.context.JobContextParameter)6 ArrayList (java.util.ArrayList)3 JobContext (org.talend.core.model.context.JobContext)3 IContextParameter (org.talend.core.model.process.IContextParameter)3 HashMap (java.util.HashMap)2 List (java.util.List)2 ContextParameterTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 EList (org.eclipse.emf.common.util.EList)1 StyledText (org.eclipse.swt.custom.StyledText)1 Shell (org.eclipse.swt.widgets.Shell)1 Text (org.eclipse.swt.widgets.Text)1 IEditorReference (org.eclipse.ui.IEditorReference)1 Test (org.junit.Test)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 ECodeLanguage (org.talend.core.language.ECodeLanguage)1 JobContextManager (org.talend.core.model.context.JobContextManager)1 IContext (org.talend.core.model.process.IContext)1