Search in sources :

Example 41 with DatabaseConnectionItem

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

the class AddTablesDialog method setRootNode.

//$NON-NLS-1$
@SuppressWarnings("unchecked")
public void setRootNode(RepositoryNode rootNode) {
    this.rootNode = rootNode;
    DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(getRootNode());
    tables = new HashSet<MetadataTable>();
    tables.addAll(ConnectionHelper.getTables((DatabaseConnection) item.getConnection()));
}
Also used : MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 42 with DatabaseConnectionItem

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

the class ControllerRepositoryValueHander method fastRepositoryUpdateQuery.

private void fastRepositoryUpdateQuery(IElementParameter param) {
    if (param != null && param.getValue() != null) {
        String queryIdAndName = (String) param.getValue();
        //$NON-NLS-1$
        String[] names = queryIdAndName.split(" - ");
        if (names.length < 2) {
            return;
        }
        String linkedRepository = names[0];
        String queryName = null;
        if (names.length == 2) {
            queryName = names[1];
        } else if (names.length > 2) {
            queryName = queryIdAndName.substring(linkedRepository.length() + 3);
        }
        if (lastItemUsed != null) {
            if (!linkedRepository.equals(lastItemUsed.getProperty().getId())) {
                lastItemUsed = null;
            }
        }
        if (lastItemUsed == null) {
            IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
            Item item;
            try {
                IRepositoryViewObject object = factory.getLastVersion(linkedRepository);
                if (object == null) {
                    return;
                }
                item = object.getProperty().getItem();
                lastItemUsed = (ConnectionItem) item;
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
        Assert.isTrue(lastItemUsed instanceof DatabaseConnectionItem);
        QueriesConnection queriesConnection = ((DatabaseConnection) lastItemUsed.getConnection()).getQueries();
        EList<Query> queries = queriesConnection.getQuery();
        String repositoryAliasName = RepositoryObjectHelper.getRepositoryAliasName(lastItemUsed);
        for (Query currentQuery : queries) {
            if (currentQuery.getLabel().equals(queryName)) {
                String displayName = //$NON-NLS-1$
                repositoryAliasName + ":" + lastItemUsed.getProperty().getLabel() + " - " + //$NON-NLS-1$
                currentQuery.getLabel();
                param.setListItemsDisplayName(new String[] { displayName });
                param.setListItemsValue(new String[] { (String) param.getValue() });
            /* query cache should be deleted ,bug 16969 */
            // dynamicProperty.getRepositoryQueryStoreMap().clear();
            // dynamicProperty.getRepositoryQueryStoreMap().put((String) param.getValue(), currentQuery);
            }
        }
    }
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) RulesItem(org.talend.core.model.properties.RulesItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) FileItem(org.talend.core.model.properties.FileItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Query(org.talend.core.model.metadata.builder.connection.Query) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 43 with DatabaseConnectionItem

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

the class SqlMemoController method findRepositoryItem.

/**
     * Find the label of DatabaseConnectionItem that contains current query.
     * 
     * @param queryId
     * @return
     */
private DatabaseConnectionItem findRepositoryItem(String queryId) {
    try {
        //$NON-NLS-1$
        String[] names = queryId.split(" - ");
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        IRepositoryViewObject node = factory.getLastVersion(names[0]);
        DatabaseConnectionItem item = (DatabaseConnectionItem) node.getProperty().getItem();
        return item;
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 44 with DatabaseConnectionItem

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

the class SqlMemoController method refreshConnectionCommand.

private Command refreshConnectionCommand() {
    // open sql builder in repository mode, just use query object, no need for connection information
    ConnectionParameters connParameters = new ConnectionParameters();
    String queryId = (String) elem.getPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
    Query query = MetadataToolHelper.getQueryFromRepository(queryId);
    DatabaseConnectionItem item = findRepositoryItem(queryId);
    if (item != null) {
        connParameters.setRepositoryName(item.getProperty().getLabel());
        connParameters.setRepositoryId(item.getProperty().getId());
    }
    connParameters.setQueryObject(query);
    connParameters.setQuery(query.getValue());
    TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
    String processName = null;
    if (elem instanceof IProcess) {
        processName = ((IProcess) elem).getName();
    } else if (elem instanceof INode) {
        processName = ((INode) elem).getProcess().getName();
    } else if (elem instanceof IConnection) {
        processName = ((IConnection) elem).getSource().getProcess().getName();
    }
    connParameters.setNodeReadOnly(false);
    connParameters.setFromRepository(true);
    ISQLBuilderService sqlBuilderService = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
    Dialog sqlBuilder = sqlBuilderService.openSQLBuilderDialog(composite.getShell(), processName, connParameters);
    String sql = null;
    if (Window.OK == sqlBuilder.open()) {
        sql = connParameters.getQuery();
    }
    if (sql != null && !queryText.isDisposed()) {
        queryText.setText(sql);
        String propertyName = (String) openSQLEditorButton.getData(PARAMETER_NAME);
        return new PropertyChangeCommand(elem, propertyName, sql);
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Query(org.talend.core.model.metadata.builder.connection.Query) ModelSelectionDialog(org.talend.commons.ui.swt.dialogs.ModelSelectionDialog) Dialog(org.eclipse.jface.dialogs.Dialog) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IConnection(org.talend.core.model.process.IConnection) IProcess(org.talend.core.model.process.IProcess) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 45 with DatabaseConnectionItem

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

the class ProjectSettingMultipleThreadDynamicComposite method updateConnectionFromRepository.

private void updateConnectionFromRepository() {
    if (repositoryPropertyName == null || repositoryPropertyName.split(":").length != 2 || connectionUpdated) {
        return;
    }
    String[] split = repositoryPropertyName.split(":");
    String parentParamName = split[0];
    Element elementParams = elem;
    IElementParameter elementParameter = elementParams.getElementParameter(parentParamName);
    if (elementParameter != null && elementParameter.isShow(elem.getElementParameters()) && elementParameter.getChildParameters() != null) {
        if (elementParameter.getChildParameters().get("PROPERTY_TYPE") != null && !EmfComponent.BUILTIN.equals(elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue())) {
            DatabaseConnection connection = null;
            String id = (String) elementParameter.getChildParameters().get("REPOSITORY_PROPERTY_TYPE").getValue();
            // bug 0018192
            String propertyType = (String) elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue();
            ProxyRepositoryFactory proxyRepositoryFactory = ProxyRepositoryFactory.getInstance();
            IRepositoryViewObject lastVersion = null;
            if (null != id && !"".equals(id)) {
                try {
                    lastVersion = proxyRepositoryFactory.getLastVersion(id);
                    if (null == lastVersion && propertyType.equals(EmfComponent.REPOSITORY)) {
                        List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
                        if (connectionItems.isEmpty()) {
                            elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", "");
                            ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, null, parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.REPOSITORY);
                            changeValuesFromRepository1.execute();
                        }
                        for (ConnectionItem cItem : connectionItems) {
                            if (cItem instanceof DatabaseConnectionItem) {
                                id = cItem.getProperty().getId();
                                lastVersion = proxyRepositoryFactory.getLastVersion(id);
                                elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
                                break;
                            }
                        }
                    }
                } catch (PersistenceException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
                    for (ConnectionItem cItem : connectionItems) {
                        if (cItem instanceof DatabaseConnectionItem) {
                            lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(cItem.getProperty().getId());
                            id = cItem.getProperty().getId();
                            lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(id);
                            elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
                            break;
                        }
                    }
                } catch (PersistenceException e) {
                    e.printStackTrace();
                }
            }
            if (lastVersion != null && lastVersion.getProperty() != null) {
                Item item = lastVersion.getProperty().getItem();
                if (item instanceof DatabaseConnectionItem) {
                    DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                    connection = (DatabaseConnection) dbItem.getConnection();
                }
            }
            if (connection != null) {
                boolean sameValues = true;
                for (IElementParameter param : elementParams.getElementParameters()) {
                    String repositoryValue = param.getRepositoryValue();
                    if (param.isShow(elementParams.getElementParameters()) && repositoryValue != null && !param.getName().equals("PROPERTY_TYPE")) {
                        Object repValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, null);
                        if (repValue == null) {
                            continue;
                        }
                        if (repositoryValue.equals(UpdatesConstants.TYPE)) {
                            // datebase type
                            boolean found = false;
                            String[] list = param.getListRepositoryItems();
                            for (int i = 0; (i < list.length) && (!found); i++) {
                                if (repValue.equals(list[i])) {
                                    found = true;
                                }
                            }
                            if (!found) {
                                sameValues = false;
                                break;
                            }
                        } else {
                            // check the value
                            if (!param.getValue().equals(repValue)) {
                                sameValues = false;
                                break;
                            }
                        }
                    }
                }
                if (!sameValues) {
                    ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, connection, repositoryPropertyName, id);
                    changeValuesFromRepository.execute();
                    connectionUpdated = true;
                }
            }
        // bug 0018192
        // else {
        // change to build in
        // ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem,
        // null,
        // parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.BUILTIN);
        // changeValuesFromRepository1.execute();
        // }
        }
    }
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Element(org.talend.core.model.process.Element) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) 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)

Aggregations

DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)50 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)40 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 PersistenceException (org.talend.commons.exception.PersistenceException)16 Connection (org.talend.core.model.metadata.builder.connection.Connection)13 Item (org.talend.core.model.properties.Item)13 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 ArrayList (java.util.ArrayList)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 IElementParameter (org.talend.core.model.process.IElementParameter)10 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)9 Query (org.talend.core.model.metadata.builder.connection.Query)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 INode (org.talend.core.model.process.INode)7 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)6 ContextItem (org.talend.core.model.properties.ContextItem)6 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)6 Node (org.talend.designer.core.ui.editor.nodes.Node)6 List (java.util.List)5 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)5