Search in sources :

Example 71 with DatabaseConnection

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

the class ConnectionInfoPage method getConnectionRepNodeFromInput.

/**
 * get ConnectionRepNode From editorInput
 *
 * @param editorInput
 * @return
 */
private DBConnectionRepNode getConnectionRepNodeFromInput(IEditorInput editorInput) {
    if (editorInput instanceof FileEditorInput) {
        Property property = PropertyHelper.getProperty(((FileEditorInput) editorInput).getFile());
        if (property == null) {
            IFile file = ((FileEditorInput) editorInput).getFile();
            IPath fullPath = file.getFullPath();
            String replace = fullPath.lastSegment().replace(this.oldDataproviderName, nameText.getText().trim());
            IPath removeLastSegments = fullPath.removeLastSegments(1);
            IPath newPath = removeLastSegments.append(replace);
            IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(newPath);
            editorInput = new FileEditorInput(file2);
            this.setInput(editorInput);
            property = PropertyHelper.getProperty(((FileEditorInput) editorInput).getFile());
        }
        Item item = property.getItem();
        if (item instanceof ConnectionItem) {
            DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) item).getConnection();
            return RepositoryNodeHelper.recursiveFindDatabaseConnection(connection);
        }
    } else if (editorInput instanceof ConnectionItemEditorInput) {
        return ((ConnectionItemEditorInput) editorInput).getRepNode();
    }
    return null;
}
Also used : Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ConnectionItem(org.talend.core.model.properties.ConnectionItem) FileEditorInput(org.eclipse.ui.part.FileEditorInput) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property)

Example 72 with DatabaseConnection

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

the class RepositoryNodeHelper method getInWhichProject.

/**
 * the modelelement can belong to current project or referenced project.
 *
 * @param analysis
 * @return
 */
private static org.talend.core.model.general.Project getInWhichProject(ModelElement modelElement) {
    if (modelElement instanceof DatabaseConnection || modelElement instanceof DelimitedFileConnection) {
        if (modelElement.eIsProxy()) {
            modelElement = (ModelElement) EObjectHelper.resolveObject(modelElement);
        }
        // TDQ-12245: fix a NPE when the modelElement is ref project model
        String projectName = EObjectHelper.getURI(modelElement).segment(1);
        java.util.Set<Project> allProjects = ProxyRepositoryManager.getInstance().getAllProjects();
        for (Project project : allProjects) {
            if (project.getTechnicalLabel().equals(projectName)) {
                return project;
            }
        }
    }
    Property property = PropertyHelper.getProperty(modelElement);
    org.talend.core.model.properties.Project project = ProjectManager.getInstance().getProject(property);
    return new org.talend.core.model.general.Project(project);
}
Also used : DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Project(org.talend.core.model.general.Project) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property)

Example 73 with DatabaseConnection

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

the class DbmsLanguage method getCatalogOrSchemaName.

/**
 * get the catalog or schema name according to the analyzed column.
 *
 * @param analyzedColumn
 * @return if the catalog is not null, return catalog's name, else if schema is not null, return schema's name, else
 * return null
 */
