Search in sources :

Example 6 with QueriesConnection

use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.

the class QueryTypeController 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) {
    String paramName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter param = elem.getElementParameter(paramName);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    String name = param.getName();
    String value = combo.getText();
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    if (name.equals(EParameterName.QUERYSTORE_TYPE.getName())) {
        if (elem instanceof Node) {
            String querySelected;
            Query repositoryQuery = null;
            // Map<String, Query> repositoryQueryStoreMap = this.dynamicProperty.getRepositoryQueryStoreMap();
            IElementParameter repositoryParam = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
            querySelected = (String) repositoryParam.getValue();
            /* value can be devided means the value like "connectionid - label" */
            String[] keySplitValues = querySelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = querySelected.split(" - ")[0];
                String queryLabel = querySelected.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 DatabaseConnectionItem) {
                    Connection conn = ((DatabaseConnectionItem) item).getConnection();
                    if (conn instanceof DatabaseConnection) {
                        DatabaseConnection dbconn = (DatabaseConnection) conn;
                        QueriesConnection queryConnection = dbconn.getQueries();
                        for (Query query : queryConnection.getQuery()) {
                            if (query.getLabel().equals(queryLabel)) {
                                repositoryQuery = query;
                                break;
                            }
                        }
                    }
                }
            }
            if (switchParam != null) {
                switchParam.setValue(Boolean.FALSE);
            }
            if (repositoryQuery != null) {
                return new RepositoryChangeQueryCommand(elem, repositoryQuery, name, value);
            } else {
                return new PropertyChangeCommand(elem, name, value);
            }
        }
    }
    return null;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) 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) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) 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) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 7 with QueriesConnection

use of org.talend.core.model.metadata.builder.connection.QueriesConnection 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 8 with QueriesConnection

use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.

the class DynamicComposite method updateRepositoryList.

/**
     * ftang Comment method "updateRepositoryList".
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private void updateRepositoryList() {
    IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    tableIdAndDbTypeMap = new HashMap<String, String>();
    tableIdAndDbSchemaMap = new HashMap<String, String>();
    List<ConnectionItem> metadataConnectionsItem = null;
    String[] repositoryTableNameList = new String[] {};
    String[] repositoryTableValueList = new String[] {};
    String[] repositoryConnectionNameList = new String[] {};
    String[] repositoryConnectionValueList = new String[] {};
    String[] repositoryQueryNameList = new String[] {};
    String[] repositoryQueryValueList = new String[] {};
    try {
        metadataConnectionsItem = getConnectionItems();
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
    if (metadataConnectionsItem != null) {
        repositoryTableMap.clear();
        repositoryQueryStoreMap.clear();
        repositoryConnectionItemMap.clear();
        tablesMap.clear();
        queriesMap.clear();
        List<String> tableNamesList = new ArrayList<String>();
        List<String> tableValuesList = new ArrayList<String>();
        List<String> queryStoreNameList = new ArrayList<String>();
        List<String> queryStoreValuesList = new ArrayList<String>();
        for (ConnectionItem connectionItem : metadataConnectionsItem) {
            Connection connection = connectionItem.getConnection();
            if (!connection.isReadOnly()) {
                //$NON-NLS-1$
                repositoryConnectionItemMap.put(connectionItem.getProperty().getId() + "", connectionItem);
                for (Object tableObj : ConnectionHelper.getTables(connection)) {
                    org.talend.core.model.metadata.builder.connection.MetadataTable table;
                    table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
                    if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
                        if (!factory.isDeleted(table)) {
                            String name = //$NON-NLS-1$
                            getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
                            table.getLabel();
                            //$NON-NLS-1$
                            String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
                            IMetadataTable newTable = ConvertionHelper.convert(table);
                            repositoryTableMap.put(value, newTable);
                            if (connection instanceof DatabaseConnection) {
                                String dbType = ((DatabaseConnection) connection).getDatabaseType();
                                String schema = ((DatabaseConnection) connection).getUiSchema();
                                tableIdAndDbTypeMap.put(newTable.getId(), dbType);
                                if (schema != null && !schema.equals("")) {
                                    //$NON-NLS-1$
                                    tableIdAndDbSchemaMap.put(newTable.getId(), schema);
                                }
                            }
                            addOrderDisplayNames(tableValuesList, tableNamesList, value, name);
                        // tableNamesList.add(name);
                        // tableValuesList.add(value);
                        }
                    }
                }
            }
            tablesMap.put(connectionItem.getProperty().getId(), tableValuesList);
            if (connection instanceof DatabaseConnection && !connection.isReadOnly()) {
                DatabaseConnection dbConnection = (DatabaseConnection) connection;
                QueriesConnection queriesConnection = dbConnection.getQueries();
                if (queriesConnection != null) {
                    List<Query> qs = queriesConnection.getQuery();
                    for (Query query : qs) {
                        String name = //$NON-NLS-1$
                        getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
                        query.getLabel();
                        //$NON-NLS-1$
                        String value = connectionItem.getProperty().getId() + " - " + query.getLabel();
                        repositoryQueryStoreMap.put(value, query);
                        addOrderDisplayNames(queryStoreValuesList, queryStoreNameList, value, name);
                    // queryStoreNameList.add(name);
                    // queryStoreValuesList.add(value);
                    }
                }
            }
            queriesMap.put(connectionItem.getProperty().getId(), queryStoreValuesList);
        }
        repositoryTableNameList = tableNamesList.toArray(new String[0]);
        repositoryTableValueList = tableValuesList.toArray(new String[0]);
        repositoryQueryNameList = queryStoreNameList.toArray(new String[0]);
        repositoryQueryValueList = queryStoreValuesList.toArray(new String[0]);
    }
    initMaps();
    for (int i = 0; i < elem.getElementParameters().size(); i++) {
        IElementParameter param = elem.getElementParameters().get(i);
        if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
            IElementParameter repositoryType = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            repositoryType.setListItemsDisplayName(repositoryTableNameList);
            repositoryType.setListItemsValue(repositoryTableValueList);
            if (!repositoryTableMap.keySet().contains(repositoryType.getValue())) {
                IElementParameter repositoryPropertyType = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, param.getCategory());
                if (repositoryPropertyType != null) {
                    List<String> list2 = tablesMap.get(repositoryPropertyType.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue());
                    boolean isNeeded = list2 != null && !list2.isEmpty();
                    if (repositoryTableNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
                        repositoryType.setValue(getDefaultRepository(param, true, repositoryConnectionValueList[0]));
                    }
                }
            }
        }
        if (param.getFieldType().equals(EParameterFieldType.QUERYSTORE_TYPE)) {
            IElementParameter repositoryType = param.getChildParameters().get(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
            repositoryType.setListItemsDisplayName(repositoryQueryNameList);
            repositoryType.setListItemsValue(repositoryQueryValueList);
            if (!repositoryQueryStoreMap.keySet().contains(repositoryType.getValue())) {
                IElementParameter repositoryPropertyType = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, param.getCategory());
                if (repositoryPropertyType != null) {
                    List<String> list2 = queriesMap.get(repositoryPropertyType.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue());
                    boolean isNeeded = list2 != null && !list2.isEmpty();
                    if (repositoryQueryNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
                        repositoryType.setValue(getDefaultRepository(elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE), false, repositoryConnectionValueList[0]));
                    }
                }
            }
        }
        if (param.getFieldType().equals(EParameterFieldType.PROPERTY_TYPE)) {
            IElementParameter repositoryType = param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            List<String> nameList = new ArrayList<String>();
            List<String> valueList = new ArrayList<String>();
            updateRepositoryListExtra(repositoryType, nameList, valueList, false);
            repositoryConnectionNameList = nameList.toArray(new String[0]);
            repositoryConnectionValueList = valueList.toArray(new String[0]);
        }
    }
}
Also used : Query(org.talend.core.model.metadata.builder.connection.Query) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) WSDLSchemaConnection(org.talend.core.model.metadata.builder.connection.WSDLSchemaConnection) GenericSchemaConnection(org.talend.core.model.metadata.builder.connection.GenericSchemaConnection) PositionalFileConnection(org.talend.core.model.metadata.builder.connection.PositionalFileConnection) RegexpFileConnection(org.talend.core.model.metadata.builder.connection.RegexpFileConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) LDAPSchemaConnection(org.talend.core.model.metadata.builder.connection.LDAPSchemaConnection) FileExcelConnection(org.talend.core.model.metadata.builder.connection.FileExcelConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 9 with QueriesConnection

use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.

the class EMFRepositoryNodeManager method getQueryByLabel.

/**
     * dev Comment method "getQueryByLabel".
     * 
     * @param node all repository node Type
     * @param label search query label
     * @return
     */
