Search in sources :

Example 46 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class QueryTypeController method getGuessQueryCommand.

/**
     * DOC nrousseau Comment method "getGuessQueryCommand".
     * 
     * @return
     */
private QueryGuessCommand getGuessQueryCommand() {
    // Map<String, IMetadataTable> repositoryTableMap = null;
    IMetadataTable newRepositoryMetadata = null;
    String realTableName = null;
    String realTableId = null;
    String schemaName = "";
    // Only for getting the real table name.
    if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
        IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        if (repositorySchemaTypeParameter != null) {
            final Object value = repositorySchemaTypeParameter.getValue();
            if (elem instanceof Node) {
                /* value can be devided means the value like "connectionid - label" */
                String[] keySplitValues = value.toString().split(" - ");
                if (keySplitValues.length > 1) {
                    String connectionId = value.toString().split(" - ")[0];
                    String tableLabel = value.toString().split(" - ")[1];
                    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                    Item item = null;
                    try {
                        IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                        if (repobj != null) {
                            Property property = repobj.getProperty();
                            if (property != null) {
                                item = property.getItem();
                            }
                        }
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                    if (item != null && item instanceof ConnectionItem) {
                        Connection connection = ((ConnectionItem) item).getConnection();
                        for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                            // bug 20365
                            if (table.getLabel().equals(tableLabel)) {
                                IMetadataTable repositoryMetadata = ConvertionHelper.convert(table);
                                realTableName = repositoryMetadata.getTableName();
                                realTableId = repositoryMetadata.getId();
                                // }
                                break;
                            }
                        }
                    }
                }
            // if (repositoryTableMap.containsKey(value)) {
            // IMetadataTable repositoryMetadata = repositoryTableMap.get(value);
            // realTableName = repositoryMetadata.getTableName();
            // realTableId = repositoryMetadata.getId();
            // }
            }
        }
    // }
    // }
    }
    // Ends
    Connection repositoryConnection = null;
    boolean useExisting = false;
    IElementParameter elementParameter = elem.getElementParameter(EParameterName.USE_EXISTING_CONNECTION.name());
    if (elem instanceof Node) {
        IProcess process = ((Node) elem).getProcess();
        if (elementParameter != null && Boolean.valueOf(String.valueOf(elementParameter.getValue()))) {
            String connName = (String) elem.getPropertyValue("CONNECTION");
            for (INode node : process.getGraphicalNodes()) {
                if (node.getElementName().equals(connName)) {
                    useExisting = true;
                    final Object propertyValue = node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                    if (propertyValue != null) {
                        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                        Item item = null;
                        try {
                            IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
                            if (repobj != null) {
                                Property property = repobj.getProperty();
                                if (property != null) {
                                    item = property.getItem();
                                }
                            }
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        if (item != null && item instanceof ConnectionItem) {
                            repositoryConnection = ((ConnectionItem) item).getConnection();
                        } else {
                            initConnectionParameters();
                            repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
                        }
                    }
                    break;
                }
            }
        }
    }
    if (!useExisting && elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
        final Object propertyValue = elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
        if (propertyValue != null) {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            Item item = null;
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            if (item != null && item instanceof ConnectionItem) {
                repositoryConnection = ((ConnectionItem) item).getConnection();
            }
        }
    } else {
        initConnectionParameters();
        repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
    }
    QueryGuessCommand cmd = null;
    INode node = null;
    if (elem instanceof INode) {
        node = (INode) elem;
    } else {
        // else instanceof Connection
        node = ((IConnection) elem).getSource();
    }
    List<IMetadataTable> metadataList = node.getMetadataList();
    newRepositoryMetadata = metadataList.get(0);
    // for tInformixRow
    if (newRepositoryMetadata.getListColumns().size() == 0 && metadataList.size() > 1) {
        newRepositoryMetadata = metadataList.get(1);
    }
    if (newRepositoryMetadata == null) {
        String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        if (schemaSelected != null) {
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        } else if (newRepositoryMetadata == null) {
            MessageDialog.openWarning(new Shell(), Messages.getString("QueryTypeController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("QueryTypeController.nothingToGuess"));
            return cmd;
        }
    }
    cmd = new QueryGuessCommand(node, newRepositoryMetadata, repositoryConnection);
    cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
    //$NON-NLS-1$
    String type = getValueFromRepositoryName("TYPE");
    if ("Oracle".equalsIgnoreCase(type)) {
        type = EDatabaseTypeName.ORACLEFORSID.getDisplayName();
    }
    cmd.setParameters(realTableId, realTableName, type);
    return cmd;
}
Also used : INode(org.talend.core.model.process.INode) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) 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) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Shell(org.eclipse.swt.widgets.Shell) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 47 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class QueryTypeController method createButtonCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createButtonCommand(org
     * .eclipse.swt.widgets.Button)
     */
