use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.
the class PostgresGenerationManager method getHandledTableName.
protected String getHandledTableName(DbMapComponent component, String name, String aliasName, boolean generateSubSql) {
List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
if (inputConnections == null) {
return name;
}
for (IConnection iconn : inputConnections) {
boolean inputIsELTDBMap = false;
INode source = iconn.getSource();
String schemaStr = "";
String tableNameStr = "";
if (source != null) {
inputIsELTDBMap = isELTDBMap(source);
if (inputIsELTDBMap) {
tableNameStr = iconn.getName();
} else {
IElementParameter schema = source.getElementParameter("ELT_SCHEMA_NAME");
IElementParameter tableName = source.getElementParameter("ELT_TABLE_NAME");
if (schema != null && schema.getValue() != null) {
schemaStr = TalendTextUtils.removeQuotes(schema.getValue().toString());
}
if (tableName != null && tableName.getValue() != null) {
tableNameStr = TalendTextUtils.removeQuotes(tableName.getValue().toString());
}
}
}
String tableName = schemaStr;
if ("".equals(tableName)) {
tableName = tableNameStr;
} else {
if (!"".equals(tableNameStr)) {
tableName = tableName + "." + tableNameStr;
}
}
if (tableName.equals(name)) {
StringBuffer sb = new StringBuffer();
if (inputIsELTDBMap && generateSubSql) {
DbMapComponent externalNode = null;
if (source instanceof DbMapComponent) {
externalNode = (DbMapComponent) source;
} else {
externalNode = (DbMapComponent) source.getExternalNode();
}
DbGenerationManager genManager = externalNode.getGenerationManager();
String deliveredTable = genManager.buildSqlSelect(externalNode, iconn.getMetadataTable().getTableName(), //$NON-NLS-1$
tabSpaceString + " ");
int begin = 1;
int end = deliveredTable.length() - 1;
if (begin <= end) {
//$NON-NLS-1$ //$NON-NLS-2$
sb.append("(").append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(" ");
sb.append(deliveredTable.substring(begin, end)).append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(//$NON-NLS-1$
" ) ");
}
if (aliasName != null && !aliasName.trim().isEmpty()) {
tableNameStr = aliasName;
}
}
StringBuffer tempExp = getSchemaAndTable(schemaStr, tableNameStr);
sb.append(tempExp);
return sb.toString();
}
}
return name;
}
use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.
the class OracleGenerationManagerTest method setUp.
@Before
public void setUp() throws Exception {
dbMapComponent = new DbMapComponent();
List<IConnection> incomingConnections = new ArrayList<IConnection>();
conn = mock(IConnection.class);
incomingConnections.add(conn);
dbMapComponent.setIncomingConnections(incomingConnections);
oracleManager = new OracleGenerationManager();
}
use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.
the class UpdateELTMapComponentCommandTest method before.
@Before
public void before() {
Process process = new Process(createProperty());
sourceNode = new Node(sourceComponent, process);
INodeConnector connector = new NodeConnector(sourceNode);
connector.setName("connector");
connector.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
ArrayList<INodeConnector> connectors = new ArrayList<INodeConnector>();
connectors.add(connector);
sourceNode.setListConnector(connectors);
targetNode = new Node(targetComponent, process);
DbMapComponent component = new DbMapComponent();
targetNode.setExternalNode(component);
connection = new Connection(sourceNode, targetNode, EConnectionType.FLOW_MAIN, "connector", "meta", "oldTable", true);
inputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getInputTables();
ExternalDbMapTable input = new ExternalDbMapTable();
input.setName("oldTable");
input.setTableName("oldTable");
inputs.add(input);
outputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getOutputTables();
ExternalDbMapTable output = new ExternalDbMapTable();
ExternalDbMapEntry entry = new ExternalDbMapEntry("oldTable", "oldTable.column");
output.setMetadataTableEntries(new ArrayList<ExternalDbMapEntry>());
output.getMetadataTableEntries().add(entry);
outputs.add(output);
}
use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.
the class DbGenerationManager method buildTableDeclaration.
protected void buildTableDeclaration(DbMapComponent component, StringBuilder sb, ExternalDbMapTable inputTable) {
Object inConns = component.getIncomingConnections();
List<IConnection> inputConnections = null;
if (inConns != null) {
inputConnections = (List<IConnection>) inConns;
}
if (inputConnections != null) {
IConnection iconn = this.getConnectonByName(inputConnections, inputTable.getTableName());
if (iconn == null) {
return;
}
boolean replace = false;
String inputTableName = inputTable.getName();
IMetadataTable metadataTable = iconn.getMetadataTable();
INode source = iconn.getSource();
String tableName = metadataTable.getTableName();
if (isELTDBMap(source)) {
DbMapComponent externalNode = null;
if (source instanceof DbMapComponent) {
externalNode = (DbMapComponent) source;
} else {
externalNode = (DbMapComponent) source.getExternalNode();
}
DbGenerationManager genManager = externalNode.getGenerationManager();
/* the new tabSpaceString in subquery must not be same with the parent!!! */
//$NON-NLS-1$
String deliveredTable = genManager.buildSqlSelect(externalNode, tableName, tabSpaceString + " ");
int begin = 1;
int end = deliveredTable.length() - 1;
if (begin <= end) {
//$NON-NLS-1$ //$NON-NLS-2$
sb.append("(").append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(" ");
sb.append(deliveredTable.substring(begin, end)).append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(//$NON-NLS-1$
" ) ");
}
}
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (inputTableName.contains(".") && tableName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(inputTableName);
for (Map<String, String> tableNameMap : tableNameList) {
Set<Entry<String, String>> setTable = tableNameMap.entrySet();
Iterator<Entry<String, String>> iteTable = setTable.iterator();
while (iteTable.hasNext()) {
Entry<String, String> tableEntry = iteTable.next();
String tableLabel = tableEntry.getKey();
String schemaValue = tableEntry.getValue();
if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
sb.append(schemaValue);
//$NON-NLS-1$
sb.append(".");
sb.append(tableName);
replace = true;
}
}
}
} else if (tableName != null) {
if (inputTableName.equals(metadataTable.getLabel()) && tableColneName.equals(inputTableName)) {
sb.append(tableName);
replace = true;
}
}
if (!replace) {
sb.append(inputTable.getName());
}
}
}
use of org.talend.designer.dbmap.DbMapComponent in project tdi-studio-se by Talend.
the class DbGenerationManagerTest method setUp.
@Before
public void setUp() throws Exception {
dbMapComponent = new DbMapComponent();
ExternalDbMapData externalDbMapData = new ExternalDbMapData();
dbMapComponent.setExternalData(externalDbMapData);
List<ExternalDbMapTable> inputTables = new ArrayList<>();
externalDbMapData.setInputTables(inputTables);
ExternalDbMapTable externalDbMapTable = new ExternalDbMapTable();
inputTables.add(externalDbMapTable);
externalDbMapTable.setName("t1");
externalDbMapTable.setAlias("t1");
externalDbMapTable.setTableName("t1");
externalDbMapTable.setJoinType("NO_JOIN");
tableEntries = new ArrayList<>();
externalDbMapTable.setMetadataTableEntries(tableEntries);
extMapEntry = new ExternalDbMapEntry("id", "t1.id");
tableEntries.add(extMapEntry);
List<IConnection> incomingConnections = new ArrayList<IConnection>();
String[] columns = new String[] { "\\\"id\\\"" };
incomingConnections.add(createConnection("t1", "t1", "id", columns));
dbMapComponent.setIncomingConnections(incomingConnections);
dbManager = new GenericDbGenerationManager();
}
Aggregations