use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class PropertyChangeCommand method getRelativeNodes.
private List<INode> getRelativeNodes(List<? extends IElementParameter> elementParameters) {
List<INode> retList = null;
if (elementParameters == null || elementParameters.size() == 0) {
return retList;
}
IElement element = elementParameters.get(0).getElement();
if (element instanceof Node) {
Node operatingNode = (Node) element;
IProcess process = operatingNode.getProcess();
if (process == null) {
return retList;
}
List<? extends INode> graphicNodes = process.getGraphicalNodes();
if (graphicNodes == null || graphicNodes.size() == 0) {
return retList;
}
String nodeName = operatingNode.getLabel();
retList = new ArrayList<INode>();
for (INode node : graphicNodes) {
List<? extends IElementParameter> nodeElementParameters = node.getElementParameters();
if (nodeElementParameters == null || nodeElementParameters.size() == 0) {
continue;
}
for (IElementParameter elementParameter : nodeElementParameters) {
if (elementParameter.getFieldType() == EParameterFieldType.COMPONENT_LIST) {
Object objName = elementParameter.getValue();
if (objName == null) {
continue;
}
String relatedComponentsName = objName.toString();
if (relatedComponentsName.equals(nodeName)) {
retList.add(node);
}
}
}
}
}
return retList;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class QueryGuessCommand method generateNewQuery.
private String generateNewQuery() {
// used for generating new Query.
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
if (realDBType != null) {
dbType = realDBType;
}
//
if (node != null && node instanceof INode) {
process = ((INode) node).getProcess();
}
if (this.realTableId != null && this.dbNameAndDbTypeMap.containsKey(this.realTableId)) {
dbType = this.dbNameAndDbTypeMap.get(this.realTableId);
}
if (dbType == null || dbType.equals("")) {
//$NON-NLS-1$
IElementParameter ptParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (ptParam != null && ptParam.getRepositoryValue() != null) {
if (ptParam.getRepositoryValue().endsWith(EDatabaseTypeName.GENERAL_JDBC.getProduct())) {
dbType = EDatabaseTypeName.GENERAL_JDBC.getDisplayName();
}
}
}
boolean isJdbc = false;
INode connectionNode = null;
IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
if (useExistConnection) {
IElementParameter connector = node.getElementParameter("CONNECTION");
if (connector != null) {
String connectorValue = connector.getValue().toString();
List<? extends INode> graphicalNodes = process.getGeneratingNodes();
for (INode node : graphicalNodes) {
if (node.getUniqueName().equals(connectorValue)) {
connectionNode = node;
break;
}
}
}
}
// hywang add for bug 7575
if (dbType != null && dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
isJdbc = true;
String driverClassName = node.getElementParameter("DRIVER_CLASS").getValue().toString();
if (connectionNode != null) {
driverClassName = connectionNode.getElementParameter("DRIVER_CLASS").getValue().toString();
}
driverClassName = TalendTextUtils.removeQuotes(driverClassName);
//
if (driverClassName != null && !"".equals(driverClassName)) {
boolean isContextModeDriverClass = ContextParameterUtils.containContextVariables(driverClassName);
if (isContextModeDriverClass) {
driverClassName = JavaProcessUtil.getContextOriginalValue(process, driverClassName);
}
}
// specil handle Sybase Database's driverClassName
if (driverClassName != null && !"".equals(driverClassName)) {
if (driverClassName.equals("com.sybase.jdbc3.jdbc.SybDataSource")) {
driverClassName = EDatabase4DriverClassName.SYBASEASE.getDriverClass();
}
}
// DRIVER_JAR:
String driverJarName = node.getElementParameter("DRIVER_JAR").getValue().toString();
if (connectionNode != null) {
driverJarName = connectionNode.getElementParameter("DRIVER_JAR").getValue().toString();
}
if (driverJarName != null && driverJarName.startsWith("[") && driverJarName.endsWith("]")) {
driverJarName = driverJarName.substring(1, driverJarName.length() - 1);
if (driverJarName != null && driverJarName.startsWith("{") && driverJarName.endsWith("}")) {
driverJarName = driverJarName.substring(1, driverJarName.length() - 1);
}
}
if (driverJarName != null && !"".equals(driverJarName)) {
boolean isContextMode = ContextParameterUtils.containContextVariables(driverJarName);
if (isContextMode) {
driverJarName = JavaProcessUtil.getContextOriginalValue(process, driverJarName);
}
dbType = extractMeta.getDbTypeByClassNameAndDriverJar(driverClassName, driverJarName);
} else {
dbType = extractMeta.getDbTypeByClassName(driverClassName);
}
DatabaseConnection dbConn = null;
if (dbType == null) {
// handle context mode
if (conn != null) {
if (conn instanceof DatabaseConnection) {
dbConn = (DatabaseConnection) conn;
}
driverClassName = DatabaseConnectionParameterUtil.getTrueParamValue(dbConn, driverClassName);
dbType = extractMeta.getDbTypeByClassName(driverClassName);
}
}
if (dbType == null) {
// if we can not get the DB Type from the existing driver list, just set back the type to ORACLE
// since it's one DB unknown from Talend.
// it might not work directly for all DB, but it will generate a standard query.
dbType = EDatabaseTypeName.ORACLE_OCI.getDisplayName();
}
// data view, conn=null
// need add code here for dbtype(oracle)
}
if (dbNameAndSchemaMap != null) {
schema = this.dbNameAndSchemaMap.get(this.realTableId);
}
String propertyType = (String) node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
boolean isTeradata = false;
if (dbType != null) {
isTeradata = dbType.equalsIgnoreCase(EDatabaseTypeName.TERADATA.getDisplayName());
}
if (propertyType != null && !propertyType.equals(EmfComponent.REPOSITORY)) {
List<? extends IElementParameter> elementParameters = this.node.getElementParameters();
if (useExistConnection) {
elementParameters = connectionNode.getElementParameters();
}
for (IElementParameter param : elementParameters) {
if (param.getRepositoryValue() != null) {
if (//$NON-NLS-1$
(!isTeradata && param.getRepositoryValue().equals("SCHEMA")) || (isTeradata && param.getRepositoryValue().equals("SID"))) {
// check if dbtype is //$NON-NLS-1$
// Teradata, always keep the
// query style like
// "dbname.tablename.columnname" on build-in mode
schema = (String) param.getValue();
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replace("\"", "");
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replace("\'", "");
break;
}
}
}
} else if (schema == null) {
IElementParameter param = node.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (param != null) {
try {
IRepositoryViewObject object = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getLastVersion((String) param.getValue());
if (object != null) {
Item item = object.getProperty().getItem();
if (item != null && item instanceof DatabaseConnectionItem) {
if (isTeradata) {
schema = (String) RepositoryToComponentProperty.getValue(((DatabaseConnectionItem) item).getConnection(), "SID", //$NON-NLS-1$
null);
} else {
schema = (String) RepositoryToComponentProperty.getValue(((DatabaseConnectionItem) item).getConnection(), "SCHEMA", //$NON-NLS-1$
null);
}
schema = TalendTextUtils.removeQuotes(schema);
}
}
} catch (PersistenceException e) {
//
}
}
}
// if (conn instanceof DatabaseConnection && conn.isContextMode()) {
// schema = DatabaseConnectionParameterUtil.getContextTrueValue((DatabaseConnection) conn, schema);
// }
String newQuery = null;
realTableName = QueryUtil.getTableName(node, newOutputMetadataTable, schema, dbType, realTableName);
if (realTableName.startsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.endsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.length() > 2) {
realTableName = realTableName.substring(1, realTableName.length() - 1);
}
if (conn != null && (isJdbc || dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || (StringUtils.isEmpty(schema) && (EDatabaseTypeName.ORACLE_CUSTOM.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLEFORSID.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLESN.equals(EDatabaseTypeName.getTypeFromDbType(dbType)) || EDatabaseTypeName.ORACLE_OCI.equals(EDatabaseTypeName.getTypeFromDbType(dbType)))))) {
schema = getDefaultSchema(realTableName);
}
newQuery = QueryUtil.generateNewQuery(node, newOutputMetadataTable, isJdbc, dbType, schema, realTableName);
// Added yyin TDQ-5616: if there are where clause, append it to the query
if (whereClause != null) {
// the where clause is inputted by the user, so no need to modify it.
//$NON-NLS-1$
newQuery = newQuery.substring(0, newQuery.length() - 1) + whereClause + "\"";
}
return TalendTextUtils.addSQLQuotes(newQuery);
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class RepositoryChangeQueryCommand method execute.
//$NON-NLS-1$
@SuppressWarnings("unchecked")
@Override
public void execute() {
// Force redraw of Commponents propoerties
elem.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), new Boolean(true));
if (propertyName.equals(EParameterName.QUERYSTORE_TYPE.getName()) && (EmfComponent.BUILTIN.equals(value))) {
for (IElementParameter param : elem.getElementParameters()) {
if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
param.setRepositoryValueUsed(false);
param.setReadOnly(false);
}
}
} else {
for (IElementParameter param : (List<IElementParameter>) elem.getElementParameters()) {
if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
// modified by hyWang
String queryStr = query.getValue();
if (!query.isContextMode()) {
queryStr = QueryUtil.checkAndAddQuotes(query.getValue());
}
elem.setPropertyValue(param.getName(), queryStr);
oldValue = elem.getPropertyValue(param.getName());
param.setRepositoryValueUsed(true);
param.setReadOnly(true);
}
}
}
if (propertyName.equals(EParameterName.QUERYSTORE_TYPE.getName())) {
elem.setPropertyValue(EParameterName.QUERYSTORE_TYPE.getName(), value);
} else {
oldMetadata = elem.getPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
elem.setPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), value);
}
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class SetParallelizationCommand method isComponentNeedRepartion.
private boolean isComponentNeedRepartion(IConnection con, Node needToPar) {
String partitioning = needToPar.getComponent().getPartitioning();
if (partitioning.equals("AUTO")) {
if (ParallelExecutionUtils.existPreviousPar((Node) con.getSource()) || ParallelExecutionUtils.existPreviousDepar((Node) con.getSource()) || ParallelExecutionUtils.existPreviousRepar((Node) con.getSource()) || ParallelExecutionUtils.existPreviousNone((Node) con.getSource())) {
return false;
}
return true;
} else {
// compare the target node's key with the previous tPartitioner's hashKeys to see if need repartitioning.
boolean needRepar = false;
IConnection previousParCon = ParallelExecutionUtils.getPreviousParCon((Node) con.getSource());
if (previousParCon != null) {
String[] partitionKey = partitioning.split("\\.");
IElementParameter parTableCon = previousParCon.getElementParameter(HASH_KEYS);
IElementParameter parTableNode = needToPar.getElementParameter(partitionKey[0]);
if (parTableNode != null) {
// for the partition key
String clumnKeyListName = "KEY_COLUMN";
String clumnNodeListName = partitionKey[1];
List<String> parKeyValues = new ArrayList<String>();
List<String> columnKeyValues = new ArrayList<String>();
ElementParameter nodeElemForList = null;
for (Map conColumnListMap : (List<Map>) parTableCon.getValue()) {
if (conColumnListMap.get(clumnKeyListName) instanceof String) {
parKeyValues.add((String) conColumnListMap.get(clumnKeyListName));
}
}
for (Object nodeItemList : parTableNode.getListItemsValue()) {
if (((ElementParameter) nodeItemList).getFieldType().equals(EParameterFieldType.PREV_COLUMN_LIST) || ((ElementParameter) nodeItemList).getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
nodeElemForList = (ElementParameter) nodeItemList;
break;
}
}
if (nodeElemForList != null) {
for (Map nodeColumnListMap : (List<Map>) parTableNode.getValue()) {
Object value = nodeColumnListMap.get(clumnNodeListName);
if (nodeColumnListMap.get(clumnNodeListName) instanceof String) {
columnKeyValues.add((String) value);
} else if (value instanceof Integer) {
Integer index = (Integer) value;
if (nodeElemForList.getListItemsDisplayName().length > index) {
columnKeyValues.add(nodeElemForList.getListItemsDisplayName()[index]);
}
}
}
}
if (columnKeyValues.size() > 0) {
if (columnKeyValues.equals(parKeyValues)) {
needRepar = false;
} else {
needRepar = true;
}
}
}
}
return needRepar;
}
}
use of org.talend.core.model.process.IElementParameter 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);
}
}
}
Aggregations