@SuppressWarnings("unchecked")
public Query getQueryByLabel(RepositoryNode node, String label) {
    root = null;
    if (node.getObjectType().equals(ERepositoryObjectType.METADATA_CON_QUERY)) {
        root = node.getParent().getParent();
    } else {
        root = SQLBuilderRepositoryNodeManager.getRoot(node);
    }
    if (root == null) {
        return null;
    }
    DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(root);
    DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    QueriesConnection queriesConnection = connection.getQueries();
    if (queriesConnection != null) {
        List<Query> queries = queriesConnection.getQuery();
        for (Query query : queries) {
            if (query.getLabel().equals(label)) {
                return query;
            }
        }
    }
    return null;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 10 with QueriesConnection

use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.

the class MetadataColumnComparator method getALLQueryLabels.

/**
     * dev Comment method "getALLQueryLabels".
     * 
     * @param repositoryNode current RepositoryNode.
     * @return all QueryLabels in Emf.
     */
@SuppressWarnings("unchecked")
public List<String> getALLQueryLabels(RepositoryNode repositoryNode) {
    List<String> allQueries = new ArrayList<String>();
    DatabaseConnectionItem item = getEMFItem(repositoryNode.getObject().getId());
    DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    QueriesConnection queriesConnection = connection.getQueries();
    if (queriesConnection != null) {
        List<Query> qs = queriesConnection.getQuery();
        for (Query q1 : qs) {
            allQueries.add(q1.getLabel());
        }
    }
    return allQueries;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

QueriesConnection (org.talend.core.model.metadata.builder.connection.QueriesConnection)10 Query (org.talend.core.model.metadata.builder.connection.Query)9 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)8 PersistenceException (org.talend.commons.exception.PersistenceException)6 ConnectionItem (org.talend.core.model.properties.ConnectionItem)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 Connection (org.talend.core.model.metadata.builder.connection.Connection)5 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 ArrayList (java.util.ArrayList)4 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 IElementParameter (org.talend.core.model.process.IElementParameter)3 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)2 FileExcelConnection (org.talend.core.model.metadata.builder.connection.FileExcelConnection)2 GenericSchemaConnection (org.talend.core.model.metadata.builder.connection.GenericSchemaConnection)2 LDAPSchemaConnection (org.talend.core.model.metadata.builder.connection.LDAPSchemaConnection)2 PositionalFileConnection (org.talend.core.model.metadata.builder.connection.PositionalFileConnection)2 RegexpFileConnection (org.talend.core.model.metadata.builder.connection.RegexpFileConnection)2 SalesforceSchemaConnection (org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection)2 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)2