Search in sources :

Example 1 with QueriesConnection

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

the class DBTreeProvider method createQueries.

private void createQueries(RepositoryNode node, final IRepositoryViewObject repObj, DatabaseConnection metadataConnection, boolean isBuildIn) {
    QueriesConnection queriesConnection = metadataConnection.getQueries();
    if (queriesConnection != null) {
        QueriesConnectionRepositoryObject repositoryObject = new QueriesConnectionRepositoryObject(repObj, queriesConnection);
        repositoryObject.setImage(IMAGES_APPEND_TO_EDITOR);
        //$NON-NLS-1$
        repositoryObject.setSourceName(Messages.getString("DBTreeProvider.sourceName"));
        RepositoryNode queriesConnectionNode = new RepositoryNodeExt(repositoryObject, node, ENodeType.REPOSITORY_ELEMENT);
        queriesConnectionNode.setProperties(EProperties.CONTENT_TYPE, RepositoryNodeType.QUERIESCONNECTION);
        node.getChildren().add(queriesConnectionNode);
        createQuery(queriesConnectionNode, repObj, queriesConnection);
    }
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) RepositoryNode(org.talend.repository.model.RepositoryNode) RepositoryNodeExt(org.talend.sqlbuilder.RepositoryNodeExt)

Example 2 with QueriesConnection

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

the class MetadataColumnComparator method saveEMFQuery.

/**
     * method "saveQuery" use save inputed Query to EMF's xml File.
     * 
     * @param repositoryNode current RepositoryNode
     * @param query need to save Query
     */
private void saveEMFQuery(String id, Query query, String oldQuery) {
    DatabaseConnectionItem item = getEMFItem(id);
    if (query != null) {
        Connection connection = item.getConnection();
        QueriesConnection queriesConnection = connection.getQueries();
        if (queriesConnection == null) {
            queriesConnection = ConnectionFactory.eINSTANCE.createQueriesConnection();
            queriesConnection.setConnection(connection);
            connection.setQueries(queriesConnection);
        }
        boolean isModify = false;
        List<Query> queries = queriesConnection.getQuery();
        for (Query query2 : queries) {
            if (oldQuery != null && (query2.getLabel().equals(oldQuery)) || query2.getLabel().equals(query.getLabel())) {
                // reset new label, if changed
                query2.setLabel(query.getLabel());
                query2.setComment(query.getComment());
                query2.setValue(query.getValue());
                // add by hywang
                query2.setContextMode(query.isContextMode());
                // assign id to old query without id
                assignQueryId(query2, queriesConnection);
                isModify = true;
            }
        }
        if (!isModify) {
            // assign id to new query
            assignQueryId(query, queriesConnection);
            queriesConnection.getQuery().add(query);
        }
    }
    deleteNouseTables(item.getConnection());
    saveMetaData(item);
}
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) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 3 with QueriesConnection

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

the class RepositoryValueUtils method updateRepositoryList.

private void updateRepositoryList() {
    IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    tableIdAndDbTypeMap = new HashMap<String, String>();
    tableIdAndDbSchemaMap = new HashMap<String, String>();
    repositoryTableMap = new HashMap<String, IMetadataTable>();
    repositoryQueryStoreMap = new HashMap<String, Query>();
    repositoryConnectionItemMap = new HashMap<String, ConnectionItem>();
    List<ConnectionItem> metadataConnectionsItem = null;
    try {
        metadataConnectionsItem = factory.getMetadataConnectionsItem();
    } 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);
                repositoryDBIdAndNameMap.put(connectionItem.getProperty().getId(), getRepositoryAliasName(connectionItem) + //$NON-NLS-1$
                ":" + connectionItem.getProperty().getLabel());
                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);
                                }
                            }
                            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);
                        queryStoreNameList.add(name);
                        queryStoreValuesList.add(value);
                    }
                }
            }
            queriesMap.put(connectionItem.getProperty().getId(), queryStoreValuesList);
        }
    }
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 4 with QueriesConnection

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

the class DynamicTabbedPropertySection method updateRepositoryList.

/**
     * ftang Comment method "updateRepositoryList".
     */
@SuppressWarnings("unchecked")
public 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 = factory.getMetadataConnectionsItem();
    } 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) || param.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) {
            IElementParameter repositorySchemaType = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            repositorySchemaType.setListItemsDisplayName(repositoryTableNameList);
            repositorySchemaType.setListItemsValue(repositoryTableValueList);
            if (!repositoryTableMap.keySet().contains(repositorySchemaType.getValue())) {
                List<String> list2 = tablesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
                boolean isNeeded = list2 != null && !list2.isEmpty();
                if (repositoryTableNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
                    repositorySchemaType.setValue(getDefaultRepository(param, true, repositoryConnectionValueList[0]));
                // elem.setPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName(),
                // getDefaultRepository(
                // true, repositoryConnectionValueList[0]));
                }
            }
        }
        if (param.getName().equals(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName())) {
            param.setListItemsDisplayName(repositoryQueryNameList);
            param.setListItemsValue(repositoryQueryValueList);
            if (!repositoryQueryStoreMap.keySet().contains(param.getValue())) {
                List<String> list2 = queriesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
                boolean isNeeded = list2 != null && !list2.isEmpty();
                if (repositoryQueryNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
                    elem.setPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), getDefaultRepository(elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE), false, repositoryConnectionValueList[0]));
                }
            }
        }
        if (param.getName().equals(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())) {
            updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, false);
        }
    // // for job settings extra (feature 2710)
    // if (param.getName().equals(extraRepositoryPropertyTypeName)) {
    // updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, true);
    // }
    }
    updateQuery();
}
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) 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) IConnection(org.talend.core.model.process.IConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) 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) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 5 with QueriesConnection

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

the class DowngradeParameterHelper method getOldLabelFromId.

/**
     * DOC nrousseau Comment method "getOldLabelFromId".
     * 
     * @param id
     * @param type
     * @return
     */
private static String getOldLabelFromId(String id, ERepositoryObjectType type) {
    final IProxyRepositoryFactory proxyRepositoryFactory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    try {
        ERepositoryObjectType repositoryConnectionsNeeded;
        if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
            repositoryConnectionsNeeded = ERepositoryObjectType.METADATA_CONNECTIONS;
        } else {
            repositoryConnectionsNeeded = ERepositoryObjectType.METADATA;
        }
        List<IRepositoryViewObject> objects = proxyRepositoryFactory.getAll(repositoryConnectionsNeeded);
        ConnectionItem connectionItem = null;
        for (IRepositoryViewObject object : objects) {
            connectionItem = (ConnectionItem) object.getProperty().getItem();
            if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
                QueriesConnection queries = connectionItem.getConnection().getQueries();
                if (queries == null) {
                    continue;
                }
                for (Query query : (List<Query>) queries.getQuery()) {
                    if (query.getId().equals(id)) {
                        return connectionItem.getProperty().getId() + SEPARATOR + query.getLabel();
                    }
                }
            } else if (type == ERepositoryObjectType.METADATA_CON_TABLE) {
                for (MetadataTable table : (Set<MetadataTable>) ConnectionHelper.getTables(connectionItem.getConnection())) {
                    if (table.getId().equals(id)) {
                        return connectionItem.getProperty().getId() + SEPARATOR + table.getLabel();
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        return null;
    }
    return null;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) ConnectionItem(org.talend.core.model.properties.ConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

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