Search in sources :

Example 1 with RepositoryChangeMetadataCommand

use of org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand in project tdi-studio-se by Talend.

the class SchemaReferenceController method createButtonCommand.

@Override
protected Command createButtonCommand(Button button) {
    if (checkForRepositoryShema(button)) {
        return null;
    }
    Button inputButton = button;
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    if (inputButton.getData(NAME).equals(SCHEMA)) {
        // this map wil hold the all input connection for the tUnite component
        Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
        INode node;
        if (elem instanceof Node) {
            node = (INode) elem;
        } else {
            // else instanceof Connection
            node = ((IConnection) elem).getSource();
        }
        IMetadataTable inputMetadata = null, inputMetaCopy = null;
        Connection inputConec = null;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
        String connectionName = null;
        if (connectionParam != null) {
            connectionName = (String) connectionParam.getValue();
        }
        Object obj = button.getData(FORCE_READ_ONLY);
        boolean forceReadOnly = false;
        if (obj != null) {
            forceReadOnly = (Boolean) obj;
        }
        boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
        for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
            if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE) || connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) || connec.getLineStyle() == EConnectionType.FLOW_REF)) {
                if (connectionName != null && !connec.getName().equals(connectionName)) {
                    continue;
                }
                inputMetadata = connec.getMetadataTable();
                inputMetaCopy = inputMetadata.clone();
                inputConec = connec;
                if (connec.getSource().isReadOnly()) {
                    inputReadOnlyNode = true;
                } else {
                    for (IElementParameter curParam : connec.getSource().getElementParameters()) {
                        if (curParam.getFieldType() == EParameterFieldType.SCHEMA_REFERENCE) {
                            if (curParam.isReadOnly()) {
                                inputReadOnlyParam = true;
                            }
                        }
                    }
                }
                // check if the inputMetadata is readonly
                if (inputMetadata != null) {
                    for (IMetadataColumn column : inputMetadata.getListColumns(true)) {
                        IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
                        columnCopied.setCustom(column.isCustom());
                        columnCopied.setReadOnly(column.isReadOnly());
                    }
                    inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
                    inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
                }
                // store the value for Dialog
                Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
                oneInput.put(inputMetaCopy, inputReadOnly);
                inputInfos.put(connec.getSource(), oneInput);
            }
        }
        if (connectionParam != null && inputMetadata == null) {
            //$NON-NLS-1$
            MessageDialog.openError(//$NON-NLS-1$
            button.getShell(), //$NON-NLS-1$
            Messages.getString("SchemaReferenceController.inputNotSet"), //$NON-NLS-1$
            Messages.getString("SchemaReferenceController.connectionNotAvaliable"));
            return null;
        }
        IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
        // check if the outputMetadata is readonly
        IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
        // when several schema_type button ,need get the right one which is opening
        //$NON-NLS-1$
        IElementParameter schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        // need setRepository here
        if (!param.getContext().equals(schemaParam.getContext())) {
            //$NON-NLS-1$
            schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        }
        if (schemaParam != null && EmfComponent.REPOSITORY.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(true);
            }
        } else if (schemaParam != null && EmfComponent.BUILTIN.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(false);
            }
        }
        IMetadataTable outputMetaCopy = originaleOutputTable.clone(true);
        for (IMetadataColumn column : originaleOutputTable.getListColumns(true)) {
            IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
            columnCopied.setCustom(column.isCustom());
            columnCopied.setReadOnly(column.isReadOnly());
        }
        outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
        //$NON-NLS-1$
        IElementParameter schemaTypeParam = param.getChildParameters().get("SCHEMA_TYPE");
        List<IElementParameterDefaultValue> defaultValues = schemaTypeParam.getDefaultValues();
        for (IElementParameterDefaultValue elementParameterDefaultValue : defaultValues) {
            if (elementParameterDefaultValue.getDefaultValue() instanceof MetadataTable) {
                MetadataTable table = (MetadataTable) elementParameterDefaultValue.getDefaultValue();
                outputMetaCopy.setReadOnlyColumnPosition(table.getReadOnlyColumnPosition());
                break;
            }
        }
        outputMetaCopy.sortCustomColumns();
        if (!forceReadOnly) {
            outputReadOnly = prepareReadOnlyTable(outputMetaCopy, param.isReadOnly(), node.isReadOnly());
        } else {
            outputReadOnly = true;
        }
        MetadataDialog metaDialog = null;
        if (inputMetadata != null) {
            if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
                MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
                //$NON-NLS-1$
                metaDialogForMerge.setText(Messages.getString("SchemaReferenceController.schemaOf") + node.getLabel());
                metaDialogForMerge.setInputReadOnly(inputReadOnly);
                metaDialogForMerge.setOutputReadOnly(outputReadOnly);
                if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
                    outputMetaCopy = metaDialogForMerge.getOutputMetaData();
                    // check if the metadata is modified
                    boolean modified = false;
                    if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                        modified = true;
                    } else {
                        if (inputMetadata != null) {
                            // Notice: the Map inputInfos maybe is modified by the dialog.
                            Set<INode> inputNodes = inputInfos.keySet();
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
                                    modified = true;
                                }
                            }
                        }
                    }
                    // create the changeMetadataCommand
                    if (modified) {
                        if (switchParam != null) {
                            switchParam.setValue(Boolean.FALSE);
                        }
                        Command changeMetadataCommand = null;
                        // only output, no input
                        if (inputInfos.isEmpty()) {
                            changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
                        } else {
                            Set<INode> inputNodes = inputInfos.keySet();
                            int count = 0;
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (count == 0) {
                                    changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
                                } else {
                                    changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
                                }
                                count++;
                            }
                        }
                        return changeMetadataCommand;
                    }
                }
            } else {
                INode inputNode = (inputConec.getSource());
                if (inputMetaCopy.getAttachedConnector() == null) {
                    INodeConnector mainConnector;
                    if (inputNode.isELTComponent()) {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
                    } else {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
                    }
                    inputMetaCopy.setAttachedConnector(mainConnector.getName());
                }
                metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
            }
        } else {
            metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
        }
        if (metaDialog != null) {
            //$NON-NLS-1$
            metaDialog.setText(Messages.getString("SchemaReferenceController.schema.title", node.getLabel()));
            metaDialog.setInputReadOnly(inputReadOnly);
            metaDialog.setOutputReadOnly(outputReadOnly);
            if (metaDialog.open() == MetadataDialog.OK) {
                inputMetaCopy = metaDialog.getInputMetaData();
                outputMetaCopy = metaDialog.getOutputMetaData();
                boolean modified = false;
                if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                    modified = true;
                } else {
                    if (inputMetadata != null) {
                        if (!inputMetaCopy.sameMetadataAs(inputMetadata, IMetadataColumn.OPTIONS_NONE)) {
                            modified = true;
                        }
                    }
                }
                if (modified) {
                    if (switchParam != null) {
                        switchParam.setValue(Boolean.FALSE);
                    }
                    INode inputNode = null;
                    if (inputConec != null) {
                        inputNode = inputConec.getSource();
                    }
                    // update the component schema
                    if (param instanceof GenericElementParameter) {
                        GenericElementParameter genericElementParameter = (GenericElementParameter) param;
                        String paramName = genericElementParameter.getName();
                        ComponentProperties componentProperties = node.getComponentProperties();
                        if (componentProperties != null) {
                            org.talend.daikon.properties.property.Property schemaProperty = componentProperties.getValuedProperty(paramName);
                            if (schemaProperty != null) {
                                SchemaUtils.updateComponentSchema(node, outputMetaCopy, null);
                            }
                        }
                    }
                    if (node.getComponent().isSchemaAutoPropagated()) {
                        ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
                        return changeMetadataCommand;
                    } else {
                        ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
                        changeMetadataCommand.setPropagate(Boolean.FALSE);
                        return changeMetadataCommand;
                    }
                }
            }
        }
    } else if (inputButton.getData(NAME).equals(RETRIEVE_SCHEMA)) {
        Node node = (Node) elem;
        // String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        final Command cmd = RetrieveSchemaHelper.retrieveSchemasCommand(node);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (inputButton.getData(NAME).equals(RESET_COLUMNS)) {
        Node node = (Node) elem;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        final Command cmd = SynchronizeSchemaHelper.createCommand(node, param);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter schemaParam = elem.getElementParameter(paramName);
        ERepositoryObjectType type = ERepositoryObjectType.METADATA_CON_TABLE;
        String filter = schemaParam.getFilter();
        RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), type, filter);
        if (dialog.open() == RepositoryReviewDialog.OK) {
            RepositoryNode node = dialog.getResult();
            while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
                node = node.getParent();
            }
            IRepositoryViewObject object = dialog.getResult().getObject();
            Property property = object.getProperty();
            String id = property.getId();
            // The name is Table Name.
            String name = object.getLabel();
            if (name != null) {
                if (elem instanceof Node) {
                    //$NON-NLS-1$
                    String value = id + " - " + name;
                    //$NON-NLS-1$
                    paramName = paramName + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                    Command selectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(value));
                    executeCommand(selectorCommand);
                }
            }
            //$NON-NLS-1$
            String value = id + " - " + name;
            //$NON-NLS-1$
            String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
            org.talend.core.model.metadata.builder.connection.Connection connection = null;
            if (elem instanceof Node) {
                IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
                connection = MetadataToolHelper.getConnectionFromRepository(value);
                // For validation rule.
                boolean isValRulesLost = false;
                IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
                if (currentValRuleObj != null) {
                    List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(value);
                    if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
                        if (!MessageDialog.openConfirm(button.getShell(), //$NON-NLS-1$
                        Messages.getString("SchemaReferenceController.validationrule.title.confirm"), Messages.getString("SchemaReferenceController.validationrule.selectMetadataMsg"))) {
                            //$NON-NLS-1$
                            return null;
                        } else {
                            isValRulesLost = true;
                        }
                    }
                }
                if (repositoryMetadata == null) {
                    repositoryMetadata = new MetadataTable();
                }
                if (switchParam != null) {
                    switchParam.setValue(Boolean.FALSE);
                }
                CompoundCommand cc = new CompoundCommand();
                RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, null, null);
                changeMetadataCommand.setConnection(connection);
                cc.add(changeMetadataCommand);
                if (isValRulesLost) {
                    ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
                }
                return cc;
            }
        }
    } else if (button.getData(NAME).equals(COPY_CHILD_COLUMNS)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter param = elem.getElementParameter(paramName);
        IElementParameter processParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
        IElementParameter processIdParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
        String id = (String) processIdParam.getValue();
        Item item = ItemCacheManager.getProcessItem(id);
        Node node = (Node) elem;
        copySchemaFromChildJob(node, item);
        // pop up the schema dialog
        MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), node.getMetadataList().get(0), node, getCommandStack());
        //$NON-NLS-1$
        metaDialog.setText(Messages.getString("SchemaReferenceController.schemaOf") + node.getLabel());
        if (metaDialog.open() == MetadataDialog.OK) {
            IMetadataTable outputMetaData = metaDialog.getOutputMetaData();
            return new ChangeMetadataCommand(node, param, null, outputMetaData);
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) RepositoryNode(org.talend.repository.model.RepositoryNode) INode(org.talend.core.model.process.INode) INodeConnector(org.talend.core.model.process.INodeConnector) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) Button(org.eclipse.swt.widgets.Button) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) MetadataDialog(org.talend.core.ui.metadata.dialog.MetadataDialog) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) RepositoryNode(org.talend.repository.model.RepositoryNode) RepositoryReviewDialog(org.talend.repository.ui.dialog.RepositoryReviewDialog) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HashMap(java.util.HashMap) Map(java.util.Map) MetadataDialogForMerge(org.talend.core.ui.metadata.dialog.MetadataDialogForMerge)

