Search in sources :

Example 1 with DatabaseConnection

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

the class TracesConnectionUtils method createConnection.

/**
     * DOC hwang Comment method "createConnection".
     */
public static DatabaseConnection createConnection(ConnectionParameters parameters) {
    ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
    String dbType = parameters.getDbType();
    boolean isNeedSchema = EDatabaseTypeName.getTypeFromDbType(dbType).isNeedSchema();
    String productName = EDatabaseTypeName.getTypeFromDisplayName(dbType).getProduct();
    // boolean isOralceWithSid = productName.equals(EDatabaseTypeName.ORACLEFORSID.getProduct());
    String schema = parameters.getSchema();
    EDatabaseTypeName type = EDatabaseTypeName.getTypeFromDbType(dbType);
    if (ManagerConnection.isSchemaFromSidOrDatabase(type)) {
        schema = parameters.getDbName();
    }
    if ("".equals(schema) && EDatabaseTypeName.INFORMIX.getProduct().equals(productName)) {
        //$NON-NLS-1$
        schema = parameters.getUserName();
    }
    if (EDatabaseTypeName.EXASOL.getProduct().equals(productName)) {
        schema = parameters.getDbName();
    }
    boolean isSchemaInValid = //$NON-NLS-1$ //$NON-NLS-2$
    (schema == null) || (schema.equals("\'\'")) || (schema.equals("\"\"")) || //$NON-NLS-1$
    (schema.trim().equals(""));
    // from 616 till line 622 modified by hyWang
    NotReallyNeedSchemaDBS dbs = new NotReallyNeedSchemaDBS();
    dbs.init();
    List<String> names = dbs.getNeedSchemaDBNames();
    boolean ifNeedSchemaDB = names.contains(productName);
    if (isNeedSchema && isSchemaInValid && !ifNeedSchemaDB) {
        //$NON-NLS-1$
        parameters.setConnectionComment(Messages.getString("TracesConnectionUtils.connectionComment"));
        return null;
    }
    DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    connection.setFileFieldName(parameters.getFilename());
    connection.setDatabaseType(dbType);
    connection.setUsername(parameters.getUserName());
    connection.setPort(parameters.getPort());
    connection.setRawPassword(parameters.getPassword());
    if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName()) && parameters.getLocalServiceName() != null && !"".equals(parameters.getLocalServiceName())) {
        connection.setSID(parameters.getLocalServiceName());
    } else {
        connection.setSID(parameters.getDbName());
    }
    connection.setLabel(parameters.getDbName());
    connection.setDatasourceName(parameters.getDatasource());
    if (parameters.getDbType().equals(EDatabaseTypeName.GODBC.getDisplayName()) && StringUtils.isEmpty(parameters.getDatasource())) {
        connection.setDatasourceName(parameters.getDbName());
    }
    if ("".equals(connection.getLabel())) {
        //$NON-NLS-1$
        connection.setLabel(parameters.getDatasource());
    }
    String driverClassByDbType = null;
    if (parameters.getDriverClass() != null) {
        driverClassByDbType = parameters.getDriverClass();
    } else {
        driverClassByDbType = extractMeta.getDriverClassByDbType(dbType);
    }
    String driverJar = parameters.getDriverJar();
    connection.setDriverClass(driverClassByDbType);
    connection.setDriverJarPath(driverJar);
    String databaseType = connection.getDatabaseType();
    if (driverClassByDbType != null && !"".equals(driverClassByDbType) && EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(parameters.getDbType())) {
        if (driverClassByDbType.startsWith("\"") && driverClassByDbType.endsWith("\"")) {
            driverClassByDbType = TalendTextUtils.removeQuotes(driverClassByDbType);
        }
        String dbTypeByClassName = "";
        if (driverJar != null && !"".equals(driverJar)) {
            dbTypeByClassName = extractMeta.getDbTypeByClassNameAndDriverJar(driverClassByDbType, driverJar);
        } else {
            dbTypeByClassName = extractMeta.getDbTypeByClassName(driverClassByDbType);
        }
        if (dbTypeByClassName != null) {
            databaseType = dbTypeByClassName;
        }
    }
    final String product = EDatabaseTypeName.getTypeFromDisplayName(databaseType).getProduct();
    ;
    connection.setProductId(product);
    if (MetadataTalendType.getDefaultDbmsFromProduct(product) != null) {
        final String mapping = MetadataTalendType.getDefaultDbmsFromProduct(product).getId();
        connection.setDbmsId(mapping);
    }
    if (!isSchemaInValid && isNeedSchema) {
        //$NON-NLS-1$ //$NON-NLS-2$
        schema = schema.replaceAll("\'", "");
        //$NON-NLS-1$ //$NON-NLS-2$
        schema = schema.replaceAll("\"", "");
        connection.setUiSchema(schema);
    }
    connection.setServerName(parameters.getHost());
    connection.setAdditionalParams(parameters.getJdbcProperties());
    connection.setURL(parameters.getCombineURL());
    connection.setDBRootPath(parameters.getDirectory());
    connection.setDbVersionString(parameters.getDbVersion());
    // Added by Marvin Wang to add other parameters.
    Map<String, String> params = parameters.getParameters();
    if (params != null && params.size() > 0) {
        Set<Entry<String, String>> collection = params.entrySet();
        for (Entry<String, String> para : collection) {
            connection.getParameters().put(para.getKey(), para.getValue());
        }
    }
    return connection;
}
Also used : Entry(java.util.Map.Entry) NotReallyNeedSchemaDBS(org.talend.designer.core.sqlbuilder.NotReallyNeedSchemaDBS) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName)

