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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations