use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method propagate.
private void propagate(Node jobletNode, boolean needPro) {
if (!needPro) {
return;
}
for (IConnection outConn : jobletNode.getOutgoingConnections()) {
IMetadataTable tab = jobletNode.getMetadataFromConnector(outConn.getConnectorName());
IMetadataTable tmpClone = tab.clone(true);
IMetadataTable newOutputMetadata = jobletNode.getMetadataTable(outConn.getConnectorName());
IMetadataTable toCopy = newOutputMetadata.clone();
Node targetNode = (Node) outConn.getTarget();
String dbmsId = null;
IMetadataTable copy = null;
if (targetNode.getMetadataFromConnector(outConn.getConnectorName()) != null) {
dbmsId = targetNode.getMetadataFromConnector(outConn.getConnectorName()).getDbms();
MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
toCopy = tmpClone;
// only if the target node have exactly the same connector
copy = targetNode.getMetadataFromConnector(outConn.getConnectorName()).clone(true);
} else {
// can only be FLOW right now for this case. //$NON-NLS-1$
final String mainConnector = "FLOW";
dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms();
MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
toCopy = tmpClone;
// if don't have the same connector, take the main connector of the component.
copy = targetNode.getMetadataFromConnector(mainConnector).clone(true);
}
MetadataToolHelper.copyTable(dbmsId, toCopy, copy);
// inputSchemaParam);
ChangeMetadataCommand cmd = new ChangeMetadataCommand(targetNode, null, null, copy, null);
cmd.execute(true);
}
try {
ProxyRepositoryFactory.getInstance().save(((Process) jobletNode.getProcess()).getProperty().getItem());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method updateGraphicalNodesSchema.
/**
* qzhang Comment method "updateGraphicalNodesSchema".
*
* this method is moved from class AbstractTalendEditor.
*
* @param evt
*/
@SuppressWarnings("unchecked")
private void updateGraphicalNodesSchema(Process process, PropertyChangeEvent evt) {
if (!(evt.getSource() instanceof INode)) {
return;
}
INode sourceNode = (INode) evt.getSource();
String componentName = sourceNode.getComponent().getName();
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(componentName, process.getComponentsType());
if (newComponent == null) {
return;
}
Object[] newMetadataTables = (Object[]) evt.getNewValue();
List<IMetadataTable> newInputTableList = (List<IMetadataTable>) newMetadataTables[0];
List<IMetadataTable> newOutputTableList = (List<IMetadataTable>) newMetadataTables[1];
for (Node node : (List<Node>) process.getGraphicalNodes()) {
if (node.getComponent().getName().equals(componentName)) {
List<IElementParameter> outputElemParams = new ArrayList<IElementParameter>();
IElementParameter outputElemParam = null;
List<? extends IElementParameter> elementParameters = node.getElementParameters();
for (IElementParameter elementParameter : elementParameters) {
if (EParameterFieldType.SCHEMA_TYPE.equals(elementParameter.getFieldType())) {
outputElemParams.add(elementParameter);
}
}
ChangeMetadataCommand command;
List<? extends IConnection> incomingConnections = node.getIncomingConnections();
if (incomingConnections.size() <= 1) {
for (int i = 0; i < incomingConnections.size(); i++) {
IConnection connection = incomingConnections.get(i);
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
if (newInputMetadataTable != null && !metadataTable.sameMetadataAs(newInputMetadataTable)) {
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, newInputMetadataTable);
command.execute(Boolean.FALSE);
}
}
} else {
for (IElementParameter param : node.getElementParameters()) {
if (param.isShow(node.getElementParameters()) && param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
IMetadataTable table = node.getMetadataFromConnector(param.getContext());
IElementParameter connParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
if (table != null && connParam != null && !StringUtils.isEmpty((String) connParam.getValue())) {
for (IConnection connection : incomingConnections) {
if (connection.isActivate() && connection.getName().equals(connParam.getValue())) {
if (!table.sameMetadataAs(connection.getMetadataTable(), IMetadataColumn.OPTIONS_IGNORE_KEY | IMetadataColumn.OPTIONS_IGNORE_NULLABLE | IMetadataColumn.OPTIONS_IGNORE_COMMENT | IMetadataColumn.OPTIONS_IGNORE_PATTERN | IMetadataColumn.OPTIONS_IGNORE_DBCOLUMNNAME | IMetadataColumn.OPTIONS_IGNORE_DBTYPE | IMetadataColumn.OPTIONS_IGNORE_DEFAULT | IMetadataColumn.OPTIONS_IGNORE_BIGGER_SIZE)) {
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, table);
command.execute(Boolean.FALSE);
}
}
}
}
}
}
}
List<? extends IConnection> outgoingConnections = node.getOutgoingConnections();
for (int i = 0; i < outgoingConnections.size(); i++) {
IConnection connection = outgoingConnections.get(i);
Node target = (Node) connection.getTarget();
IMetadataTable metadataTable = connection.getMetadataTable();
if (metadataTable != null) {
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
if (newOutputMetadataTable != null && !metadataTable.sameMetadataAs(newOutputMetadataTable)) {
IElementParameter elementParam = target.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(target, elementParam, target.getMetadataFromConnector(metadataTable.getAttachedConnector()), newOutputMetadataTable);
command.execute(Boolean.FALSE);
}
}
}
List<IMetadataTable> metadataList = node.getMetadataList();
for (IMetadataTable metadataTable : metadataList) {
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
outputElemParam = UpdateManagerUtils.getElemParam(outputElemParams, metadataTable.getAttachedConnector());
if (outputElemParam != null && newInputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newInputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newInputMetadataTable, metadataFromConnector);
} else if (outputElemParam != null && newOutputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newOutputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newOutputMetadataTable, metadataFromConnector);
}
}
}
}
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class DbGenerationManager method initExpression.
protected String initExpression(DbMapComponent component, ExternalDbMapEntry dbMapEntry) {
String expression = dbMapEntry.getExpression();
if (expression != null) {
List<Map<String, String>> itemNameList = null;
// MapExpressionParser mapParser = new MapExpressionParser("((\\s*(\\w+)\\s*\\.)*)(\\w+)");
// List<String> parseInTableEntryLocations = mapParser.parseInTableEntryLocations2(expression);
// for (String entryLocation : parseInTableEntryLocations) {
//
// }
// context.schema.context.table.column
// context.schema.table.column
// schema.context.table.column
// schema.table.column
// table.column
// add \\w*#* for oracle 12 , schema name start with C##
//$NON-NLS-1$
MapExpressionParser mapParser1 = new MapExpressionParser("((\\s*(\\w*#*\\w+)\\s*\\.)*)(\\w+)");
itemNameList = mapParser1.parseInTableEntryLocations2(expression);
if (itemNameList == null || itemNameList.isEmpty()) {
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
itemNameList = mapParser2.parseInTableEntryLocations(expression);
}
for (Map<String, String> itemNamemap : itemNameList) {
Set<Entry<String, String>> set = itemNamemap.entrySet();
Iterator<Entry<String, String>> ite = set.iterator();
while (ite.hasNext()) {
Entry<String, String> entry = ite.next();
String columnValue = entry.getKey();
String tableValue = entry.getValue();
String tableNameValue = tableValue;
// find original table name if tableValue is alias
String originaltableName = tableValue;
ExternalDbMapData externalData = (ExternalDbMapData) component.getExternalData();
final List<ExternalDbMapTable> inputTables = externalData.getInputTables();
for (ExternalDbMapTable inputTable : inputTables) {
if (inputTable.getAlias() != null && inputTable.getAlias().equals(tableValue)) {
originaltableName = inputTable.getTableName();
tableNameValue = inputTable.getAlias();
}
}
List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
if (inputConnections == null) {
return expression;
}
for (IConnection iconn : inputConnections) {
IMetadataTable metadataTable = iconn.getMetadataTable();
String tName = iconn.getName();
if ((originaltableName.equals(tName) || tableValue.equals(tName)) && metadataTable != null) {
List<IMetadataColumn> lColumn = metadataTable.getListColumns();
String tableName = metadataTable.getTableName();
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (tableValue.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(tableValue);
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)) {
//$NON-NLS-1$//$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
//$NON-NLS-1$
expression = expression.replaceFirst(tableValue, schemaValue + "." + tableName);
}
}
}
} else if (tableName != null) {
if (tableValue.equals(metadataTable.getLabel()) && tableColneName.equals(tableValue)) {
//$NON-NLS-1$ //$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
expression = expression.replaceFirst(tableValue, tableName);
}
}
for (IMetadataColumn co : lColumn) {
if (columnValue.equals(co.getLabel())) {
String oriName = co.getOriginalDbColumnName();
// if OriginalDbColumn is empty , still use label to generate sql
if (oriName == null || "".equals(oriName)) {
//$NON-NLS-1$
continue;
}
if (expression.trim().equals(tableValue + "." + oriName)) {
continue;
}
if (expression.trim().equals(originaltableName + "." + oriName)) {
continue;
}
// if it is temp delived table, use label to generate sql
if (iconn.getLineStyle() == EConnectionType.TABLE_REF) {
continue;
}
//$NON-NLS-1$ //$NON-NLS-2$
oriName = oriName.replaceAll("\\$", "\\\\\\$");
expression = //$NON-NLS-1$
expression.replaceFirst(//$NON-NLS-1$
"\\." + co.getLabel(), //$NON-NLS-1$
"\\." + oriName);
expression = expression.replace("\"", "\\\"");
}
}
}
}
}
}
}
return expression;
}
use of org.talend.core.model.process.IConnection 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.core.model.process.IConnection in project tdi-studio-se by Talend.
the class DbMapComponent method removeInput.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.process.AbstractNode#removeInput(org.talend.core.model.process.IConnection)
*/
@Override
public void removeInput(IConnection connection) {
Connection conn = null;
DBMapData externalEmfData = (DBMapData) getExternalEmfData();
InputTable toRemove = null;
for (InputTable inputTable : externalEmfData.getInputTables()) {
if (inputTable.getTableName() != null && inputTable.getTableName().equals(connection.getName())) {
toRemove = inputTable;
break;
}
}
if (toRemove != null) {
EList<InputTable> inputTableList = externalEmfData.getInputTables();
inputTableList.remove(toRemove);
ExternalNodeUtils.prepareExternalNodeReadyToOpen(getExternalNode());
IODataComponentContainer iContainer = getIODataComponents();
if (iContainer != null) {
mapperMain.initIOConnections(iContainer);
mapperMain.getMapperManager().initInternalData();
}
buildExternalData(externalEmfData);
}
}
Aggregations