Search in sources :

Example 56 with IConnection

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);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PersistenceException(org.talend.commons.exception.PersistenceException) IConnection(org.talend.core.model.process.IConnection) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process)

Example 57 with IConnection

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);
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List)

Example 58 with IConnection

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;
}
Also used : ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) Entry(java.util.Map.Entry) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 59 with IConnection

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());
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) Entry(java.util.Map.Entry) DbMapComponent(org.talend.designer.dbmap.DbMapComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with IConnection

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);
    }
}
Also used : InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) IODataComponentContainer(org.talend.core.model.components.IODataComponentContainer)

Aggregations

IConnection (org.talend.core.model.process.IConnection)149 ArrayList (java.util.ArrayList)79 INode (org.talend.core.model.process.INode)63 List (java.util.List)60 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)57 Node (org.talend.designer.core.ui.editor.nodes.Node)47 HashMap (java.util.HashMap)36 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)33 IElementParameter (org.talend.core.model.process.IElementParameter)31 Map (java.util.Map)25 Connection (org.talend.designer.core.ui.editor.connections.Connection)25 INodeConnector (org.talend.core.model.process.INodeConnector)24 Point (org.eclipse.swt.graphics.Point)13 Process (org.talend.designer.core.ui.editor.process.Process)13 IJobletProviderService (org.talend.core.ui.IJobletProviderService)12 HashSet (java.util.HashSet)11 MetadataTable (org.talend.core.model.metadata.MetadataTable)10 IProcess (org.talend.core.model.process.IProcess)10 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)9 IExternalNode (org.talend.core.model.process.IExternalNode)8