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()); } } } }
/** * 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; }
@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(); 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(); }
@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)); }
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(); 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 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); // 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(); String clientId = ElementParameterParser.getValue(node, "__CLIENT_ID__"); String clientSecret = ElementParameterParser.getValue(node, "__CLIENT_SECRET__"); String projectId = ElementParameterParser.getValue(node, "__PROJECT_ID__"); String authorizationCode = ElementParameterParser.getValue(node, "__AUTHORIZATION_CODE__"); String query = ElementParameterParser.getValue(node, "__QUERY__"); query = query.replaceAll("\n", " "); query = query.replaceAll("\r", " "); String tokenFile = ElementParameterParser.getValue(node, "__TOKEN_NAME__"); boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__")); stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); stringBuffer.append(clientId); stringBuffer.append(TEXT_33); String passwordFieldName = "__CLIENT_SECRET__"; stringBuffer.append(TEXT_34); if (ElementParameterParser.canEncrypt(node, passwordFieldName)) { stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName)); stringBuffer.append(TEXT_37); } else { stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName)); stringBuffer.append(TEXT_40); } stringBuffer.append(TEXT_41); stringBuffer.append(cid); stringBuffer.append(TEXT_42); stringBuffer.append(clientId); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(projectId); 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); stringBuffer.append(cid); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); if (isLog4jEnabled) { stringBuffer.append(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); stringBuffer.append(cid); stringBuffer.append(TEXT_59); } stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); stringBuffer.append(tokenFile); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_69); if (isLog4jEnabled) { stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); stringBuffer.append(cid); stringBuffer.append(TEXT_72); } stringBuffer.append(TEXT_73); stringBuffer.append(cid); stringBuffer.append(TEXT_74); if (isLog4jEnabled) { stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); stringBuffer.append(cid); stringBuffer.append(TEXT_77); } 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(cid); stringBuffer.append(TEXT_84); stringBuffer.append(cid); stringBuffer.append(TEXT_85); stringBuffer.append(cid); stringBuffer.append(TEXT_86); stringBuffer.append(cid); stringBuffer.append(TEXT_87); if (isLog4jEnabled) { stringBuffer.append(TEXT_88); stringBuffer.append(cid); stringBuffer.append(TEXT_89); } stringBuffer.append(TEXT_90); stringBuffer.append(cid); stringBuffer.append(TEXT_91); stringBuffer.append(cid); stringBuffer.append(TEXT_92); if (isLog4jEnabled) { stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); } if (authorizationCode == null || "".equals(authorizationCode) || "\"\"".equals(authorizationCode)) { 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(cid); stringBuffer.append(TEXT_99); stringBuffer.append(cid); stringBuffer.append(TEXT_100); if (isLog4jEnabled) { stringBuffer.append(TEXT_101); stringBuffer.append(cid); stringBuffer.append(TEXT_102); stringBuffer.append(cid); stringBuffer.append(TEXT_103); } stringBuffer.append(TEXT_104); } else { stringBuffer.append(TEXT_105); stringBuffer.append(cid); stringBuffer.append(TEXT_106); stringBuffer.append(authorizationCode); stringBuffer.append(TEXT_107); if (isLog4jEnabled) { stringBuffer.append(TEXT_108); stringBuffer.append(cid); stringBuffer.append(TEXT_109); } stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); stringBuffer.append(cid); stringBuffer.append(TEXT_112); stringBuffer.append(cid); 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); if (isLog4jEnabled) { stringBuffer.append(TEXT_122); stringBuffer.append(cid); stringBuffer.append(TEXT_123); } 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(TEXT_136); stringBuffer.append(cid); stringBuffer.append(TEXT_137); stringBuffer.append(query); stringBuffer.append(TEXT_138); stringBuffer.append(cid); stringBuffer.append(TEXT_139); if (isLog4jEnabled) { stringBuffer.append(TEXT_140); stringBuffer.append(cid); stringBuffer.append(TEXT_141); stringBuffer.append(cid); stringBuffer.append(TEXT_142); } stringBuffer.append(TEXT_143); stringBuffer.append(cid); stringBuffer.append(TEXT_144); stringBuffer.append(cid); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_160); stringBuffer.append(cid); 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(cid); stringBuffer.append(TEXT_165); stringBuffer.append(cid); stringBuffer.append(TEXT_166); if (isLog4jEnabled) { stringBuffer.append(TEXT_167); stringBuffer.append(cid); stringBuffer.append(TEXT_168); } stringBuffer.append(TEXT_169); stringBuffer.append(cid); stringBuffer.append(TEXT_170); if (isLog4jEnabled) { stringBuffer.append(TEXT_171); stringBuffer.append(cid); stringBuffer.append(TEXT_172); stringBuffer.append(cid); stringBuffer.append(TEXT_173); } stringBuffer.append(TEXT_174); stringBuffer.append(cid); stringBuffer.append(TEXT_175); stringBuffer.append(cid); stringBuffer.append(TEXT_176); if (isLog4jEnabled) { stringBuffer.append(TEXT_177); stringBuffer.append(cid); stringBuffer.append(TEXT_178); } stringBuffer.append(TEXT_179); stringBuffer.append(cid); stringBuffer.append(TEXT_180); stringBuffer.append(cid); stringBuffer.append(TEXT_181); stringBuffer.append(cid); stringBuffer.append(TEXT_182); stringBuffer.append(cid); stringBuffer.append(TEXT_183); stringBuffer.append(cid); stringBuffer.append(TEXT_184); if (isLog4jEnabled) { stringBuffer.append(TEXT_185); stringBuffer.append(cid); stringBuffer.append(TEXT_186); } stringBuffer.append(TEXT_187); stringBuffer.append(cid); stringBuffer.append(TEXT_188); stringBuffer.append(cid); stringBuffer.append(TEXT_189); stringBuffer.append(cid); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_195); stringBuffer.append(cid); stringBuffer.append(TEXT_196); stringBuffer.append(cid); stringBuffer.append(TEXT_197); stringBuffer.append(cid); stringBuffer.append(TEXT_198); stringBuffer.append(cid); stringBuffer.append(TEXT_199); stringBuffer.append(cid); stringBuffer.append(TEXT_200); stringBuffer.append(cid); stringBuffer.append(TEXT_201); stringBuffer.append(cid); stringBuffer.append(TEXT_202); List<? extends IConnection> conns = node.getOutgoingSortedConnections(); if (conns != null) { if (conns.size() > 0) { IConnection conn = conns.get(0); String connName = conn.getName(); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { String encoding = ElementParameterParser.getValue(node, "__ENCODING__"); String advancedSeparatorStr = ElementParameterParser.getValue(node, "__ADVANCED_SEPARATOR__"); boolean advancedSeparator = (advancedSeparatorStr != null && !("").equals(advancedSeparatorStr)) ? ("true").equals(advancedSeparatorStr) : false; String thousandsSeparator = ElementParameterParser.getValueWithJavaType( node, "__THOUSANDS_SEPARATOR__", JavaTypesManager.CHARACTER); String decimalSeparator = ElementParameterParser.getValueWithJavaType( node, "__DECIMAL_SEPARATOR__", JavaTypesManager.CHARACTER); List<IMetadataColumn> columns = metadata.getListColumns(); int nbColumns = columns.size(); for (int i = 0; i < nbColumns; i++) { IMetadataColumn column = columns.get(i); String columnName = column.getLabel(); 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_203); stringBuffer.append(cid); stringBuffer.append(TEXT_204); stringBuffer.append(cid); stringBuffer.append(TEXT_205); stringBuffer.append(i); stringBuffer.append(TEXT_206); stringBuffer.append(cid); stringBuffer.append(TEXT_207); stringBuffer.append(cid); stringBuffer.append(TEXT_208); stringBuffer.append(cid); stringBuffer.append(TEXT_209); if (javaType == JavaTypesManager.STRING) { stringBuffer.append(TEXT_210); stringBuffer.append(connName); stringBuffer.append(TEXT_211); stringBuffer.append(columnName); stringBuffer.append(TEXT_212); stringBuffer.append(cid); stringBuffer.append(TEXT_213); } else if (javaType == JavaTypesManager.OBJECT) { stringBuffer.append(TEXT_214); stringBuffer.append(connName); stringBuffer.append(TEXT_215); stringBuffer.append(columnName); stringBuffer.append(TEXT_216); stringBuffer.append(cid); stringBuffer.append(TEXT_217); } else if (javaType == JavaTypesManager.DATE) { stringBuffer.append(TEXT_218); stringBuffer.append(connName); stringBuffer.append(TEXT_219); stringBuffer.append(columnName); stringBuffer.append(TEXT_220); stringBuffer.append(cid); stringBuffer.append(TEXT_221); stringBuffer.append(patternValue); stringBuffer.append(TEXT_222); } else if (advancedSeparator && JavaTypesManager.isNumberType(javaType)) { stringBuffer.append(TEXT_223); stringBuffer.append(connName); stringBuffer.append(TEXT_224); stringBuffer.append(columnName); stringBuffer.append(TEXT_225); stringBuffer.append(typeToGenerate); stringBuffer.append(TEXT_226); stringBuffer.append(cid); stringBuffer.append(TEXT_227); stringBuffer.append(thousandsSeparator); stringBuffer.append(TEXT_228); stringBuffer.append(decimalSeparator); stringBuffer.append(TEXT_229); } else if (javaType == JavaTypesManager.BYTE_ARRAY) { stringBuffer.append(TEXT_230); stringBuffer.append(connName); stringBuffer.append(TEXT_231); stringBuffer.append(columnName); stringBuffer.append(TEXT_232); stringBuffer.append(cid); stringBuffer.append(TEXT_233); stringBuffer.append(encoding); stringBuffer.append(TEXT_234); } else { stringBuffer.append(TEXT_235); stringBuffer.append(connName); stringBuffer.append(TEXT_236); stringBuffer.append(columnName); stringBuffer.append(TEXT_237); stringBuffer.append(typeToGenerate); stringBuffer.append(TEXT_238); stringBuffer.append(cid); stringBuffer.append(TEXT_239); } stringBuffer.append(TEXT_240); stringBuffer.append(connName); stringBuffer.append(TEXT_241); stringBuffer.append(columnName); stringBuffer.append(TEXT_242); stringBuffer.append( JavaTypesManager.getDefaultValueFromJavaType( typeToGenerate, column.getDefault())); stringBuffer.append(TEXT_243); } log4jFileUtil.debugRetriveData(node); } } } } } stringBuffer.append(TEXT_244); 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); } } } }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); final BigDataCodeGeneratorArgument codeGenArgument = (BigDataCodeGeneratorArgument) argument; final INode node = (INode) codeGenArgument.getArgument(); final String cid = node.getUniqueName(); IMetadataTable metadata = null; IConnection conn = null; List<IMetadataColumn> columns = null; List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { metadata = metadatas.get(0); if (metadata != null) { columns = metadata.getListColumns(); } } List<? extends IConnection> conns = node.getIncomingConnections(); if (conns != null && conns.size() > 0 && conns.get(0).getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { conn = conns.get(0); } if (columns == null || columns.isEmpty() || conn == null) { return ""; } String inRowStruct = codeGenArgument.getRecordStructName(conn); String connName = conn.getName(); String nodes = ElementParameterParser.getValue(node, "__NODES__"); String index = ElementParameterParser.getValue(node, "__INDEX__"); String type = ElementParameterParser.getValue(node, "__TYPE__"); boolean jsonDoc = "JSON".equals(ElementParameterParser.getValue(node, "__DOC_TYPE__")); List<Map<String, String>> configuration = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__CONFIGURATION__"); List<Map<String, String>> docMetadatas = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__DOC_METADATA__"); Map<String, String> docMetadataMapping = new HashMap<String, String>(); org.talend.core.model.metadata.MetadataTable docColumnTable = new org.talend.core.model.metadata.MetadataTable(); // for non-metadata column List<IMetadataColumn> docColumnList = new ArrayList<IMetadataColumn>(); docColumnTable.setListColumns(docColumnList); for (Map<String, String> docMetadata : docMetadatas) { if ("true".equals(docMetadata.get("AS_META"))) { docMetadataMapping.put(docMetadata.get("SCHEMA_COLUMN"), docMetadata.get("TYPE")); } else { for (IMetadataColumn col : columns) { if (col.getLabel().equals(docMetadata.get("SCHEMA_COLUMN"))) { docColumnList.add(col); } } } } final boolean definedDocMetadata = docMetadataMapping.size() > 0; if (definedDocMetadata && !jsonDoc) { codeGenArgument .getRecordStructGenerator() .generateRecordStruct("doc_" + connName, docColumnTable); } if (definedDocMetadata) { stringBuffer.append(TEXT_1); stringBuffer.append(connName); stringBuffer.append(TEXT_2); stringBuffer.append(connName); stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); } else { if (jsonDoc) { stringBuffer.append(TEXT_5); stringBuffer.append(connName); stringBuffer.append(TEXT_6); stringBuffer.append(connName); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); } else { stringBuffer.append(TEXT_9); stringBuffer.append(inRowStruct); stringBuffer.append(TEXT_10); stringBuffer.append(connName); stringBuffer.append(TEXT_11); stringBuffer.append(connName); stringBuffer.append(TEXT_12); } } stringBuffer.append(TEXT_13); 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(cid); stringBuffer.append(TEXT_18); stringBuffer.append(connName); stringBuffer.append(TEXT_19); stringBuffer.append(TEXT_20); return stringBuffer.toString(); }
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(); 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(); }
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 processID = ElementParameterParser.getValue(node, "__PROCESS_ID__"); boolean dieOnError = ("true").equals(ElementParameterParser.getValue(node, "__DIE_ON_ERROR__")); stringBuffer.append(TEXT_2); List<? extends IConnection> conns = node.getIncomingConnections(); if (conns != null && conns.size() > 0 && conns.get(0) != null) { IConnection conn = conns.get(0); if (conn != null && conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { INode previousNode = conn.getSource(); if (previousNode != null) { List<IMetadataTable> metadatas = previousNode.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { List<IMetadataColumn> columns = metadata.getListColumns(); int sizeColumns = columns.size(); for (int i = 0; i < sizeColumns; i++) { stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append((columns.get(i)).getLabel()); stringBuffer.append(TEXT_5); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_6); stringBuffer.append((columns.get(i)).getLabel()); stringBuffer.append(TEXT_7); } } } } } } stringBuffer.append(TEXT_8); stringBuffer.append(cid); 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); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { List<? extends IConnection> conns_out = node.getOutgoingConnections(); for (IConnection conn : conns_out) { String connName = conn.getName(); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { List<IMetadataColumn> columns = metadata.getListColumns(); int sizeColumns = columns.size(); for (int i = 0; i < sizeColumns; i++) { if ("ProcessInstanceUUID".equals(columns.get(i).getLabel())) { stringBuffer.append(TEXT_15); stringBuffer.append(connName); stringBuffer.append(TEXT_16); stringBuffer.append((columns.get(i)).getLabel()); stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(TEXT_18); break; } } } } } } stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(cid); stringBuffer.append(TEXT_21); if (dieOnError) { stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); } else { stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); } 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(TEXT_30); 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(); 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) { IConnection outgoingConn = outgoingConns.get(0); if (outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { String authType = ElementParameterParser.getValue(node, "__AUTH_TYPE__"); boolean isAPI2011 = ("API_2011").equals(ElementParameterParser.getValue(node, "__API_VERSION__")); String discWSDL = ElementParameterParser.getValue(node, "__DISC_WSDL__"); if (!isAPI2011 || ("ON_PREMISE").equals(authType)) { 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(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); 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); } else { stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(cid); 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(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); 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 propagateRecordset = ElementParameterParser.getValue(node, "__PROPAGATE_RECORD_SET__"); String recordsetColumn = ElementParameterParser.getValue(node, "__RECORD_SET_COLUMN__"); String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"); String incomingConnName = null; 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); } } String dbquery = ElementParameterParser.getValue(node, "__QUERY__"); dbquery = dbquery.replaceAll("\n", " "); dbquery = dbquery.replaceAll("\r", " "); stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { List<? extends IConnection> conns = node.getIncomingConnections(); columnList = metadata.getListColumns(); if (conns != null && conns.size() > 0) { IConnection conn = conns.get(0); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { incomingConnName = conn.getName(); } } // end of connection size. } // end of metadatas } if (!hasOutgoingDataConnection || columnList == null || columnList.size() < 1) { propagateRecordset = "false"; } stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(dbquery); stringBuffer.append(TEXT_8); stringBuffer.append(cid); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); if (propagateRecordset.equals("true")) { stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); } stringBuffer.append(TEXT_13); if (propagateRecordset.equals("true")) { 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); } else { stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); } stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); if (dieOnError.equals("true")) { stringBuffer.append(TEXT_23); } else { if (rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) { stringBuffer.append(TEXT_24); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_25); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_26); if (incomingConnName != null) { for (IMetadataColumn column : columnList) { stringBuffer.append(TEXT_27); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_28); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_29); stringBuffer.append(incomingConnName); stringBuffer.append(TEXT_30); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_31); } } stringBuffer.append(TEXT_32); stringBuffer.append(rejectConnName); stringBuffer.append(TEXT_33); } else { stringBuffer.append(TEXT_34); } } stringBuffer.append(TEXT_35); if (outgoingConns != null && outgoingConns.size() > 0) { stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); for (IConnection outgoingConn : outgoingConns) { if (rejectConnName == null || (rejectConnName != null && !outgoingConn.getName().equals(rejectConnName))) { if (outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { stringBuffer.append(TEXT_38); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_39); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_40); for (IMetadataColumn column : columnList) { if (propagateRecordset.equals("true") && column.getLabel().equals(recordsetColumn)) { stringBuffer.append(TEXT_41); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_42); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); } else { if (incomingConnName != null) { stringBuffer.append(TEXT_45); stringBuffer.append(outgoingConn.getName()); stringBuffer.append(TEXT_46); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_47); stringBuffer.append(incomingConnName); stringBuffer.append(TEXT_48); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_49); } } } } } } stringBuffer.append(TEXT_50); } if (!useExistingConn.equals("true")) { if (!commitEvery.equals("") && !commitEvery.equals("0")) { stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); stringBuffer.append(cid); stringBuffer.append(TEXT_53); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); } } return stringBuffer.toString(); }
@Override public void execute() { propagatedChange.clear(); propagateDatas(true); if (currentInputMetadata != null) { if (!currentInputMetadata.sameMetadataAs(newInputMetadata, IMetadataColumn.OPTIONS_NONE)) { if (!currentInputMetadata.sameMetadataAs( newInputMetadata, IMetadataColumn.OPTIONS_IGNORE_USED)) { String type = (String) inputNode.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()); if (type != null) { if (type.equals(EmfComponent.REPOSITORY)) { inputWasRepository = true; inputNode.setPropertyValue( EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN); } } } MetadataToolHelper.copyTable(newInputMetadata, currentInputMetadata); } } if (!currentOutputMetadata.sameMetadataAs(newOutputMetadata, IMetadataColumn.OPTIONS_NONE)) { if (!currentOutputMetadata.sameMetadataAs( newOutputMetadata, IMetadataColumn.OPTIONS_IGNORE_USED)) { String type = (String) node.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()); if (type != null && type.equals(EmfComponent.REPOSITORY) && !repositoryMode) { // for one node has several schema_type,set mode for the current one if ((node.getElementParameter("SCHEMA_TYPE") .getContext() .equals(currentOutputMetadata.getAttachedConnector()))) { outputWasRepository = true; node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN); } } } MetadataToolHelper.copyTable(newOutputMetadata, currentOutputMetadata); } if (inputSchemaParam != null && inputSchemaParam.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()) != null && EmfComponent.REPOSITORY.equals( inputSchemaParam .getChildParameters() .get(EParameterName.SCHEMA_TYPE.getName()) .getValue())) { // add by wzhang to fix bug 7898. IElementParameter elementParameter = node.getElementParameter(EParameterName.MAPPING.getName()); if (elementParameter != null) { if (elementParameter.getValue() instanceof String) { String value = (String) elementParameter.getValue(); if (!isDBComponent(value)) { schemaParam .getChildParameters() .get(EParameterName.SCHEMA_TYPE.getName()) .setValue(EmfComponent.REPOSITORY); schemaParam .getChildParameters() .get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName()) .setValue( inputSchemaParam .getChildParameters() .get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName()) .getValue()); } } } } for (INodeConnector connector : node.getListConnector()) { if ((!connector.getName().equals(currentConnector)) && connector.getBaseSchema().equals(currentConnector)) { if (node.getComponent() != null && "tSalesforceOutput".equals(node.getComponent().getName()) && "REJECT".equals(connector.getName())) { IMetadataTable clone = newOutputMetadata.clone(true); Iterator<IMetadataColumn> iterator = clone.getListColumns().iterator(); while (iterator.hasNext()) { IMetadataColumn column = iterator.next(); if (column.isCustom()) { iterator.remove(); } } MetadataToolHelper.copyTable(clone, node.getMetadataFromConnector(connector.getName())); } else { // if there is some other schema dependant of this one, modify them MetadataToolHelper.copyTable( newOutputMetadata, node.getMetadataFromConnector(connector.getName())); } } } List<ColumnNameChanged> columnNameChanged = MetadataToolHelper.getColumnNameChanged(oldOutputMetadata, newOutputMetadata); ColumnListController.updateColumnList(node, columnNameChanged, true); if (inputNode != null) { List<ColumnNameChanged> inputColumnNameChangedExt = MetadataToolHelper.getColumnNameChangedExt(inputNode, oldInputMetadata, newInputMetadata); ColumnListController.updateColumnList(node, inputColumnNameChangedExt); } // List<ColumnNameChanged> outputColumnNameChangedExt = MetadataToolHelper.getColumnNameChangedExt(node, oldOutputMetadata, newOutputMetadata); syncOutputNodeColumnsList(outputColumnNameChangedExt); setXMLMAPPING(); if (!internal) { updateColumnList(oldOutputMetadata, newOutputMetadata); ((Process) node.getProcess()).checkProcess(); } refreshMetadataChanged(); }
private void propagateDatas(boolean isExecute) { String baseConnectorForCurrentNode = node.getConnectorFromName(currentConnector).getBaseSchema(); // Propagate : if (outputdataContainer != null && (!outputdataContainer.getInputs().isEmpty() || !outputdataContainer.getOuputs().isEmpty())) { for (IODataComponent currentIO : outputdataContainer.getInputs()) { INode sourceNode = currentIO.getSource(); if (currentIO.hasChanged() && (sourceNode .getConnectorFromName(currentIO.getConnection().getConnectorName()) .getBaseSchema() .equals(baseConnectorForCurrentNode))) { sourceNode.metadataOutputChanged(currentIO, currentIO.getName()); if (isExecute) { currentIO.setTable(oldInputMetadata); currentIO.setColumnNameChanged(null); } else { currentIO.setTable(newInputMetadata); currentIO.setColumnNameChanged(null); } } } for (IODataComponent currentIO : outputdataContainer.getOuputs()) { INodeConnector nodeConnector = null; String baseConnector = null; Node sourceNode = (Node) currentIO.getSource(); nodeConnector = sourceNode.getConnectorFromName(currentIO.getConnection().getConnectorName()); baseConnector = nodeConnector.getBaseSchema(); INode targetNode = currentIO.getTarget(); boolean sourceIsBuiltIn = ((Node) currentIO.getSource()) .getConnectorFromType(currentIO.getConnection().getLineStyle()) .isMultiSchema(); boolean targetIsBuiltIn = ((Node) targetNode) .getConnectorFromType(currentIO.getConnection().getLineStyle()) .isMultiSchema(); boolean isJoblet = ((Node) targetNode).isJoblet(); if (!isJoblet && baseConnector.equals(baseConnectorForCurrentNode) && (targetIsBuiltIn || (targetNode.getMetadataFromConnector(baseConnector) != null && !targetNode .getMetadataFromConnector(baseConnector) .sameMetadataAs(newOutputMetadata)))) { targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName()); if (isExecute) { if (targetNode instanceof Node) { if (((Node) targetNode).getComponent().isSchemaAutoPropagated() && getPropagate() && targetNode.getMetadataList().size() > 0) { IMetadataTable tmpClone; if (sourceIsBuiltIn) { IMetadataTable tab = node.getMetadataTable( currentIO.getConnection().getMetadataTable().getTableName()); if (tab == null && node.getJobletNode() != null) { tab = node.getJobletNode() .getMetadataTable( currentIO.getConnection().getMetadataTable().getTableName()); } tmpClone = tab.clone(true); } else { IMetadataTable tab = node.getMetadataFromConnector(currentIO.getConnection().getConnectorName()); if (tab == null && node.getJobletNode() != null) { tab = node.getJobletNode() .getMetadataFromConnector(currentIO.getConnection().getConnectorName()); } tmpClone = tab.clone(true); } IMetadataTable toCopy = newOutputMetadata.clone(); // wzhang modify to add feature 7611 String dbmsId = null; IMetadataTable copy; if (((Node) targetNode).getMetadataFromConnector(baseConnector) != null) { dbmsId = targetNode.getMetadataFromConnector(baseConnector).getDbms(); MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone); toCopy = tmpClone; // only if the target node have exactly the same connector copy = ((Node) targetNode).getMetadataFromConnector(baseConnector).clone(true); } else { final String mainConnector = "FLOW"; // can only be FLOW right now for this case. //$NON-NLS-1$ dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms(); MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone); toCopy = tmpClone; // if don't have the same connector, take the main connector of the component. copy = ((Node) targetNode).getMetadataFromConnector(mainConnector).clone(true); } // MetadataTool.copyTable(toCopy, copy); // wzhang modify to add feature 7611 MetadataToolHelper.copyTable(dbmsId, toCopy, copy); ChangeMetadataCommand cmd = new ChangeMetadataCommand(targetNode, null, null, copy, inputSchemaParam); if (outputdataContainer.getOuputs().size() > 0) { List<ColumnNameChanged> columnNameChanged = outputdataContainer.getOuputs().get(0).getColumnNameChanged(); for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) { dataComp.setColumnNameChanged(columnNameChanged); } } cmd.execute(true); propagatedChange.add(cmd); } } currentIO.setTable(oldOutputMetadata); currentIO.setColumnNameChanged(null); } else { if (targetNode instanceof Node) { if (!targetIsBuiltIn && getPropagate()) { if (((Node) targetNode).getComponent().isSchemaAutoPropagated()) { if (outputdataContainer.getOuputs().size() > 0) { List<ColumnNameChanged> columnNameChanged = outputdataContainer.getOuputs().get(0).getColumnNameChanged(); for (ChangeMetadataCommand cmd : propagatedChange) { for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) { dataComp.setColumnNameChanged(columnNameChanged); } } } } } } currentIO.setTable(newOutputMetadata); currentIO.setColumnNameChanged(null); } } } } else if (dataComponent != null) { for (IConnection outgoingConnection : node.getOutgoingConnections()) { if (outgoingConnection.getConnectorName().equals(currentConnector)) { outgoingConnection .getTarget() .metadataInputChanged(dataComponent, outgoingConnection.getName()); } } } else { if (!node.getOutgoingConnections().isEmpty()) { IMetadataTable relativeOldOutputMetadata = null; IMetadataTable relativeNewOutputMetadata = null; if (isExecute) { relativeOldOutputMetadata = oldOutputMetadata; relativeNewOutputMetadata = newOutputMetadata; } else { relativeOldOutputMetadata = newOutputMetadata; relativeNewOutputMetadata = oldOutputMetadata; } for (IConnection outgoingConnection : node.getOutgoingConnections()) { final Node target = (Node) outgoingConnection.getTarget(); if (target != null && target.getExternalNode() != null) { List<IMetadataColumn> oldListColumns = relativeOldOutputMetadata.getListColumns(); List<IMetadataColumn> newListColumns = relativeNewOutputMetadata.getListColumns(); List<ColumnNameChanged> columnNameChanges = new ArrayList<ColumnNameChanged>(); int size = oldListColumns.size(); int newSize = newListColumns.size(); if (newSize < size) { size = newSize; } IODataComponent output = new IODataComponent(outgoingConnection, relativeNewOutputMetadata); if (newListColumns != null) { List<ColumnNameChanged> newColumnsList = output.getNewMetadataColumns(); // new added columns list Set<String> newAddedColumns = new HashSet<String>(); // newest columns after user changed Set<String> newestColumns = new HashSet<String>(); // init if (newColumnsList != null) { for (ColumnNameChanged columnChanged : newColumnsList) { newAddedColumns.add(columnChanged.getNewName()); } } for (IMetadataColumn metadataColumn : newListColumns) { newestColumns.add(metadataColumn.getLabel()); } // check for (int i = 0; i < size; i++) { IMetadataColumn oldMetadataColumn = oldListColumns.get(i); String columnName = oldMetadataColumn.getLabel(); // if this column(before changing) is not exists in the new columns(after changing), // there are two possible truth: 1. this column has been renamed; 2. this column has // been removed if (!newestColumns.contains(columnName)) { IMetadataColumn newMetadataColumn = newListColumns.get(i); String newColumnNameAtThisIndex = newMetadataColumn.getLabel(); // if the column at the same position in new table is a new column(two possible // truth: 1. an old column's name has been changed; 2. user add a new column); // For now, Seems it is very hard to judge whether it is a renamed column or a new // column, so we suppose the more possible truth is that it is a renamed column if (newAddedColumns.contains(newColumnNameAtThisIndex)) { columnNameChanges.add( new ColumnNameChanged(columnName, newColumnNameAtThisIndex)); } } } } if (GlobalServiceRegister.getDefault().isServiceRegistered(IXmlMapService.class)) { final IXmlMapService service = (IXmlMapService) GlobalServiceRegister.getDefault().getService(IXmlMapService.class); if (service.isXmlMapComponent(target.getExternalNode())) { output.setColumnNameChanged(columnNameChanges); target.metadataInputChanged(output, outgoingConnection.getName()); } } if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkMapService.class)) { final ISparkMapService service = (ISparkMapService) GlobalServiceRegister.getDefault().getService(ISparkMapService.class); if (service.isSparkMapComponent(target.getExternalNode())) { output.setColumnNameChanged(columnNameChanges); target.metadataInputChanged(output, outgoingConnection.getName()); } } if (GlobalServiceRegister.getDefault().isServiceRegistered(IDbMapService.class)) { final IDbMapService service = (IDbMapService) GlobalServiceRegister.getDefault().getService(IDbMapService.class); if (service.isDbMapComponent(target.getExternalNode())) { // TDI-25307:should setColumNameChanged here for ELtDbMap in case the propagate // schema // does not affect it. output.setColumnNameChanged(columnNameChanges); target.metadataInputChanged(output, outgoingConnection.getName()); } } } } } } if (inputdataContainer != null) { for (IODataComponent currentIO : inputdataContainer.getOuputs()) { if (currentIO.hasChanged() && (currentIO .getSource() .getConnectorFromName(currentIO.getConnection().getConnectorName()) .getBaseSchema() .equals(currentConnector))) { INode targetNode = currentIO.getTarget(); targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName()); if (isExecute) { currentIO.setTable(oldInputMetadata); currentIO.setColumnNameChanged(null); } else { currentIO.setTable(newInputMetadata); currentIO.setColumnNameChanged(null); } } } } // End propagate }
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(); stringBuffer.append(TEXT_1); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String dbtable = null; String dbschema = ElementParameterParser.getValue(node, "__ELT_SCHEMA_NAME__"); String uniqueNameConnection = null; INode previousNode = null; String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__"); boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__")); stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); List<IConnection> connections = (List<IConnection>) node.getIncomingConnections(); if (connections != null && connections.size() > 0 && connections.get(0) != null) { IConnection connection = connections.get(0); previousNode = connection.getSource(); String previousComponentName = previousNode.getUniqueName(); dbtable = connection.getName(); uniqueNameConnection = connection.getUniqueName(); stringBuffer.append(TEXT_4); stringBuffer.append(previousComponentName); stringBuffer.append(TEXT_5); stringBuffer.append(uniqueNameConnection); stringBuffer.append(TEXT_6); } if ((dbschema != null) && (!"\"\"".equals(dbschema.replaceAll(" ", "").trim()))) { stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(dbschema); stringBuffer.append(TEXT_9); stringBuffer.append(useDifferentTable ? differenttable : "\"" + dbtable + "\""); stringBuffer.append(TEXT_10); } else { stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(useDifferentTable ? differenttable : "\"" + dbtable + "\""); stringBuffer.append(TEXT_13); } String dbtypeDefinition = ElementParameterParser.getValue(node, "__TYPE__"); String tableName = ElementParameterParser.getValue(node, "__TABLE__"); String dataAction = ElementParameterParser.getValue(node, "__DATA_ACTION__"); String dbhost = null; String dbport = null; String dbname = null; String dbuser = null; String dbpwd = null; String connectionType = null; boolean useExistingConn = false; String dbproperties = null; if (previousNode != null) { dbhost = ElementParameterParser.getValue(previousNode, "__HOST__"); dbport = ElementParameterParser.getValue(previousNode, "__PORT__"); dbname = ElementParameterParser.getValue(previousNode, "__DBNAME__"); dbuser = ElementParameterParser.getValue(previousNode, "__USER__"); dbpwd = ElementParameterParser.getValue(previousNode, "__PASS__"); connectionType = ElementParameterParser.getValue(previousNode, "__CONNECTION_TYPE__"); useExistingConn = ("true") .equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__")); dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__"); } // String tableAction = ElementParameterParser.getValue( // node, // "__TABLE_ACTION__" // ); String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__"); stringBuffer.append(TEXT_14); if (useExistingConn) { String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__"); String conn = "conn_" + connection; stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); stringBuffer.append(conn); stringBuffer.append(TEXT_17); } else { stringBuffer.append(TEXT_18); if (connectionType == null || ("ORACLE_SID").equals(connectionType)) { stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(dbhost); stringBuffer.append(TEXT_21); stringBuffer.append(dbport); stringBuffer.append(TEXT_22); stringBuffer.append(dbname); stringBuffer.append(TEXT_23); } else if (("ORACLE_SERVICE_NAME").equals(connectionType)) { stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); stringBuffer.append(dbhost); stringBuffer.append(TEXT_26); stringBuffer.append(dbport); stringBuffer.append(TEXT_27); stringBuffer.append(dbname); stringBuffer.append(TEXT_28); } else if ("ORACLE_RAC".equals(connectionType)) { String rac_url = ElementParameterParser.getValue(previousNode, "__RAC_URL__"); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(rac_url); stringBuffer.append(TEXT_31); } stringBuffer.append(TEXT_32); stringBuffer.append(cid); stringBuffer.append(TEXT_33); stringBuffer.append(dbuser); stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); stringBuffer.append(dbpwd); stringBuffer.append(TEXT_36); if (dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) { 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); stringBuffer.append(cid); stringBuffer.append(TEXT_41); } else { stringBuffer.append(TEXT_42); stringBuffer.append(cid); stringBuffer.append(TEXT_43); stringBuffer.append(dbproperties); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(cid); 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); stringBuffer.append(cid); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); } stringBuffer.append(TEXT_57); } stringBuffer.append(TEXT_58); List<IMetadataColumn> columnList = null; List<IMetadataTable> metadatas = node.getMetadataList(); if (metadatas != null && metadatas.size() > 0) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { columnList = metadata.getListColumns(); } } stringBuffer.append(TEXT_59); if (("INSERT_OR_UPDATE").equals(dataAction) || ("UPDATE_OR_INSERT").equals(dataAction)) { 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); } else { stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); } if (columnList != null && columnList.size() > 0) { class Column { IMetadataColumn column; String name; String sqlStmt; String value; String validateName; boolean addCol; List<Column> replacement = new ArrayList<Column>(); public Column(String colName, String sqlStmt, boolean addCol) { this.column = null; this.name = colName; this.sqlStmt = sqlStmt; this.value = "?"; this.addCol = addCol; this.validateName = MetadataToolHelper.validateValue(colName); } public Column(IMetadataColumn column) { this.column = column; this.name = column.getLabel(); this.sqlStmt = "=?"; this.value = "?"; this.addCol = false; this.validateName = MetadataToolHelper.validateValue(column.getLabel()); } public boolean isReplaced() { return replacement.size() > 0; } public void replace(Column column) { this.replacement.add(column); } public List<Column> getReplacement() { return this.replacement; } public void setColumn(IMetadataColumn column) { this.column = column; } public IMetadataColumn getColumn() { return this.column; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setIsAddCol(boolean isadd) { this.addCol = isadd; } public boolean isAddCol() { return this.addCol; } public void setSqlStmt(String sql) { this.sqlStmt = sql; } public String getSqlStmt() { return this.sqlStmt; } public void setValue(String value) { this.value = value; } public String getValue() { return this.value; } public String getValidateName() { return this.validateName; } } StringBuilder insertColName = new StringBuilder(); StringBuilder insertValueStmt = new StringBuilder(); StringBuilder updateSetStmt = new StringBuilder(); StringBuilder updateWhereStmt = new StringBuilder(); StringBuilder mergeCondition = new StringBuilder(); List<Column> stmtStructure = new LinkedList<Column>(); for (IMetadataColumn column : columnList) { stmtStructure.add(new Column(column)); } int counterOuter = 0; boolean firstKey = true; boolean firstNoneKey = true; boolean isfirstKey = true; for (Column colStmt : stmtStructure) { String colName = colStmt.getName(); if (!colName.equals(colStmt.getValidateName())) { colStmt.setName("\\\"" + colName + "\\\""); } String suffix = ","; if (colStmt.getColumn().isKey()) { if (isfirstKey) { isfirstKey = false; } else { mergeCondition.append(" AND "); } mergeCondition.append( "target." + colStmt.getColumn().getLabel() + "=source." + colStmt.getColumn().getLabel()); } if (colStmt.isReplaced()) { List<Column> replacedColumns = colStmt.getReplacement(); int counterReplace = 0; if (counterOuter == (stmtStructure.size() - 1) && counterReplace == (replacedColumns.size() - 1)) { suffix = ""; } for (Column replacement : replacedColumns) { insertColName.append(replacement.getName() + suffix); insertValueStmt.append(replacement.getSqlStmt() + suffix); if (!colStmt.getColumn().isKey()) { if (!firstNoneKey) { updateSetStmt.append(","); } else { firstNoneKey = false; } updateSetStmt.append(replacement.getName()); updateSetStmt.append(replacement.getSqlStmt()); } else { if (!firstKey) { updateWhereStmt.append(" AND "); } else { firstKey = false; } updateWhereStmt.append(replacement.getName()); updateWhereStmt.append(replacement.getSqlStmt()); } counterReplace++; } } else { if (counterOuter == (stmtStructure.size() - 1)) { suffix = ""; } if (colStmt.isAddCol()) { insertColName.append(colStmt.getName() + suffix); insertValueStmt.append(colStmt.getSqlStmt() + suffix); updateSetStmt.append(colStmt.getName()); updateSetStmt.append(colStmt.getSqlStmt() + suffix); } else { insertColName.append(colStmt.getName() + suffix); insertValueStmt.append(colStmt.getValue() + suffix); if (!colStmt.getColumn().isKey()) { if (!firstNoneKey) { updateSetStmt.append(","); } else { firstNoneKey = false; } updateSetStmt.append(colStmt.getName()); updateSetStmt.append(colStmt.getSqlStmt()); } else { if (!firstKey) { updateWhereStmt.append(" AND "); } else { firstKey = false; } updateWhereStmt.append(colStmt.getName()); updateWhereStmt.append(colStmt.getSqlStmt()); } } } counterOuter++; } ///// hint options///// boolean useHintOptions = ("true").equals(ElementParameterParser.getValue(node, "__USE_HINT_OPTIONS__")); Map<String, String> hintsValues = null; if (useHintOptions) { List<Map<String, String>> hintOptions = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__HINT_OPTIONS__"); hintsValues = new HashMap<String, String>(); String hintValue = null; boolean firstInsert = true; boolean firstUpdate = true; boolean firstDelete = true; boolean firstTableName = true; for (java.util.Map<String, String> option : hintOptions) { // get if (option.get("HINT").matches("\"/\\*NORMALIZED_HINT\\*/\"")) { String id = cid.replace(node.getComponent().getName() + "_", ""); hintValue = "\"/*\"+" + dbtable + "+\".\" + " + "\"" + option.get("SQL_STMT") + ".\"" + "+" + id + "+\"*/\" "; } else if (option.get("HINT").matches("\"/\\*+.*\\*/\"")) { hintValue = option.get("HINT"); } // set if ("INSERT".equalsIgnoreCase(option.get("SQL_STMT"))) { if (firstInsert) { hintsValues.put("INSERT", hintValue); firstInsert = false; } else { hintsValues.put("INSERT", hintsValues.get("INSERT") + "+" + hintValue); } } else if ("UPDATE".equalsIgnoreCase(option.get("SQL_STMT"))) { if (firstUpdate) { hintsValues.put("UPDATE", hintValue); firstUpdate = false; } else { hintsValues.put("UPDATE", hintsValues.get("UPDATE") + "+" + hintValue); } } else if ("DELETE".equalsIgnoreCase(option.get("SQL_STMT"))) { if (firstDelete) { hintsValues.put("DELETE", hintValue); firstDelete = false; } else { hintsValues.put("DELETE", hintsValues.get("DELETE") + "+" + hintValue); } } else if ("TABLE_NAME".equalsIgnoreCase(option.get("SQL_STMT"))) { if (firstTableName) { hintsValues.put("TABLE_NAME", hintValue); firstTableName = false; } else { hintsValues.put("TABLE_NAME", hintsValues.get("TABLE_NAME") + "+" + hintValue); } } } } //// hint options end //// if (("INSERT").equals(dataAction)) { stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(insertColName.toString()); stringBuffer.append(TEXT_68); if (useHintOptions && hintsValues.get("INSERT") != null) { stringBuffer.append(TEXT_69); stringBuffer.append(cid); stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); stringBuffer.append(hintsValues.get("INSERT")); stringBuffer.append(TEXT_72); stringBuffer.append(cid); stringBuffer.append(TEXT_73); } stringBuffer.append(TEXT_74); stringBuffer.append(cid); stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); } else if (("UPDATE").equals(dataAction)) { stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); stringBuffer.append(insertColName.toString()); stringBuffer.append(TEXT_79); if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) { stringBuffer.append(TEXT_80); stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause)); } stringBuffer.append(TEXT_81); if (useHintOptions && hintsValues.get("UPDATE") != null) { stringBuffer.append(TEXT_82); stringBuffer.append(cid); stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(hintsValues.get("UPDATE")); stringBuffer.append(TEXT_85); stringBuffer.append(cid); stringBuffer.append(TEXT_86); } stringBuffer.append(TEXT_87); stringBuffer.append(cid); stringBuffer.append(TEXT_88); stringBuffer.append(cid); stringBuffer.append(TEXT_89); } else if (("INSERT_OR_UPDATE").equals(dataAction)) { stringBuffer.append(TEXT_90); stringBuffer.append(cid); stringBuffer.append(TEXT_91); stringBuffer.append(insertColName.toString()); stringBuffer.append(TEXT_92); stringBuffer.append(cid); stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); stringBuffer.append(cid); stringBuffer.append(TEXT_95); stringBuffer.append(insertColName.toString()); stringBuffer.append(TEXT_96); if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) { stringBuffer.append(TEXT_97); stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause)); } stringBuffer.append(TEXT_98); stringBuffer.append(cid); stringBuffer.append(TEXT_99); stringBuffer.append(cid); stringBuffer.append(TEXT_100); } else if (("UPDATE_OR_INSERT").equals(dataAction)) { stringBuffer.append(TEXT_101); stringBuffer.append(cid); stringBuffer.append(TEXT_102); stringBuffer.append(insertColName.toString()); stringBuffer.append(TEXT_103); if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) { stringBuffer.append(TEXT_104); stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause)); } 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(insertColName.toString()); stringBuffer.append(TEXT_109); stringBuffer.append(cid); stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); } else if (("DELETE").equals(dataAction)) { stringBuffer.append(TEXT_112); stringBuffer.append(cid); stringBuffer.append(TEXT_113); if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) { stringBuffer.append(TEXT_114); stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause)); } stringBuffer.append(TEXT_115); if (useHintOptions && hintsValues.get("DELETE") != null) { stringBuffer.append(TEXT_116); stringBuffer.append(cid); stringBuffer.append(TEXT_117); stringBuffer.append(cid); stringBuffer.append(TEXT_118); stringBuffer.append(hintsValues.get("DELETE")); stringBuffer.append(TEXT_119); stringBuffer.append(cid); stringBuffer.append(TEXT_120); } stringBuffer.append(TEXT_121); stringBuffer.append(cid); stringBuffer.append(TEXT_122); stringBuffer.append(cid); stringBuffer.append(TEXT_123); } else if ("MERGE".equals(dataAction)) { // get parameter boolean useMergeUpdate = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__USE_MERGE_UPDATE__")); boolean useMergeInsert = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__USE_MERGE_INSERT__")); boolean useUpdateWhere = "true" .equalsIgnoreCase( ElementParameterParser.getValue(node, "__USE_MERGE_UPDATE_WHERE__")); boolean useUpdateDeleteWhere = "true" .equalsIgnoreCase( ElementParameterParser.getValue(node, "__USE_MERGE_UPDATE_DELETE_WHERE__")); boolean useInsertWhere = "true" .equalsIgnoreCase( ElementParameterParser.getValue(node, "__USE_MERGE_INSERT_WHERE__")); List<Map<String, String>> updateColumns = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SCHEMA_UPDATE__"); List<Map<String, String>> insertColumns = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SCHEMA_INSERT__"); StringBuilder mergeUpdate = new StringBuilder(); StringBuilder mergeInsertName = new StringBuilder(); StringBuilder mergeInsertValue = new StringBuilder(); stringBuffer.append(TEXT_124); stringBuffer.append(cid); stringBuffer.append(TEXT_125); stringBuffer.append(mergeCondition); stringBuffer.append(TEXT_126); if (!useMergeUpdate) useUpdateWhere = false; if (useMergeUpdate) { boolean isfirstUpdateSet = true; String keyColumnName = null; for (Map<String, String> keyColumn : updateColumns) { if (keyColumn.get("UPDATE").equals("true")) { if (isfirstUpdateSet) { isfirstUpdateSet = false; } else { mergeUpdate.append(","); } keyColumnName = keyColumn.get("SCHEMA_COLUMN"); if (!(keyColumnName != null && keyColumnName.equals(MetadataToolHelper.validateValue(keyColumnName)))) { keyColumnName = "\\\"" + keyColumnName + "\\\""; } mergeUpdate.append("target." + keyColumnName + "=source." + keyColumnName); } } stringBuffer.append(TEXT_127); stringBuffer.append(mergeUpdate); stringBuffer.append(TEXT_128); if (useUpdateWhere) { String useUpdateWhereString = ElementParameterParser.getValue(node, "__MERGE_UPDATE_WHERE_STRING__"); if (useUpdateWhereString == null || useUpdateWhereString.length() == 0) { stringBuffer.append(TEXT_129); } else { stringBuffer.append(TEXT_130); stringBuffer.append(useUpdateWhereString); stringBuffer.append(TEXT_131); } } stringBuffer.append(TEXT_132); if (useUpdateDeleteWhere) { String useUpdateDeleteWhereString = ElementParameterParser.getValue(node, "__MERGE_UPDATE_DELETE_WHERE_STRING__"); if (useUpdateDeleteWhereString == null || useUpdateDeleteWhereString.length() == 0) { stringBuffer.append(TEXT_133); } else { stringBuffer.append(TEXT_134); stringBuffer.append(useUpdateDeleteWhereString); stringBuffer.append(TEXT_135); } } stringBuffer.append(TEXT_136); } stringBuffer.append(TEXT_137); if (!useMergeInsert) useInsertWhere = false; if (useMergeInsert) { boolean isfirstInsertWhere = true; String keyColumnName = null; for (Map<String, String> keyColumn : insertColumns) { if (isfirstInsertWhere) { isfirstInsertWhere = false; } else { mergeInsertName.append(","); mergeInsertValue.append(","); } if (keyColumn.get("INSERT").equals("true")) { keyColumnName = keyColumn.get("SCHEMA_COLUMN"); if (!(keyColumnName != null && keyColumnName.equals(MetadataToolHelper.validateValue(keyColumnName)))) { keyColumnName = "\\\"" + keyColumnName + "\\\""; } mergeInsertName.append(keyColumnName); mergeInsertValue.append("source." + keyColumnName); } } stringBuffer.append(TEXT_138); stringBuffer.append(mergeInsertName); stringBuffer.append(TEXT_139); stringBuffer.append(mergeInsertValue); stringBuffer.append(TEXT_140); } if (useInsertWhere) { String useInsertWhereString = ElementParameterParser.getValue(node, "__MERGE_INSERT_WHERE_STRING__"); if (useInsertWhereString == null || useInsertWhereString.length() == 0) { stringBuffer.append(TEXT_141); } else { stringBuffer.append(TEXT_142); stringBuffer.append(useInsertWhereString); stringBuffer.append(TEXT_143); } } stringBuffer.append(TEXT_144); stringBuffer.append(cid); stringBuffer.append(TEXT_145); stringBuffer.append(cid); stringBuffer.append(TEXT_146); } 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); } // MAIN String incomingConnName = null; columnList = null; List<? extends IConnection> conns = node.getIncomingConnections(); if (conns != null && conns.size() > 0) { IConnection conn = conns.get(0); incomingConnName = conn.getName(); } metadatas = node.getMetadataList(); if (metadatas != null && metadatas.size() > 0) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { columnList = metadata.getListColumns(); } } if (incomingConnName != null && columnList != null) { if (("INSERT").equals(dataAction)) { 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); } else if (("UPDATE").equals(dataAction)) { 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); } else if (("INSERT_OR_UPDATE").equals(dataAction)) { stringBuffer.append(TEXT_160); stringBuffer.append(cid); 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(cid); stringBuffer.append(TEXT_165); stringBuffer.append(cid); stringBuffer.append(TEXT_166); } else if (("UPDATE_OR_INSERT").equals(dataAction)) { stringBuffer.append(TEXT_167); stringBuffer.append(cid); stringBuffer.append(TEXT_168); stringBuffer.append(cid); stringBuffer.append(TEXT_169); stringBuffer.append(cid); stringBuffer.append(TEXT_170); stringBuffer.append(cid); stringBuffer.append(TEXT_171); stringBuffer.append(cid); stringBuffer.append(TEXT_172); stringBuffer.append(cid); stringBuffer.append(TEXT_173); } else if (("DELETE").equals(dataAction)) { 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); } else if (("MERGE").equals(dataAction)) { stringBuffer.append(TEXT_178); stringBuffer.append(cid); stringBuffer.append(TEXT_179); } } // END if (("INSERT_OR_UPDATE").equals(dataAction) || ("UPDATE_OR_INSERT").equals(dataAction)) { stringBuffer.append(TEXT_180); stringBuffer.append(cid); stringBuffer.append(TEXT_181); stringBuffer.append(cid); stringBuffer.append(TEXT_182); stringBuffer.append(cid); stringBuffer.append(TEXT_183); stringBuffer.append(cid); stringBuffer.append(TEXT_184); } else { stringBuffer.append(TEXT_185); stringBuffer.append(cid); stringBuffer.append(TEXT_186); } stringBuffer.append(TEXT_187); if (!useExistingConn) { stringBuffer.append(TEXT_188); stringBuffer.append(cid); stringBuffer.append(TEXT_189); stringBuffer.append(cid); stringBuffer.append(TEXT_190); stringBuffer.append(cid); stringBuffer.append(TEXT_191); } stringBuffer.append(TEXT_192); stringBuffer.append(cid); stringBuffer.append(TEXT_193); stringBuffer.append(cid); stringBuffer.append(TEXT_194); stringBuffer.append(cid); stringBuffer.append(TEXT_195); stringBuffer.append(cid); stringBuffer.append(TEXT_196); stringBuffer.append(cid); stringBuffer.append(TEXT_197); stringBuffer.append(cid); stringBuffer.append(TEXT_198); stringBuffer.append(cid); stringBuffer.append(TEXT_199); stringBuffer.append(cid); stringBuffer.append(TEXT_200); stringBuffer.append(TEXT_201); 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(); 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(); 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(); }
@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(); 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(); String dbtable = null; String dbschema = ElementParameterParser.getValue(node, "__ELT_SCHEMA_NAME__"); String uniqueNameConnection = null; INode previousNode = null; String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__"); boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__")); stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); List<IConnection> connections = (List<IConnection>) node.getIncomingConnections(); if (connections != null && connections.size() > 0 && connections.get(0) != null) { IConnection connection = connections.get(0); previousNode = connection.getSource(); String previousComponentName = previousNode.getUniqueName(); dbtable = connection.getName(); uniqueNameConnection = connection.getUniqueName(); stringBuffer.append(TEXT_4); stringBuffer.append(previousComponentName); stringBuffer.append(TEXT_5); stringBuffer.append(uniqueNameConnection); stringBuffer.append(TEXT_6); stringBuffer.append(previousComponentName); stringBuffer.append(TEXT_7); stringBuffer.append(uniqueNameConnection); stringBuffer.append(TEXT_8); } stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(dbschema); 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(dbschema); stringBuffer.append(TEXT_15); stringBuffer.append(useDifferentTable ? differenttable : "\"" + dbtable + "\""); stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); stringBuffer.append(useDifferentTable ? differenttable : "\"" + dbtable + "\""); stringBuffer.append(TEXT_18); String dataAction = ElementParameterParser.getValue(node, "__DATA_ACTION__"); String dbhost = null; String dbport = null; String dbname = null; String dbuser = null; String dbpwd = null; boolean useExistingConn = false; if (previousNode != null) { dbhost = ElementParameterParser.getValue(previousNode, "__HOST__"); dbport = ElementParameterParser.getValue(previousNode, "__PORT__"); dbname = ElementParameterParser.getValue(previousNode, "__DBNAME__"); dbuser = ElementParameterParser.getValue(previousNode, "__USER__"); dbpwd = ElementParameterParser.getValue(previousNode, "__PASS__"); useExistingConn = ("true") .equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__")); } String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__"); stringBuffer.append(TEXT_19); if (useExistingConn) { String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__"); String conn = "conn_" + connection; stringBuffer.append(TEXT_20); stringBuffer.append(cid); stringBuffer.append(TEXT_21); stringBuffer.append(conn); stringBuffer.append(TEXT_22); } else { stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(dbhost); stringBuffer.append(TEXT_25); stringBuffer.append(dbport); stringBuffer.append(TEXT_26); stringBuffer.append(dbname); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(dbuser); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(dbpwd); 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(cid); stringBuffer.append(TEXT_35); } List<IMetadataColumn> columnList = null; List<IMetadataTable> metadatas = node.getMetadataList(); if (metadatas != null && metadatas.size() > 0) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { columnList = metadata.getListColumns(); } } stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); if (columnList != null && columnList.size() > 0) { class Column { IMetadataColumn column; String name; String sqlStmt; String value; boolean addCol; List<Column> replacement = new ArrayList<Column>(); public Column(IMetadataColumn column) { this.column = column; String columname = column.getOriginalDbColumnName(); if (columname != null && columname.trim().length() > 0) { this.name = columname; } else { this.name = column.getLabel(); } this.sqlStmt = "=?"; this.value = "?"; this.addCol = false; } public boolean isReplaced() { return replacement.size() > 0; } public List<Column> getReplacement() { return this.replacement; } public IMetadataColumn getColumn() { return this.column; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public boolean isAddCol() { return this.addCol; } public String getSqlStmt() { return this.sqlStmt; } public String getValue() { return this.value; } } StringBuilder insertColName = new StringBuilder(); StringBuilder insertValueStmt = new StringBuilder(); StringBuilder updateSetStmt = new StringBuilder(); StringBuilder updateWhereStmt = new StringBuilder(); List<Column> stmtStructure = new LinkedList<Column>(); for (IMetadataColumn column : columnList) { stmtStructure.add(new Column(column)); } int counterOuter = 0; boolean firstKey = true; boolean firstNoneKey = true; boolean isfirstKey = true; for (Column colStmt : stmtStructure) { String suffix = ","; String colName = "\\\"" + colStmt.getName() + "\\\""; colStmt.setName(colName); if (colStmt.getColumn().isKey()) { if (isfirstKey) { isfirstKey = false; } } if (colStmt.isReplaced()) { List<Column> replacedColumns = colStmt.getReplacement(); int counterReplace = 0; if (counterOuter == (stmtStructure.size() - 1) && counterReplace == (replacedColumns.size() - 1)) { suffix = ""; } for (Column replacement : replacedColumns) { insertColName.append(replacement.getName() + suffix); insertValueStmt.append(replacement.getSqlStmt() + suffix); if (!colStmt.getColumn().isKey()) { if (!firstNoneKey) { updateSetStmt.append(","); } else { firstNoneKey = false; } updateSetStmt.append(replacement.getName()); updateSetStmt.append(replacement.getSqlStmt()); } else { if (!firstKey) { updateWhereStmt.append(" AND "); } else { firstKey = false; } updateWhereStmt.append(replacement.getName()); updateWhereStmt.append(replacement.getSqlStmt()); } counterReplace++; } } else { if (counterOuter == (stmtStructure.size() - 1)) { suffix = ""; } if (colStmt.isAddCol()) { insertColName.append(colStmt.getName() + suffix); insertValueStmt.append(colStmt.getSqlStmt() + suffix); updateSetStmt.append(colStmt.getName()); updateSetStmt.append(colStmt.getSqlStmt() + suffix); } else { insertColName.append(colStmt.getName() + suffix); insertValueStmt.append(colStmt.getValue() + suffix); if (!colStmt.getColumn().isKey()) { updateSetStmt.append( colStmt.getName() + "=\"+selectQueryColumnsName.split(\",\")[ " + counterOuter + "]+\"" + suffix); } } } counterOuter++; } if (("INSERT").equals(dataAction)) { stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append(insertColName.toString()); stringBuffer.append(TEXT_40); stringBuffer.append(cid); stringBuffer.append(TEXT_41); stringBuffer.append(cid); stringBuffer.append(TEXT_42); } else if (("UPDATE").equals(dataAction)) { stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append(updateSetStmt.toString()); stringBuffer.append(TEXT_45); if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) { stringBuffer.append(TEXT_46); stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause)); stringBuffer.append(TEXT_47); } stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); } else if (("DELETE").equals(dataAction)) { stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) { stringBuffer.append(TEXT_53); stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause)); stringBuffer.append(TEXT_54); } stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); } 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); } if (dbtable != null && columnList != null) { if (("INSERT").equals(dataAction)) { 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); } else if (("UPDATE").equals(dataAction)) { 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); } else if (("DELETE").equals(dataAction)) { 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(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); if (!useExistingConn) { 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(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); stringBuffer.append(cid); stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(cid); 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); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_93); stringBuffer.append(TEXT_94); 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(); 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(); }