public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); cid = cid.replaceAll("_Loop", ""); List<IMetadataTable> metadatas = node.getMetadataList(); IMetadataTable metadata = null; if ((metadatas != null) && (metadatas.size() > 0)) { metadata = metadatas.get(0); } stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(cid); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); if (metadata.isDynamicSchema()) { stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); } stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); if (metadata.isDynamicSchema()) { stringBuffer.append(TEXT_20); stringBuffer.append(cid); stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); } stringBuffer.append(TEXT_23); stringBuffer.append(TEXT_24); return stringBuffer.toString(); }
/** * create ProcessDescription and set it. * * <p>WARNING ::field FieldSeparator, RowSeparator, EscapeChar and TextEnclosure are surround by * double quote. * * @return processDescription */ private ProcessDescription getProcessDescription( SalesforceSchemaConnection originalValueConnection) { ProcessDescription processDescription = ShadowProcessHelper.getProcessDescription(originalValueConnection); SalesforceSchemaBean bean = new SalesforceSchemaBean(); bean.setWebServerUrl(originalValueConnection.getWebServiceUrl()); bean.setUserName(originalValueConnection.getUserName()); bean.setPassword( originalValueConnection.getValue(originalValueConnection.getPassword(), false)); bean.setModuleName(originalValueConnection.getModuleName()); bean.setQueryCondition(originalValueConnection.getQueryCondition()); // add for feature 7507 bean.setBatchSize(originalValueConnection.getBatchSize()); bean.setUseProxy(originalValueConnection.isUseProxy()); bean.setUesHttp(originalValueConnection.isUseHttpProxy()); bean.setProxyHost(originalValueConnection.getProxyHost()); bean.setProxyPort(originalValueConnection.getProxyPort()); bean.setProxyUsername(originalValueConnection.getProxyUsername()); bean.setProxyPassword( originalValueConnection.getValue(originalValueConnection.getProxyPassword(), false)); processDescription.setSalesforceSchemaBean(bean); List<IMetadataTable> tableSchema = new ArrayList<IMetadataTable>(); IMetadataTable tableGet = getMetadatasForSalesforce( bean.getWebServerUrl(), bean.getUserName(), bean.getPassword(), String.valueOf(bean.getTimeOut()), bean.getModuleName(), bean.getBatchSize(), bean.isUseProxy(), bean.isUesHttp(), bean.getProxyHost(), bean.getProxyPort(), bean.getProxyUsername(), bean.getProxyPassword(), false); IMetadataTable table = new org.talend.core.model.metadata.MetadataTable(); List<IMetadataColumn> schema = new ArrayList<IMetadataColumn>(); for (IMetadataColumn column : tableGet.getListColumns()) { schema.add(column.clone()); } table.setTableName("tSalesforceInput"); // $NON-NLS-1$ table.setListColumns(schema); tableSchema.add(table); processDescription.setSchema(tableSchema); processDescription.setEncoding(TalendQuoteUtils.addQuotes("ISO-8859-15")); // $NON-NLS-1$ return processDescription; }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); BigDataCodeGeneratorArgument codeGenArgument = (BigDataCodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); List<IMetadataTable> metadatas = node.getMetadataList(); if (metadatas != null && metadatas.size() > 0) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { String folder = ElementParameterParser.getValue(node, "__FILENAME__"); String fileAction = ElementParameterParser.getValue(node, "__FILE_ACTION__"); List<? extends IConnection> conns = node.getIncomingConnections(); if (conns != null) { if (conns.size() > 0) { IConnection conn = conns.get(0); String connName = conn.getName(); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { List<IMetadataColumn> columns = metadata.getListColumns(); if (((org.talend.core.model.process.AbstractNode) node).isMapOnlyAfterReduce()) { stringBuffer.append(TEXT_1); stringBuffer.append(connName); stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); stringBuffer.append(connName); stringBuffer.append(TEXT_4); } else { stringBuffer.append(TEXT_5); stringBuffer.append(connName); stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(connName); stringBuffer.append(TEXT_8); } } } } } } return stringBuffer.toString(); }
public IMetadataTable getMetadataFromConnector(String connector) { if (metadataList == null) { return null; } for (IMetadataTable table : metadataList) { if (table.getAttachedConnector().equals(connector)) { return table; } } return null; }
@Test public void testConvertMetadataTable() { SAPBWTable table = ConnectionFactory.eINSTANCE.createSAPBWTable(); table.setSourceSystemName("TALEND"); table.setInnerIOType(SAPBWTableHelper.IO_INNERTYPE_HIERARCHY); IMetadataTable newTable = ConvertionHelper.convert(table); String sourceSysName = newTable.getAdditionalProperties().get(SAPBWTableHelper.SAP_DATASOURCE_SOURCESYSNAME); String innerIOType = newTable.getAdditionalProperties().get(SAPBWTableHelper.SAP_INFOOBJECT_INNER_TYPE); assertEquals("TALEND", sourceSysName); assertEquals(SAPBWTableHelper.IO_INNERTYPE_HIERARCHY, innerIOType); }
public void rebuildInputTable( InputTable inputTable, IMetadataTable metadataTable, PigMapData mapData) { if (metadataTable != null && metadataTable.getListColumns() != null) { List<IMetadataColumn> listColumns = metadataTable.getListColumns(); EList<TableNode> nodes = inputTable.getNodes(); for (int i = 0; i < listColumns.size(); i++) { IMetadataColumn column = listColumns.get(i); TableNode found = null; int j = 0; for (; j < nodes.size(); j++) { TableNode node = nodes.get(j); if (node.getName() != null && node.getName().equals(column.getLabel())) { found = node; break; } } if (found != null) { // set in case talend type changed in metadata found.setType(column.getTalendType()); if (i != j) { // do switch to keep the same sequence TableNode temp = nodes.get(j); nodes.remove(j); nodes.add(i, temp); } } else { found = PigmapFactory.eINSTANCE.createTableNode(); found.setName(column.getLabel()); found.setType(column.getTalendType()); found.setNullable(column.isNullable()); nodes.add(i, found); } } if (nodes.size() > listColumns.size()) { List unUsed = new ArrayList(); for (int i = listColumns.size(); i < nodes.size(); i++) { PigMapUtil.detachNodeConnections(nodes.get(i), mapData); unUsed.add(nodes.get(i)); } nodes.removeAll(unUsed); } } // re-build the connections in case any unnecessary connections are created because of previous // bugs and can't // be deleted if (inputTable.isLookup()) { rebuildInputNodesConnections(inputTable.getNodes(), mapData); } }
/* * use to synchronize column list for output connections. */ private void syncOutputNodeColumnsList(List<ColumnNameChanged> columnNameChanged) { if (outputdataContainer == null) { return; } for (IConnection conn : node.getOutgoingConnections()) { INode targetNode = conn.getTarget(); EConnectionType connStyle = conn.getLineStyle(); if (EConnectionType.FLOW_MAIN.equals(connStyle) || EConnectionType.FLOW_MERGE.equals(connStyle) || EConnectionType.FLOW_REF.equals(connStyle)) { ColumnListController.updateColumnList(targetNode, columnNameChanged); // fix for TDI-23202 // reset value in order to call "firePropertyChange(RETURNS_CHANGED, null, null)" IElementParameter defaultMap = targetNode.getElementParameter(EParameterName.DEFAULT_MAP.getName()); if (defaultMap != null) { if ("tFlowToIterate".equals(targetNode.getComponent().getName())) { // update target properties incase any old columns are removed IElementParameter elementParameter = targetNode.getElementParameter("MAP"); if (elementParameter != null) { Object value = elementParameter.getValue(); if (value instanceof List) { for (Object obj : (List) value) { if (obj instanceof Map) { Object object = ((Map) obj).get("VALUE"); if (newOutputMetadata != null && !newOutputMetadata.getListColumns().isEmpty()) { boolean found = false; for (IMetadataColumn column : newOutputMetadata.getListColumns()) { if (column.getLabel().equals(object)) { found = true; } } if (!found) { ((Map) obj) .put("VALUE", newOutputMetadata.getListColumns().get(0).getLabel()); } } else { ((Map) obj).put("VALUE", ""); } } } } } } targetNode.setPropertyValue(EParameterName.DEFAULT_MAP.getName(), defaultMap.getValue()); } } } }
public void init( INode node, IElementParameter schemaParam, IMetadataTable currentOutputMetadata, IMetadataTable newOutputMetadata) { this.node = node; this.schemaParam = schemaParam; if (schemaParam == null) { if (newOutputMetadata.getAttachedConnector() != null) { currentConnector = newOutputMetadata.getAttachedConnector(); } else { if (node.isELTComponent()) { currentConnector = EConnectionType.TABLE.getName(); } else { currentConnector = EConnectionType.FLOW_MAIN.getName(); } } for (IElementParameter param : node.getElementParameters()) { if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) && param.getContext().equals(currentConnector)) { this.schemaParam = param; } } } else { currentConnector = this.schemaParam.getContext(); } this.inputNode = null; this.currentInputMetadata = null; this.newInputMetadata = null; oldInputMetadata = null; this.currentOutputMetadata = currentOutputMetadata; if (this.currentOutputMetadata == null) { this.currentOutputMetadata = node.getMetadataFromConnector(currentConnector); } if (currentOutputMetadata == null && newOutputMetadata != null) { currentOutputMetadata = newOutputMetadata.clone(true); } oldOutputMetadata = this.currentOutputMetadata.clone(true); this.newOutputMetadata = newOutputMetadata.clone(true); this.newOutputMetadata.setReadOnly(this.currentOutputMetadata.isReadOnly()); initializeContainer(); setLabel(Messages.getString("ChangeMetadataCommand.changeMetadataValues")); // $NON-NLS-1$ }
private void initializeContainer() { outputdataContainer = new IODataComponentContainer(); for (Connection connec : (List<Connection>) node.getIncomingConnections()) { if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) { IODataComponent input = null; if (newInputMetadata == null) { input = new IODataComponent(connec); } else { if (connec.getMetaName().equals(newInputMetadata.getTableName())) { input = new IODataComponent(connec, newInputMetadata); } } if (input != null) { outputdataContainer.getInputs().add(input); } } } for (Connection connec : (List<Connection>) node.getOutgoingConnections()) { if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || isinputContainerOutput(connec) || ((connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) && (connec.getInputId() == 1)))) { if ((!connec.getSource().getConnectorFromType(connec.getLineStyle()).isMultiSchema()) || (connec.getMetaName().equals(newOutputMetadata.getTableName()))) { IODataComponent output = new IODataComponent(connec, newOutputMetadata); outputdataContainer.getOuputs().add(output); } } } if (inputNode != null) { inputdataContainer = new IODataComponentContainer(); for (Connection connec : (List<Connection>) inputNode.getOutgoingConnections()) { if (connec.getTarget().equals(node)) { if ((!connec.getSource().getConnectorFromType(connec.getLineStyle()).isMultiSchema()) || (connec.getMetaName().equals(newInputMetadata.getTableName()))) { IODataComponent output = new IODataComponent(connec, newInputMetadata); inputdataContainer.getOuputs().add(output); } } } } }
private static void updateToolBarButtonsOnSelection( ISelection currentSelection, MetadataTableEditorView tableEditorView, IMetadataTable table, final MetadataTableEditorView linkedTableEditorView, final IMetadataTable linkedTable, boolean readOnly) { IStructuredSelection selection = (IStructuredSelection) currentSelection; boolean isThereCustom = false; boolean isThereReadOnly = false; for (Iterator iter = selection.iterator(); iter.hasNext(); ) { IMetadataColumn column = (IMetadataColumn) iter.next(); if (column.isCustom()) { isThereCustom = true; } if (column.isReadOnly()) { isThereReadOnly = true; } } if (isThereReadOnly) { tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false); } if (isThereCustom || table.isReadOnly()) { tableEditorView.getToolBar().getMoveDownButton().getButton().setEnabled(false); tableEditorView.getToolBar().getMoveUpButton().getButton().setEnabled(false); tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false); tableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false); ResetDBTypesPushButton resetDBTypesButton = tableEditorView.getToolBar().getResetDBTypesButton(); if (resetDBTypesButton != null) { resetDBTypesButton.getButton().setEnabled(false); } } if (linkedTable != null) { if (linkedTable.isReadOnly() && linkedTableEditorView != null) { linkedTableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false); } } }
@Test public void testReadonlyStatusInConvert() { String C1 = "C1"; // $NON-NLS-1$ String C2 = "C2"; // $NON-NLS-1$ IMetadataTable table = new MetadataTable(); IMetadataColumn column = new MetadataColumn(); column.setLabel(C1); table.getListColumns().add(column); column = new MetadataColumn(); column.setLabel(C2); table.getListColumns().add(column); org.talend.core.model.metadata.builder.connection.MetadataTable newTable = ConvertionHelper.convert(table); assertFalse(isColumnTaggedAsReadonly(newTable, C2)); table.getColumn(C2).setReadOnly(true); newTable = ConvertionHelper.convert(table); assertTrue(isColumnTaggedAsReadonly(newTable, C2)); }
@Override public void handleTableRelevantParameters( Connection connection, IElement ele, IMetadataTable metadataTable) { if (ele == null || metadataTable == null) { return; } String tableName = metadataTable.getTableName(); IElementParameter tableNameParameter = ele.getElementParameter(EHCatalogRepositoryToComponent.TABLE_NAME.getParameterName()); if (tableNameParameter != null) { tableNameParameter.setValue(getRepositoryValueOfStringType(connection, tableName)); } String partition = metadataTable.getAdditionalProperties().get(HCatalogConstants.PARTITIONS); if (StringUtils.isNotEmpty(partition)) { IElementParameter partitionParameter = ele.getElementParameter(EHCatalogRepositoryToComponent.PARTITION_NAME.getParameterName()); if (partitionParameter != null) { String partitionName = ExtractMetaDataFromHCatalog.extractPartitionNameByJsonStr(partition); if (StringUtils.isNotEmpty(partitionName)) { partitionParameter.setValue(getRepositoryValueOfStringType(connection, partitionName)); } } } }
@Override public boolean isValidForDataViewer(Connection connection, IMetadataTable metadataTable) { if (!canHandle(connection)) { return false; } if (metadataTable == null) { return false; } String partition = metadataTable.getAdditionalProperties().get(HCatalogConstants.PARTITIONS); String partitionName = ExtractMetaDataFromHCatalog.extractPartitionNameByJsonStr(partition); if (StringUtils.isEmpty(partitionName)) { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); MessageDialog.openWarning( shell, Messages.getString("HCatalogDragAndDropHandler.dataViewer.warning.title"), // $NON-NLS-1$ Messages.getString("HCatalogDragAndDropHandler.dataViewer.warning.msg")); // $NON-NLS-1$ return false; } return true; }
public ChangeMetadataCommand( INode node, IElementParameter schemaParam, INode inputNode, IMetadataTable currentInputMetadata, IMetadataTable newInputMetadata, IMetadataTable currentOutputMetadata, IMetadataTable newOutputMetadata) { this.node = node; this.inputNode = inputNode; this.schemaParam = schemaParam; if (schemaParam == null) { currentConnector = EConnectionType.FLOW_MAIN.getName(); for (IElementParameter param : node.getElementParameters()) { if ((param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || param.getFieldType().equals(EParameterFieldType.DCSCHEMA)) && param.getContext().equals(currentConnector)) { this.schemaParam = param; } } } else { currentConnector = this.schemaParam.getContext(); } this.currentInputMetadata = currentInputMetadata; if (currentInputMetadata != null) { oldInputMetadata = currentInputMetadata.clone(); } else { oldInputMetadata = null; } this.newInputMetadata = newInputMetadata; this.currentOutputMetadata = currentOutputMetadata; if (this.currentOutputMetadata == null) { this.currentOutputMetadata = node.getMetadataFromConnector(currentConnector); } oldOutputMetadata = this.currentOutputMetadata.clone(); this.newOutputMetadata = newOutputMetadata; initializeContainer(); setLabel(Messages.getString("ChangeMetadataCommand.changeMetadataValues")); // $NON-NLS-1$ }
@Override public void undo() { propagateDatas(false); if (currentInputMetadata != null) { if (!currentInputMetadata.sameMetadataAs(oldInputMetadata, IMetadataColumn.OPTIONS_NONE)) { currentInputMetadata.setListColumns(oldInputMetadata.getListColumns()); if (inputWasRepository) { inputNode.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.REPOSITORY); } } } if (!currentOutputMetadata.sameMetadataAs(oldOutputMetadata, IMetadataColumn.OPTIONS_NONE)) { List<IMetadataColumn> currentColumns = new ArrayList<IMetadataColumn>(oldOutputMetadata.getListColumns()); currentOutputMetadata.setListColumns(currentColumns); MetadataToolHelper.copyTable(oldOutputMetadata, currentOutputMetadata); } for (INodeConnector connector : node.getListConnector()) { if ((!connector.getName().equals(currentConnector)) && connector.getBaseSchema().equals(currentConnector)) { MetadataToolHelper.copyTable( oldOutputMetadata, node.getMetadataFromConnector(connector.getName())); } } if (outputWasRepository) { node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.REPOSITORY); } for (ChangeMetadataCommand cmd : propagatedChange) { cmd.undo(); } List<ColumnNameChanged> columnNameChanged = MetadataToolHelper.getColumnNameChanged(oldOutputMetadata, newOutputMetadata); ColumnListController.updateColumnList(node, columnNameChanged, true); // newOutputMetadata.setListColumns(new // ArrayList<IMetadataColumn>(oldOutputMetadata.getListColumns())); if (!internal) { updateColumnList(newOutputMetadata, oldOutputMetadata); ((Process) node.getProcess()).checkProcess(); } refreshMetadataChanged(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); class BasicLogUtil { protected String cid = ""; protected org.talend.core.model.process.INode node = null; protected boolean log4jEnabled = false; private String logID = ""; private BasicLogUtil() {} public BasicLogUtil(org.talend.core.model.process.INode node) { this.node = node; String cidx = this.node.getUniqueName(); if (cidx.matches("^.*?tAmazonAuroraOutput_\\d+_out$")) { cidx = cidx.substring(0, cidx.length() - 4); // 4 ==> "_out".length(); } this.cid = cidx; this.log4jEnabled = ("true") .equals( org.talend.core.model.process.ElementParameterParser.getValue( this.node.getProcess(), "__LOG4J_ACTIVATE__")); this.log4jEnabled = this.log4jEnabled && this.node.getComponent().isLog4JEnabled() && !"JOBLET".equals(node.getComponent().getComponentType().toString()); this.logID = this.cid; } public String var(String varName) { return varName + "_" + this.cid; } public String str(String content) { return "\"" + content + "\""; } public void info(String... message) { log4j("info", message); } public void debug(String... message) { log4j("debug", message); } public void warn(String... message) { log4j("warn", message); } public void error(String... message) { log4j("error", message); } public void fatal(String... message) { log4j("fatal", message); } public void trace(String... message) { log4j("trace", message); } java.util.List<String> checkableList = java.util.Arrays.asList(new String[] {"info", "debug", "trace"}); public void log4j(String level, String... messages) { if (this.log4jEnabled) { if (checkableList.contains(level)) { stringBuffer.append(TEXT_2); stringBuffer.append(level.substring(0, 1).toUpperCase() + level.substring(1)); stringBuffer.append(TEXT_3); } stringBuffer.append(TEXT_4); stringBuffer.append(level); stringBuffer.append(TEXT_5); stringBuffer.append(logID); stringBuffer.append(TEXT_6); for (String message : messages) { stringBuffer.append(TEXT_7); stringBuffer.append(message); stringBuffer.append(TEXT_8); } stringBuffer.append(TEXT_9); } } public boolean isActive() { return this.log4jEnabled; } } class LogUtil extends BasicLogUtil { private LogUtil() {} public LogUtil(org.talend.core.model.process.INode node) { super(node); } public void startWork() { info(str("Start to work.")); } public void endWork() { info(str("Done.")); } public void logIgnoredException(String exception) { warn(exception); } public void logPrintedException(String exception) { error(exception); } public void logException(String exception) { fatal(exception); } public void logCompSetting() { if (log4jEnabled) { stringBuffer.append(TEXT_10); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_11); stringBuffer.append(TEXT_12); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_13); java.util.Set<org.talend.core.model.process.EParameterFieldType> ignoredParamsTypes = new java.util.HashSet<org.talend.core.model.process.EParameterFieldType>(); ignoredParamsTypes.addAll( java.util.Arrays.asList( org.talend.core.model.process.EParameterFieldType.SCHEMA_TYPE, org.talend.core.model.process.EParameterFieldType.LABEL, org.talend.core.model.process.EParameterFieldType.EXTERNAL, org.talend.core.model.process.EParameterFieldType.MAPPING_TYPE, org.talend.core.model.process.EParameterFieldType.IMAGE, org.talend.core.model.process.EParameterFieldType.TNS_EDITOR, org.talend.core.model.process.EParameterFieldType.WSDL2JAVA, org.talend.core.model.process.EParameterFieldType.GENERATEGRAMMARCONTROLLER, org.talend.core.model.process.EParameterFieldType .GENERATE_SURVIVORSHIP_RULES_CONTROLLER, org.talend.core.model.process.EParameterFieldType.REFRESH_REPORTS, org.talend.core.model.process.EParameterFieldType.BROWSE_REPORTS, org.talend.core.model.process.EParameterFieldType.PALO_DIM_SELECTION, org.talend.core.model.process.EParameterFieldType.GUESS_SCHEMA, org.talend.core.model.process.EParameterFieldType.MATCH_RULE_IMEX_CONTROLLER, org.talend.core.model.process.EParameterFieldType.MEMO_PERL, org.talend.core.model.process.EParameterFieldType.DBTYPE_LIST, org.talend.core.model.process.EParameterFieldType.VERSION, org.talend.core.model.process.EParameterFieldType.TECHNICAL, org.talend.core.model.process.EParameterFieldType.ICON_SELECTION, org.talend.core.model.process.EParameterFieldType.JAVA_COMMAND, org.talend.core.model.process.EParameterFieldType.TREE_TABLE, org.talend.core.model.process.EParameterFieldType.VALIDATION_RULE_TYPE, org.talend.core.model.process.EParameterFieldType.DCSCHEMA, org.talend.core.model.process.EParameterFieldType.SURVIVOR_RELATION, org.talend.core.model.process.EParameterFieldType.REST_RESPONSE_SCHEMA_TYPE)); for (org.talend.core.model.process.IElementParameter ep : org.talend.core.model.utils.NodeUtil.getDisplayedParameters(node)) { if (!ep.isLog4JEnabled() || ignoredParamsTypes.contains(ep.getFieldType())) { continue; } String name = ep.getName(); if (org.talend.core.model.process.EParameterFieldType.PASSWORD.equals( ep.getFieldType())) { String epName = "__" + name + "__"; String password = ""; if (org.talend.core.model.process.ElementParameterParser.canEncrypt(node, epName)) { password = org.talend.core.model.process.ElementParameterParser.getEncryptedValue( node, epName); } else { String passwordValue = org.talend.core.model.process.ElementParameterParser.getValue(node, epName); if (passwordValue == null || "".equals(passwordValue.trim())) { // for the value which empty passwordValue = "\"\""; } password = "******" + passwordValue + ")"; } stringBuffer.append(TEXT_14); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_15); stringBuffer.append(name); stringBuffer.append(TEXT_16); stringBuffer.append(password); stringBuffer.append(TEXT_17); } else { String value = org.talend.core.model.utils.NodeUtil.getNormalizeParameterValue(node, ep); stringBuffer.append(TEXT_18); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_19); stringBuffer.append(name); stringBuffer.append(TEXT_20); stringBuffer.append(value); stringBuffer.append(TEXT_21); } stringBuffer.append(TEXT_22); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_23); } } debug(var("log4jParamters")); } // no use for now, because we log the data by rowStruct public void traceData( String rowStruct, java.util.List<org.talend.core.model.metadata.IMetadataColumn> columnList, String nbline) { if (log4jEnabled) { stringBuffer.append(TEXT_24); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_25); for (org.talend.core.model.metadata.IMetadataColumn column : columnList) { org.talend.core.model.metadata.types.JavaType javaType = org.talend.core.model.metadata.types.JavaTypesManager.getJavaTypeFromId( column.getTalendType()); String columnName = column.getLabel(); boolean isPrimit = org.talend.core.model.metadata.types.JavaTypesManager.isJavaPrimitiveType( column.getTalendType(), column.isNullable()); if (isPrimit) { stringBuffer.append(TEXT_26); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_27); stringBuffer.append(rowStruct); stringBuffer.append(TEXT_28); stringBuffer.append(columnName); stringBuffer.append(TEXT_29); } else { stringBuffer.append(TEXT_30); stringBuffer.append(rowStruct); stringBuffer.append(TEXT_31); stringBuffer.append(columnName); stringBuffer.append(TEXT_32); stringBuffer.append(TEXT_33); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_34); stringBuffer.append(TEXT_35); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_36); stringBuffer.append(rowStruct); stringBuffer.append(TEXT_37); stringBuffer.append(columnName); stringBuffer.append(TEXT_38); } stringBuffer.append(TEXT_39); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_40); } } trace(str("Content of the record "), nbline, str(": "), var("log4jSb")); } } class LogHelper { java.util.Map<String, String> pastDict = null; public LogHelper() { pastDict = new java.util.HashMap<String, String>(); pastDict.put("insert", "inserted"); pastDict.put("update", "updated"); pastDict.put("delete", "deleted"); pastDict.put("upsert", "upserted"); } public String upperFirstChar(String data) { return data.substring(0, 1).toUpperCase() + data.substring(1); } public String toPastTense(String data) { return pastDict.get(data); } } LogHelper logHelper = new LogHelper(); LogUtil log = null; CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); log = new LogUtil(node); boolean useExistingConn = ("true").equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); stringBuffer.append(TEXT_41); List<? extends IConnection> inputConnections = node.getIncomingConnections(); if ((inputConnections == null) || (inputConnections.size() == 0)) { return ""; } IConnection inputConnection = inputConnections.get(0); if (!inputConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { return ""; } List<? extends IConnection> outputConnections = node.getOutgoingSortedConnections(); if ((outputConnections == null) || (outputConnections.size() == 0)) { return ""; } IConnection outputConnection = outputConnections.get(0); if (!outputConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { return ""; } IMetadataTable inputMetadata = inputConnection.getMetadataTable(); if (inputMetadata == null) { return ""; } List<IMetadataColumn> inputColumnList = inputMetadata.getListColumns(); if ((inputColumnList == null) || (inputColumnList.size() == 0)) { return ""; } IMetadataTable outputMetadata = outputConnection.getMetadataTable(); if (outputMetadata == null) { return ""; } List<IMetadataColumn> outputColumnList = outputMetadata.getListColumns(); if ((outputColumnList == null) || (outputColumnList.size() == 0)) { return ""; } int count = 0; for (IConnection inConnection : inputConnections) { if (inConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { count++; } } for (IConnection outConnection : outputConnections) { if (outConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { count++; } } if (count != 2) { return ""; } stringBuffer.append(TEXT_42); if (!useExistingConn) { stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); log.info(log.str("Closing the connection.")); stringBuffer.append(TEXT_46); stringBuffer.append(cid); stringBuffer.append(TEXT_47); log.info(log.str("Connection has closed.")); stringBuffer.append(TEXT_48); } stringBuffer.append(TEXT_49); stringBuffer.append(TEXT_50); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String operation = ElementParameterParser.getValue(node, "__OPERATION__"); boolean mutipleOperation = ("true").equals(ElementParameterParser.getValue(node, "__MUTIPLE_OPERATION__")); boolean isMutiple = false; if (mutipleOperation && !operation.equals("ISMEMBEROFLIST")) { isMutiple = true; } boolean strict = ("true").equals(ElementParameterParser.getValue(node, "__STRICT__")); String rejectConnName = null; List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT"); if (rejectConns != null && rejectConns.size() > 0) { IConnection rejectConn = rejectConns.get(0); rejectConnName = rejectConn.getName(); } String mainConnName = null; List<? extends IConnection> mainConns = node.getOutgoingConnections("OUTPUT_MAIN"); if (mainConns != null && mainConns.size() > 0) { IConnection mainConn = mainConns.get(0); mainConnName = mainConn.getName(); } List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections(); if (outgoingConns != null) { for (int i = 0; i < outgoingConns.size(); i++) { IConnection outgoingConn = outgoingConns.get(i); if (outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { stringBuffer.append(TEXT_1); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_2); } } } List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { // 1 IMetadataTable metadata = metadatas.get(0); if (metadata != null) { // 2 List<? extends IConnection> conns = node.getIncomingConnections(); for (IConnection conn : conns) { // 3 if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { // 4 boolean useSoapAPI = ("true").equals(ElementParameterParser.getValue(node, "__USE_SOAP_API__")); boolean useRestAPI = ("true").equals(ElementParameterParser.getValue(node, "__USE_REST_API__")); if (useSoapAPI) { stringBuffer.append(TEXT_3); if (isMutiple) { stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(operation); stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(strict); stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); if (strict) { stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); } else { stringBuffer.append(TEXT_32); stringBuffer.append(cid); stringBuffer.append(TEXT_33); } stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_37); stringBuffer.append(cid); stringBuffer.append(TEXT_38); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_39); stringBuffer.append(cid); stringBuffer.append(TEXT_40); stringBuffer.append(cid); stringBuffer.append(TEXT_41); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_42); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_43); } else { stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(cid); stringBuffer.append(TEXT_46); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_47); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(operation); stringBuffer.append(TEXT_52); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_53); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(strict); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); stringBuffer.append(cid); stringBuffer.append(TEXT_59); stringBuffer.append(cid); stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); stringBuffer.append(cid); stringBuffer.append(TEXT_62); stringBuffer.append(cid); stringBuffer.append(TEXT_63); stringBuffer.append(cid); stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); stringBuffer.append(cid); stringBuffer.append(TEXT_66); if (strict) { stringBuffer.append(TEXT_67); stringBuffer.append(cid); stringBuffer.append(TEXT_68); } else { if (rejectConnName != null) { stringBuffer.append(TEXT_69); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_70); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_71); stringBuffer.append(TEXT_72); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_73); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_74); stringBuffer.append(TEXT_75); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_76); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_77); stringBuffer.append(TEXT_78); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_79); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_80); stringBuffer.append(TEXT_81); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_82); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_83); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_84); stringBuffer.append(cid); stringBuffer.append(TEXT_85); } else { stringBuffer.append(TEXT_86); stringBuffer.append(cid); stringBuffer.append(TEXT_87); } } stringBuffer.append(TEXT_88); stringBuffer.append(cid); stringBuffer.append(TEXT_89); } if (mainConnName != null) { stringBuffer.append(TEXT_90); if (!isMutiple) { stringBuffer.append(TEXT_91); stringBuffer.append(cid); stringBuffer.append(TEXT_92); } stringBuffer.append(TEXT_93); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_94); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_95); if (!isMutiple) { stringBuffer.append(TEXT_96); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_97); stringBuffer.append(cid); stringBuffer.append(TEXT_98); } stringBuffer.append(TEXT_99); for (IMetadataColumn column : metadata.getListColumns()) { if (!isMutiple) { if ("Success".equals(column.getLabel())) continue; } stringBuffer.append(TEXT_100); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_101); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_102); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_103); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_104); } stringBuffer.append(TEXT_105); if (!isMutiple) { stringBuffer.append(TEXT_106); } } stringBuffer.append(TEXT_107); } if (useRestAPI) { stringBuffer.append(TEXT_108); if (isMutiple) { stringBuffer.append(TEXT_109); stringBuffer.append(cid); stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_112); stringBuffer.append(cid); stringBuffer.append(TEXT_113); stringBuffer.append(cid); stringBuffer.append(TEXT_114); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_115); stringBuffer.append(cid); stringBuffer.append(TEXT_116); stringBuffer.append(cid); stringBuffer.append(TEXT_117); stringBuffer.append(operation); stringBuffer.append(TEXT_118); stringBuffer.append(cid); stringBuffer.append(TEXT_119); stringBuffer.append(cid); stringBuffer.append(TEXT_120); stringBuffer.append(cid); stringBuffer.append(TEXT_121); stringBuffer.append(cid); stringBuffer.append(TEXT_122); stringBuffer.append(cid); stringBuffer.append(TEXT_123); stringBuffer.append(cid); stringBuffer.append(TEXT_124); stringBuffer.append(cid); stringBuffer.append(TEXT_125); stringBuffer.append(cid); stringBuffer.append(TEXT_126); if (strict) { stringBuffer.append(TEXT_127); stringBuffer.append(cid); stringBuffer.append(TEXT_128); } else { stringBuffer.append(TEXT_129); stringBuffer.append(cid); stringBuffer.append(TEXT_130); } stringBuffer.append(TEXT_131); stringBuffer.append(cid); stringBuffer.append(TEXT_132); stringBuffer.append(cid); stringBuffer.append(TEXT_133); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_134); stringBuffer.append(cid); stringBuffer.append(TEXT_135); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_136); } else { stringBuffer.append(TEXT_137); stringBuffer.append(cid); stringBuffer.append(TEXT_138); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_139); stringBuffer.append(cid); stringBuffer.append(TEXT_140); stringBuffer.append(cid); stringBuffer.append(TEXT_141); stringBuffer.append(cid); stringBuffer.append(TEXT_142); stringBuffer.append(cid); stringBuffer.append(TEXT_143); stringBuffer.append(operation); stringBuffer.append(TEXT_144); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_145); stringBuffer.append(cid); stringBuffer.append(TEXT_146); stringBuffer.append(cid); stringBuffer.append(TEXT_147); stringBuffer.append(cid); stringBuffer.append(TEXT_148); stringBuffer.append(cid); stringBuffer.append(TEXT_149); stringBuffer.append(cid); stringBuffer.append(TEXT_150); stringBuffer.append(cid); stringBuffer.append(TEXT_151); stringBuffer.append(cid); stringBuffer.append(TEXT_152); stringBuffer.append(cid); stringBuffer.append(TEXT_153); stringBuffer.append(cid); stringBuffer.append(TEXT_154); stringBuffer.append(cid); stringBuffer.append(TEXT_155); stringBuffer.append(cid); stringBuffer.append(TEXT_156); stringBuffer.append(cid); stringBuffer.append(TEXT_157); stringBuffer.append(cid); stringBuffer.append(TEXT_158); stringBuffer.append(cid); stringBuffer.append(TEXT_159); if (strict) { stringBuffer.append(TEXT_160); stringBuffer.append(cid); stringBuffer.append(TEXT_161); } else { if (rejectConnName != null) { stringBuffer.append(TEXT_162); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_163); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_164); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_165); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_166); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_167); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_168); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_169); stringBuffer.append(cid); stringBuffer.append(TEXT_170); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_171); stringBuffer.append(cid); stringBuffer.append(TEXT_172); } else { stringBuffer.append(TEXT_173); stringBuffer.append(cid); stringBuffer.append(TEXT_174); } } stringBuffer.append(TEXT_175); stringBuffer.append(cid); stringBuffer.append(TEXT_176); } if (mainConnName != null) { stringBuffer.append(TEXT_177); if (!isMutiple) { stringBuffer.append(TEXT_178); stringBuffer.append(cid); stringBuffer.append(TEXT_179); } stringBuffer.append(TEXT_180); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_181); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_182); for (IMetadataColumn column : metadata.getListColumns()) { if (!isMutiple) { if ("Status".equals(column.getLabel())) { stringBuffer.append(TEXT_183); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_184); stringBuffer.append(cid); stringBuffer.append(TEXT_185); } } stringBuffer.append(TEXT_186); stringBuffer.append(mainConnName); stringBuffer.append(TEXT_187); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_188); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_189); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_190); } stringBuffer.append(TEXT_191); if (!isMutiple) { stringBuffer.append(TEXT_192); } } stringBuffer.append(TEXT_193); } } // 4 } // 3 } // 2 } // 1 stringBuffer.append(TEXT_194); stringBuffer.append(TEXT_195); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); // this util class use by set log4j debug paramters class DefaultLog4jFileUtil { INode node = null; String cid = null; boolean isLog4jEnabled = false; String label = null; public DefaultLog4jFileUtil() {} public DefaultLog4jFileUtil(INode node) { this.node = node; this.cid = node.getUniqueName(); this.label = cid; this.isLog4jEnabled = ("true") .equals( org.talend.core.model.process.ElementParameterParser.getValue( node.getProcess(), "__LOG4J_ACTIVATE__")); } public void setCid(String cid) { this.cid = cid; } // for all tFileinput* components public void startRetriveDataInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_1); stringBuffer.append(label); stringBuffer.append(TEXT_2); } } public void retrievedDataNumberInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_3); stringBuffer.append(label); stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); } } public void retrievedDataNumberInfoFromGlobalMap(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_6); stringBuffer.append(label); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); } } // for all tFileinput* components public void retrievedDataNumberInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_9); stringBuffer.append(label); stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); } } public void writeDataFinishInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_12); stringBuffer.append(label); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); } } // TODO delete it and remove all log4jSb parameter from components public void componentStartInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); } } // TODO rename or delete it public void debugRetriveData(INode node, boolean hasIncreased) { if (isLog4jEnabled) { stringBuffer.append(TEXT_17); stringBuffer.append(label); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(hasIncreased ? "" : "+1"); stringBuffer.append(TEXT_19); } } // TODO rename or delete it public void debugRetriveData(INode node) { debugRetriveData(node, true); } // TODO rename or delete it public void debugWriteData(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_20); stringBuffer.append(label); stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); } } public void logCurrentRowNumberInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_23); stringBuffer.append(label); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); } } public void logDataCountInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_26); stringBuffer.append(label); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); } } } final DefaultLog4jFileUtil log4jFileUtil = new DefaultLog4jFileUtil( (INode) (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument) .getArgument())); class DefaultLog4jCodeGenerateUtil extends DefaultLog4jFileUtil { String connection = ""; boolean hasInit = false; String dataAction; String dataOperationPrefix; String useBatchSize; String batchSize; String dbSchema; boolean logCommitCounter = false; public DefaultLog4jCodeGenerateUtil() {} public DefaultLog4jCodeGenerateUtil(INode node) { super(node); init(); } public void beforeComponentProcess(INode node) { this.node = node; init(); } private void init() { if (hasInit) { return; } this.cid = node.getUniqueName(); this.isLog4jEnabled = ("true") .equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__")); String useConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"); if (useConn == null || "".equals(useConn) || "true".equals(useConn)) { connection = ElementParameterParser.getValue(node, "__CONNECTION__"); if (!"".equals(connection)) { connection = "'" + connection + "' "; } } // for output dataAction = ElementParameterParser.getValue(node, "__DATA_ACTION__"); if (dataAction != null && !("").equals(dataAction)) { logCommitCounter = true; } useBatchSize = ElementParameterParser.getValue(node, "__USE_BATCH_SIZE__"); batchSize = ElementParameterParser.getValue(node, "__BATCH_SIZE__"); hasInit = true; } public void debugDriverClassName() { logInfo(node, "debug", cid + " - Driver ClassName: \"+driverClass_" + cid + "+\"."); } public void debugConnectionParams(INode node) { beforeComponentProcess(node); debugDriverClassName(); } public void useExistConnection(INode node) { beforeComponentProcess(node); if (isLog4jEnabled) { stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); if (cid.startsWith("tImpala") || cid.startsWith("tHive")) { stringBuffer.append(TEXT_32); stringBuffer.append(cid); stringBuffer.append(TEXT_33); stringBuffer.append(connection); stringBuffer.append(TEXT_34); } else { stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); stringBuffer.append(cid); stringBuffer.append(TEXT_38); } stringBuffer.append(TEXT_39); } } public void connect(INode node) { beforeComponentProcess(node); connect(); } public void connect() { connect_begin(); stringBuffer.append(TEXT_40); stringBuffer.append(cid); stringBuffer.append(TEXT_41); stringBuffer.append(cid); stringBuffer.append(TEXT_42); stringBuffer.append(cid); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); connect_end(); } public void connect_begin() { logInfo( node, "info", cid + " - Connection attempt to '\" + url_" + cid + " + \"' with the username '\" + dbUser_" + cid + " + \"'."); } public void connect_begin_noUser() { logInfo(node, "info", cid + " - Connection attempt to '\" + url_" + cid + " + \"'."); } public void connect_end() { logInfo(node, "info", cid + " - Connection to '\" + url_" + cid + " + \"' has succeeded."); } public void rollback(INode node) { beforeComponentProcess(node); logInfo(node, "debug", cid + " - Connection " + connection + "starting to rollback."); stringBuffer.append(TEXT_45); stringBuffer.append(cid); stringBuffer.append(TEXT_46); logInfo(node, "debug", cid + " - Connection " + connection + "rollback has succeeded."); } public void commit(INode node) { beforeComponentProcess(node); commit(); } private void commit() { commit_begin(); stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); commit_end(); } private void commit_begin() { if (logCommitCounter) { logInfo( node, "debug", cid + " - Connection " + connection + "starting to commit \" + commitCounter_" + cid + "+ \" records."); } else { logInfo(node, "debug", cid + " - Connection " + connection + "starting to commit."); } } private void commit_end() { logInfo(node, "debug", cid + " - Connection " + connection + "commit has succeeded."); } public void close(INode node) { beforeComponentProcess(node); close(); } private void close() { close_begin(); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); close_end(); } public void close_begin() { logInfo(node, "info", cid + " - Closing the connection " + connection + "to the database."); } public void close_end() { logInfo(node, "info", cid + " - Connection " + connection + "to the database closed."); } public void autoCommit(INode node, boolean autoCommit) { beforeComponentProcess(node); logInfo(node, "debug", cid + " - Connection is set auto commit to '" + autoCommit + "'."); stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); stringBuffer.append(autoCommit); stringBuffer.append(TEXT_53); } public void query(INode node) { beforeComponentProcess(node); // for input String dbquery = ElementParameterParser.getValue(node, "__QUERY__"); dbquery = dbquery.replaceAll("\n", " "); dbquery = dbquery.replaceAll("\r", " "); logInfo(node, "info", cid + " - Executing the query: '\" + " + dbquery + " + \"'."); } public void retrieveRecordsCount(INode node) { beforeComponentProcess(node); logInfo(node, "info", cid + " - Retrieved records count: \"+nb_line_" + cid + " + \" ."); } public void logError(INode node, String logLevel, String exception) { beforeComponentProcess(node); if (isLog4jEnabled) { stringBuffer.append(TEXT_54); stringBuffer.append(logLevel); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(exception); stringBuffer.append(TEXT_57); } } public void logError(INode node, String logLevel) { logError(node, logLevel, "e"); } public void logInfo(INode node, String logLevel, String message) { beforeComponentProcess(node); if (isLog4jEnabled) { stringBuffer.append(TEXT_58); stringBuffer.append(logLevel); stringBuffer.append(TEXT_59); stringBuffer.append(message); stringBuffer.append(TEXT_60); } } /** * batchType : 1: do not get return value of executeBatch(); 2: get return value of * executeBatch(); */ public void executeBatch(INode node, int batchType) { beforeComponentProcess(node); boolean logBatch = ("true").equals(useBatchSize) && !("").equals(batchSize) && !("0").equals(batchSize); if (logBatch) { logInfo(node, "debug", cid + " - Executing the " + dataAction + " batch."); } if (batchType == 1) { stringBuffer.append(TEXT_61); stringBuffer.append(cid); stringBuffer.append(TEXT_62); } else if (batchType == 2) { boolean isMysqlBatchInsert = false; if ((node.getUniqueName().contains("tMysqlOutput") || node.getUniqueName().contains("tAmazonMysqlOutput")) && ("INSERT").equals(dataAction)) { isMysqlBatchInsert = true; } stringBuffer.append(TEXT_63); stringBuffer.append(cid); stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); stringBuffer.append(cid); stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(cid); stringBuffer.append(TEXT_68); stringBuffer.append(isMysqlBatchInsert ? "1" : "countEach_" + cid); stringBuffer.append(TEXT_69); } if (logBatch) { logInfo(node, "debug", cid + " - The " + dataAction + " batch execution has succeeded."); } } } DefaultLog4jCodeGenerateUtil log4jCodeGenerateUtil = new DefaultLog4jCodeGenerateUtil(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String localServiceName = ElementParameterParser.getValue(node, "__LOCAL_SERVICE_NAME__"); String dbuser = ElementParameterParser.getValue(node, "__USER__"); String dataTable = ElementParameterParser.getValue(node, "__DATATABLE__"); String tableSchema = ElementParameterParser.getValue(node, "__SCHEMA_DB__"); String dbVersion = ElementParameterParser.getValue(node, "__DB_VERSION__"); boolean setDataSchema = "true".equals(ElementParameterParser.getValue(node, "__SET_DATA_TABLE_SCHEMA__")); String dataSchema = ElementParameterParser.getValue(node, "__DATA_TABLE_SCHEMA__"); String inBoundServer = ElementParameterParser.getValue(node, "__INBOUND_SERVER__"); boolean isUseExistingConn = "true".equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); String inputField = ElementParameterParser.getValue(node, "__INPUT_FIELD__"); String ackInterval = ElementParameterParser.getValue(node, "__ACK_INTERVAL__"); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); stringBuffer.append(cid); stringBuffer.append(TEXT_72); if (isUseExistingConn) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); String conn = "conn_" + connection; stringBuffer.append(TEXT_73); stringBuffer.append(cid); stringBuffer.append(TEXT_74); stringBuffer.append(conn); stringBuffer.append(TEXT_75); log4jCodeGenerateUtil.useExistConnection(node); } else { stringBuffer.append(TEXT_76); if ("ORACLE_11".equals(dbVersion) || "ORACLE_11-6".equals(dbVersion) || "ORACLE_12".equals(dbVersion)) { stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); } else { stringBuffer.append(TEXT_79); } stringBuffer.append(TEXT_80); stringBuffer.append(cid); stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); stringBuffer.append(localServiceName); stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(dbuser); stringBuffer.append(TEXT_85); String passwordFieldName = "__PASS__"; stringBuffer.append(TEXT_86); if (ElementParameterParser.canEncrypt(node, passwordFieldName)) { stringBuffer.append(TEXT_87); stringBuffer.append(cid); stringBuffer.append(TEXT_88); stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName)); stringBuffer.append(TEXT_89); } else { stringBuffer.append(TEXT_90); stringBuffer.append(cid); stringBuffer.append(TEXT_91); stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName)); stringBuffer.append(TEXT_92); } stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); stringBuffer.append(cid); stringBuffer.append(TEXT_95); log4jCodeGenerateUtil.debugConnectionParams(node); log4jCodeGenerateUtil.connect(node); } List<IMetadataColumn> columns = metadata.getListColumns(); boolean isInputLCRObj = false; boolean isInputXMLDoc = false; for (IMetadataColumn column : columns) { JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType()); boolean isPrimitive = JavaTypesManager.isJavaPrimitiveType(javaType, column.isNullable()); if (inputField.equals(column.getLabel())) { if ("id_Document".equals(column.getTalendType())) { isInputXMLDoc = true; } if ((javaType == JavaTypesManager.OBJECT)) { isInputLCRObj = true; } } break; } if (!isInputXMLDoc && !isInputLCRObj) { stringBuffer.append(TEXT_96); stringBuffer.append(inputField); stringBuffer.append(TEXT_97); } if (isInputXMLDoc) { stringBuffer.append(TEXT_98); stringBuffer.append(cid); stringBuffer.append(TEXT_99); stringBuffer.append(cid); stringBuffer.append(TEXT_100); stringBuffer.append(cid); stringBuffer.append(TEXT_101); stringBuffer.append(cid); stringBuffer.append(TEXT_102); } stringBuffer.append(TEXT_103); stringBuffer.append(cid); stringBuffer.append(TEXT_104); stringBuffer.append(cid); stringBuffer.append(TEXT_105); stringBuffer.append(cid); stringBuffer.append(TEXT_106); stringBuffer.append(cid); stringBuffer.append(TEXT_107); stringBuffer.append(cid); stringBuffer.append(TEXT_108); stringBuffer.append(cid); stringBuffer.append(TEXT_109); log4jCodeGenerateUtil.logInfo( node, "info", cid + " - Try to attach to inbound server:\"+" + inBoundServer + "+\""); stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); stringBuffer.append(cid); stringBuffer.append(TEXT_112); stringBuffer.append(inBoundServer); stringBuffer.append(TEXT_113); stringBuffer.append(cid); stringBuffer.append(TEXT_114); stringBuffer.append(ackInterval); stringBuffer.append(TEXT_115); log4jCodeGenerateUtil.logInfo(node, "info", cid + " - Attached successfully."); stringBuffer.append(TEXT_116); stringBuffer.append(cid); stringBuffer.append(TEXT_117); stringBuffer.append(inBoundServer); stringBuffer.append(TEXT_118); log4jCodeGenerateUtil.logInfo( node, "error", cid + " - Cannot attach to the inbound server: \"+" + inBoundServer + "+\""); stringBuffer.append(TEXT_119); stringBuffer.append(cid); stringBuffer.append(TEXT_120); stringBuffer.append(cid); stringBuffer.append(TEXT_121); stringBuffer.append(cid); stringBuffer.append(TEXT_122); stringBuffer.append(cid); stringBuffer.append(TEXT_123); stringBuffer.append(cid); stringBuffer.append(TEXT_124); stringBuffer.append(cid); stringBuffer.append(TEXT_125); stringBuffer.append(cid); stringBuffer.append(TEXT_126); stringBuffer.append(cid); stringBuffer.append(TEXT_127); stringBuffer.append(cid); stringBuffer.append(TEXT_128); stringBuffer.append(cid); stringBuffer.append(TEXT_129); stringBuffer.append(cid); stringBuffer.append(TEXT_130); stringBuffer.append(cid); stringBuffer.append(TEXT_131); stringBuffer.append(cid); stringBuffer.append(TEXT_132); stringBuffer.append(cid); stringBuffer.append(TEXT_133); stringBuffer.append(cid); stringBuffer.append(TEXT_134); stringBuffer.append(cid); stringBuffer.append(TEXT_135); stringBuffer.append(cid); stringBuffer.append(TEXT_136); stringBuffer.append(cid); stringBuffer.append(TEXT_137); stringBuffer.append(cid); stringBuffer.append(TEXT_138); stringBuffer.append(cid); stringBuffer.append(TEXT_139); stringBuffer.append(cid); stringBuffer.append(TEXT_140); } } stringBuffer.append(TEXT_141); stringBuffer.append(TEXT_142); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String version_selection = ElementParameterParser.getValue(node, "__VERSION_SELECTION__"); if (version_selection.equals("VTIGER_50")) { String serverAddr = ElementParameterParser.getValue(node, "__SERVERADDR__"); String port = ElementParameterParser.getValue(node, "__PORT__"); String vtigerPath = ElementParameterParser.getValue(node, "__VTIGERPATH__"); String userName = ElementParameterParser.getValue(node, "__USERNAME__"); String password = ElementParameterParser.getValue(node, "__PASSWORD__"); String version = ElementParameterParser.getValue(node, "__VERSION__"); String method = ElementParameterParser.getValue(node, "__METHODNAME__"); String outgoingConnName = null; List<? extends IConnection> conns = node.getOutgoingSortedConnections(); if (conns != null && conns.size() > 0) { IConnection conn = conns.get(0); outgoingConnName = conn.getName(); } List<IMetadataColumn> metadataColumns = null; List<IMetadataTable> metadataTables = node.getMetadataList(); stringBuffer.append(TEXT_1); stringBuffer.append(cid); stringBuffer.append(TEXT_2); stringBuffer.append(userName); stringBuffer.append(TEXT_3); stringBuffer.append(password); stringBuffer.append(TEXT_4); stringBuffer.append(version); stringBuffer.append(TEXT_5); stringBuffer.append(serverAddr); stringBuffer.append(TEXT_6); stringBuffer.append(port); stringBuffer.append(TEXT_7); stringBuffer.append(vtigerPath); stringBuffer.append(TEXT_8); if (metadataTables != null && metadataTables.size() > 0) { IMetadataTable metadataTable = metadataTables.get(0); if (metadataTable != null) { metadataColumns = metadataTable.getListColumns(); if (("searchContactsByEmail").equals(method) || ("getContacts").equals(method) || ("getTasks").equals(method) || ("getClndr").equals(method) || ("get_KBase_details").equals(method)) { if (("searchContactsByEmail").equals(method) || ("getContacts").equals(method)) { stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); stringBuffer.append(method); stringBuffer.append(TEXT_12); } else if (("getTasks").equals(method)) { stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(method); stringBuffer.append(TEXT_16); } else if (("getClndr").equals(method)) { stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(method); stringBuffer.append(TEXT_20); } else if (("get_KBase_details").equals(method)) { stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(method); stringBuffer.append(TEXT_24); } stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); for (IMetadataColumn metadataColumn : metadataColumns) { if (("searchContactsByEmail").equals(method) || ("getContacts").equals(method) || ("getTasks").equals(method) || ("getClndr").equals(method)) { stringBuffer.append(TEXT_27); stringBuffer.append(outgoingConnName); stringBuffer.append(TEXT_28); stringBuffer.append(metadataColumn.getLabel()); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(metadataColumn.getLabel().substring(0, 1).toUpperCase()); stringBuffer.append(metadataColumn.getLabel().substring(1)); stringBuffer.append(TEXT_31); } else if (("get_KBase_details").equals(method)) { stringBuffer.append(TEXT_32); stringBuffer.append(outgoingConnName); stringBuffer.append(TEXT_33); stringBuffer.append(metadataColumn.getLabel()); stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); } } stringBuffer.append(TEXT_36); } else { for (IMetadataColumn metadataColumn : metadataColumns) { stringBuffer.append(TEXT_37); stringBuffer.append(outgoingConnName); stringBuffer.append(TEXT_38); stringBuffer.append(metadataColumn.getLabel()); stringBuffer.append(TEXT_39); stringBuffer.append(cid); stringBuffer.append(TEXT_40); stringBuffer.append(method); stringBuffer.append(TEXT_41); } } } } // *****************************************************version 5.1 // start************************************** } else { stringBuffer.append(TEXT_42); stringBuffer.append(cid); stringBuffer.append(TEXT_43); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { List<IMetadataColumn> columnList = metadata.getListColumns(); int nbSchemaColumns = columnList.size(); List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections(); // If output columns are defined if (nbSchemaColumns > 0 && outgoingConns != null && outgoingConns.size() > 0) { String endpoint = ElementParameterParser.getValue(node, "__ENDPOINT__"); String username = ElementParameterParser.getValue(node, "__USERNAME_510__"); String accessKey = ElementParameterParser.getValue(node, "__ACCESS_KEY__"); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(endpoint); stringBuffer.append(TEXT_46); stringBuffer.append(cid); stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(username); stringBuffer.append(TEXT_49); stringBuffer.append(accessKey); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); stringBuffer.append(cid); stringBuffer.append(TEXT_53); boolean bIsManualQuery = ("true").equals(ElementParameterParser.getValue(node, "__MANUAL_QUERY__")); String sql = ""; // Build the request SQL if (bIsManualQuery) { sql = ElementParameterParser.getValue(node, "__QUERY__"); sql = sql.replaceAll("\n", " ").replaceAll("\r", " "); } else { String modulename = ElementParameterParser.getValue(node, "__MODULENAME_510__").trim(); String condition = ElementParameterParser.getValue(node, "__CONDITION__").trim(); StringBuilder sb = new StringBuilder("\"select "); for (IMetadataColumn column : columnList) { sb.append(column.getLabel()); sb.append(","); } sb.deleteCharAt(sb.lastIndexOf(",")); sb.append(" from ").append(modulename); if (condition != null && condition.length() > 3) { sb.append(" where ").append(condition.substring(1, condition.length() - 1)); } sb.append("\""); sql = sb.toString(); } IConnection outgoingConn = outgoingConns.get(0); if (outgoingConn .getLineStyle() .hasConnectionCategory(IConnectionCategory.DATA)) { // start 1 stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(sql); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); stringBuffer.append(cid); stringBuffer.append(TEXT_59); stringBuffer.append(cid); stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); stringBuffer.append(cid); stringBuffer.append(TEXT_62); stringBuffer.append(cid); stringBuffer.append(TEXT_63); stringBuffer.append(cid); stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); stringBuffer.append(cid); stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(cid); stringBuffer.append(TEXT_68); for (int i = 0; i < columnList.size(); i++) { IMetadataColumn column = columnList.get(i); String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable()); JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType()); String patternValue = column.getPattern() == null || column.getPattern().trim().length() == 0 ? null : column.getPattern(); stringBuffer.append(TEXT_69); stringBuffer.append(cid); stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); stringBuffer.append(columnList.get(i).getLabel()); stringBuffer.append(TEXT_72); stringBuffer.append(cid); stringBuffer.append(TEXT_73); stringBuffer.append(cid); stringBuffer.append(TEXT_74); stringBuffer.append(cid); stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); if (javaType == JavaTypesManager.STRING || javaType == JavaTypesManager.OBJECT) { // String or Object stringBuffer.append(TEXT_77); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_78); stringBuffer.append(columnList.get(i).getLabel()); stringBuffer.append(TEXT_79); stringBuffer.append(cid); stringBuffer.append(TEXT_80); } else if (javaType == JavaTypesManager.DATE) { // Date stringBuffer.append(TEXT_81); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_82); stringBuffer.append(columnList.get(i).getLabel()); stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(patternValue); stringBuffer.append(TEXT_85); } else if (javaType == JavaTypesManager.BYTE_ARRAY) { // byte[] stringBuffer.append(TEXT_86); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_87); stringBuffer.append(columnList.get(i).getLabel()); stringBuffer.append(TEXT_88); stringBuffer.append(cid); stringBuffer.append(TEXT_89); } else { // other stringBuffer.append(TEXT_90); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_91); stringBuffer.append(columnList.get(i).getLabel()); stringBuffer.append(TEXT_92); stringBuffer.append(typeToGenerate); stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); } stringBuffer.append(TEXT_95); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_96); stringBuffer.append(columnList.get(i).getLabel()); stringBuffer.append(TEXT_97); stringBuffer.append(JavaTypesManager.getDefaultValueFromJavaType(typeToGenerate)); stringBuffer.append(TEXT_98); } stringBuffer.append(TEXT_99); } } } } } // version 5.1.0 end stringBuffer.append(TEXT_100); stringBuffer.append(TEXT_101); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); List<? extends IConnection> outputConnections = node.getOutgoingSortedConnections(); if ((outputConnections == null) || (outputConnections.size() == 0)) { return ""; } IConnection outputConnection = outputConnections.get(0); if (!outputConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { return ""; } List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas == null) && (metadatas.size() == 0) || (metadatas.get(0) == null)) { return ""; } IMetadataTable metadata = metadatas.get(0); List<IMetadataColumn> columnList = metadata.getListColumns(); if ((columnList == null) || (columnList.size() == 0)) { return ""; } String client = ElementParameterParser.getValue(node, "__CLIENT__"); String userid = ElementParameterParser.getValue(node, "__USERID__"); String password = ElementParameterParser.getValue(node, "__PASSWORD__"); String language = ElementParameterParser.getValue(node, "__LANGUAGE__"); String hostname = ElementParameterParser.getValue(node, "__HOSTNAME__"); String systemnumber = ElementParameterParser.getValue(node, "__SYSTEMNUMBER__"); String systemId = ElementParameterParser.getValue(node, "__SYSTEMID__"); String groupName = ElementParameterParser.getValue(node, "__GROUPNAME__"); String serverType = ElementParameterParser.getValue(node, "__SERVERTYPE__"); String tableName = ElementParameterParser.getValue(node, "__TABLE__"); String filter = ElementParameterParser.getValue(node, "__FILTER__"); String startRowNumber = ElementParameterParser.getValue(node, "__START_ROW__"); String maxRowCount = ElementParameterParser.getValue(node, "__MAX_ROW_COUNT__"); List<Map<String, String>> sapProps = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SAP_PROPERTIES__"); String passwordFieldName = "__PASSWORD__"; boolean activeSNC = ("true").equals(ElementParameterParser.getValue(node, "__SNC_ACTIVE__")); String partnerSNCName = ElementParameterParser.getValue(node, "__SNC_PARTNER_NAME__"); String mySNCName = ElementParameterParser.getValue(node, "__SNC_MY_NAME__"); String sncLevel = ElementParameterParser.getValue(node, "__SNC_LEVEL__"); String sncLibPath = ElementParameterParser.getValue(node, "__SNC_LIB_PATH__"); boolean hasSNCLibPath = sncLibPath != null && !"".equals(sncLibPath); boolean hasMySNCName = mySNCName != null && !"".equals(mySNCName); boolean useExistingConn = ("true").equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); stringBuffer.append(TEXT_2); if (useExistingConn) { stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append(connection); stringBuffer.append(TEXT_5); INode connectionNode = null; for (INode processNode : node.getProcess().getGeneratingNodes()) { if (connection.equals(processNode.getUniqueName())) { connectionNode = processNode; break; } } boolean specify_alias = "true" .equals( ElementParameterParser.getValue(connectionNode, "__SPECIFY_DATASOURCE_ALIAS__")); if (specify_alias) { String alias = ElementParameterParser.getValue(connectionNode, "__SAP_DATASOURCE_ALIAS__"); if (null != alias && !("".equals(alias))) { stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(alias); stringBuffer.append(TEXT_9); } } stringBuffer.append(TEXT_10); } else { stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); boolean specify_alias = "true".equals(ElementParameterParser.getValue(node, "__SPECIFY_DATASOURCE_ALIAS__")); if (specify_alias) { String alias = ElementParameterParser.getValue(node, "__SAP_DATASOURCE_ALIAS__"); if (null != alias && !("".equals(alias))) { stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); stringBuffer.append(alias); stringBuffer.append(TEXT_15); } stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); } stringBuffer.append(TEXT_18); if (ElementParameterParser.canEncrypt(node, passwordFieldName)) { stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName)); stringBuffer.append(TEXT_21); } else { stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName)); stringBuffer.append(TEXT_24); } stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(client); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(userid); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); stringBuffer.append(cid); stringBuffer.append(TEXT_33); stringBuffer.append(language); stringBuffer.append(TEXT_34); if ("ApplicationServer".equals(serverType)) { stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(hostname); stringBuffer.append(TEXT_37); stringBuffer.append(cid); stringBuffer.append(TEXT_38); stringBuffer.append(systemnumber); stringBuffer.append(TEXT_39); } else { stringBuffer.append(TEXT_40); stringBuffer.append(cid); stringBuffer.append(TEXT_41); stringBuffer.append(hostname); stringBuffer.append(TEXT_42); stringBuffer.append(cid); stringBuffer.append(TEXT_43); stringBuffer.append(systemId); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(groupName); stringBuffer.append(TEXT_46); } stringBuffer.append(TEXT_47); if (activeSNC) { stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); stringBuffer.append(partnerSNCName); stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); stringBuffer.append(sncLevel); stringBuffer.append(TEXT_53); if (hasMySNCName) { stringBuffer.append(TEXT_54); stringBuffer.append(mySNCName); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(mySNCName); stringBuffer.append(TEXT_57); } stringBuffer.append(TEXT_58); if (hasSNCLibPath) { stringBuffer.append(TEXT_59); stringBuffer.append(sncLibPath); stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); stringBuffer.append(sncLibPath); stringBuffer.append(TEXT_62); } stringBuffer.append(TEXT_63); } stringBuffer.append(TEXT_64); if (sapProps != null) { for (Map<String, String> item : sapProps) { stringBuffer.append(TEXT_65); stringBuffer.append(cid); stringBuffer.append(TEXT_66); stringBuffer.append(item.get("PROPERTY")); stringBuffer.append(TEXT_67); stringBuffer.append(item.get("VALUE")); stringBuffer.append(TEXT_68); } } stringBuffer.append(TEXT_69); stringBuffer.append(cid); stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); if (specify_alias) { stringBuffer.append(TEXT_72); } } stringBuffer.append(TEXT_73); stringBuffer.append(cid); stringBuffer.append(TEXT_74); stringBuffer.append(cid); stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); for (int i = 0; i < columnList.size(); i++) { IMetadataColumn column = columnList.get(i); String tableField = column.getOriginalDbColumnName(); stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); stringBuffer.append(tableField); stringBuffer.append(TEXT_79); } stringBuffer.append(TEXT_80); stringBuffer.append(cid); stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); stringBuffer.append(tableName); stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(filter); stringBuffer.append(TEXT_85); stringBuffer.append(maxRowCount); stringBuffer.append(TEXT_86); stringBuffer.append(startRowNumber); stringBuffer.append(TEXT_87); stringBuffer.append(cid); stringBuffer.append(TEXT_88); stringBuffer.append(cid); stringBuffer.append(TEXT_89); stringBuffer.append(cid); stringBuffer.append(TEXT_90); stringBuffer.append(cid); stringBuffer.append(TEXT_91); stringBuffer.append(cid); stringBuffer.append(TEXT_92); for (int i = 0; i < columnList.size(); i++) { IMetadataColumn column = columnList.get(i); String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable()); JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType()); String dbType = column.getType(); if (javaType == JavaTypesManager.STRING) { stringBuffer.append(TEXT_93); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_94); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_95); stringBuffer.append(cid); stringBuffer.append(TEXT_96); stringBuffer.append(i); stringBuffer.append(TEXT_97); } else if (javaType == JavaTypesManager.INTEGER) { stringBuffer.append(TEXT_98); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_99); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_100); stringBuffer.append(cid); stringBuffer.append(TEXT_101); stringBuffer.append(i); stringBuffer.append(TEXT_102); } else if (javaType == JavaTypesManager.SHORT) { stringBuffer.append(TEXT_103); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_104); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_105); stringBuffer.append(cid); stringBuffer.append(TEXT_106); stringBuffer.append(i); stringBuffer.append(TEXT_107); } else if (javaType == JavaTypesManager.DATE) { stringBuffer.append(TEXT_108); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_109); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); stringBuffer.append(i); stringBuffer.append(TEXT_112); } else if (javaType == JavaTypesManager.BYTE) { stringBuffer.append(TEXT_113); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_114); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_115); stringBuffer.append(cid); stringBuffer.append(TEXT_116); stringBuffer.append(i); stringBuffer.append(TEXT_117); } else if (javaType == JavaTypesManager.BYTE_ARRAY) { stringBuffer.append(TEXT_118); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_119); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_120); stringBuffer.append(cid); stringBuffer.append(TEXT_121); stringBuffer.append(i); stringBuffer.append(TEXT_122); } else if (javaType == JavaTypesManager.DOUBLE) { stringBuffer.append(TEXT_123); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_124); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_125); stringBuffer.append(cid); stringBuffer.append(TEXT_126); stringBuffer.append(i); stringBuffer.append(TEXT_127); } else if (javaType == JavaTypesManager.BIGDECIMAL) { stringBuffer.append(TEXT_128); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_129); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_130); stringBuffer.append(cid); stringBuffer.append(TEXT_131); stringBuffer.append(i); stringBuffer.append(TEXT_132); } else if (javaType == JavaTypesManager.OBJECT && "BIG_INTEGER".equals(dbType)) { stringBuffer.append(TEXT_133); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_134); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_135); stringBuffer.append(cid); stringBuffer.append(TEXT_136); stringBuffer.append(i); stringBuffer.append(TEXT_137); } else if (javaType == JavaTypesManager.OBJECT) { stringBuffer.append(TEXT_138); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_139); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_140); stringBuffer.append(cid); stringBuffer.append(TEXT_141); stringBuffer.append(i); stringBuffer.append(TEXT_142); } else { stringBuffer.append(TEXT_143); stringBuffer.append(outputConnection.getName()); stringBuffer.append(TEXT_144); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_145); stringBuffer.append(typeToGenerate); stringBuffer.append(TEXT_146); stringBuffer.append(cid); stringBuffer.append(TEXT_147); stringBuffer.append(i); stringBuffer.append(TEXT_148); } } return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String dieOnError = ElementParameterParser.getValue(node, "__DIE_ON_ERROR__"); String commitEvery = ElementParameterParser.getValue(node, "__COMMIT_EVERY__"); String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"); String propagateRecordset = ElementParameterParser.getValue(node, "__PROPAGATE_RECORD_SET__"); String recordsetColumn = ElementParameterParser.getValue(node, "__RECORD_SET_COLUMN__"); boolean usePrepareStatement = "true".equals(ElementParameterParser.getValue(node, "__USE_PREPAREDSTATEMENT__")); String dbquery = ElementParameterParser.getValue(node, "__QUERY__"); dbquery = dbquery.replaceAll("\n", " "); dbquery = dbquery.replaceAll("\r", " "); List<Map<String, String>> prepareStatementParameters = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SET_PREPAREDSTATEMENT_PARAMETERS__"); String incomingConnName = null; Set<String> inputCols = new HashSet<String>(); List<IMetadataColumn> columnList = null; String rejectConnName = null; List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT"); if (rejectConns != null && rejectConns.size() > 0) { IConnection rejectConn = rejectConns.get(0); rejectConnName = rejectConn.getName(); } List<IMetadataColumn> rejectColumnList = null; IMetadataTable metadataTable = node.getMetadataFromConnector("REJECT"); if (metadataTable != null) { rejectColumnList = metadataTable.getListColumns(); } List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections(); boolean hasOutgoingDataConnection = false; for (IConnection conn : outgoingConns) { if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { if (!hasOutgoingDataConnection) { hasOutgoingDataConnection = true; } stringBuffer.append(TEXT_2); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_3); } } stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); stringBuffer.append(dbquery); stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { List<? extends IConnection> inConnections = node.getIncomingConnections(); columnList = metadata.getListColumns(); if (inConnections != null && inConnections.size() > 0) { IConnection conn = inConnections.get(0); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { incomingConnName = conn.getName(); IMetadataTable inputMetadataTable = conn.getMetadataTable(); for (IMetadataColumn inputCol : inputMetadataTable.getListColumns()) { inputCols.add(inputCol.getLabel()); } } } // end of connection size. } // end of metadatas } if (!hasOutgoingDataConnection || columnList == null || columnList.size() < 1) { propagateRecordset = "false"; } stringBuffer.append(TEXT_8); stringBuffer.append(cid); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); if (("true").equals(propagateRecordset)) { stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); } stringBuffer.append(TEXT_13); if (usePrepareStatement) { for (Map<String, String> param : prepareStatementParameters) { if ("Date".equals(param.get("PARAMETER_TYPE"))) { stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(param.get("PARAMETER_INDEX")); stringBuffer.append(TEXT_16); stringBuffer.append(param.get("PARAMETER_VALUE")); stringBuffer.append(TEXT_17); } else { stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(param.get("PARAMETER_TYPE")); stringBuffer.append(TEXT_20); stringBuffer.append(param.get("PARAMETER_INDEX")); stringBuffer.append(TEXT_21); stringBuffer.append(param.get("PARAMETER_VALUE")); stringBuffer.append(TEXT_22); } } if (("true").equals(propagateRecordset)) { stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); } else { stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); } } else { if (("true").equals(propagateRecordset)) { stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); } else { stringBuffer.append(TEXT_32); stringBuffer.append(cid); stringBuffer.append(TEXT_33); stringBuffer.append(cid); stringBuffer.append(TEXT_34); } } stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); if (("true").equals(dieOnError)) { stringBuffer.append(TEXT_37); } else { if (rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) { stringBuffer.append(TEXT_38); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_39); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_40); if (incomingConnName != null) { for (IMetadataColumn column : columnList) { if (inputCols.contains(column.getLabel())) { stringBuffer.append(TEXT_41); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_42); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_43); stringBuffer.append(incomingConnName); stringBuffer.append(TEXT_44); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_45); } } } stringBuffer.append(TEXT_46); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_47); stringBuffer.append(TEXT_48); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_49); stringBuffer.append(node.getUniqueName()); stringBuffer.append(TEXT_50); } else { stringBuffer.append(TEXT_51); } } stringBuffer.append(TEXT_52); if (outgoingConns != null && outgoingConns.size() > 0) { stringBuffer.append(TEXT_53); stringBuffer.append(cid); stringBuffer.append(TEXT_54); for (IConnection outgoingConn : outgoingConns) { if (rejectConnName == null || (rejectConnName != null && !outgoingConn.getName().equals(rejectConnName))) { if (outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { stringBuffer.append(TEXT_55); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_56); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_57); for (IMetadataColumn column : columnList) { if (("true").equals(propagateRecordset) && column.getLabel().equals(recordsetColumn)) { stringBuffer.append(TEXT_58); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_59); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); } else { if (incomingConnName != null) { if (inputCols.contains(column.getLabel())) { stringBuffer.append(TEXT_62); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_63); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_64); stringBuffer.append(incomingConnName); stringBuffer.append(TEXT_65); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_66); } } } } } } } stringBuffer.append(TEXT_67); } if (!("true").equals(useExistingConn)) { if (!("").equals(commitEvery) && !("0").equals(commitEvery)) { stringBuffer.append(TEXT_68); stringBuffer.append(cid); stringBuffer.append(TEXT_69); stringBuffer.append(cid); stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); stringBuffer.append(cid); stringBuffer.append(TEXT_72); stringBuffer.append(cid); stringBuffer.append(TEXT_73); } } stringBuffer.append(TEXT_74); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { String filename = ElementParameterParser.getValue(node, "__JRXML_FILE__"); String tempDirectory = ElementParameterParser.getValue(node, "__TEMP_FILE__"); String encoding = ElementParameterParser.getValue(node, "__ENCODING__"); stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append(filename); stringBuffer.append(TEXT_5); stringBuffer.append(filename); stringBuffer.append(TEXT_6); stringBuffer.append(filename); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(tempDirectory); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); stringBuffer.append(encoding); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); List<IMetadataColumn> columns = metadata.getListColumns(); int sizeColumns = columns.size(); stringBuffer.append(TEXT_20); stringBuffer.append(cid); stringBuffer.append(TEXT_21); stringBuffer.append(sizeColumns); stringBuffer.append(TEXT_22); for (int i = 0; i < sizeColumns; i++) { IMetadataColumn column = columns.get(i); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(i); stringBuffer.append(TEXT_25); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_26); } stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); } } stringBuffer.append(TEXT_32); return stringBuffer.toString(); }
public static void addCustomManagementToToolBar( final MetadataTableEditorView tableEditorView, final IMetadataTable table, final boolean readOnly, final MetadataTableEditorView linkedTableEditorView, final IMetadataTable linkedTable, final boolean toPropagate) { tableEditorView .getTableViewerCreator() .getTableViewer() .addPostSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateToolBarButtonsOnSelection( event.getSelection(), tableEditorView, table, linkedTableEditorView, linkedTable, readOnly); } }); boolean isThereCustom = false; for (IMetadataColumn column : table.getListColumns()) { if (column.isCustom()) { isThereCustom = true; } } if (isThereCustom) { tableEditorView.getToolBar().getImportButton().getButton().setEnabled(false); } if (table.isReadOnly()) { tableEditorView.getToolBar().getAddButton().getButton().setEnabled(false); tableEditorView.getToolBar().getMoveDownButton().getButton().setEnabled(false); tableEditorView.getToolBar().getMoveUpButton().getButton().setEnabled(false); tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false); tableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false); ResetDBTypesPushButton resetDBTypesButton = tableEditorView.getToolBar().getResetDBTypesButton(); if (resetDBTypesButton != null) { resetDBTypesButton.getButton().setEnabled(false); } } else { tableEditorView .getToolBar() .getAddButton() .getButton() .addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { table.sortCustomColumns(); tableEditorView.getTableViewerCreator().getTableViewer().refresh(); } }); } SelectionListener customListener = new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { updateToolBarButtonsOnSelection( tableEditorView.getTableViewerCreator().getTableViewer().getSelection(), tableEditorView, table, linkedTableEditorView, linkedTable, readOnly); } }; tableEditorView.getToolBar().getRemoveButton().getButton().addSelectionListener(customListener); tableEditorView.getToolBar().getCopyButton().getButton().addSelectionListener(customListener); if (toPropagate) { if (linkedTable.isReadOnly()) { SelectionListener updateLinkedTableListener = new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { MetadataToolHelper.copyTable(table, linkedTable); linkedTableEditorView.getTableViewerCreator().refresh(); if (linkedTableEditorView != null) { linkedTableEditorView.getTableViewerCreator().getTableViewer().refresh(); } } }; tableEditorView.getToolBar().getButtons(); for (Object element2 : tableEditorView.getToolBar().getButtons()) { ExtendedPushButton element = (ExtendedPushButton) element2; element.getButton().addSelectionListener(updateLinkedTableListener); } } } }
@Override public void addComponents(boolean forceRedraw) { if (conSchema()) { disposeChildren(); curRowSize = 0; List<? extends IElementParameter> listParam = ((Connection) elem).getSource().getElementParameters(); generator.initController(this); for (IElementParameter cur : listParam) { if ((cur.getFieldType() == EParameterFieldType.SCHEMA_TYPE) && (cur.getContext().equals(((Connection) elem).getConnectorName()))) { AbstractElementPropertySectionController contorller = generator.getController(EParameterFieldType.SCHEMA_TYPE, this); contorller.createControl(composite, cur, 0, 0, 0, null); } } FormData data = new FormData(); data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE); data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE); data.top = new FormAttachment(0, curRowSize + ITabbedPropertyConstants.VSPACE); data.width = 300; // to correct bug of table growing indefinitly IMetadataTable outputMetaTable = ((Connection) elem).getMetadataTable(); if (outputMetaTable != null) { // Composite compositeEditorView = new Composite(composite, SWT.BORDER); // compositeEditorView.setLayoutData(data); metadataTableEditor = new MetadataTableEditor( outputMetaTable, "Schema from " //$NON-NLS-1$ + ((Connection) elem).getSource().getElementName() + " output "); //$NON-NLS-1$ metadataTableEditorView = new MetadataTableEditorView( composite, SWT.NONE, metadataTableEditor, true, false, true, false); MetadataDialog.initializeMetadataTableView( metadataTableEditorView, ((Connection) elem).getSource(), outputMetaTable); metadataTableEditorView.initGraphicComponents(); metadataTableEditorView.getExtendedTableViewer().setCommandStack(getCommandStack()); CustomTableManager.addCustomManagementToTable(metadataTableEditorView, true); Composite compositeEditorView = metadataTableEditorView.getMainComposite(); compositeEditorView.setLayoutData(data); // compositeEditorView.getParent().layout(); Table table = metadataTableEditorView.getTable(); int currentHeightEditor = table.getHeaderHeight() + outputMetaTable.getListColumns().size() * table.getItemHeight() + table.getItemHeight() + 50; curRowSize = currentHeightEditor + ITabbedPropertyConstants.VSPACE + curRowSize; } super.addComponents(forceRedraw, false); } else if (conIf()) { super.addComponents(forceRedraw); } else { disposeChildren(); } }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); List<? extends IConnection> conns = node.getIncomingConnections(); IMetadataTable inMetadata = null; String connName = ""; if (conns != null) { for (IConnection conn : conns) { if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { connName = conn.getName(); inMetadata = conn.getMetadataTable(); break; } } if (metadata != null && inMetadata != null) { List<IMetadataColumn> columns = inMetadata.getListColumns(); Map<String, String> typesMap = new HashMap<String, String>(); Map<String, String> patternsMap = new HashMap<String, String>(); for (IMetadataColumn column : columns) { String type = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable()); typesMap.put(column.getLabel(), type); String pattern = ((column.getPattern() == null) || (column.getPattern().trim().length() == 0)) ? "" : column.getPattern(); patternsMap.put(column.getLabel(), pattern); } String rowCount = ElementParameterParser.getValue(node, "__ROW_COUNT__"); // ?? i think we need it List<Map<String, String>> denormalizes = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__DENORMALIZE_COLUMNS__"); List<String> denormalizeColumns = new ArrayList<String>(); List<String> denormalizeColumnsType = new ArrayList<String>(); List<String> denormalizeDelimiters = new ArrayList<String>(); List<Boolean> denormalizeMergeFlags = new ArrayList<Boolean>(); List<IMetadataColumn> groupColumns = new ArrayList<IMetadataColumn>(); for (Map<String, String> denormalize : denormalizes) { String columnName = denormalize.get("INPUT_COLUMN"); if (denormalizeColumns.contains(columnName)) { continue; } denormalizeColumns.add(columnName); denormalizeColumnsType.add(typesMap.get(columnName)); denormalizeDelimiters.add(denormalize.get("DELIMITER")); denormalizeMergeFlags.add(("true").equals(denormalize.get("MERGE"))); } for (IMetadataColumn column : columns) { String columnName = column.getLabel(); if (denormalizeColumns.contains(columnName)) { continue; } groupColumns.add(column); } stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); if (groupColumns.size() > 0) { stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); } stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); for (IMetadataColumn column : groupColumns) { stringBuffer.append(TEXT_9); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); stringBuffer.append(connName); stringBuffer.append(TEXT_12); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_13); } for (int i = 0; i < denormalizeColumns.size(); i++) { String columnName = denormalizeColumns.get(i); String columnType = denormalizeColumnsType.get(i); if (denormalizeMergeFlags.get(i)) { stringBuffer.append(TEXT_14); stringBuffer.append(columnName); stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); stringBuffer.append(connName); stringBuffer.append(TEXT_17); stringBuffer.append(columnName); stringBuffer.append(TEXT_18); } else { if ((("java.util.Date").equals(columnType)) && (patternsMap.get(columnName).length() != 0)) { stringBuffer.append(TEXT_19); stringBuffer.append(columnName); stringBuffer.append(TEXT_20); stringBuffer.append(cid); stringBuffer.append(TEXT_21); stringBuffer.append(connName); stringBuffer.append(TEXT_22); stringBuffer.append(columnName); stringBuffer.append(TEXT_23); stringBuffer.append(patternsMap.get(columnName)); stringBuffer.append(TEXT_24); } else { stringBuffer.append(TEXT_25); stringBuffer.append(columnName); stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(connName); stringBuffer.append(TEXT_28); stringBuffer.append(columnName); stringBuffer.append(TEXT_29); } } } stringBuffer.append(TEXT_30); if (groupColumns.size() > 0) { // while loop stringBuffer.append(TEXT_31); for (int i = 0; i < groupColumns.size(); i++) { String columnName = groupColumns.get(i).getLabel(); if (!JavaTypesManager.isJavaPrimitiveType( groupColumns.get(i).getTalendType(), groupColumns.get(i).isNullable())) { stringBuffer.append(TEXT_32); stringBuffer.append(columnName); stringBuffer.append(TEXT_33); stringBuffer.append(cid); stringBuffer.append(TEXT_34); stringBuffer.append(connName); stringBuffer.append(TEXT_35); stringBuffer.append(columnName); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); stringBuffer.append(columnName); stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append(columnName); stringBuffer.append(TEXT_40); stringBuffer.append(cid); stringBuffer.append(TEXT_41); stringBuffer.append(connName); stringBuffer.append(TEXT_42); stringBuffer.append(columnName); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); } else { stringBuffer.append(TEXT_45); stringBuffer.append(columnName); stringBuffer.append(TEXT_46); stringBuffer.append(cid); stringBuffer.append(TEXT_47); stringBuffer.append(connName); stringBuffer.append(TEXT_48); stringBuffer.append(columnName); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); } if (i + 1 == groupColumns.size()) { stringBuffer.append(TEXT_51); } } stringBuffer.append(TEXT_52); stringBuffer.append(cid); stringBuffer.append(TEXT_53); } // while loop end for (int i = 0; i < denormalizeColumns.size(); i++) { String columnName = denormalizeColumns.get(i); String columnType = denormalizeColumnsType.get(i); if (denormalizeMergeFlags.get(i)) { stringBuffer.append(TEXT_54); stringBuffer.append(columnName); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(connName); stringBuffer.append(TEXT_57); stringBuffer.append(columnName); stringBuffer.append(TEXT_58); stringBuffer.append(columnName); stringBuffer.append(TEXT_59); stringBuffer.append(cid); stringBuffer.append(TEXT_60); stringBuffer.append(connName); stringBuffer.append(TEXT_61); stringBuffer.append(columnName); stringBuffer.append(TEXT_62); } else { stringBuffer.append(TEXT_63); stringBuffer.append(columnName); stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); stringBuffer.append(denormalizeDelimiters.get(i)); stringBuffer.append(TEXT_66); if ((("java.util.Date").equals(columnType)) && (patternsMap.get(columnName).length() != 0)) { stringBuffer.append(TEXT_67); stringBuffer.append(columnName); stringBuffer.append(TEXT_68); stringBuffer.append(cid); stringBuffer.append(TEXT_69); stringBuffer.append(connName); stringBuffer.append(TEXT_70); stringBuffer.append(columnName); stringBuffer.append(TEXT_71); stringBuffer.append(patternsMap.get(columnName)); stringBuffer.append(TEXT_72); } else { stringBuffer.append(TEXT_73); stringBuffer.append(columnName); stringBuffer.append(TEXT_74); stringBuffer.append(cid); stringBuffer.append(TEXT_75); stringBuffer.append(connName); stringBuffer.append(TEXT_76); stringBuffer.append(columnName); stringBuffer.append(TEXT_77); } } } if (groupColumns.size() > 0) { stringBuffer.append(TEXT_78); } stringBuffer.append(TEXT_79); stringBuffer.append(cid); stringBuffer.append(TEXT_80); if (groupColumns.size() > 0) { // ?? stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); stringBuffer.append(cid); stringBuffer.append(TEXT_83); // do out start ... conns = null; conns = node.getOutgoingSortedConnections(); if (conns != null) { if (conns.size() > 0) { IConnection conn = conns.get(0); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { for (IMetadataColumn column : groupColumns) { stringBuffer.append(TEXT_84); stringBuffer.append(cid); stringBuffer.append(TEXT_85); stringBuffer.append(cid); stringBuffer.append(TEXT_86); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_87); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_88); stringBuffer.append(cid); stringBuffer.append(TEXT_89); } for (int i = 0; i < denormalizeColumns.size(); i++) { String columnName = denormalizeColumns.get(i); String columnType = denormalizeColumnsType.get(i); if (denormalizeMergeFlags.get(i)) { stringBuffer.append(TEXT_90); stringBuffer.append(cid); stringBuffer.append(TEXT_91); stringBuffer.append(cid); stringBuffer.append(TEXT_92); stringBuffer.append(typesMap.get(columnName)); stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); stringBuffer.append(columnName); stringBuffer.append(TEXT_95); stringBuffer.append(cid); stringBuffer.append(TEXT_96); stringBuffer.append(cid); stringBuffer.append(TEXT_97); stringBuffer.append(cid); stringBuffer.append(TEXT_98); stringBuffer.append(denormalizeDelimiters.get(i)); stringBuffer.append(TEXT_99); if ((("java.util.Date").equals(columnType)) && (patternsMap.get(columnName).length() != 0)) { stringBuffer.append(TEXT_100); stringBuffer.append(cid); stringBuffer.append(TEXT_101); stringBuffer.append(cid); stringBuffer.append(TEXT_102); stringBuffer.append(patternsMap.get(columnName)); stringBuffer.append(TEXT_103); } else { stringBuffer.append(TEXT_104); stringBuffer.append(cid); stringBuffer.append(TEXT_105); stringBuffer.append(cid); stringBuffer.append(TEXT_106); } stringBuffer.append(TEXT_107); stringBuffer.append(columnName); stringBuffer.append(TEXT_108); stringBuffer.append(cid); stringBuffer.append(TEXT_109); stringBuffer.append(cid); stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); stringBuffer.append(columnName); stringBuffer.append(TEXT_112); stringBuffer.append(cid); stringBuffer.append(TEXT_113); } else { stringBuffer.append(TEXT_114); stringBuffer.append(cid); stringBuffer.append(TEXT_115); stringBuffer.append(cid); stringBuffer.append(TEXT_116); stringBuffer.append(columnName); stringBuffer.append(TEXT_117); stringBuffer.append(columnName); stringBuffer.append(TEXT_118); stringBuffer.append(cid); stringBuffer.append(TEXT_119); stringBuffer.append(columnName); stringBuffer.append(TEXT_120); stringBuffer.append(cid); stringBuffer.append(TEXT_121); stringBuffer.append(columnName); stringBuffer.append(TEXT_122); stringBuffer.append(cid); stringBuffer.append(TEXT_123); } } } } } // do out end ... // do first for (IMetadataColumn column : groupColumns) { stringBuffer.append(TEXT_124); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_125); stringBuffer.append(cid); stringBuffer.append(TEXT_126); stringBuffer.append(connName); stringBuffer.append(TEXT_127); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_128); } for (int i = 0; i < denormalizeColumns.size(); i++) { String columnName = denormalizeColumns.get(i); String columnType = denormalizeColumnsType.get(i); if (denormalizeMergeFlags.get(i)) { stringBuffer.append(TEXT_129); stringBuffer.append(columnName); stringBuffer.append(TEXT_130); stringBuffer.append(cid); stringBuffer.append(TEXT_131); stringBuffer.append(connName); stringBuffer.append(TEXT_132); stringBuffer.append(columnName); stringBuffer.append(TEXT_133); } else { if ((("java.util.Date").equals(columnType)) && (patternsMap.get(columnName).length() != 0)) { stringBuffer.append(TEXT_134); stringBuffer.append(columnName); stringBuffer.append(TEXT_135); stringBuffer.append(cid); stringBuffer.append(TEXT_136); stringBuffer.append(connName); stringBuffer.append(TEXT_137); stringBuffer.append(columnName); stringBuffer.append(TEXT_138); stringBuffer.append(patternsMap.get(columnName)); stringBuffer.append(TEXT_139); } else { stringBuffer.append(TEXT_140); stringBuffer.append(columnName); stringBuffer.append(TEXT_141); stringBuffer.append(cid); stringBuffer.append(TEXT_142); stringBuffer.append(connName); stringBuffer.append(TEXT_143); stringBuffer.append(columnName); stringBuffer.append(TEXT_144); } } } stringBuffer.append(TEXT_145); } ///////////////////////////////////////////////// stringBuffer.append(TEXT_146); stringBuffer.append(cid); stringBuffer.append(TEXT_147); stringBuffer.append(rowCount); stringBuffer.append(TEXT_148); stringBuffer.append(cid); stringBuffer.append(TEXT_149); // do out start ... conns = null; conns = node.getOutgoingSortedConnections(); if (conns != null) { if (conns.size() > 0) { IConnection conn = conns.get(0); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { for (IMetadataColumn column : groupColumns) { stringBuffer.append(TEXT_150); stringBuffer.append(cid); stringBuffer.append(TEXT_151); stringBuffer.append(cid); stringBuffer.append(TEXT_152); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_153); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_154); stringBuffer.append(cid); stringBuffer.append(TEXT_155); } for (int i = 0; i < denormalizeColumns.size(); i++) { String columnName = denormalizeColumns.get(i); String columnType = denormalizeColumnsType.get(i); if (denormalizeMergeFlags.get(i)) { stringBuffer.append(TEXT_156); stringBuffer.append(cid); stringBuffer.append(TEXT_157); stringBuffer.append(cid); stringBuffer.append(TEXT_158); stringBuffer.append(typesMap.get(columnName)); stringBuffer.append(TEXT_159); stringBuffer.append(cid); stringBuffer.append(TEXT_160); stringBuffer.append(columnName); stringBuffer.append(TEXT_161); stringBuffer.append(cid); stringBuffer.append(TEXT_162); stringBuffer.append(cid); stringBuffer.append(TEXT_163); stringBuffer.append(cid); stringBuffer.append(TEXT_164); stringBuffer.append(denormalizeDelimiters.get(i)); stringBuffer.append(TEXT_165); if ((("java.util.Date").equals(columnType)) && (patternsMap.get(columnName).length() != 0)) { stringBuffer.append(TEXT_166); stringBuffer.append(cid); stringBuffer.append(TEXT_167); stringBuffer.append(cid); stringBuffer.append(TEXT_168); stringBuffer.append(patternsMap.get(columnName)); stringBuffer.append(TEXT_169); } else { stringBuffer.append(TEXT_170); stringBuffer.append(cid); stringBuffer.append(TEXT_171); stringBuffer.append(cid); stringBuffer.append(TEXT_172); } stringBuffer.append(TEXT_173); stringBuffer.append(columnName); stringBuffer.append(TEXT_174); stringBuffer.append(cid); stringBuffer.append(TEXT_175); stringBuffer.append(cid); stringBuffer.append(TEXT_176); stringBuffer.append(cid); stringBuffer.append(TEXT_177); stringBuffer.append(columnName); stringBuffer.append(TEXT_178); stringBuffer.append(cid); stringBuffer.append(TEXT_179); } else { stringBuffer.append(TEXT_180); stringBuffer.append(cid); stringBuffer.append(TEXT_181); stringBuffer.append(cid); stringBuffer.append(TEXT_182); stringBuffer.append(columnName); stringBuffer.append(TEXT_183); stringBuffer.append(columnName); stringBuffer.append(TEXT_184); stringBuffer.append(cid); stringBuffer.append(TEXT_185); stringBuffer.append(columnName); stringBuffer.append(TEXT_186); stringBuffer.append(cid); stringBuffer.append(TEXT_187); stringBuffer.append(columnName); stringBuffer.append(TEXT_188); stringBuffer.append(cid); stringBuffer.append(TEXT_189); } } } } } // do out end ... stringBuffer.append(TEXT_190); stringBuffer.append(cid); stringBuffer.append(TEXT_191); stringBuffer.append(cid); stringBuffer.append(TEXT_192); stringBuffer.append(cid); stringBuffer.append(TEXT_193); stringBuffer.append(cid); stringBuffer.append(TEXT_194); conns = null; conns = node.getOutgoingSortedConnections(); if (conns != null) { for (int i = 0; i < conns.size(); i++) { IConnection conn = conns.get(i); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { for (IMetadataColumn column : metadata.getListColumns()) { stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_195); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_196); stringBuffer.append(cid); stringBuffer.append(TEXT_197); stringBuffer.append(cid); stringBuffer.append(TEXT_198); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_199); } } } } stringBuffer.append(TEXT_200); stringBuffer.append(cid); stringBuffer.append(TEXT_201); } } } stringBuffer.append(TEXT_202); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); // this util class use by set log4j debug paramters class DefaultLog4jFileUtil { INode node = null; String cid = null; boolean isLog4jEnabled = false; String label = null; public DefaultLog4jFileUtil() {} public DefaultLog4jFileUtil(INode node) { this.node = node; this.cid = node.getUniqueName(); this.label = cid; this.isLog4jEnabled = ("true") .equals( org.talend.core.model.process.ElementParameterParser.getValue( node.getProcess(), "__LOG4J_ACTIVATE__")); } public void setCid(String cid) { this.cid = cid; } // for all tFileinput* components public void startRetriveDataInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_2); stringBuffer.append(label); stringBuffer.append(TEXT_3); } } public void retrievedDataNumberInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_4); stringBuffer.append(label); stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); } } public void retrievedDataNumberInfoFromGlobalMap(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_7); stringBuffer.append(label); stringBuffer.append(TEXT_8); stringBuffer.append(cid); stringBuffer.append(TEXT_9); } } // for all tFileinput* components public void retrievedDataNumberInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_10); stringBuffer.append(label); stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); } } public void writeDataFinishInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_13); stringBuffer.append(label); stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); } } // TODO delete it and remove all log4jSb parameter from components public void componentStartInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); } } // TODO rename or delete it public void debugRetriveData(INode node, boolean hasIncreased) { if (isLog4jEnabled) { stringBuffer.append(TEXT_18); stringBuffer.append(label); stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(hasIncreased ? "" : "+1"); stringBuffer.append(TEXT_20); } } // TODO rename or delete it public void debugRetriveData(INode node) { debugRetriveData(node, true); } // TODO rename or delete it public void debugWriteData(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_21); stringBuffer.append(label); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); } } public void logCurrentRowNumberInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_24); stringBuffer.append(label); stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); } } public void logDataCountInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_27); stringBuffer.append(label); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); } } } final DefaultLog4jFileUtil log4jFileUtil = new DefaultLog4jFileUtil( (INode) (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument) .getArgument())); stringBuffer.append(TEXT_30); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); boolean customEncoding = "true".equals(ElementParameterParser.getValue(node, "__CUSTOM_ENCODING__")); String encoding = ElementParameterParser.getValue(node, "__ENCODING__"); List<? extends IConnection> conns = node.getOutgoingSortedConnections(); String firstConnName = ""; if (conns != null) { if (conns.size() > 0) { IConnection conn = conns.get(0); if (conn != null && conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { firstConnName = conn.getName(); stringBuffer.append(TEXT_31); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_32); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_33); } } } List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0) && firstConnName.length() > 0) { IMetadataTable metadata = metadatas.get(0); String typeFile = ElementParameterParser.getValue(node, "__TYPEFILE__"); if (typeFile.equals("SEQUENCE")) { String keyColumn = ElementParameterParser.getValue(node, "__KEYCOLUMN__"); String valueColumn = ElementParameterParser.getValue(node, "__VALUECOLUMN__"); List<IMetadataColumn> listColumns = metadata.getListColumns(); String talendKeyClass = ""; String talendValueClass = ""; for (IMetadataColumn column : listColumns) { if (column.getLabel().equals(keyColumn)) { talendKeyClass = column.getTalendType(); } if (column.getLabel().equals(valueColumn)) { talendValueClass = column.getTalendType(); } } String hadoopVersion = null; String distribution = null; boolean useExistingConnection = "true".equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); if (!useExistingConnection) { distribution = ElementParameterParser.getValue(node, "__DISTRIBUTION__"); hadoopVersion = ElementParameterParser.getValue(node, "__DB_VERSION__"); } else { String connectionSid = ElementParameterParser.getValue(node, "__CONNECTION__"); List<? extends INode> nodes = node.getProcess().getGeneratingNodes(); for (INode targetNode : nodes) { if (targetNode.getUniqueName().equals(connectionSid)) { hadoopVersion = ElementParameterParser.getValue(targetNode, "__DB_VERSION__"); distribution = ElementParameterParser.getValue(targetNode, "__DISTRIBUTION__"); break; } } } org.talend.hadoop.distribution.component.HDFSComponent hdfsDistrib = null; try { hdfsDistrib = (org.talend.hadoop.distribution.component.HDFSComponent) org.talend.hadoop.distribution.DistributionFactory.buildDistribution( distribution, hadoopVersion); } catch (java.lang.Exception e) { e.printStackTrace(); return ""; } boolean isCustom = hdfsDistrib instanceof org.talend.hadoop.distribution.custom.CustomDistribution; stringBuffer.append(TEXT_34); String keyClass = "org.apache.hadoop.io.Text"; if (talendKeyClass.equals("id_Boolean")) keyClass = "org.apache.hadoop.io.BooleanWritable"; if (talendKeyClass.equals("id_Byte")) keyClass = "org.apache.hadoop.io.ByteWritable"; if (talendKeyClass.equals("id_byte[]")) keyClass = "org.apache.hadoop.io.BytesWritable"; if (talendKeyClass.equals("id_Double")) keyClass = "org.apache.hadoop.io.DoubleWritable"; if (talendKeyClass.equals("id_Float")) keyClass = "org.apache.hadoop.io.FloatWritable"; if (talendKeyClass.equals("id_Integer")) keyClass = "org.apache.hadoop.io.IntWritable"; if (talendKeyClass.equals("id_Long")) keyClass = "org.apache.hadoop.io.LongWritable"; if (talendKeyClass.equals("id_String")) keyClass = "org.apache.hadoop.io.Text"; if (talendKeyClass.equals("id_Short")) { if (isCustom || hdfsDistrib.doSupportSequenceFileShortType()) { keyClass = "org.apache.hadoop.io.ShortWritable"; } else { keyClass = "org.apache.hadoop.io.IntWritable"; } } String valueClass = "org.apache.hadoop.io.Text"; if (talendValueClass.equals("id_Boolean")) valueClass = "org.apache.hadoop.io.BooleanWritable"; if (talendValueClass.equals("id_Byte")) valueClass = "org.apache.hadoop.io.ByteWritable"; if (talendValueClass.equals("id_byte[]")) valueClass = "org.apache.hadoop.io.BytesWritable"; if (talendValueClass.equals("id_Double")) valueClass = "org.apache.hadoop.io.DoubleWritable"; if (talendValueClass.equals("id_Float")) valueClass = "org.apache.hadoop.io.FloatWritable"; if (talendValueClass.equals("id_Integer")) valueClass = "org.apache.hadoop.io.IntWritable"; if (talendValueClass.equals("id_Long")) valueClass = "org.apache.hadoop.io.LongWritable"; if (talendValueClass.equals("id_String")) valueClass = "org.apache.hadoop.io.Text"; if (talendValueClass.equals("id_Short")) { if (isCustom || hdfsDistrib.doSupportSequenceFileShortType()) { valueClass = "org.apache.hadoop.io.ShortWritable"; } else { valueClass = "org.apache.hadoop.io.IntWritable"; } } stringBuffer.append(TEXT_35); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_36); stringBuffer.append(keyColumn); stringBuffer.append(TEXT_37); stringBuffer.append(talendKeyClass.equals("id_Short") ? "(short)" : ""); stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append( ((keyClass.equals("org.apache.hadoop.io.Text")) ? "toString()" : "get()")); stringBuffer.append(TEXT_40); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_41); stringBuffer.append(valueColumn); stringBuffer.append(TEXT_42); stringBuffer.append(talendValueClass.equals("id_Short") ? "(short)" : ""); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append( ((valueClass.equals("org.apache.hadoop.io.Text")) ? "toString()" : "get()")); stringBuffer.append(TEXT_45); } else { if (metadata != null) { List<IMetadataColumn> listColumns = metadata.getListColumns(); for (int valueN = 0; valueN < listColumns.size(); valueN++) { IMetadataColumn column = listColumns.get(valueN); String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable()); JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType()); String patternValue = column.getPattern() == null || column.getPattern().trim().length() == 0 ? null : column.getPattern(); if (javaType == JavaTypesManager.STRING || javaType == JavaTypesManager.OBJECT) { stringBuffer.append(TEXT_46); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_47); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); stringBuffer.append(valueN); stringBuffer.append(TEXT_50); } else { stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); stringBuffer.append(valueN); stringBuffer.append(TEXT_53); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(valueN); stringBuffer.append(TEXT_55); if (javaType == JavaTypesManager.DATE) { stringBuffer.append(TEXT_56); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_57); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_58); stringBuffer.append(cid); stringBuffer.append(TEXT_59); stringBuffer.append(valueN); stringBuffer.append(TEXT_60); stringBuffer.append(patternValue); stringBuffer.append(TEXT_61); } else if (javaType == JavaTypesManager.BYTE_ARRAY) { stringBuffer.append(TEXT_62); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_63); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); stringBuffer.append(valueN); stringBuffer.append(TEXT_66); stringBuffer.append((customEncoding ? encoding : "utf8Charset")); stringBuffer.append(TEXT_67); } else { stringBuffer.append(TEXT_68); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_69); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_70); stringBuffer.append(typeToGenerate); stringBuffer.append(TEXT_71); stringBuffer.append(cid); stringBuffer.append(TEXT_72); stringBuffer.append(valueN); stringBuffer.append(TEXT_73); } stringBuffer.append(TEXT_74); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_75); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_76); stringBuffer.append(JavaTypesManager.getDefaultValueFromJavaType(typeToGenerate)); stringBuffer.append(TEXT_77); } } // for } } stringBuffer.append(TEXT_78); stringBuffer.append(cid); stringBuffer.append(TEXT_79); log4jFileUtil.debugRetriveData(node); } stringBuffer.append(TEXT_80); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(TEXT_1); /* Algorithm: * For each procedure arguments * If argument type is IN or IN OUT * Bind parameter to procedure call * If argument type is OUT or IN OUT * Register output parameter in procedure call * * Execute procedure * * For each column in first output schema * If column match a procedure argument * If argument type is IN * Copy argument value from input flow * If argument type is OUT or IN OUT * Retrieve argument value from procedure call * Copy argument value from first output schema to each output schema * Else * If column is defined in input schema * Copy column value from input schema to each output schema */ CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); List<Map<String, String>> spArgs = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SP_ARGS__"); // Functions have an additionnal output parameter boolean isFunction = ("true").equals(ElementParameterParser.getValue(node, "__IS_FUNCTION__")); if (isFunction) { // Add return value at first position of parameters list String returnField = ElementParameterParser.getValue(node, "__RETURN__"); HashMap<String, String> returnValue = new HashMap<String, String>(); returnValue.put("COLUMN", returnField); returnValue.put("TYPE", "RETURN_FUNCTION"); spArgs.add(returnValue); } class JavaToDbType { public String convert(String javaType) { if (("String").equals(javaType)) { return "VARCHAR"; } else if (javaType.equalsIgnoreCase("char") || ("Character").equals(javaType)) { return "CHAR"; } else if (("byte[]").equals(javaType)) { return "RAW"; } else if (("java.util.Date").equals(javaType)) { return "DATE"; } else if (javaType.equalsIgnoreCase("boolean")) { return "BOOLEAN"; } else if (javaType.equalsIgnoreCase("byte")) { return "TINYINT"; } else if (javaType.equalsIgnoreCase("short")) { return "SMALLINT"; } else if (javaType.equalsIgnoreCase("int") || ("Integer").equals(javaType)) { return "INTEGER"; } else if (javaType.equalsIgnoreCase("long")) { return "BIGINT"; } else if (javaType.equalsIgnoreCase("float")) { return "FLOAT"; } else if (javaType.equalsIgnoreCase("double")) { return "DOUBLE"; } else { return "OTHER"; } } } JavaToDbType converter = new JavaToDbType(); // Search incoming schema IMetadataTable inMetadata = null; IConnection inConnection = null; String inConnectionName = null; List<? extends IConnection> inConnections = node.getIncomingConnections(); if (inConnections != null) { for (int i = 0; i < inConnections.size(); i++) { IConnection connection = inConnections.get(i); if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { inConnection = connection; inConnectionName = inConnection.getName(); inMetadata = inConnection.getMetadataTable(); } } } // If there is an IN or an INOUT argument, the component must have an input // connection boolean canGenerate = true; if (inConnection == null) { for (int i = 0; i < spArgs.size(); i++) { String argType = spArgs.get(i).get("TYPE"); if (("IN").equals(argType) || ("INOUT").equals(argType)) { stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); canGenerate = false; break; } } } if (canGenerate) { // Search outgoing schema IMetadataTable metadata = null; List<IMetadataTable> metadatas = node.getMetadataList(); if (metadatas != null && metadatas.size() > 0) { metadata = metadatas.get(0); } // We only generate output if outgoing schema is defined if (metadata != null) { List<IMetadataColumn> columnList = metadata.getListColumns(); // Iterate over procedure arguments for (int i = 0; i < spArgs.size(); i++) { Map<String, String> spArg = spArgs.get(i); String argName = spArg.get("COLUMN"); String argType = spArg.get("TYPE"); // Search Java type of argument, based on schema column String typeToGenerate = null; boolean nullable = false; for (IMetadataColumn column : columnList) { if (column.getLabel().equals(argName)) { typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable()); nullable = column.isNullable(); break; } } if (typeToGenerate == null) continue; // Note: first argument in JDBC is arg #1, and for functions, arg #1 is return value int argIndex = i + 1; // Input argument if (("IN").equals(argType) || ("INOUT").equals(argType)) { if (nullable) { stringBuffer.append(TEXT_4); stringBuffer.append(inConnectionName); stringBuffer.append(TEXT_5); stringBuffer.append(argName); stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(argIndex); stringBuffer.append(TEXT_8); stringBuffer.append(converter.convert(typeToGenerate)); stringBuffer.append(TEXT_9); } String method; if (("byte[]").equals(typeToGenerate)) { method = "Bytes"; } else if (("Integer").equals(typeToGenerate)) { method = "Int"; } else { method = typeToGenerate.substring(0, 1).toUpperCase() + typeToGenerate.substring(1); } // Bind parameter to CallableStatement if (("char").equals(typeToGenerate) || ("Character").equals(typeToGenerate)) { stringBuffer.append(TEXT_10); stringBuffer.append(inConnectionName); stringBuffer.append(TEXT_11); stringBuffer.append(argName); stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(argIndex); stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(argIndex); stringBuffer.append(TEXT_16); stringBuffer.append(inConnectionName); stringBuffer.append(TEXT_17); stringBuffer.append(argName); stringBuffer.append(TEXT_18); } else if (("java.util.Date").equals(typeToGenerate)) { stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(argIndex); stringBuffer.append(TEXT_21); stringBuffer.append(inConnectionName); stringBuffer.append(TEXT_22); stringBuffer.append(argName); stringBuffer.append(TEXT_23); } else { stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); stringBuffer.append(method); stringBuffer.append(TEXT_26); stringBuffer.append(argIndex); stringBuffer.append(TEXT_27); stringBuffer.append(inConnectionName); stringBuffer.append(TEXT_28); stringBuffer.append(argName); stringBuffer.append(TEXT_29); } if (nullable) { stringBuffer.append(TEXT_30); } } // Output argument if (("OUT").equals(argType) || ("INOUT").equals(argType)) { stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); stringBuffer.append(argIndex); stringBuffer.append(TEXT_33); stringBuffer.append(converter.convert(typeToGenerate)); stringBuffer.append(TEXT_34); } } stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); List<? extends IConnection> outConnections = node.getOutgoingConnections(); IConnection firstOutConnection = null; if (outConnections != null) { // Search first outgoing connection, if exists int connectionIndex = -1; for (int i = 0; i < outConnections.size(); i++) { IConnection connection = outConnections.get(i); if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { firstOutConnection = connection; connectionIndex = i; break; } } if (firstOutConnection != null) { columns: for (IMetadataColumn column : columnList) { // Retrieve OUT arguments value, and copy IN arguments from input flow for (int i = 0; i < spArgs.size(); i++) { Map<String, String> spArg = spArgs.get(i); String argName = spArg.get("COLUMN"); if (column.getLabel().equals(argName)) { String argType = spArg.get("TYPE"); String typeToGenerate = JavaTypesManager.getTypeToGenerate( column.getTalendType(), column.isNullable()); boolean nullable = column.isNullable(); int argIndex = i + 1; if (("IN").equals(argType)) { // Copy parameter value from input flow stringBuffer.append(TEXT_37); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_38); stringBuffer.append(argName); stringBuffer.append(TEXT_39); stringBuffer.append(inConnectionName); stringBuffer.append(TEXT_40); stringBuffer.append(argName); stringBuffer.append(TEXT_41); } else if (("RECORDSET").equals(argType)) { stringBuffer.append(TEXT_42); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_43); stringBuffer.append(argName); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); } else if (("RETURN_FUNCTION").equals(argType)) { stringBuffer.append(TEXT_46); stringBuffer.append(cid); stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); String method; argIndex = 1; if (("byte[]").equals(typeToGenerate)) { method = "Bytes"; } else if (("java.util.Date").equals(typeToGenerate)) { method = "Date"; } else if (("Integer").equals(typeToGenerate)) { method = "Int"; } else { method = typeToGenerate.substring(0, 1).toUpperCase() + typeToGenerate.substring(1); } if (method.equalsIgnoreCase("char") || ("Character").equals(method)) { stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); stringBuffer.append(argIndex); stringBuffer.append(TEXT_53); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_56); stringBuffer.append(argName); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); } else if (("Date").equals(method)) { stringBuffer.append(TEXT_59); stringBuffer.append(cid); stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); stringBuffer.append(argIndex); stringBuffer.append(TEXT_62); stringBuffer.append(cid); stringBuffer.append(TEXT_63); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_64); stringBuffer.append(argName); stringBuffer.append(TEXT_65); stringBuffer.append(cid); stringBuffer.append(TEXT_66); } else { stringBuffer.append(TEXT_67); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_68); stringBuffer.append(argName); stringBuffer.append(TEXT_69); stringBuffer.append(cid); stringBuffer.append(TEXT_70); stringBuffer.append(method); stringBuffer.append(TEXT_71); stringBuffer.append(argIndex); stringBuffer.append(TEXT_72); } stringBuffer.append(TEXT_73); } else { // Retrieve parameter value (INOUT or OUT) String method; if (("byte[]").equals(typeToGenerate)) { method = "Bytes"; } else if (("java.util.Date").equals(typeToGenerate)) { method = "Date"; } else if (("Integer").equals(typeToGenerate)) { method = "Int"; } else { method = typeToGenerate.substring(0, 1).toUpperCase() + typeToGenerate.substring(1); } if (method.equalsIgnoreCase("char") || ("Character").equals(method)) { stringBuffer.append(TEXT_74); stringBuffer.append(cid); stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); stringBuffer.append(argIndex); stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); stringBuffer.append(cid); stringBuffer.append(TEXT_79); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_80); stringBuffer.append(argName); stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); } else if (("Date").equals(method)) { stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(cid); stringBuffer.append(TEXT_85); stringBuffer.append(argIndex); stringBuffer.append(TEXT_86); stringBuffer.append(cid); stringBuffer.append(TEXT_87); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_88); stringBuffer.append(argName); stringBuffer.append(TEXT_89); stringBuffer.append(cid); stringBuffer.append(TEXT_90); } else { stringBuffer.append(TEXT_91); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_92); stringBuffer.append(argName); stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); stringBuffer.append(method); stringBuffer.append(TEXT_95); stringBuffer.append(argIndex); stringBuffer.append(TEXT_96); } if (nullable) { stringBuffer.append(TEXT_97); stringBuffer.append(cid); stringBuffer.append(TEXT_98); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_99); stringBuffer.append(argName); stringBuffer.append(TEXT_100); } } for (int j = connectionIndex + 1; j < outConnections.size(); j++) { IConnection connection = outConnections.get(j); if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { stringBuffer.append(TEXT_101); stringBuffer.append(connection.getName()); stringBuffer.append(TEXT_102); stringBuffer.append(argName); stringBuffer.append(TEXT_103); stringBuffer.append(firstOutConnection.getName()); stringBuffer.append(TEXT_104); stringBuffer.append(argName); stringBuffer.append(TEXT_105); } } continue columns; } } // Copy columns defined in input and output schema which are not arguments if (inMetadata != null && inMetadata.getListColumns() != null) { for (IMetadataColumn inColumn : inMetadata.getListColumns()) { if (column.getLabel().equals(inColumn.getLabel())) { for (int j = 0; j < outConnections.size(); j++) { IConnection connection = outConnections.get(j); if (connection .getLineStyle() .hasConnectionCategory(IConnectionCategory.DATA)) { stringBuffer.append(TEXT_106); stringBuffer.append(connection.getName()); stringBuffer.append(TEXT_107); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_108); stringBuffer.append(inConnectionName); stringBuffer.append(TEXT_109); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_110); } } } } } } } } } else { stringBuffer.append(TEXT_111); stringBuffer.append(cid); stringBuffer.append(TEXT_112); } } stringBuffer.append(TEXT_113); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String connUrl = ElementParameterParser.getValue(node, "__DBNAME__"); String query = ElementParameterParser.getValue(node, "__QUERY__"); query = query.replaceAll("\n", ""); query = query.replaceAll("\r", ""); String encoding = ElementParameterParser.getValue(node, "__ENCODING__"); String assemblyName = ElementParameterParser.getValue(node, "__ASSEMBLY_NAME__"); String className = ElementParameterParser.getValue(node, "__CLASS_NAME__"); boolean whetherTrimAllCol = ("true").equals(ElementParameterParser.getValue(node, "__TRIM_ALL_COLUMN__")); List<Map<String, String>> trimColumnList = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__TRIM_COLUMN__"); List<IMetadataTable> metadatas = node.getMetadataList(); stringBuffer.append(TEXT_1); stringBuffer.append(cid); stringBuffer.append(TEXT_2); stringBuffer.append(assemblyName); stringBuffer.append(TEXT_3); stringBuffer.append(className); stringBuffer.append(TEXT_4); stringBuffer.append(TEXT_5); stringBuffer.append(connUrl); stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(assemblyName); stringBuffer.append(TEXT_9); stringBuffer.append(TEXT_10); stringBuffer.append(query); stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); IMetadataTable metadata = metadatas.get(0); List<? extends IConnection> connsout = node.getOutgoingConnections(); String connName = null; if (node.getIncomingConnections().size() == 1) { IConnection conn = node.getIncomingConnections().get(0); connName = conn.getName(); } List<IMetadataColumn> columnsout = metadata.getListColumns(); String populateOutput = ""; String outName = null; if (connsout != null) { for (int i = 0; i < connsout.size(); i++) { IConnection connout = connsout.get(i); if (connout.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { outName = connout.getName(); for (int j = 0; j < columnsout.size(); j++) { IMetadataColumn columnout = columnsout.get(j); stringBuffer.append(TEXT_15); stringBuffer.append(columnout.getTalendType()); stringBuffer.append(TEXT_16); stringBuffer.append(columnout.getLabel()); stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(columnout.getLabel()); stringBuffer.append(TEXT_20); populateOutput += "val_" + cid + " = reader_" + cid + ".invokeGeneric(\"GetValue\"," + "new java.lang.Object[] { id" + columnout.getLabel() + "_" + cid + " });\nnew TypeConverter_" + cid + "().doConversion(val_" + cid + "," + connout.getName() + ",\"" + columnout.getLabel() + "\");\n"; if (columnout.getTalendType().equals("id_String")) { boolean whetherTrimCol = false; if ((trimColumnList != null && trimColumnList.size() > 0) && !whetherTrimAllCol) { for (Map<String, String> trimColumn : trimColumnList) { if (columnout.getLabel().equals(trimColumn.get("SCHEMA_COLUMN"))) { if (("true").equals(trimColumn.get("TRIM"))) { whetherTrimCol = true; break; } } } } if (whetherTrimAllCol || whetherTrimCol) { populateOutput += connout.getName() + "." + columnout.getLabel() + " = " + connout.getName() + "." + columnout.getLabel() + ".trim();\n"; } } } } } } stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); stringBuffer.append(TEXT_32); stringBuffer.append(populateOutput); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { String cid = node.getUniqueName(); String filename = ElementParameterParser.getValue(node, "__FILENAME__"); boolean isAppend = ("true").equals(ElementParameterParser.getValue(node, "__APPEND__")); List<Map<String, String>> colDef = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__COLDEFINE__"); String relation = ElementParameterParser.getValue(node, "__RELATION__"); stringBuffer.append(TEXT_1); stringBuffer.append(cid); stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); stringBuffer.append(filename); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(cid); stringBuffer.append(TEXT_9); if (("true").equals(ElementParameterParser.getValue(node, "__CREATE__"))) { stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); } List<IMetadataColumn> columns = metadata.getListColumns(); int sizeColumns = columns.size(); for (int i = 0; i < colDef.size(); i++) { if (("Nominal").equals(colDef.get(i).get("TYPE"))) { stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(i); stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(i); stringBuffer.append(TEXT_18); stringBuffer.append(colDef.get(i).get("PATTERN")); stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(i); stringBuffer.append(TEXT_20); stringBuffer.append(cid); stringBuffer.append(i); stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(i); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(i); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(i); stringBuffer.append(TEXT_24); } } stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); stringBuffer.append(sizeColumns); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); if (isAppend) { stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); stringBuffer.append(cid); stringBuffer.append(TEXT_33); stringBuffer.append(cid); stringBuffer.append(TEXT_34); stringBuffer.append(colDef.size()); stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); int attIndex = 0; for (Map<String, String> colD : colDef) { if (("String").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_40); } else if (("Numeric").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_41); stringBuffer.append(cid); stringBuffer.append(TEXT_42); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_43); } else if (("Date").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_46); stringBuffer.append(colD.get("PATTERN")); stringBuffer.append(TEXT_47); } else if (("Nominal").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(attIndex); stringBuffer.append(TEXT_51); } attIndex++; } stringBuffer.append(TEXT_52); stringBuffer.append(cid); stringBuffer.append(TEXT_53); stringBuffer.append(relation); stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); } else { stringBuffer.append(TEXT_58); stringBuffer.append(cid); stringBuffer.append(TEXT_59); stringBuffer.append(colDef.size()); stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); stringBuffer.append(cid); stringBuffer.append(TEXT_62); int attIndex = 0; for (Map<String, String> colD : colDef) { // for 1 if (("String").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_63); stringBuffer.append(cid); stringBuffer.append(TEXT_64); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_65); } else if (("Numeric").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_68); } else if (("Date").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_69); stringBuffer.append(cid); stringBuffer.append(TEXT_70); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_71); stringBuffer.append(colD.get("PATTERN")); stringBuffer.append(TEXT_72); } else if (("Nominal").equals(colD.get("TYPE"))) { stringBuffer.append(TEXT_73); stringBuffer.append(cid); stringBuffer.append(TEXT_74); stringBuffer.append(columns.get(attIndex).getLabel()); stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(attIndex); stringBuffer.append(TEXT_76); } attIndex++; } // for 1 stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); stringBuffer.append(relation); stringBuffer.append(TEXT_79); stringBuffer.append(cid); stringBuffer.append(TEXT_80); stringBuffer.append(cid); stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); } stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(cid); stringBuffer.append(TEXT_85); } } stringBuffer.append(TEXT_86); stringBuffer.append(TEXT_87); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); boolean isStaging = "STAGING".equalsIgnoreCase(ElementParameterParser.getValue(node, "__CONTAINER_TYPE__")); String destination = ElementParameterParser.getValue(node, "__DESTINATION__"); boolean withReport = ("true").equals(ElementParameterParser.getValue(node, "__WITHREPORT__")); String needCheck = ElementParameterParser.getValue(node, "__ISINVOKE__"); boolean isMassInsert = ("true").equals(ElementParameterParser.getValue(node, "__EXTENDINSERT__")); String numMassInsert = ElementParameterParser.getValue(node, "__COMMIT_LEVEL__"); String sourceName = ElementParameterParser.getValue(node, "__SOURCE__"); boolean dieOnError = ("true").equals(ElementParameterParser.getValue(node, "__DIE_ON_ERROR__")); String isUpdate = ElementParameterParser.getValue(node, "__ISUPDATE__"); List<Map<String, String>> keysReturn = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__RETURN_IDS__"); boolean addTaskID = ("true").equals(ElementParameterParser.getValue(node, "__ADD_TASKID__")); boolean isCustom = "true".equals(ElementParameterParser.getValue(node, "__CUSTOM__")); String taskID = ElementParameterParser.getValue(node, "__TASKID__"); String prevColumn = ElementParameterParser.getValue(node, "__PREV_COLUMN_TASK_ID__"); boolean usePartialUpdate = ("true").equals(ElementParameterParser.getValue(node, "__USE_PARTIAL_UPDATE__")); boolean usePartialDelete = ("true").equals(ElementParameterParser.getValue(node, "__PARTIAL_DELETE__")); String pivot = ElementParameterParser.getValue(node, "__PIVOT__"); boolean overwrite = ("true").equals(ElementParameterParser.getValue(node, "__OVERWRITE__")); String key = ElementParameterParser.getValue(node, "__KEY__"); String position = ElementParameterParser.getValue(node, "__POSITION__"); String dataModel = ElementParameterParser.getValue(node, "__DATAMODEL__"); String dataCluster = ElementParameterParser.getValue(node, "__DATACLUSTER__"); String doc = ElementParameterParser.getValue(node, "__DOCUMENT__"); List<IMetadataTable> metadatas = node.getMetadataList(); if (destination != null && !"".equals(destination)) { cid = destination; } if (metadatas != null && metadatas.size() > 0) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { List<? extends IConnection> outputConns = node.getOutgoingConnections(EConnectionType.FLOW_MAIN); List<IMetadataColumn> inputColumnList = null; List<IMetadataColumn> outputColumnList = null; List<IMetadataColumn> columnList = metadata.getListColumns(); String rejectConnName = null; List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT"); List<IMetadataColumn> rejectColumnList = null; if (rejectConns != null && rejectConns.size() > 0) { IConnection rejectConn = rejectConns.get(0); if (rejectConn != null) { rejectConnName = rejectConn.getName(); IMetadataTable metadataTable = rejectConn.getMetadataTable(); if (metadataTable != null) { rejectColumnList = metadataTable.getListColumns(); } } } String outConnName = null; String inputConnName = null; List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections(); for (IConnection tmpconn : outgoingConns) { if (tmpconn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { if (rejectConnName == null || !rejectConnName.equals(tmpconn.getName())) { outConnName = tmpconn.getName(); IMetadataTable outputMetadata = tmpconn.getMetadataTable(); if (outputMetadata != null) { outputColumnList = outputMetadata.getListColumns(); } } stringBuffer.append(TEXT_1); stringBuffer.append(tmpconn.getName()); stringBuffer.append(TEXT_2); } } List<? extends IConnection> inputConns = node.getIncomingConnections(); if (inputConns != null && inputConns.size() > 0) { IConnection inputConn = inputConns.get(0); if (inputConn != null) { inputConnName = inputConn.getName(); IMetadataTable inputMetadata = inputConn.getMetadataTable(); if (inputMetadata != null) { inputColumnList = inputMetadata.getListColumns(); } } } if (outConnName != null && inputConnName != null) { stringBuffer.append(TEXT_3); stringBuffer.append(outConnName); stringBuffer.append(TEXT_4); stringBuffer.append(outConnName); stringBuffer.append(TEXT_5); for (IMetadataColumn outputColumn : outputColumnList) { for (IMetadataColumn inputColumn : inputColumnList) { if (outputColumn.getLabel().equals(inputColumn.getLabel())) { if (doc != null && doc.equals(outputColumn.getLabel())) { if ("id_Document".equals(outputColumn.getTalendType())) { stringBuffer.append(TEXT_6); stringBuffer.append(outConnName); stringBuffer.append(TEXT_7); stringBuffer.append(doc); stringBuffer.append(TEXT_8); stringBuffer.append(inputConnName); stringBuffer.append(TEXT_9); stringBuffer.append(doc); stringBuffer.append(TEXT_10); } else { stringBuffer.append(TEXT_11); stringBuffer.append(outConnName); stringBuffer.append(TEXT_12); stringBuffer.append(doc); stringBuffer.append(TEXT_13); stringBuffer.append(inputConnName); stringBuffer.append(TEXT_14); stringBuffer.append(doc); stringBuffer.append(TEXT_15); } } else { // to those which do not match doc columns stringBuffer.append(TEXT_16); stringBuffer.append(outConnName); stringBuffer.append(TEXT_17); stringBuffer.append(outputColumn.getLabel()); stringBuffer.append(TEXT_18); stringBuffer.append(inputConnName); stringBuffer.append(TEXT_19); stringBuffer.append(inputColumn.getLabel()); stringBuffer.append(TEXT_20); } } // if input column matches output column } // for input column } // for output column } stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(inputConnName); stringBuffer.append(TEXT_23); stringBuffer.append(doc); stringBuffer.append(TEXT_24); if (usePartialUpdate) { // partial String dataclusterString = ""; if (isStaging) { dataclusterString = dataCluster + " + \"#STAGING\""; } else { dataclusterString = dataCluster; } stringBuffer.append(TEXT_25); stringBuffer.append(usePartialDelete); stringBuffer.append(TEXT_26); stringBuffer.append(position.equals("") ? null : position); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(dataclusterString); stringBuffer.append(TEXT_29); stringBuffer.append(dataModel); stringBuffer.append(TEXT_30); stringBuffer.append(usePartialDelete); stringBuffer.append(TEXT_31); stringBuffer.append(key.equals("") ? null : key); stringBuffer.append(TEXT_32); stringBuffer.append(overwrite); stringBuffer.append(TEXT_33); stringBuffer.append(pivot); stringBuffer.append(TEXT_34); stringBuffer.append(true == isStaging ? false : withReport); stringBuffer.append(TEXT_35); stringBuffer.append(sourceName); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); stringBuffer.append(cid); stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append(cid); stringBuffer.append(TEXT_40); if (outConnName != null && !isMassInsert && keysReturn.size() > 0) { for (int i = 0; i < keysReturn.size(); i++) { Map<String, String> map = keysReturn.get(i); stringBuffer.append(TEXT_41); stringBuffer.append(outConnName); stringBuffer.append(TEXT_42); stringBuffer.append(map.get("OUTPUT_COLUMN")); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append(i); stringBuffer.append(TEXT_45); } } stringBuffer.append(TEXT_46); } else { // not partial stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(isUpdate); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); if (!isStaging && withReport) { stringBuffer.append(TEXT_53); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(needCheck); stringBuffer.append(TEXT_55); stringBuffer.append(sourceName); stringBuffer.append(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); if (isMassInsert) { stringBuffer.append(TEXT_58); if (addTaskID) { stringBuffer.append(TEXT_59); stringBuffer.append(cid); stringBuffer.append(TEXT_60); stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn); stringBuffer.append(TEXT_61); } stringBuffer.append(TEXT_62); stringBuffer.append(cid); stringBuffer.append(TEXT_63); stringBuffer.append(cid); stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); stringBuffer.append(numMassInsert); stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(cid); stringBuffer.append(TEXT_68); stringBuffer.append(cid); stringBuffer.append(TEXT_69); stringBuffer.append(cid); stringBuffer.append(TEXT_70); if (addTaskID) { stringBuffer.append(TEXT_71); stringBuffer.append(cid); stringBuffer.append(TEXT_72); stringBuffer.append(cid); stringBuffer.append(TEXT_73); stringBuffer.append(cid); stringBuffer.append(TEXT_74); stringBuffer.append(cid); stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); stringBuffer.append(cid); stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); stringBuffer.append(cid); stringBuffer.append(TEXT_79); stringBuffer.append(cid); stringBuffer.append(TEXT_80); stringBuffer.append(cid); stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); stringBuffer.append(cid); stringBuffer.append(TEXT_83); } stringBuffer.append(TEXT_84); } else { stringBuffer.append(TEXT_85); stringBuffer.append(cid); stringBuffer.append(TEXT_86); stringBuffer.append(cid); stringBuffer.append(TEXT_87); stringBuffer.append(cid); stringBuffer.append(TEXT_88); if (addTaskID) { stringBuffer.append(TEXT_89); stringBuffer.append(cid); stringBuffer.append(TEXT_90); stringBuffer.append(cid); stringBuffer.append(TEXT_91); stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn); stringBuffer.append(TEXT_92); stringBuffer.append(cid); stringBuffer.append(TEXT_93); } stringBuffer.append(TEXT_94); } if (outConnName != null && !isMassInsert && keysReturn.size() > 0) { for (int i = 0; i < keysReturn.size(); i++) { Map<String, String> map = keysReturn.get(i); stringBuffer.append(TEXT_95); stringBuffer.append(outConnName); stringBuffer.append(TEXT_96); stringBuffer.append(map.get("OUTPUT_COLUMN")); stringBuffer.append(TEXT_97); stringBuffer.append(cid); stringBuffer.append(TEXT_98); stringBuffer.append(i); stringBuffer.append(TEXT_99); } } } else { if (isMassInsert) { stringBuffer.append(TEXT_100); if (addTaskID) { stringBuffer.append(TEXT_101); stringBuffer.append(cid); stringBuffer.append(TEXT_102); stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn); stringBuffer.append(TEXT_103); } stringBuffer.append(TEXT_104); stringBuffer.append(cid); stringBuffer.append(TEXT_105); stringBuffer.append(cid); stringBuffer.append(TEXT_106); stringBuffer.append(cid); stringBuffer.append(TEXT_107); stringBuffer.append(numMassInsert); stringBuffer.append(TEXT_108); stringBuffer.append(cid); stringBuffer.append(TEXT_109); stringBuffer.append(cid); stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); stringBuffer.append(cid); stringBuffer.append(TEXT_112); if (addTaskID) { stringBuffer.append(TEXT_113); stringBuffer.append(cid); stringBuffer.append(TEXT_114); stringBuffer.append(cid); stringBuffer.append(TEXT_115); stringBuffer.append(cid); stringBuffer.append(TEXT_116); stringBuffer.append(cid); stringBuffer.append(TEXT_117); stringBuffer.append(cid); stringBuffer.append(TEXT_118); stringBuffer.append(cid); stringBuffer.append(TEXT_119); stringBuffer.append(cid); stringBuffer.append(TEXT_120); stringBuffer.append(cid); stringBuffer.append(TEXT_121); stringBuffer.append(cid); stringBuffer.append(TEXT_122); stringBuffer.append(cid); stringBuffer.append(TEXT_123); stringBuffer.append(cid); stringBuffer.append(TEXT_124); stringBuffer.append(cid); stringBuffer.append(TEXT_125); } stringBuffer.append(TEXT_126); } else { stringBuffer.append(TEXT_127); stringBuffer.append(cid); stringBuffer.append(TEXT_128); stringBuffer.append(cid); stringBuffer.append(TEXT_129); stringBuffer.append(cid); stringBuffer.append(TEXT_130); if (addTaskID) { stringBuffer.append(TEXT_131); stringBuffer.append(cid); stringBuffer.append(TEXT_132); stringBuffer.append(cid); stringBuffer.append(TEXT_133); stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn); stringBuffer.append(TEXT_134); stringBuffer.append(cid); stringBuffer.append(TEXT_135); } stringBuffer.append(TEXT_136); if (outConnName != null && !isMassInsert && keysReturn.size() > 0) { for (int i = 0; i < keysReturn.size(); i++) { Map<String, String> map = keysReturn.get(i); stringBuffer.append(TEXT_137); stringBuffer.append(outConnName); stringBuffer.append(TEXT_138); stringBuffer.append(map.get("OUTPUT_COLUMN")); stringBuffer.append(TEXT_139); stringBuffer.append(cid); stringBuffer.append(TEXT_140); stringBuffer.append(i); stringBuffer.append(TEXT_141); } } } } stringBuffer.append(TEXT_142); } // end partial stringBuffer.append(TEXT_143); if (dieOnError) { stringBuffer.append(TEXT_144); } else { if (rejectConnName != null) { if (outConnName != null) { stringBuffer.append(TEXT_145); stringBuffer.append(outConnName); stringBuffer.append(TEXT_146); } stringBuffer.append(TEXT_147); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_148); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_149); for (IMetadataColumn column : columnList) { if (!"xml".equals(column.getLabel()) && !"errorCode".equals(column.getLabel()) && !"errorMessage".equals(column.getLabel())) { if (column.getLabel().equals(doc) && "id_String".equals(column.getTalendType())) { stringBuffer.append(TEXT_150); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_151); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_152); stringBuffer.append(inputConnName); stringBuffer.append(TEXT_153); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_154); } else { stringBuffer.append(TEXT_155); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_156); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_157); stringBuffer.append(inputConnName); stringBuffer.append(TEXT_158); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_159); } } if ("xml".equals(column.getLabel())) { if ("id_String".equals(column.getTalendType())) { stringBuffer.append(TEXT_160); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_161); stringBuffer.append(cid); stringBuffer.append(TEXT_162); } else { stringBuffer.append(TEXT_163); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_164); stringBuffer.append(inputConnName); stringBuffer.append(TEXT_165); } } } stringBuffer.append(TEXT_166); stringBuffer.append(cid); stringBuffer.append(TEXT_167); stringBuffer.append(TEXT_168); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_169); stringBuffer.append(node.getUniqueName()); stringBuffer.append(TEXT_170); } else { stringBuffer.append(TEXT_171); } } stringBuffer.append(TEXT_172); stringBuffer.append(cid); stringBuffer.append(TEXT_173); } } stringBuffer.append(TEXT_174); return stringBuffer.toString(); }