@Override
protected Command createButtonCommand(Button button) {
    if (button.getData(NAME).equals(GUESS_QUERY_NAME)) {
        return getGuessQueryCommand();
    }
    if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
        RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), ERepositoryObjectType.METADATA_CON_QUERY, null);
        if (dialog.open() == RepositoryReviewDialog.OK) {
            RepositoryNode node = dialog.getResult();
            while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
                node = node.getParent();
            }
            String id = node.getObject().getProperty().getId();
            String name = dialog.getResult().getObject().getLabel();
            String paramName = (String) button.getData(PARAMETER_NAME);
            //$NON-NLS-1$
            String value = id + " - " + name;
            Query query = MetadataToolHelper.getQueryFromRepository(value);
            if (query != null) {
                IElementParameter queryText = getQueryTextElementParameter(elem);
                if (queryText != null) {
                    return new RepositoryChangeQueryCommand(elem, query, EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), value);
                }
            }
        }
    }
    return null;
}
Also used : Query(org.talend.core.model.metadata.builder.connection.Query) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) IElementParameter(org.talend.core.model.process.IElementParameter) RepositoryNode(org.talend.repository.model.RepositoryNode) RepositoryReviewDialog(org.talend.repository.ui.dialog.RepositoryReviewDialog)

Example 48 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class PropertyTypeController method initCDC.

private void initCDC(CompoundCommand cc, ConnectionItem originalConnectionItem) {
    if (!(elem instanceof Node)) {
        return;
    }
    Node node = (Node) elem;
    // ConnectionItem originalConnectionItem = repositoryConnectionItem;
    ConnectionItem connectionItem = originalConnectionItem;
    Connection originalConnection = connectionItem.getConnection();
    Connection connection = connectionItem.getConnection();
    if (node.getComponent().getName().contains("CDC")) {
        // to replace by a flag CDC in component? //$NON-NLS-1$
        if (originalConnectionItem instanceof DatabaseConnectionItem) {
            final DatabaseConnection databaseConnection = (DatabaseConnection) connection;
            CDCConnection cdcConn = databaseConnection.getCdcConns();
            if (cdcConn != null) {
                EList cdcTypes = cdcConn.getCdcTypes();
                if (cdcTypes != null && !cdcTypes.isEmpty()) {
                    CDCType cdcType = (CDCType) cdcTypes.get(0);
                    // replace property by CDC property.
                    String propertyId = cdcType.getLinkDB();
                    try {
                        IRepositoryViewObject object = ProxyRepositoryFactory.getInstance().getLastVersion(propertyId);
                        if (object != null) {
                            if (object.getProperty().getItem() instanceof DatabaseConnectionItem) {
                                DatabaseConnectionItem dbConnItem = (DatabaseConnectionItem) object.getProperty().getItem();
                                // replace connection by CDC connection
                                connectionItem = dbConnItem;
                                connection = dbConnItem.getConnection();
                            }
                        }
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                    // set cdc type mode.
                    IElementParameter logModeParam = node.getElementParameter(EParameterName.CDC_TYPE_MODE.getName());
                    if (logModeParam != null) {
                        String cdcTypeMode = ((DatabaseConnection) originalConnection).getCdcTypeMode();
                        Command logModeCmd = new PropertyChangeCommand(node, EParameterName.CDC_TYPE_MODE.getName(), CDCTypeMode.LOG_MODE.getName().equals(cdcTypeMode));
                        cc.add(logModeCmd);
                    }
                    // set lib for as400 so far.
                    //$NON-NLS-1$
                    final String name = "SOURCE_LIB";
                    IElementParameter libParam = node.getElementParameter(name);
                    if (libParam != null) {
                        Object propValue;
                        if (connection.isContextMode() && ContextParameterUtils.isContainContextParam(databaseConnection.getSID())) {
                            propValue = databaseConnection.getSID();
                        } else {
                            propValue = TalendTextUtils.addQuotes(databaseConnection.getSID());
                        }
                        Command libSettingCmd = new PropertyChangeCommand(node, name, propValue);
                        cc.add(libSettingCmd);
                    }
                }
            }
        }
    }
}
Also used : DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) 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) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EList(org.eclipse.emf.common.util.EList) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) 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) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) CDCType(org.talend.core.model.metadata.builder.connection.CDCType)