Example 2 with RepositoryChangeMetadataCommand

use of org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand in project tdi-studio-se by Talend.

the class SapSchemaTypeController method createComboCommand.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
     * .eclipse.swt.custom.CCombo)
     */
@Override
protected Command createComboCommand(CCombo combo) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        /* see bug 16969 */
        // if (repositoryTableMap.containsKey(schemaSelected)) {
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // newRepositoryIdValue = schemaSelected;// + " - " + repositoryMetadata.getLabel();
        // } else {
        // if (repositoryTableMap.keySet().size() == 0) {
        // repositoryMetadata = new MetadataTable();
        // } else {
        // newRepositoryIdValue = repositoryTableMap.keySet().iterator().next();
        // // Gets the schema of the first item in repository schema type combo.
        // repositoryMetadata = repositoryTableMap.get(newRepositoryIdValue);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // // newRepositoryIdValue = newRepositoryIdValue + " - " + repositoryMetadata.getLabel();
        // }
        // }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 3 with RepositoryChangeMetadataCommand

use of org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand in project tdi-studio-se by Talend.

the class AbstractSchemaController method createComboCommand.

@Override
protected Command createComboCommand(CCombo combo) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            if (schemaSelected == null) {
                //$NON-NLS-1$
                schemaSelected = "";
            }
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    Set<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = null;
                    IGenericWizardService wizardService = null;
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                    }
                    if (wizardService != null && wizardService.isGenericItem(item)) {
                        tables = new HashSet<>(wizardService.getMetadataTables(connection));
                    } else {
                        tables = ConnectionHelper.getTables(connection);
                    }
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) List(java.util.List) ArrayList(java.util.ArrayList) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 4 with RepositoryChangeMetadataCommand