public String getCatalogOrSchemaName(TdColumn tdColumn) {
    String name = null;
    // get the catalog/schema name from the context
    DatabaseConnection dbConn = ConnectionHelper.getTdDataProvider(tdColumn);
    if (dbConn != null && dbConn.isContextMode()) {
        name = getCatalogNameFromContext(dbConn);
        if (!StringUtils.isEmpty(name)) {
            return name;
        }
        name = getSchemaNameFromContext(dbConn);
        if (!StringUtils.isEmpty(name)) {
            return name;
        }
    }
    // if the catalog/schema name from the context is empty, get it by the column
    if (StringUtils.isEmpty(name)) {
        ColumnSet columnSet = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
        // Get catalog
        Catalog catalog = getCatalog(columnSet);
        if (catalog != null) {
            return catalog.getName();
        }
        // Get schema
        Schema schema = getSchema(columnSet);
        if (schema != null) {
            return schema.getName();
        }
        // no catalog and schema
        // $NON-NLS-1$
        log.error(Messages.getString("DbmsLanguage.NoCatalogOrSchema", columnSet.getName()));
    }
    return name;
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 74 with DatabaseConnection

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

the class DQRepositoryViewLabelProvider method isNeedAddDriverConnection.

private boolean isNeedAddDriverConnection(IRepositoryNode repNode) {
    ERepositoryObjectType objectType = repNode.getObjectType();
    if (objectType == ERepositoryObjectType.METADATA_CONNECTIONS || ConnectionUtils.isTcompJdbc(objectType.getLabel())) {
        ConnectionItem connectionItem = (ConnectionItem) repNode.getObject().getProperty().getItem();
        if (connectionItem.getConnection() instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) (connectionItem.getConnection());
            String dbType = dbConn.getDatabaseType();
            String driverClassName = JavaSqlFactory.getDriverClass(dbConn);
            if (dbType == null || driverClassName == null || PluginConstant.EMPTY_STRING.equals(driverClassName)) {
                return true;
            }
            // SQLExplorer driver.
            if (!(StringUtils.equalsIgnoreCase(EDatabaseTypeName.IMPALA.getXmlName(), dbType) || StringUtils.equalsIgnoreCase(EDatabaseTypeName.HIVE.getXmlName(), dbType))) {
                Driver driver = MetadataConnectionUtils.getDriverCache().get(driverClassName);
                if (driver != null) {
                    return false;
                }
                // "sqlExplorer" many times.no need call it at here, if don't have "sqlExplorer", return false.
                return SqlExplorerUtils.getDefault().needAddDriverConnection(dbConn);
            }
        }
    }
    return false;
}
Also used : DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Driver(java.sql.Driver) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 75 with DatabaseConnection

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

the class ColumnAnalysisSqlExecutor method canParallel.

/**
 * DOC xqliu Comment method "canParallel".
 *
 * @return
 */
private boolean canParallel(Connection connection) {
    try {
        @SuppressWarnings("deprecation") DatabaseMetaData connectionMetadata = org.talend.utils.sql.ConnectionUtils.getConnectionMetadata(connection);
        if (connectionMetadata.getDriverName() != null && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME)) {
            return false;
        }
        // because the sqlite db is not supported the parallel very well
        if ("SQLite".equals(connection.getMetaData().getDatabaseProductName())) {
            // $NON-NLS-1$
            return false;
        }
        if (ExtractMetaDataUtils.getInstance().isHiveConnection(connection)) {
            // TDQ-12020 only Hive2 supports connection concurrency.
            org.talend.core.model.metadata.builder.connection.Connection analysisDataProvider = getAnalysisDataProvider(cachedAnalysis);
            DatabaseConnection dbConn = ((DatabaseConnection) analysisDataProvider);
            String hiveVersion = dbConn.getParameters().get(ConnParameterKeys.HIVE_SERVER_VERSION);
            if (HiveServerVersionInfo.HIVE_SERVER_1.getKey().equals(hiveVersion)) {
                return false;
            }
            // TDQ-13909: when run Hive on Spark not support Parallel
            // TODO: if we have a new hive on spark envirement and test profiling run well, we can remove this part
            String jdbcProperties = dbConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HIVE_JDBC_PROPERTIES);
            List<Map<String, Object>> hiveJDBCPropertiesList = HadoopRepositoryUtil.getHadoopPropertiesList(jdbcProperties);
            if (!hiveJDBCPropertiesList.isEmpty()) {
                List keyList = new ArrayList();
                List valueList = new ArrayList();
                for (Map<String, Object> propertyMap : hiveJDBCPropertiesList) {
                    // $NON-NLS-1$
                    keyList.add(propertyMap.get("PROPERTY"));
                    // $NON-NLS-1$
                    valueList.add(propertyMap.get("VALUE"));
                }
                if (keyList.contains("hive.execution.engine") && valueList.contains("spark")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return false;
                }
            }
            // TDQ-13909~
            return true;
        }
    } catch (SQLException e) {
        log.warn(e, e);
    }
    return this.parallel;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseMetaData(java.sql.DatabaseMetaData) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) Map(java.util.Map) HashMap(java.util.HashMap)

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