Example 2 with DatabaseConnection

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

the class TAmazonOracleDndFilter method except.

@Override
public boolean except(Item item, ERepositoryObjectType type, RepositoryNode seletetedNode, IComponent component, String repositoryType) {
    if (component != null) {
        // for tAmazonOracleInput/Output/Connection/Row
        if (component.getName().startsWith("tAmazonOracle")) {
            //$NON-NLS-1$
            String dbType = null;
            if (item != null && item instanceof DatabaseConnectionItem) {
                if (((DatabaseConnectionItem) item).getConnection() instanceof DatabaseConnection) {
                    dbType = ((DatabaseConnection) ((DatabaseConnectionItem) item).getConnection()).getDatabaseType();
                }
            }
            Node node = new Node(component);
            if (node != null) {
                //$NON-NLS-1$
                IElementParameter param = node.getElementParameter("CONNECTION_TYPE");
                if (param != null) {
                    Object[] valuesList = param.getListItemsValue();
                    for (Object element : valuesList) {
                        String conType = EDatabaseTypeName.getTypeFromDbType(element.toString()).getDisplayName();
                        if (conType != null && dbType != null && conType.equals(dbType)) {
                            return false;
                        }
                    }
                }
            }
            return true;
        } else if (("tOracleCDCOutput").equals(component.getName())) {
            //$NON-NLS-1$
            if (item != null && item instanceof DatabaseConnectionItem) {
                if (((DatabaseConnectionItem) item).getConnection() instanceof DatabaseConnection) {
                    DatabaseConnection connection = ((DatabaseConnection) ((DatabaseConnectionItem) item).getConnection());
                    if (MetadataConnectionUtils.isOracle(connection)) {
                        String version = connection.getDbVersionString();
                        if (EDatabaseVersion4Drivers.ORACLE_12.name().equals(version)) {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : RepositoryNode(org.talend.repository.model.RepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 3 with DatabaseConnection

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

the class MysqlOutputDBVersionForBug13250 method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        boolean modify = false;
        DatabaseConnectionItem mysqlConnItem = (DatabaseConnectionItem) item;
        if (mysqlConnItem.getConnection() instanceof DatabaseConnection) {
            DatabaseConnection mysqlConnection = (DatabaseConnection) mysqlConnItem.getConnection();
            if ("MySQL".equalsIgnoreCase(mysqlConnection.getDatabaseType())) {
                if (mysqlConnection.getDbVersionString() == null || "".equals(mysqlConnection.getDbVersionString())) {
                    mysqlConnection.setDbVersionString("MYSQL_5");
                    modify = true;
                }
            }
        }
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 4 with DatabaseConnection

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

the class RenameDbProductIdMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    try {
        DatabaseConnection connection = (DatabaseConnection) ((DatabaseConnectionItem) item).getConnection();
        String id = connection.getProductId();
        for (int i = 0; i < CHANGE_SET.length; i++) {
            if (id.equals(CHANGE_SET[i][OLD])) {
                connection.setProductId(CHANGE_SET[i][NEW]);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            }
        }
        return ExecutionResult.NOTHING_TO_DO;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 5 with DatabaseConnection

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

the class SchemaTypeProcessor method selectRepositoryNode.

@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    if (super.selectRepositoryNode(viewer, parentNode, node)) {
        IRepositoryViewObject object = node.getObject();
        if (object != null) {
            // query
            if (object instanceof Query) {
                return false;
            }
        }
        // cdc
        ICDCProviderService cdcService = null;
        if (PluginChecker.isCDCPluginLoaded()) {
            cdcService = (ICDCProviderService) GlobalServiceRegister.getDefault().getService(ICDCProviderService.class);
        }
        String repositoryType = getRepositoryType();
        if (ERepositoryCategoryType.CDC.getName().equals(repositoryType) && (object != null)) {
            if (object.getRepositoryObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
                DatabaseConnectionItem item = (DatabaseConnectionItem) object.getProperty().getItem();
                DatabaseConnection connection = (DatabaseConnection) item.getConnection();
                if (cdcService != null && cdcService.canCreateCDCConnection(connection)) {
                    return true;
                }
                return false;
            }
            if (object instanceof MetadataTable) {
                return ((MetadataTableRepositoryObject) object).getTable().isActivatedCDC();
            }
        }
        return true;
    }
    return false;
}
Also used : Query(org.talend.core.model.metadata.Query) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ICDCProviderService(org.talend.core.ui.ICDCProviderService) 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