Example 49 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class AbstractPreferenceComposite method updateContextValue.

protected void updateContextValue(boolean update) {
    if (!update) {
        return;
    }
    IElementParameter proElement = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
    Object value = proElement.getValue();
    if (value instanceof String && ((String) value).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
        String id = (String) elem.getElementParameter(//$NON-NLS-1$
        EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
        String propertyType = EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
        ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(id);
        Connection connection = connectionItem.getConnection();
        ChangeValuesFromRepository command = new ChangeValuesFromRepository(elem, connection, propertyType, id);
        getCommandStack().execute(command);
    }
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 50 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class ImplicitContextLoadHelper method loadPropertyTypeFromPreference.

/**
     * DOC hcw Comment method "reloadPropertyType".
     * 
     * @param element
     * @param extraComposite
     * @param languagePrefix
     * @param elementParameter
     */
private static void loadPropertyTypeFromPreference(Element element, ExtraComposite extraComposite, String languagePrefix, IElementParameter elementParameter) {
    String propertyType = (String) getPreferenceValue(languagePrefix, EParameterName.PROPERTY_TYPE, String.class);
    String id = (String) getPreferenceValue(languagePrefix, EParameterName.REPOSITORY_PROPERTY_TYPE, String.class);
    Connection repositoryConnection = null;
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    Item item = null;
    try {
        IRepositoryViewObject repobj = factory.getLastVersion(id);
        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) {
        repositoryConnection = ((ConnectionItem) item).getConnection();
    } else {
        repositoryConnection = null;
    }
    ChangeValuesFromRepository cmd1 = new ChangeValuesFromRepository(element, repositoryConnection, getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.PROPERTY_TYPE.getName(), //$NON-NLS-1$
    propertyType);
    ChangeValuesFromRepository cmd2 = new ChangeValuesFromRepository(element, repositoryConnection, getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
    id);
    AbstractMultiPageTalendEditor part = (AbstractMultiPageTalendEditor) ((IProcess2) element).getEditor();
    if (part instanceof AbstractMultiPageTalendEditor) {
        Object adapter = (part).getTalendEditor().getAdapter(CommandStack.class);
        if (adapter != null) {
            CommandStack commandStack = ((CommandStack) adapter);
            commandStack.execute(cmd1);
            commandStack.execute(cmd2);
        }
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) CommandStack(org.eclipse.gef.commands.CommandStack) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) RepositoryToComponentProperty(org.talend.core.model.metadata.designerproperties.RepositoryToComponentProperty) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ConnectionItem (org.talend.core.model.properties.ConnectionItem)79 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)44 PersistenceException (org.talend.commons.exception.PersistenceException)38 Connection (org.talend.core.model.metadata.builder.connection.Connection)38 IElementParameter (org.talend.core.model.process.IElementParameter)38 Item (org.talend.core.model.properties.Item)34 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)31 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)27 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)20 ArrayList (java.util.ArrayList)19 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)19 Property (org.talend.core.model.properties.Property)17 ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)17 RepositoryNode (org.talend.repository.model.RepositoryNode)17 INode (org.talend.core.model.process.INode)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 List (java.util.List)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)13 ProcessItem (org.talend.core.model.properties.ProcessItem)12