use of org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand in project tdi-studio-se by Talend.

the class ComponentChooseDialog method getSAPCommand.

/**
     * Added by Marvin Wang on July 12, 2012 for getting the command of SAP.
     *
     * @param object
     * @param connectionItem
     * @param table
     * @param node
     * @return
     */
private void getSAPCommand(CompoundCommand cc, IRepositoryViewObject object, ConnectionItem connectionItem, MetadataTable table, Node node) {
    SAPFunctionUnit functionUnit = null;
    if (object instanceof MetadataTableRepositoryObject) {
        IElementParameter schemaParam = null;
        List<IElementParameter> schemaTypeList = node.getElementParametersFromField(EParameterFieldType.SCHEMA_TYPE);
        for (IElementParameter param : schemaTypeList) {
            if (param.getName().equals("SCHEMA")) {
                //$NON-NLS-1$
                schemaParam = param;
                break;
            }
        }
        if (table.eContainer() instanceof SAPFunctionUnit) {
            // function parameter table
            functionUnit = (SAPFunctionUnit) table.eContainer();
            // To judge what the current node is, tSAPOutput or tSAPInput component.
            String sapComponentName = node.getComponent().getName();
            if ("tSAPBapi".equals(sapComponentName)) {
                //$NON-NLS-1$
                RepositoryChangeMetadataForSAPBapi command = new RepositoryChangeMetadataForSAPBapi(node, (SAPFunctionUnit) table.eContainer(), ConvertionHelper.convert(table), null);
                cc.add(command);
            } else {
                if (schemaParam != null) {
                    // repository id should be connectionid - sapfunctionName/type/tableName
                    String type = table.getTableType() == null ? MetadataSchemaType.OUTPUT.name() : table.getTableType();
                    String value = connectionItem.getProperty().getId() + " - " + functionUnit.getLabel() + "/" + type + "/" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    table.getLabel();
                    RepositoryChangeMetadataCommand changeValueCmd = new RepositoryChangeMetadataCommand(node, //$NON-NLS-1$
                    schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, ConvertionHelper.convert(table), null, connectionItem.getConnection());
                    cc.add(changeValueCmd);
                }
                IElementParameter schemasParam = node.getElementParameter(ISAPConstant.TABLE_SCHEMAS);
                if (schemasParam != null) {
                    Command sapCmd = new RepositoryChangeMetadataForSAPCommand(node, ISAPConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table), functionUnit);
                    cc.add(sapCmd);
                }
            }
        } else {
            // Sap Table : keep repository id as before
            if (schemaParam != null) {
                //$NON-NLS-1$
                String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
                RepositoryChangeMetadataCommand changeValueCmd = new RepositoryChangeMetadataCommand(node, //$NON-NLS-1$
                schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, ConvertionHelper.convert(table), null, connectionItem.getConnection(), table);
                cc.add(changeValueCmd);
            }
        }
    } else if (object instanceof SAPFunctionRepositoryObject) {
        functionUnit = (SAPFunctionUnit) ((SAPFunctionRepositoryObject) object).getAbstractMetadataObject();
        if (node.getComponent() != null && node.getComponent().getName().equals("tSAPBapi")) {
            //$NON-NLS-1$
            RepositoryChangeMetadataForSAPBapi command = new RepositoryChangeMetadataForSAPBapi(node, functionUnit, null, null);
            cc.add(command);
        } else {
            for (MetadataTable metadataTable : functionUnit.getTables()) {
                Command sapCmd = new RepositoryChangeMetadataForSAPCommand(node, ISAPConstant.TABLE_SCHEMAS, metadataTable.getLabel(), ConvertionHelper.convert(metadataTable), functionUnit);
                cc.add(sapCmd);
            }
        }
    }
}
Also used : RepositoryChangeMetadataForSAPBapi(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPBapi) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) RepositoryChangeMetadataForSAPCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) ConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.ConnectionReconnectCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) RepositoryChangeMetadataForEBCDICCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForEBCDICCommand) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) RepositoryChangeMetadataForSAPCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPCommand) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)

