Search in sources :

Example 26 with DatabaseConnection

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

the class RepositoryValueUtils method getRepositoryAliasName.

/**
     * DOC Administrator Comment method "getRepositoryAliasName".
     * 
     * @param connectionItem
     * @return
     */
public String getRepositoryAliasName(ConnectionItem connectionItem) {
    ERepositoryObjectType repositoryObjectType = ERepositoryObjectType.getItemType(connectionItem);
    String aliasName = repositoryObjectType.getAlias();
    Connection connection = connectionItem.getConnection();
    if (connection instanceof DatabaseConnection) {
        if (((DatabaseConnection) connection).getDatabaseType() != null) {
            //$NON-NLS-1$
            String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
            //$NON-NLS-1$ //$NON-NLS-2$
            aliasName += " (" + currentDbType + ")";
        }
    }
    return aliasName;
}
Also used : 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) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 27 with DatabaseConnection

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

the class DynamicTabbedPropertySection method getRepositoryAliasName.

@Override
public String getRepositoryAliasName(ConnectionItem connectionItem) {
    ERepositoryObjectType repositoryObjectType = ERepositoryObjectType.getItemType(connectionItem);
    String aliasName = repositoryObjectType.getAlias();
    Connection connection = connectionItem.getConnection();
    if (connection instanceof DatabaseConnection) {
        //$NON-NLS-1$
        String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
        //$NON-NLS-1$ //$NON-NLS-2$
        aliasName += " (" + currentDbType + ")";
    }
    return aliasName;
}
Also used : 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) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 28 with DatabaseConnection

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

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

the class UpdateUrlForRedShiftMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        Connection connection = ((DatabaseConnectionItem) item).getConnection();
        if (connection instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) connection;
            try {
                if (EDatabaseTypeName.REDSHIFT.getDisplayName().equals(dbConn.getDatabaseType())) {
                    // old url: //jdbc:[postgresql|paraccel]://localhost:5439/test
                    String oldUrl = dbConn.getURL();
                    if (oldUrl != null) {
                        //$NON-NLS-1$ //$NON-NLS-2$
                        String newUrl = oldUrl.replaceFirst("jdbc:\\w+:", "jdbc:redshift:");
                        if (!oldUrl.equals(newUrl)) {
                            dbConn.setURL(newUrl);
                            ProxyRepositoryFactory.getInstance().save(item, true);
                            return ExecutionResult.SUCCESS_NO_ALERT;
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 30 with DatabaseConnection

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

the class UpdateDbVersionForVerticaMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
        if (dbItem.getConnection() instanceof DatabaseConnection) {
            DatabaseConnection dbConnection = (DatabaseConnection) dbItem.getConnection();
            if (EDatabaseTypeName.VERTICA.equals(EDatabaseTypeName.getTypeFromDbType(dbConnection.getDatabaseType()))) {
                boolean modified = false;
                if (dbConnection.getDbVersionString().equals(EDatabaseVersion4Drivers.VERTICA_6.name())) {
                    dbConnection.setDbVersionString(EDatabaseVersion4Drivers.VERTICA_6.getVersionValue());
                    modified = true;
                }
                if (modified) {
                    try {
                        ProxyRepositoryFactory.getInstance().save(item, true);
                        return ExecutionResult.SUCCESS_WITH_ALERT;
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    }
                }
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14