use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class ConvertLabelForConnectionItemMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
boolean changed = false;
if (item instanceof ConnectionItem) {
ConnectionItem conItem = (ConnectionItem) item;
Connection connection = conItem.getConnection();
Set tables = ConnectionHelper.getTables(connection);
for (Object tableObj : tables) {
MetadataTable table = (MetadataTable) tableObj;
String label = table.getLabel();
if (label != null) {
String validateValue = MetadataToolHelper.validateValue(label);
if (validateValue != null && !label.equals(validateValue)) {
table.setLabel(validateValue);
changed = true;
}
}
}
}
if (changed) {
try {
FACTORY.save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class RepositoryChangeMetadataCommand method setTableRelevantParameterValues.
protected void setTableRelevantParameterValues() {
Connection conn = connection;
if (conn == null) {
if (newPropValue != null && newPropValue instanceof String) {
String schemaId = (String) newPropValue;
//$NON-NLS-1$
String[] values = schemaId.split(" - ");
String repositoryID = values[0];
IRepositoryNode repositoryNode = RepositorySeekerManager.getInstance().searchRepoViewNode(repositoryID);
if (repositoryNode != null && repositoryNode.getObject() != null) {
Item item = repositoryNode.getObject().getProperty().getItem();
if (item instanceof ConnectionItem) {
ConnectionItem conItem = (ConnectionItem) item;
conn = conItem.getConnection();
}
}
}
}
for (IDragAndDropServiceHandler handler : DragAndDropManager.getHandlers()) {
if (handler.canHandle(conn)) {
handler.handleTableRelevantParameters(conn, node, newOutputMetadata);
}
}
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class ComponentChooseDialog method propaHadoopCfgChanges.
/**
* DOC ycbai Comment method "propaHadoopCfgChanges".
*
* <P>
* Propagate the changes from hadoop cluster to M/R process when drag&drop hadoop subnode from repository view to
* M/R process.
* </P>
*
* @param repositoryNode
*/
private void propaHadoopCfgChanges(IRepositoryNode repositoryNode) {
if (repositoryNode == null || repositoryNode.getObject() == null) {
return;
}
IHadoopClusterService hadoopClusterService = HadoopRepositoryUtil.getHadoopClusterService();
if (hadoopClusterService == null || !hadoopClusterService.isHadoopSubnode(repositoryNode)) {
return;
}
IProcess process = editor.getProcess();
if (!ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
return;
}
if ((process instanceof IProcess2) && (((IProcess2) process).getProperty().getItem() instanceof JobletProcessItem)) {
return;
}
Item subItem = repositoryNode.getObject().getProperty().getItem();
String propertyParamName = MR_PROPERTY_PREFIX + EParameterName.PROPERTY_TYPE.getName();
String propertyRepTypeParamName = MR_PROPERTY_PREFIX + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
IElementParameter propertyParam = process.getElementParameter(propertyParamName);
if (propertyParam == null) {
return;
}
String repositoryValue = propertyParam.getRepositoryValue();
if (repositoryValue == null) {
return;
}
//$NON-NLS-1$
String[] supportedRepositoryTypes = repositoryValue.split("\\|");
String repositoryType = hadoopClusterService.getRepositoryTypeOfHadoopSubItem(subItem);
if (!ArrayUtils.contains(supportedRepositoryTypes, repositoryType)) {
return;
}
Item hadoopClusterItem = hadoopClusterService.getHadoopClusterBySubitemId(new Project(ProjectManager.getInstance().getProject(subItem)), subItem.getProperty().getId());
String hadoopClusterId = hadoopClusterItem.getProperty().getId();
if (EmfComponent.REPOSITORY.equals(propertyParam.getValue())) {
// do nothing when select the same hadoop cluster.
String propertyId = (String) process.getElementParameter(propertyRepTypeParamName).getValue();
if (hadoopClusterId.equals(propertyId)) {
return;
}
}
Connection connection = ((ConnectionItem) subItem).getConnection();
if (hadoopClusterService.hasDiffsFromClusterToProcess(subItem, process)) {
boolean confirmUpdate = MessageDialog.openConfirm(editor.getSite().getShell(), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.title"), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.msg"));
if (confirmUpdate) {
// Update spark mode to YARN_CLIENT if repository
if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
IElementParameter sparkLocalParam = process.getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
IElementParameter sparkParam = process.getElementParameter(HadoopConstants.SPARK_MODE);
if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
sparkLocalParam.setValue(false);
}
if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
}
}
propertyParam.setValue(EmfComponent.REPOSITORY);
ChangeValuesFromRepository command = new ChangeValuesFromRepository(process, connection, propertyRepTypeParamName, subItem.getProperty().getId());
execCommandStack(command);
}
}
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method setAllConnectionParameters.
private void setAllConnectionParameters(String typ, IElement element) {
IElementParameter basePropertyParameter = null;
for (IElementParameter param : elem.getElementParameters()) {
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
if (param.getRepositoryValue().startsWith("DATABASE")) {
basePropertyParameter = param;
break;
}
}
}
// jobsetting view load the db info from current selected category
IElementParameter updateBasePropertyParameter = updateBasePropertyParameter();
if (updateBasePropertyParameter != null && !updateBasePropertyParameter.equals(basePropertyParameter)) {
basePropertyParameter = updateBasePropertyParameter;
}
String type = null;
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
if (typ != null && !typ.equals("")) {
//$NON-NLS-1$
type = typ;
} else {
//$NON-NLS-1$
type = getValueFromRepositoryName(element, "TYPE", basePropertyParameter);
}
if (type.equals("Oracle") || type.contains("OCLE")) {
IElementParameter ele = element.getElementParameter("CONNECTION_TYPE");
if (ele != null) {
type = (String) ele.getValue();
} else {
//$NON-NLS-1$
type = "ORACLE_SID";
}
}
// Get real hsqldb type
if (type.equals(EDatabaseTypeName.HSQLDB.name()) && getValueFromRepositoryName(element, "RUNNING_MODE", basePropertyParameter).equals("HSQLDB_INPROGRESS_PERSISTENT")) {
//$NON-NLS-1$
type = EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName();
}
// If the dbtype has been setted don't reset it again unless the dbtype of connParameters is null.
if (StringUtils.trimToNull(type) == null && StringUtils.trimToNull(connParameters.getDbType()) == null) {
type = EDatabaseTypeName.GENERAL_JDBC.getXmlName();
}
if (StringUtils.trimToNull(type) != null) {
connParameters.setDbType(type);
}
//$NON-NLS-1$
String frameWorkKey = getValueFromRepositoryName(element, "FRAMEWORK_TYPE", basePropertyParameter);
connParameters.setFrameworkType(frameWorkKey);
String schema = getValueFromRepositoryName(element, EConnectionParameterName.SCHEMA.getName(), basePropertyParameter);
connParameters.setSchema(schema);
String userName = getValueFromRepositoryName(element, EConnectionParameterName.USERNAME.getName(), basePropertyParameter);
connParameters.setUserName(userName);
String password = getValueFromRepositoryName(element, EConnectionParameterName.PASSWORD.getName(), basePropertyParameter);
connParameters.setPassword(password);
String host = getValueFromRepositoryName(element, EConnectionParameterName.SERVER_NAME.getName(), basePropertyParameter);
connParameters.setHost(host);
String port = getValueFromRepositoryName(element, EConnectionParameterName.PORT.getName(), basePropertyParameter);
connParameters.setPort(port);
boolean https = Boolean.parseBoolean(getValueFromRepositoryName(element, EConnectionParameterName.HTTPS.getName(), basePropertyParameter));
connParameters.setHttps(https);
boolean isOracleOCI = type.equals(EDatabaseTypeName.ORACLE_OCI.getXmlName()) || type.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName());
if (isOracleOCI) {
String localServiceName = getValueFromRepositoryNameAndParameterName(element, EConnectionParameterName.SID.getName(), EParameterName.LOCAL_SERVICE_NAME.getName());
// sid is the repository value both for DBName and Local_service_name
connParameters.setLocalServiceName(localServiceName);
}
String datasource = getValueFromRepositoryName(element, EConnectionParameterName.DATASOURCE.getName(), basePropertyParameter);
connParameters.setDatasource(datasource);
// qli modified to fix the bug "7364".
String dbName = getValueFromRepositoryName(element, EConnectionParameterName.SID.getName(), basePropertyParameter);
if (EDatabaseTypeName.EXASOL.getDisplayName().equals(connParameters.getDbType())) {
if (dbName.contains("\\\"")) {
dbName = dbName.replace("\\\"", "");
}
dbName = TextUtil.removeQuots(dbName);
} else if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(connParameters.getDbType())) {
//$NON-NLS-1$
dbName = "";
}
connParameters.setDbName(dbName);
if (connParameters.getDbType().equals(EDatabaseTypeName.SQLITE.getXmlName()) || connParameters.getDbType().equals(EDatabaseTypeName.ACCESS.getXmlName()) || connParameters.getDbType().equals(EDatabaseTypeName.FIREBIRD.getXmlName())) {
String file = getValueFromRepositoryName(element, EConnectionParameterName.FILE.getName(), basePropertyParameter);
connParameters.setFilename(file);
}
String dir = getValueFromRepositoryName(element, EConnectionParameterName.DIRECTORY.getName(), basePropertyParameter);
if (type.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName())) {
dir = getValueFromRepositoryName(elem, EConnectionParameterName.DBPATH.getName(), basePropertyParameter);
}
connParameters.setDirectory(dir);
// General jdbc
String url = getValueFromRepositoryName(element, EConnectionParameterName.URL.getName(), basePropertyParameter);
if (StringUtils.isEmpty(url)) {
// to get the Oracle RAC url.
if (EDatabaseTypeName.ORACLE_CUSTOM.getXmlName().equals(type)) {
url = getValueFromRepositoryName(element, "RAC_" + EConnectionParameterName.URL.getName(), basePropertyParameter);
}
}
connParameters.setUrl(TalendTextUtils.removeQuotes(url));
String driverJar = getValueFromRepositoryName(element, EConnectionParameterName.DRIVER_JAR.getName(), basePropertyParameter);
connParameters.setDriverJar(TalendTextUtils.removeQuotes(driverJar));
String driverClass = getValueFromRepositoryName(element, EConnectionParameterName.DRIVER_CLASS.getName(), basePropertyParameter);
String dbVersion = getValueFromRepositoryName(element, "DB_VERSION", basePropertyParameter);
connParameters.setDbVersion(dbVersion);
if (EDatabaseVersion4Drivers.VERTICA_5_1.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_6.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_6_1_X.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_7.getVersionValue().equals(dbVersion)) {
driverClass = EDatabase4DriverClassName.VERTICA2.getDriverClass();
}
connParameters.setDriverClass(TalendTextUtils.removeQuotes(driverClass));
if (driverClass != null && !"".equals(driverClass) && !EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(connParameters.getDbType())) {
if (driverClass.startsWith("\"") && driverClass.endsWith("\"")) {
driverClass = TalendTextUtils.removeQuotes(driverClass);
}
String dbTypeByClassName = "";
if (driverJar != null && !"".equals(driverJar)) {
dbTypeByClassName = extractMeta.getDbTypeByClassNameAndDriverJar(driverClass, driverJar);
} else {
dbTypeByClassName = extractMeta.getDbTypeByClassName(driverClass);
}
if (dbTypeByClassName != null) {
connParameters.setDbType(dbTypeByClassName);
}
}
String jdbcProps = getValueFromRepositoryName(element, EConnectionParameterName.PROPERTIES_STRING.getName(), basePropertyParameter);
connParameters.setJdbcProperties(jdbcProps);
String realTableName = null;
if (EmfComponent.REPOSITORY.equals(elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()))) {
final Object propertyValue = elem.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
IMetadataTable metadataTable = null;
String connectionId = propertyValue.toString().split(" - ")[0];
String tableLabel = propertyValue.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
if (table.getLabel().equals(tableLabel)) {
metadataTable = ConvertionHelper.convert(table);
break;
}
}
}
if (metadataTable != null) {
realTableName = metadataTable.getTableName();
}
}
connParameters.setSchemaName(QueryUtil.getTableName(elem, connParameters.getMetadataTable(), TalendTextUtils.removeQuotes(schema), type, realTableName));
}
use of org.talend.core.model.properties.ConnectionItem 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);
}
}
}
Aggregations