Example 5 with RepositoryChangeMetadataCommand

use of org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand in project tdi-studio-se by Talend.

the class ConvertRepositoryNodeToProcessNode method convertToProcessNode.

public void convertToProcessNode(ConnectionItem connectionItem, String tableName) throws ProcessorException {
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(connectionItem, ERepositoryObjectType.METADATA_CONNECTIONS);
    String componentName = null;
    componentName = name.getDefaultComponentName();
    IComponent dbInputComponent = ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    Process process = new Process(GuessSchemaProcess.getNewmockProperty());
    node = new Node(dbInputComponent, process);
    selectedContext = node.getProcess().getContextManager().getDefaultContext();
    // TDI-20011
    IMetadataTable table = UpdateRepositoryUtils.getTableByName(connectionItem, tableName);
    if (table == null) {
        table = new MetadataTable();
        table.setTableName(tableName);
        table.setLabel(tableName);
    }
    IElementParameter propertyParam = ((Node) node).getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
    IElementParameter schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
    if (schemaParam == null) {
        schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
    }
    String propertyId = connectionItem.getProperty().getId();
    String schema = databaseConnection.getUiSchema();
    String dbType = databaseConnection.getDatabaseType();
    //$NON-NLS-1$
    String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
    CompoundCommand cc = new CompoundCommand();
    // inital parameters command
    ChangeValuesFromRepository changeValueCommand = new ChangeValuesFromRepository(node, databaseConnection, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
    propertyId);
    changeValueCommand.ignoreContextMode(true);
    cc.add(changeValueCommand);
    // change metadata command
    RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) node, //$NON-NLS-1$
    schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, table, null, null);
    cc.add(changeMetadataCommand);
    // guess query command
    QueryGuessCommand queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, databaseConnection);
    cc.add(queryGuessCommand);
    // execute the commands
    cc.execute();
    //$NON-NLS-1$
    IElementParameter query = node.getElementParameter("QUERY");
    //
    memoSQL = query.getValue().toString();
    String memoSQLTemp = TalendTextUtils.removeQuotesIfExist(memoSQL);
    if ((memoSQLTemp == null || memoSQLTemp.equals("")) && tableName != null && !tableName.equals("")) {
        //$NON-NLS-1$
        boolean check = !Pattern.matches("^\\w+$", tableName);
        boolean isJDBCForMysql = databaseConnection.getURL() == null ? false : databaseConnection.getURL().startsWith("jdbc:mysql");
        if ((dbType.equals(EDatabaseTypeName.MYSQL.getDisplayName()) || isJDBCForMysql) && check) {
            tableName = TalendQuoteUtils.addQuotes(tableName, TalendQuoteUtils.ANTI_QUOTE);
        }
        memoSQL = "select * from " + tableName;
        memoSQL = TalendTextUtils.addSQLQuotes(memoSQL);
    }
}
Also used : RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) GuessSchemaProcess(org.talend.designer.core.ui.editor.properties.controllers.GuessSchemaProcess) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter)

Aggregations

IElementParameter (org.talend.core.model.process.IElementParameter)9 RepositoryChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand)9 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)8 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Command (org.eclipse.gef.commands.Command)7 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)7 MetadataTable (org.talend.core.model.metadata.MetadataTable)6 INode (org.talend.core.model.process.INode)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 RepositoryNode (org.talend.repository.model.RepositoryNode)6 List (java.util.List)5 IConnection (org.talend.core.model.process.IConnection)5 ConnectionItem (org.talend.core.model.properties.ConnectionItem)5 Item (org.talend.core.model.properties.Item)5 Node (org.talend.designer.core.ui.editor.nodes.Node)5 IRepositoryNode (org.talend.repository.model.IRepositoryNode)5 Point (org.eclipse.swt.graphics.Point)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 Property (org.talend.core.model.properties.Property)4 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)4