use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class UpdateNodeParameterCommand method syncSchemaForEBCDIC.
/**
* nrousseau Comment method "synchSchemaForEBCDIC".
*/
private void syncSchemaForEBCDIC(Node node, IMetadataTable metadataTable) {
for (IConnection conn : node.getOutgoingConnections()) {
if (conn.getLineStyle() == EConnectionType.FLOW_MAIN && metadataTable.getTableName().equals(conn.getMetadataTable().getTableName())) {
Node target = (Node) conn.getTarget();
IElementParameter schemaTypeParam = target.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
if (schemaTypeParam != null) {
ChangeMetadataCommand cmd = new ChangeMetadataCommand(target, schemaTypeParam, null, metadataTable);
cmd.setRepositoryMode(true);
cmd.execute(true);
}
}
}
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class MapperComponent method sortOutputsConnectionsLikeVisualOrder.
/**
* Sort outgoingConnections for code generation as visible output zone of tMap.
*/
@SuppressWarnings("unchecked")
private void sortOutputsConnectionsLikeVisualOrder() {
List<IConnection> outgoingConnections = (List<IConnection>) getOutgoingConnections();
Map<String, IConnection> connectionNameToOutgoingConnection = new HashMap<String, IConnection>();
for (IConnection connection : outgoingConnections) {
connectionNameToOutgoingConnection.put(connection.getName(), connection);
}
List<ExternalMapperTable> outputTables = externalData.getOutputTables();
List<IConnection> tmpList = new ArrayList<IConnection>(outgoingConnections);
outgoingConnections.clear();
int lstSize = outputTables.size();
for (int i = 0; i < lstSize; i++) {
ExternalMapperTable table = outputTables.get(i);
String tableName = table.getName();
IConnection connection = connectionNameToOutgoingConnection.get(tableName);
if (connection != null) {
outgoingConnections.add(connection);
}
}
// add connections without metadata
for (IConnection connection : tmpList) {
if (!outgoingConnections.contains(connection)) {
outgoingConnections.add(connection);
}
}
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class JobletUtil method cloneConnection.
public Connection cloneConnection(IConnection conn, INode source, INode target) {
Connection cloneConn = new Connection(source, target, conn.getLineStyle(), conn.getConnectorName(), conn.getMetaName(), conn.getName(), conn.isMonitorConnection());
if (!source.isActivate() || !target.isActivate()) {
cloneConn.setActivate(false);
}
List<? extends IElementParameter> elementParas = conn.getElementParameters();
for (IElementParameter elementPara : elementParas) {
if (elementPara.getName() != null && !elementPara.getName().equals("UNIQUE_NAME")) {
IElementParameter cloneElement = cloneConn.getElementParameter(elementPara.getName());
Object paValue = elementPara.getValue();
if (paValue instanceof List) {
List list = new ArrayList();
list.addAll((List) paValue);
cloneElement.setValue(list);
} else {
cloneElement.setContextMode(elementPara.isContextMode());
cloneElement.setValue(elementPara.getValue());
}
}
}
return cloneConn;
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class PropertiesTableByRowEditorView method createColumns.
/*
* (non-Javadoc)
*
* @see
* org.talend.commons.ui.swt.advanced.dataeditor.AbstractDataTableEditorView#createColumns(org.talend.commons.ui
* .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
*/
@Override
protected void createColumns(TableViewerCreator<B> tableViewerCreator, Table table) {
// there's two lists of values, one that will be in the table
// and the other will be stored as the current value in the property
// there is two lists because of the undo / redo capabilities
PropertiesTableEditorModel model = getModel();
TalendProposalProvider processProposalProvider = new TalendProposalProvider(model.getProcess());
String[] titles = null;
// final Element elem = model.getElement();
final IElementParameter param = model.getElemParameter();
final IElement element = model.getElement();
if (element instanceof Node) {
List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
List<String> names = new ArrayList<String>();
for (IConnection con : listConnection) {
names.add(con.getName());
}
titles = new String[names.size()];
for (int i = 0; i < names.size(); i++) {
titles[i] = names.get(i);
}
}
if (titles != null && titles.length > 0) {
for (int i = 0; i < titles.length; i++) {
final int curCol = i;
boolean toDisplay = true;
if (toDisplay) {
final TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle(titles[i]);
column.setModifiable(true);
column.setMinimumWidth(100);
column.setWeight(20);
String[] stringToDisplay = null;
if (element instanceof Node) {
List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
for (IConnection con : listConnection) {
if (con.getName().equals(titles[i])) {
List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
stringToDisplay = new String[columns.size()];
for (int j = 0; j < columns.size(); j++) {
stringToDisplay[j] = columns.get(j).getLabel();
}
}
}
}
final EditableComboBoxCellEditor cellEditor = new EditableComboBoxCellEditor(table, stringToDisplay);
// column.setLabelProvider(new IColumnLabelProvider() {
//
// @Override
// public String getLabel(Object bean) {
// if (bean instanceof Map) {
// Map valueMap = (Map) bean;
// String columnName = column.getTitle();
// if (valueMap.containsKey(columnName)) {
// String value = (String) valueMap.get(columnName);
// return value;
// }
// }
// return ""; //$NON-NLS-1$
// }
// });
// column.setCellEditor(cellEditor);
column.setCellEditor(cellEditor, new CellEditorValueAdapter() {
@Override
public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorValue) {
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
String value = (String) valueMap.get(columnName);
return value;
}
return "";
}
@Override
public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
Object returnedValue = null;
CCombo combo = (CCombo) cellEditor.getControl();
int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
String[] listToDisplay = getItem(element, column.getTitle());
if (!Arrays.equals(listToDisplay, ((ComboBoxCellEditor) cellEditor).getItems())) {
((ComboBoxCellEditor) cellEditor).setItems(listToDisplay);
}
if (cellEditorTypedValue != null && cellEditorTypedValue instanceof String) {
return cellEditorTypedValue;
}
return "";
}
;
@Override
public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
CCombo combo = (CCombo) cellEditor.getControl();
int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
String[] listToDisplay = getItem(element, column.getTitle());
if (!Arrays.equals(listToDisplay, ((ComboBoxCellEditor) cellEditor).getItems())) {
((ComboBoxCellEditor) cellEditor).setItems(listToDisplay);
}
Object returnedValue = 0;
if (originalTypedValue != null) {
String[] namesSet = listToDisplay;
for (int j = 0; j < namesSet.length; j++) {
if (namesSet[j].equals(originalTypedValue)) {
returnedValue = j;
break;
}
}
}
return returnedValue;
}
;
private String[] getItem(IElement element, String columnName) {
List<String> stringToDisplay = new ArrayList<String>();
if (element instanceof Node) {
List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
for (IConnection con : listConnection) {
if (con.getName().equals(columnName)) {
List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
for (IMetadataColumn column : columns) {
stringToDisplay.add(column.getLabel());
}
}
}
}
String[] listToDisplay = stringToDisplay.toArray(new String[0]);
return listToDisplay;
}
});
column.setColumnCellModifier(new ColumnCellModifier(column) {
@Override
public boolean canModify(Object bean) {
boolean canModify = super.canModify(bean);
return canModify;
}
@Override
public Object getValue(Object bean) {
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
String value = (String) valueMap.get(columnName);
return value;
}
return "";
}
});
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<B, Object>() {
@Override
public Object get(B bean) {
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
return valueMap.get(columnName);
}
return "";
}
@Override
public void set(B bean, Object value) {
if (value == null) {
return;
}
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
valueMap.remove(columnName);
valueMap.put(columnName, value);
} else {
valueMap.put(columnName, value);
}
}
});
}
}
}
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class OracleGenerationManager method buildSqlSelect.
/**
*
* ggu Comment method "buildSqlSelect".
*
* @param component
* @param outputTableName
* @param tabSpaceString
* @return
*/
@Override
public String buildSqlSelect(DbMapComponent component, String outputTableName, String tabString) {
//$NON-NLS-1$
queryColumnsName = "\"";
aliasAlreadyDeclared.clear();
this.tabSpaceString = tabString;
List<IConnection> outputConnections = (List<IConnection>) component.getOutgoingConnections();
Map<String, IConnection> nameToOutputConnection = new HashMap<String, IConnection>();
for (IConnection connection : outputConnections) {
nameToOutputConnection.put(connection.getUniqueName(), connection);
}
ExternalDbMapData data = (ExternalDbMapData) component.getExternalData();
StringBuilder sb = new StringBuilder();
List<ExternalDbMapTable> outputTables = data.getOutputTables();
int lstOutputTablesSize = outputTables.size();
ExternalDbMapTable outputTable = null;
for (int i = 0; i < lstOutputTablesSize; i++) {
ExternalDbMapTable temp = outputTables.get(i);
if (outputTableName.equals(temp.getName())) {
outputTable = temp;
break;
}
}
if (outputTable != null) {
IConnection connection = nameToOutputConnection.get(outputTable.getName());
List<IMetadataColumn> columns = new ArrayList<IMetadataColumn>();
if (connection != null) {
IMetadataTable metadataTable = connection.getMetadataTable();
if (metadataTable != null) {
columns.addAll(metadataTable.getListColumns());
// call this function seems no use now but only problems
// outputTable = removeUnmatchingEntriesWithColumnsOfMetadataTable(outputTable, metadataTable);
}
}
//$NON-NLS-1$
sb.append("\"");
sb.append(DbMapSqlConstants.SELECT);
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
List<ExternalDbMapEntry> metadataTableEntries = outputTable.getMetadataTableEntries();
if (metadataTableEntries != null) {
int lstSizeOutTableEntries = metadataTableEntries.size();
for (int i = 0; i < lstSizeOutTableEntries; i++) {
ExternalDbMapEntry dbMapEntry = metadataTableEntries.get(i);
String expression = dbMapEntry.getExpression();
expression = initExpression(component, dbMapEntry);
expression = addQuoteForSpecialChar(expression, component);
// for (IMetadataColumn column : columns) {
// if (expression != null && column.getLabel().equals(dbMapEntry.getName())) {
// expression = expression.replaceFirst("." + dbMapEntry.getName(), //$NON-NLS-1$
// "." + column.getOriginalDbColumnName()); //$NON-NLS-1$
// break;
// }
// }
boolean added = false;
if (!DEFAULT_TAB_SPACE_STRING.equals(this.tabSpaceString)) {
expression += DbMapSqlConstants.SPACE + DbMapSqlConstants.AS + DbMapSqlConstants.SPACE + getAliasOf(dbMapEntry.getName());
added = true;
}
if (i > 0) {
sb.append(DbMapSqlConstants.COMMA);
sb.append(DbMapSqlConstants.SPACE);
queryColumnsName += DbMapSqlConstants.COMMA + DbMapSqlConstants.SPACE;
}
if (expression != null && expression.trim().length() > 0) {
sb.append(expression);
if (component.getMapperMain() == null) {
component.getExternalEmfData();
}
if (component.getMapperMain() != null) {
MapperManager mapperManager = component.getMapperMain().getMapperManager();
DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(mapperManager.getCurrentLanguage());
TableEntryLocation[] tableEntriesLocationsSources = dataMapExpressionParser.parseTableEntryLocations(expression);
boolean columnChanged = false;
if (tableEntriesLocationsSources.length > 1) {
columnChanged = true;
} else {
for (TableEntryLocation tableEntriesLocationsSource : tableEntriesLocationsSources) {
TableEntryLocation location = tableEntriesLocationsSource;
String entryName = getAliasOf(dbMapEntry.getName());
if (location != null && entryName != null && !entryName.startsWith("_") && !entryName.equals(location.columnName)) {
//$NON-NLS-1$
columnChanged = true;
}
}
}
if (!added && columnChanged) {
sb.append(DbMapSqlConstants.SPACE + DbMapSqlConstants.AS + DbMapSqlConstants.SPACE + getAliasOf(dbMapEntry.getName()));
}
}
queryColumnsName += expression;
} else {
sb.append(DbMapSqlConstants.LEFT_COMMENT);
String str = outputTable.getName() + DbMapSqlConstants.DOT + dbMapEntry.getName();
//$NON-NLS-1$
sb.append(Messages.getString("DbGenerationManager.OuputExpSetMessage", str));
sb.append(DbMapSqlConstants.RIGHT_COMMENT);
}
}
}
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
sb.append(DbMapSqlConstants.FROM);
List<ExternalDbMapTable> inputTables = data.getInputTables();
// load input table in hash
boolean explicitJoin = false;
int lstSizeInputTables = inputTables.size();
Map<String, ExternalDbMapTable> nameToInputTable = new HashMap<String, ExternalDbMapTable>();
for (int i = 0; i < lstSizeInputTables; i++) {
ExternalDbMapTable inputTable = inputTables.get(i);
nameToInputTable.put(inputTable.getName(), inputTable);
IJoinType joinType = language.getJoin(inputTable.getJoinType());
if (!language.unuseWithExplicitJoin().contains(joinType) && i > 0) {
explicitJoin = true;
}
}
StringBuilder sbWhere = new StringBuilder();
boolean isFirstClause = true;
for (int i = 0; i < lstSizeInputTables; i++) {
ExternalDbMapTable inputTable = inputTables.get(i);
if (buildConditions(component, sbWhere, inputTable, false, isFirstClause)) {
isFirstClause = false;
}
}
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
IJoinType previousJoinType = null;
for (int i = 0; i < lstSizeInputTables; i++) {
ExternalDbMapTable inputTable = inputTables.get(i);
IJoinType joinType = null;
if (i == 0) {
joinType = AbstractDbLanguage.JOIN.NO_JOIN;
} else {
joinType = language.getJoin(inputTable.getJoinType());
}
boolean commaCouldBeAdded = !explicitJoin && i > 0;
boolean crCouldBeAdded = false;
if (language.unuseWithExplicitJoin().contains(joinType) && !explicitJoin) {
buildTableDeclaration(component, sb, inputTable, commaCouldBeAdded, crCouldBeAdded, false);
} else if (!language.unuseWithExplicitJoin().contains(joinType) && explicitJoin) {
if (i > 0) {
if (previousJoinType == null) {
buildTableDeclaration(component, sb, inputTables.get(i - 1), commaCouldBeAdded, crCouldBeAdded, true);
previousJoinType = joinType;
} else {
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
}
sb.append(DbMapSqlConstants.SPACE);
}
String labelJoinType = joinType.getLabel();
sb.append(labelJoinType);
sb.append(DbMapSqlConstants.SPACE);
if (joinType == AbstractDbLanguage.JOIN.CROSS_JOIN) {
ExternalDbMapTable nextTable = null;
if (i < lstSizeInputTables) {
nextTable = inputTables.get(i);
buildTableDeclaration(component, sb, nextTable, false, false, true);
}
} else {
// ExternalDbMapTable rightTable = joinLeftToJoinRightTables.get(inputTable.getName());
buildTableDeclaration(component, sb, inputTable, false, false, true);
// if (rightTable != null) {
// } else {
// sb.append(" <!! NO JOIN CLAUSES FOR '" + inputTable.getName() + "' !!> ");
// }
sb.append(DbMapSqlConstants.SPACE);
sb.append(DbMapSqlConstants.ON);
sb.append(DbMapSqlConstants.LEFT_BRACKET);
sb.append(DbMapSqlConstants.SPACE);
if (!buildConditions(component, sb, inputTable, true, true)) {
sb.append(DbMapSqlConstants.LEFT_COMMENT);
sb.append(DbMapSqlConstants.SPACE);
//$NON-NLS-1$
sb.append(Messages.getString("DbGenerationManager.conditionNotSet"));
sb.append(DbMapSqlConstants.SPACE);
sb.append(DbMapSqlConstants.RIGHT_COMMENT);
}
sb.append(DbMapSqlConstants.SPACE);
sb.append(DbMapSqlConstants.RIGHT_BRACKET);
}
}
}
/*
* for addition conditions
*/
// like as input.newcolumn1>100
List<String> whereAddition = new ArrayList<String>();
// olny pure start with group or order, like as order/group by input.newcolumn1
// List<String> byAddition = new ArrayList<String>();
// like as input.newcolumn1>100 group/oder by input.newcolumn1
// List<String> containWhereAddition = new ArrayList<String>();
// like as "OR/AND input.newcolumn1", will keep original
List<String> originalWhereAddition = new ArrayList<String>();
List<String> otherAddition = new ArrayList<String>();
if (outputTable != null) {
List<ExternalDbMapEntry> customWhereConditionsEntries = outputTable.getCustomWhereConditionsEntries();
if (customWhereConditionsEntries != null) {
for (ExternalDbMapEntry entry : customWhereConditionsEntries) {
String exp = initExpression(component, entry);
if (exp != null && !DbMapSqlConstants.EMPTY.equals(exp.trim())) {
// } else
if (containWith(exp, DbMapSqlConstants.OR, true) || containWith(exp, DbMapSqlConstants.AND, true)) {
originalWhereAddition.add(exp);
} else {
whereAddition.add(exp);
}
}
}
}
List<ExternalDbMapEntry> customOtherConditionsEntries = outputTable.getCustomOtherConditionsEntries();
if (customOtherConditionsEntries != null) {
for (ExternalDbMapEntry entry : customOtherConditionsEntries) {
String exp = initExpression(component, entry);
if (exp != null && !DbMapSqlConstants.EMPTY.equals(exp.trim())) {
otherAddition.add(exp);
}
}
}
}
String whereClauses = sbWhere.toString();
boolean whereFlag = whereClauses.trim().length() > 0;
boolean whereAddFlag = !whereAddition.isEmpty();
boolean whereOriginalFlag = !originalWhereAddition.isEmpty();
if (whereFlag || whereAddFlag || whereOriginalFlag) {
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
sb.append(DbMapSqlConstants.WHERE);
}
if (whereFlag) {
sb.append(whereClauses);
}
if (whereAddFlag) {
for (int i = 0; i < whereAddition.size(); i++) {
if (i == 0 && whereFlag || i > 0) {
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
sb.append(DbMapSqlConstants.SPACE);
sb.append(DbMapSqlConstants.AND);
}
sb.append(DbMapSqlConstants.SPACE);
sb.append(whereAddition.get(i));
}
}
if (whereOriginalFlag) {
for (String s : originalWhereAddition) {
sb.append(DbMapSqlConstants.NEW_LINE);
sb.append(DbMapSqlConstants.SPACE);
sb.append(s);
}
}
if (!otherAddition.isEmpty()) {
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
for (String s : otherAddition) {
sb.append(s);
sb.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
}
}
}
String sqlQuery = sb.toString();
if (DEFAULT_TAB_SPACE_STRING.equals(tabSpaceString)) {
List<String> contextList = getContextList(component);
boolean haveReplace = false;
for (String context : contextList) {
if (sqlQuery.contains(context)) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
sqlQuery = sqlQuery.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
haveReplace = true;
}
if (queryColumnsName.contains(context)) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
queryColumnsName = queryColumnsName.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
}
}
if (!haveReplace) {
List<String> connContextList = getConnectionContextList(component);
for (String context : connContextList) {
if (sqlQuery.contains(context)) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
sqlQuery = sqlQuery.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
}
if (queryColumnsName.contains(context)) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
queryColumnsName = queryColumnsName.replaceAll("\\b" + context + "\\b", "\" +" + context + "+ \"");
}
}
}
}
sqlQuery = handleQuery(sqlQuery);
queryColumnsName = handleQuery(queryColumnsName);
return sqlQuery;
}
Aggregations