public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String dllLoad = ElementParameterParser.getValue(node, "__LIBRARY__"); String clazz = ElementParameterParser.getValue(node, "__CLASS_NAME__"); List<Map<String, String>> values = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__PARAMETERS__"); String call = "org.talend.net.Object.createInstance(" + dllLoad + "," + clazz + ")"; if (values.size() > 0) { call = "org.talend.net.Object.createInstance(" + dllLoad + "," + clazz + ",parameterList_" + cid + ")"; stringBuffer.append(TEXT_1); stringBuffer.append(cid); stringBuffer.append(TEXT_2); for (int i = 0; i < values.size(); i++) { Map<String, String> line = values.get(i); stringBuffer.append(TEXT_3); stringBuffer.append(line.get("PARAMETER")); if (i < values.size() - 1) { stringBuffer.append(TEXT_4); } } stringBuffer.append(TEXT_5); } stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(call); stringBuffer.append(TEXT_8); stringBuffer.append(cid); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); 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 previous_node = ""; String start_node = ""; boolean inMain = true; boolean isExecutedThroughWebHCat = false; String previousOutputConnectionName = ""; if (node.getIncomingConnections() != null && node.getIncomingConnections().size() > 0) { IConnection connection = node.getIncomingConnections().get(0); previous_node = connection.getSource().getUniqueName(); INode loadNode = node.getDesignSubjobStartNode(); start_node = loadNode.getUniqueName(); boolean isLocal = "true".equals(ElementParameterParser.getValue(loadNode, "__LOCAL__")); isExecutedThroughWebHCat = !isLocal && "MICROSOFT_HD_INSIGHT" .equals(ElementParameterParser.getValue(loadNode, "__DISTRIBUTION__")); inMain = loadNode.isSubtreeStart(); previousOutputConnectionName = connection.getName(); } String outputConnectionName = ""; List<IConnection> outputConnections = (List<IConnection>) node.getOutgoingConnections(); if (outputConnections != null && outputConnections.size() > 0) { outputConnectionName = outputConnections.get(0).getName(); } List<Map<String, String>> configs = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__FILTER_CONFIG__"); boolean useAdvancedFilter = "true".equals(ElementParameterParser.getValue(node, "__USE_ADVANCED_FILTER__")); String advancedFilter = ElementParameterParser.getValue(node, "__ADVANCED_FILTER__"); stringBuffer.append(TEXT_2); stringBuffer.append(TEXT_3); // 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_4); stringBuffer.append(label); stringBuffer.append(TEXT_5); } } public void retrievedDataNumberInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_6); stringBuffer.append(label); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); } } public void retrievedDataNumberInfoFromGlobalMap(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_9); stringBuffer.append(label); stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); } } // for all tFileinput* components public void retrievedDataNumberInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_12); stringBuffer.append(label); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); } } public void writeDataFinishInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_15); stringBuffer.append(label); stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); } } // TODO delete it and remove all log4jSb parameter from components public void componentStartInfo(INode node) { if (isLog4jEnabled) { stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); } } // TODO rename or delete it public void debugRetriveData(INode node, boolean hasIncreased) { if (isLog4jEnabled) { stringBuffer.append(TEXT_20); stringBuffer.append(label); stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(hasIncreased ? "" : "+1"); stringBuffer.append(TEXT_22); } } // 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_23); stringBuffer.append(label); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); } } public void logCurrentRowNumberInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_26); stringBuffer.append(label); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); } } public void logDataCountInfo() { if (isLog4jEnabled) { stringBuffer.append(TEXT_29); stringBuffer.append(label); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); } } } final DefaultLog4jFileUtil log4jFileUtil = new DefaultLog4jFileUtil( (INode) (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument) .getArgument())); log4jFileUtil.componentStartInfo(node); final boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__")); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(outputConnectionName); stringBuffer.append(TEXT_37); stringBuffer.append(previous_node); stringBuffer.append(TEXT_38); stringBuffer.append(previousOutputConnectionName); stringBuffer.append(TEXT_39); if (!useAdvancedFilter) { boolean isFirst = true; String operator = ""; for (Map<String, String> configMap : configs) { if (!isFirst) { stringBuffer.append(TEXT_40); stringBuffer.append(cid); stringBuffer.append(TEXT_41); stringBuffer.append(configMap.get("LOGICAL")); stringBuffer.append(TEXT_42); } isFirst = false; if ("EQUAL".equals(configMap.get("OPERATOR"))) { operator = "=="; } else if ("NEQUAL".equals(configMap.get("OPERATOR"))) { operator = "!="; } else if ("GREATER".equals(configMap.get("OPERATOR"))) { operator = ">"; } else if ("GREATER_EQUAL".equals(configMap.get("OPERATOR"))) { operator = ">="; } else if ("LESS".equals(configMap.get("OPERATOR"))) { operator = "<"; } else if ("LESS_EQUAL".equals(configMap.get("OPERATOR"))) { operator = "<="; } else if ("MATCH".equals(configMap.get("OPERATOR"))) { operator = "matches"; } stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append("true".equals(configMap.get("NOT")) ? "NOT " : ""); stringBuffer.append(TEXT_45); stringBuffer.append(configMap.get("COLUMN_NAME")); stringBuffer.append(TEXT_46); stringBuffer.append(operator); stringBuffer.append(TEXT_47); stringBuffer.append(configMap.get("VALUE")); stringBuffer.append(TEXT_48); } } else { stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); stringBuffer.append(advancedFilter); stringBuffer.append(TEXT_51); } 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(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); if (inMain) { 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); if (isLog4jEnabled) { 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(TEXT_68); stringBuffer.append(cid); stringBuffer.append(TEXT_69); if (isExecutedThroughWebHCat) { stringBuffer.append(TEXT_70); stringBuffer.append(start_node); stringBuffer.append(TEXT_71); stringBuffer.append(cid); stringBuffer.append(TEXT_72); } else { stringBuffer.append(TEXT_73); stringBuffer.append(start_node); stringBuffer.append(TEXT_74); stringBuffer.append(cid); stringBuffer.append(TEXT_75); } stringBuffer.append(TEXT_76); stringBuffer.append(cid); stringBuffer.append(TEXT_77); if (isExecutedThroughWebHCat) { stringBuffer.append(TEXT_78); stringBuffer.append(start_node); stringBuffer.append(TEXT_79); stringBuffer.append(start_node); stringBuffer.append(TEXT_80); stringBuffer.append(cid); stringBuffer.append(TEXT_81); stringBuffer.append(start_node); stringBuffer.append(TEXT_82); stringBuffer.append(cid); stringBuffer.append(TEXT_83); } else { stringBuffer.append(TEXT_84); stringBuffer.append(start_node); stringBuffer.append(TEXT_85); stringBuffer.append(cid); stringBuffer.append(TEXT_86); } stringBuffer.append(TEXT_87); stringBuffer.append(cid); stringBuffer.append(TEXT_88); if (isExecutedThroughWebHCat) { stringBuffer.append(TEXT_89); stringBuffer.append(start_node); stringBuffer.append(TEXT_90); stringBuffer.append(cid); stringBuffer.append(TEXT_91); } else { stringBuffer.append(TEXT_92); stringBuffer.append(start_node); stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); } stringBuffer.append(TEXT_95); stringBuffer.append(cid); stringBuffer.append(TEXT_96); if (isExecutedThroughWebHCat) { stringBuffer.append(TEXT_97); stringBuffer.append(start_node); stringBuffer.append(TEXT_98); stringBuffer.append(cid); stringBuffer.append(TEXT_99); stringBuffer.append(cid); stringBuffer.append(TEXT_100); } else { stringBuffer.append(TEXT_101); stringBuffer.append(start_node); stringBuffer.append(TEXT_102); stringBuffer.append(cid); stringBuffer.append(TEXT_103); stringBuffer.append(cid); stringBuffer.append(TEXT_104); } stringBuffer.append(TEXT_105); } else { stringBuffer.append(TEXT_106); stringBuffer.append(start_node); stringBuffer.append(TEXT_107); stringBuffer.append(cid); stringBuffer.append(TEXT_108); } stringBuffer.append(TEXT_109); stringBuffer.append(cid); stringBuffer.append(TEXT_110); stringBuffer.append(TEXT_111); 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 dbhost = ElementParameterParser.getValue(node, "__HOST__"); String dbname = ElementParameterParser.getValue(node, "__DATABASE__"); String dbuser = ElementParameterParser.getValue(node, "__USERNAME__"); String dbpass = ElementParameterParser.getValue(node, "__PASSWORD__"); boolean authentication = "true" .equalsIgnoreCase(ElementParameterParser.getValue(node, "__REQUIRED_AUTHENTICATION__")); if (!authentication) { dbuser = null; dbpass = null; } String passwordFieldName = "__PASSWORD__"; stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); if (!authentication) { // do nothing } else if (ElementParameterParser.canEncrypt(node, passwordFieldName)) { stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName)); stringBuffer.append(TEXT_6); } else { stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName)); stringBuffer.append(TEXT_9); } boolean useTriggerReplicate = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__USE_TRIGGER_REPLICATE__")); String dbport = ElementParameterParser.getValue(node, "__PORT__"); List<Map<String, String>> replicaTargetDB = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__REPLICATE_TARGET_DB__"); boolean useExistingConn = "true" .equalsIgnoreCase(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__")); 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(cid); stringBuffer.append(TEXT_18); if (useExistingConn) { INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection); dbname = ElementParameterParser.getValue(connectionNode, "__DATABASE__"); stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(connection); stringBuffer.append(TEXT_21); if (isLog4jEnabled) { stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(connection); stringBuffer.append(TEXT_25); } } else { stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(dbname); stringBuffer.append(TEXT_28); stringBuffer.append(dbhost); stringBuffer.append(TEXT_29); stringBuffer.append(dbport); stringBuffer.append(TEXT_30); stringBuffer.append(dbuser); stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); if (useTriggerReplicate) { stringBuffer.append(TEXT_33); stringBuffer.append(cid); stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); int index = 0; for (Map<String, String> targetDB : replicaTargetDB) { String targetDBName = targetDB.get("TARGET_DB_NAME"); boolean isCreateTargetDB = "true".equalsIgnoreCase(targetDB.get("CREATE_TARGET")); boolean isContinuous = "true".equalsIgnoreCase(targetDB.get("CONTINUOUS")); boolean isCancel = "true".equalsIgnoreCase(targetDB.get("CANCEL_REPLICATE")); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); stringBuffer.append(cid); stringBuffer.append(TEXT_38); stringBuffer.append(dbname); stringBuffer.append(TEXT_39); stringBuffer.append(targetDBName); stringBuffer.append(TEXT_40); stringBuffer.append(isCreateTargetDB); stringBuffer.append(TEXT_41); stringBuffer.append(isContinuous); stringBuffer.append(TEXT_42); if (isContinuous && isCancel) { stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(index); stringBuffer.append(TEXT_46); stringBuffer.append(cid); stringBuffer.append(TEXT_47); stringBuffer.append(dbname); stringBuffer.append(TEXT_48); stringBuffer.append(targetDBName); stringBuffer.append(TEXT_49); stringBuffer.append(isCreateTargetDB); stringBuffer.append(TEXT_50); stringBuffer.append(isContinuous); stringBuffer.append(TEXT_51); stringBuffer.append(isCancel); stringBuffer.append(TEXT_52); stringBuffer.append(cid); stringBuffer.append(TEXT_53); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(index); stringBuffer.append(TEXT_55); index++; } } } } if (isLog4jEnabled) { stringBuffer.append(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); stringBuffer.append(dbname); stringBuffer.append(TEXT_58); } 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 projectName = codeGenArgument.getCurrentProjectName(); String processName = node.getProcess().getName(); // String endpoint = ElementParameterParser.getValue(node, "__ENDPOINT__"); String wsdlLocation = ElementParameterParser.getValue(node, "__WSDL_LOCATION__"); String serviceNS = ElementParameterParser.getValue(node, "__SERVICE_NS__"); String serviceName = ElementParameterParser.getValue(node, "__SERVICE_NAME__"); String portNS = ElementParameterParser.getValue(node, "__PORT_NS__"); String portName = ElementParameterParser.getValue(node, "__PORT_NAME__"); String methodTemp = ElementParameterParser.getValue(node, "__METHOD__"); String method = methodTemp.indexOf("(") != -1 ? methodTemp.substring(0, methodTemp.indexOf("(")) : methodTemp; Boolean useAuth = Boolean.valueOf(ElementParameterParser.getValue(node, "__NEED_AUTH__")); String authType = ElementParameterParser.getValue(node, "__AUTH_TYPE__"); String username = ElementParameterParser.getValue(node, "__AUTH_USERNAME__"); String password = ElementParameterParser.getValue(node, "__AUTH_PASSWORD__"); 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); Boolean useSl = Boolean.valueOf(ElementParameterParser.getValue(node, "__SERVICE_LOCATOR__")); if (useSl) { List<Map<String, String>> customProperties = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SERVICE_LOCATOR_CUSTOM_PROPERTIES__"); for (int k = 0; k < customProperties.size(); k++) { stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(customProperties.get(k).get("PROP_NAME")); stringBuffer.append(TEXT_9); stringBuffer.append(customProperties.get(k).get("PROP_VALUE")); stringBuffer.append(TEXT_10); } } stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(wsdlLocation); stringBuffer.append(TEXT_13); stringBuffer.append(portNS); stringBuffer.append(TEXT_14); stringBuffer.append(portName); stringBuffer.append(TEXT_15); stringBuffer.append(serviceNS); stringBuffer.append(TEXT_16); stringBuffer.append(serviceName); stringBuffer.append(TEXT_17); stringBuffer.append(method); stringBuffer.append(TEXT_18); stringBuffer.append(ElementParameterParser.getValue(node, "__SOAP_ACTION__")); stringBuffer.append(TEXT_19); stringBuffer.append(ElementParameterParser.getValue(node, "__ESB_ENDPOINT__")); stringBuffer.append(TEXT_20); stringBuffer.append(ElementParameterParser.getValue(node, "__COMMUNICATION_STYLE__")); stringBuffer.append(TEXT_21); stringBuffer.append(useSl); stringBuffer.append(TEXT_22); if (useSl) { stringBuffer.append(TEXT_23); stringBuffer.append(ElementParameterParser.getValue(node, "__SERVICE_LOCATOR_STRATEGY__")); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); } stringBuffer.append(TEXT_26); stringBuffer.append( Boolean.valueOf(ElementParameterParser.getValue(node, "__SERVICE_ACTIVITY_MONITOR__"))); stringBuffer.append(TEXT_27); if (useAuth) { stringBuffer.append(TEXT_28); stringBuffer.append(authType); stringBuffer.append(TEXT_29); stringBuffer.append(username); stringBuffer.append(TEXT_30); stringBuffer.append(password); stringBuffer.append(TEXT_31); } stringBuffer.append(TEXT_32); stringBuffer.append(projectName); stringBuffer.append(TEXT_33); stringBuffer.append(processName); stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); String connTimeoutStr = ElementParameterParser.getValue(node, "__CONNECTION_TIMEOUT__"); String connTimeoutSec = (connTimeoutStr != null && !("").equals(connTimeoutStr)) ? connTimeoutStr : "20"; long connTimeout = (long) (Double.valueOf(connTimeoutSec) * 1000); String receiveTimeoutStr = ElementParameterParser.getValue(node, "__RECEIVE_TIMEOUT__"); String receiveTimeoutSec = (receiveTimeoutStr != null && !("").equals(receiveTimeoutStr)) ? receiveTimeoutStr : "20"; long receiveTimeout = (long) (Double.valueOf(receiveTimeoutSec) * 1000); String tempPath = ElementParameterParser.getValue(node, "__TMPPATH__"); if ("".equals(tempPath)) { tempPath = "\"\""; } stringBuffer.append(TEXT_36); stringBuffer.append(serviceName); stringBuffer.append(TEXT_37); stringBuffer.append(portName); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_42); stringBuffer.append(cid); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append(cid); stringBuffer.append(TEXT_45); stringBuffer.append(cid); stringBuffer.append(TEXT_46); stringBuffer.append(connTimeout); stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(receiveTimeout); 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 ("true".equals(ElementParameterParser.getValue(node, "__NEED_SSL_TO_TRUSTSERVER__"))) { stringBuffer.append(TEXT_53); stringBuffer.append(ElementParameterParser.getValue(node, "__SSL_TRUSTSERVER_TRUSTSTORE__")); stringBuffer.append(TEXT_54); stringBuffer.append(ElementParameterParser.getValue(node, "__SSL_TRUSTSERVER_PASSWORD__")); stringBuffer.append(TEXT_55); } if (useAuth && ("BASIC".equals(authType) || "TOKEN".equals(authType))) { stringBuffer.append(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); stringBuffer.append(username); stringBuffer.append(TEXT_58); stringBuffer.append(cid); stringBuffer.append(TEXT_59); stringBuffer.append(password); stringBuffer.append(TEXT_60); if ("BASIC".equals(authType)) { stringBuffer.append(TEXT_61); stringBuffer.append(cid); stringBuffer.append(TEXT_62); } stringBuffer.append(TEXT_63); if ("TOKEN".equals(authType)) { stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); } } if ("true".equals(ElementParameterParser.getValue(node, "__USE_PROXY__"))) { stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(ElementParameterParser.getValue(node, "__PROXY_HOST__")); stringBuffer.append(TEXT_68); stringBuffer.append(cid); stringBuffer.append(TEXT_69); stringBuffer.append(ElementParameterParser.getValue(node, "__PROXY_PORT__")); stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); stringBuffer.append(ElementParameterParser.getValue(node, "__PROXY_USERNAME__")); stringBuffer.append(TEXT_72); stringBuffer.append(cid); stringBuffer.append(TEXT_73); stringBuffer.append(ElementParameterParser.getValue(node, "__PROXY_PASSWORD__")); stringBuffer.append(TEXT_74); } stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); stringBuffer.append(wsdlLocation); 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(wsdlLocation); stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); stringBuffer.append(tempPath); stringBuffer.append(TEXT_83); stringBuffer.append(cid); stringBuffer.append(TEXT_84); stringBuffer.append(wsdlLocation); stringBuffer.append(TEXT_85); stringBuffer.append(tempPath); 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(serviceNS); stringBuffer.append(TEXT_91); stringBuffer.append(serviceName); stringBuffer.append(TEXT_92); stringBuffer.append(cid); stringBuffer.append(TEXT_93); stringBuffer.append(portNS); stringBuffer.append(TEXT_94); stringBuffer.append(portName); stringBuffer.append(TEXT_95); stringBuffer.append(TEXT_96); return stringBuffer.toString(); }
public void createURL(INode node) { super.createURL(node); String connectionMode = ElementParameterParser.getValue(node, "__CONNECTION_MODE__"); String hiveVersion = ElementParameterParser.getValue(node, "__HIVE_VERSION__"); String fsDefalutName = "fs.default.name"; String hiveServer = ElementParameterParser.getValue(node, "__HIVE_SERVER__"); boolean setMapredJT = "true".equals(ElementParameterParser.getValue(node, "__SET_MAPRED_JT__")); boolean setNamenode = "true".equals(ElementParameterParser.getValue(node, "__SET_FS_DEFAULT_NAME__")); List<Map<String, String>> hadoopProps = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__HADOOP_ADVANCED_PROPERTIES__"); boolean isCustom = "CUSTOM".equals(ElementParameterParser.getValue(node, "__DISTRIBUTION__")); boolean useYarn = "true".equals(ElementParameterParser.getValue(node, "__USE_YARN__")); boolean useKrb = "true".equals(ElementParameterParser.getValue(node, "__USE_KRB__")); boolean cdh4CanBeSecured = "Cloudera_CDH4".equals(hiveVersion) && (("HIVE".equalsIgnoreCase(hiveServer) && "EMBEDDED".equalsIgnoreCase(connectionMode)) || "HIVE2".equalsIgnoreCase(hiveServer)); boolean securityIsEnabled = useKrb && (isCustom || ("HDP_1_0".equals(hiveVersion) || "HDP_1_2".equals(hiveVersion) || "HDP_1_3".equals(hiveVersion) || cdh4CanBeSecured)); boolean securedStandaloneHive2 = securityIsEnabled && "HIVE2".equalsIgnoreCase(hiveServer) && "STANDALONE".equalsIgnoreCase(connectionMode); boolean securedEmbedded = securityIsEnabled && "EMBEDDED".equalsIgnoreCase(connectionMode); String hivePrincipal = ElementParameterParser.getValue(node, "__HIVE_PRINCIPAL__"); if (hiveServer != null && !"".equals(hiveServer.trim()) && (isCustom || ("HDP_1_2".equals(hiveVersion) || "HDP_1_3".equals(hiveVersion) || "Cloudera_CDH4".equals(hiveVersion) || "Cloudera_CDH4_YARN".equals(hiveVersion) || "MAPR213".equals(hiveVersion) || "MAPR301".equals(hiveVersion) || "HDP_2_0".equals(hiveVersion)))) { hiveServer = hiveServer.toLowerCase(); if ("hive2".equals(hiveServer)) { javaDbDriver = "org.apache.hive.jdbc.HiveDriver"; } } else { hiveServer = "hive"; } if (!isCustom && (("HDP_1_0".equals(hiveVersion) && "STANDALONE".equals(connectionMode)) || ("HDP_1_2".equals(hiveVersion) && "STANDALONE".equals(connectionMode) && "HIVE".equalsIgnoreCase(hiveServer)) || ("HDP_1_3".equals(hiveVersion) && "STANDALONE".equals(connectionMode) && "HIVE".equalsIgnoreCase(hiveServer)) || ("HDP_2_0".equals(hiveVersion) && "STANDALONE".equals(connectionMode) && "HIVE".equalsIgnoreCase(hiveServer)) || ("APACHE_0_20_203".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)) || ("MAPR1".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)) || ("MapR_EMR".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)) || ("Cloudera_CDH3".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)))) { stringBuffer.append(TEXT_25); } if (hadoopProps.size() > 0) { for (Map<String, String> item : hadoopProps) { stringBuffer.append(TEXT_26); stringBuffer.append(item.get("PROPERTY")); stringBuffer.append(TEXT_27); stringBuffer.append(item.get("VALUE")); stringBuffer.append(TEXT_28); } } if (securedEmbedded) { String metastoreUrl = ElementParameterParser.getValue(node, "__METASTORE_JDBC_URL__"); String driverClass = ElementParameterParser.getValue(node, "__METASTORE_CLASSNAME__"); String metastoreUsername = ElementParameterParser.getValue(node, "__METASTORE_USERNAME__"); String metastorePassword = ElementParameterParser.getValue(node, "__METASTORE_PASSWORD__"); boolean useKeytab = "true".equals(ElementParameterParser.getValue(node, "__USE_KEYTAB__")); String userPrincipal = ElementParameterParser.getValue(node, "__PRINCIPAL__"); String keytabPath = ElementParameterParser.getValue(node, "__KEYTAB_PATH__"); stringBuffer.append(TEXT_29); stringBuffer.append(driverClass); stringBuffer.append(TEXT_30); stringBuffer.append(metastoreUrl); stringBuffer.append(TEXT_31); stringBuffer.append(metastoreUsername); stringBuffer.append(TEXT_32); stringBuffer.append(metastorePassword); stringBuffer.append(TEXT_33); stringBuffer.append(hivePrincipal); stringBuffer.append(TEXT_34); if (useKeytab) { stringBuffer.append(TEXT_35); stringBuffer.append(userPrincipal); stringBuffer.append(TEXT_36); stringBuffer.append(keytabPath); stringBuffer.append(TEXT_37); } } if (((isCustom && !useYarn) || (!isCustom && !"PIVOTAL_HD_1_0_1".equals(hiveVersion) && !"HDP_2_0".equals(hiveVersion) && !"Cloudera_CDH4_YARN".equals(hiveVersion))) && setMapredJT) { String mapredJT = ElementParameterParser.getValue(node, "__MAPRED_JT__"); stringBuffer.append(TEXT_38); stringBuffer.append(mapredJT); stringBuffer.append(TEXT_39); } if (setNamenode) { String namenode = ElementParameterParser.getValue(node, "__FS_DEFAULT_NAME__"); stringBuffer.append(TEXT_40); stringBuffer.append(fsDefalutName); stringBuffer.append(TEXT_41); stringBuffer.append(namenode); stringBuffer.append(TEXT_42); } stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); if ("EMBEDDED".equals(connectionMode)) { stringBuffer.append(TEXT_45); stringBuffer.append(dbhost); stringBuffer.append(TEXT_46); stringBuffer.append(dbport); stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(hiveServer); stringBuffer.append(TEXT_49); if (isCustom || (!isCustom && ("HDP_1_0,HDP_1_2,HDP_1_3,HDP_2_0,Cloudera_CDH4,Cloudera_CDH4_YARN,PIVOTAL_HD_1_0_1" .contains(hiveVersion)))) { String dbuser = ElementParameterParser.getValue(node, "__USER__"); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(dbuser); 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(cid); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); } } else { if (securedStandaloneHive2) { stringBuffer.append(TEXT_59); stringBuffer.append(cid); stringBuffer.append(TEXT_60); stringBuffer.append(hiveServer); stringBuffer.append(TEXT_61); stringBuffer.append(dbhost); stringBuffer.append(TEXT_62); stringBuffer.append(dbport); stringBuffer.append(TEXT_63); stringBuffer.append(dbname); stringBuffer.append(TEXT_64); stringBuffer.append(hivePrincipal); stringBuffer.append(TEXT_65); } else { stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(hiveServer); stringBuffer.append(TEXT_68); stringBuffer.append(dbhost); stringBuffer.append(TEXT_69); stringBuffer.append(dbport); stringBuffer.append(TEXT_70); stringBuffer.append(dbname); stringBuffer.append(TEXT_71); } } }
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(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String connUrl = ElementParameterParser.getValue(node, "__DBNAME__"); String query = ElementParameterParser.getValue(node, "__QUERY__"); query = query.replaceAll("\n", ""); query = query.replaceAll("\r", ""); String encoding = ElementParameterParser.getValue(node, "__ENCODING__"); String assemblyName = ElementParameterParser.getValue(node, "__ASSEMBLY_NAME__"); String className = ElementParameterParser.getValue(node, "__CLASS_NAME__"); boolean whetherTrimAllCol = ("true").equals(ElementParameterParser.getValue(node, "__TRIM_ALL_COLUMN__")); List<Map<String, String>> trimColumnList = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__TRIM_COLUMN__"); List<IMetadataTable> metadatas = node.getMetadataList(); stringBuffer.append(TEXT_1); stringBuffer.append(cid); stringBuffer.append(TEXT_2); stringBuffer.append(assemblyName); stringBuffer.append(TEXT_3); stringBuffer.append(className); stringBuffer.append(TEXT_4); stringBuffer.append(TEXT_5); stringBuffer.append(connUrl); stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(assemblyName); stringBuffer.append(TEXT_9); stringBuffer.append(TEXT_10); stringBuffer.append(query); stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); IMetadataTable metadata = metadatas.get(0); List<? extends IConnection> connsout = node.getOutgoingConnections(); String connName = null; if (node.getIncomingConnections().size() == 1) { IConnection conn = node.getIncomingConnections().get(0); connName = conn.getName(); } List<IMetadataColumn> columnsout = metadata.getListColumns(); String populateOutput = ""; String outName = null; if (connsout != null) { for (int i = 0; i < connsout.size(); i++) { IConnection connout = connsout.get(i); if (connout.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { outName = connout.getName(); for (int j = 0; j < columnsout.size(); j++) { IMetadataColumn columnout = columnsout.get(j); stringBuffer.append(TEXT_15); stringBuffer.append(columnout.getTalendType()); stringBuffer.append(TEXT_16); stringBuffer.append(columnout.getLabel()); stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(columnout.getLabel()); stringBuffer.append(TEXT_20); populateOutput += "val_" + cid + " = reader_" + cid + ".invokeGeneric(\"GetValue\"," + "new java.lang.Object[] { id" + columnout.getLabel() + "_" + cid + " });\nnew TypeConverter_" + cid + "().doConversion(val_" + cid + "," + connout.getName() + ",\"" + columnout.getLabel() + "\");\n"; if (columnout.getTalendType().equals("id_String")) { boolean whetherTrimCol = false; if ((trimColumnList != null && trimColumnList.size() > 0) && !whetherTrimAllCol) { for (Map<String, String> trimColumn : trimColumnList) { if (columnout.getLabel().equals(trimColumn.get("SCHEMA_COLUMN"))) { if (("true").equals(trimColumn.get("TRIM"))) { whetherTrimCol = true; break; } } } } if (whetherTrimAllCol || whetherTrimCol) { populateOutput += connout.getName() + "." + columnout.getLabel() + " = " + connout.getName() + "." + columnout.getLabel() + ".trim();\n"; } } } } } } stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); stringBuffer.append(TEXT_32); stringBuffer.append(populateOutput); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); 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(); 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(); stringBuffer.append(TEXT_1); stringBuffer.append(TEXT_2); 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_3); stringBuffer.append(level.substring(0, 1).toUpperCase() + level.substring(1)); stringBuffer.append(TEXT_4); } stringBuffer.append(TEXT_5); stringBuffer.append(level); stringBuffer.append(TEXT_6); stringBuffer.append(logID); stringBuffer.append(TEXT_7); for (String message : messages) { stringBuffer.append(TEXT_8); stringBuffer.append(message); stringBuffer.append(TEXT_9); } stringBuffer.append(TEXT_10); } } 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_11); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_12); stringBuffer.append(TEXT_13); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_14); 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_15); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_16); stringBuffer.append(name); stringBuffer.append(TEXT_17); stringBuffer.append(password); stringBuffer.append(TEXT_18); } else { String value = org.talend.core.model.utils.NodeUtil.getNormalizeParameterValue(node, ep); stringBuffer.append(TEXT_19); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_20); stringBuffer.append(name); stringBuffer.append(TEXT_21); stringBuffer.append(value); stringBuffer.append(TEXT_22); } stringBuffer.append(TEXT_23); stringBuffer.append(var("log4jParamters")); stringBuffer.append(TEXT_24); } } 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_25); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_26); 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_27); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_28); stringBuffer.append(rowStruct); stringBuffer.append(TEXT_29); stringBuffer.append(columnName); stringBuffer.append(TEXT_30); } else { stringBuffer.append(TEXT_31); stringBuffer.append(rowStruct); stringBuffer.append(TEXT_32); stringBuffer.append(columnName); stringBuffer.append(TEXT_33); stringBuffer.append(TEXT_34); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_35); stringBuffer.append(TEXT_36); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_37); stringBuffer.append(rowStruct); stringBuffer.append(TEXT_38); stringBuffer.append(columnName); stringBuffer.append(TEXT_39); } stringBuffer.append(TEXT_40); stringBuffer.append(var("log4jSb")); stringBuffer.append(TEXT_41); } } 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; stringBuffer.append(TEXT_42); class DBConnLogUtil extends BasicLogUtil { private DBConnLogUtil() {} protected DBConnLogUtil(org.talend.core.model.process.INode node) { super(node); } public void logJDBCDriver(String driverClass) { debug(str("Driver ClassName: "), driverClass, str(".")); } public void connTry(String url, String dbUser) { if (dbUser != null) { info( str("Connection attempts to '"), url, str("' with the username '"), dbUser, str("'.")); } else { info(str("Connection attempts to '"), url, str("'.")); } } public void connDone(String url) { info(str("Connection to '"), url, str("' has succeeded.")); } public void useExistConn(String url, String dbUser) { if (dbUser != null) { info( str("Uses an existing connection with username '"), dbUser, str("'. Connection URL: "), url, str(".")); } else { info(str("Uses an existing connection. Connection URL: "), url, str(".")); } } public void closeTry(String connCompID) { if (connCompID == null) { info(str("Closing the connection to the database.")); } else { info(str("Closing the connection "), connCompID, str(" to the database.")); } } public void closeDone(String connCompID) { if (connCompID == null) { info(str("Connection to the database has closed.")); } else { info(str("Connection "), connCompID, str(" to the database has closed.")); } } } class DBTableActionLogUtil extends BasicLogUtil { private DBTableActionLogUtil() {} protected DBTableActionLogUtil(org.talend.core.model.process.INode node) { super(node); } public void dropTry(String tableName) { tableActionTry(tableName, str("Dropping")); } public void dropDone(String tableName) { tableActionDone(tableName, str("Drop")); } public void createTry(String tableName) { tableActionTry(tableName, str("Creating")); } public void createDone(String tableName) { tableActionDone(tableName, str("Create")); } public void clearTry(String tableName) { tableActionTry(tableName, str("Clearing")); } public void clearDone(String tableName) { tableActionDone(tableName, str("Clear")); } public void truncateTry(String tableName) { tableActionTry(tableName, str("Truncating")); } public void truncateDone(String tableName) { tableActionDone(tableName, str("Truncate")); } public void truncateReuseStorageTry(String tableName) { tableActionTry(tableName, str("Truncating reuse storage")); } public void truncateReuseStorageDone(String tableName) { tableActionDone(tableName, str("Truncate reuse stroage")); } private void tableActionTry(String tableName, String action) { info(action, str(" table '"), tableName, str("'.")); } private void tableActionDone(String tableName, String action) { info(action, str(" table '"), tableName, str("' has succeeded.")); } } class DBCommitLogUtil extends BasicLogUtil { private DBCommitLogUtil() {} protected DBCommitLogUtil(org.talend.core.model.process.INode node) { super(node); } public void logAutoCommit(String autoCommit) { debug(str("Connection is set auto commit to '"), autoCommit, str("'.")); } public void commitTry(String connCompID, String commitCount) { if (commitCount == null && connCompID == null) { debug(str("Connection starting to commit.")); } else if (commitCount == null) { debug(str("Connection "), connCompID, str(" starting to commit.")); } else if (connCompID == null) { debug(str("Connection starting to commit "), commitCount, str(" record(s).")); } else { debug( str("Connection "), connCompID, str(" starting to commit "), commitCount, str(" record(s).")); } } public void commitDone(String connCompID) { if (connCompID == null) { debug(str("Connection commit has succeeded.")); } else { debug(str("Connection "), connCompID, (" commit has succeeded.")); } } } class DBBatchLogUtil extends BasicLogUtil { private DBBatchLogUtil() {} protected DBBatchLogUtil(org.talend.core.model.process.INode node) { super(node); } public void executeTry(String action) { debug(str("Executing the "), action, str(" batch.")); } public void executeDone(String action) { debug(str("The "), action, str(" batch execution has succeeded.")); } } class DBDataActionLogUtil extends BasicLogUtil { private DBDataActionLogUtil() {} protected DBDataActionLogUtil(org.talend.core.model.process.INode node) { super(node); } public void inserting(String nbline) { sqlAction(nbline, str("Inserting")); } public void deleting(String nbline) { sqlAction(nbline, str("Deleting")); } public void updating(String nbline) { sqlAction(nbline, str("Updating")); } public void replacing(String nbline) { sqlAction(nbline, str("Replacing")); } public void insertingOnDuplicateKeyUpdating(String nbline) { sqlAction(nbline, str("Inserting on duplicate key updating")); } public void insertingIgnore(String nbline) { sqlAction(nbline, str("Inserting ignore")); } private void sqlAction(String nbline, String action) { if (nbline == null) { debug(action, str(" the record.")); } else { debug(action, str(" the record "), nbline, str(".")); } } public void sqlExecuteTry(String sql) { debug(str("Executing '"), sql, str("'.")); } public void sqlExecuteDone(String sql) { debug(str("Execute '"), sql, str("' has succeeded.")); } public void addingToBatch(String nbline, String batchAction) { debug(str("Adding the record "), nbline, str(" to the "), batchAction, str(" batch.")); } } class DBStateLogUtil extends BasicLogUtil { private DBStateLogUtil() {} protected DBStateLogUtil(org.talend.core.model.process.INode node) { super(node); } public void logInsertedLines(String nbline) { logFinishedLines(nbline, str("inserted")); } public void logUpdatedLines(String nbline) { logFinishedLines(nbline, str("updated")); } public void logDeletedLines(String nbline) { logFinishedLines(nbline, str("deleted")); } public void logRejectedLines(String nbline) { logFinishedLines(nbline, str("rejected")); } private void logFinishedLines(String nbline, String action) { info(str("Has "), action, str(" "), nbline, str(" record(s).")); } } class DBLogUtil extends LogUtil { DBConnLogUtil conn = null; DBTableActionLogUtil table = null; DBCommitLogUtil commit = null; DBBatchLogUtil batch = null; DBDataActionLogUtil data = null; DBStateLogUtil state = null; private DBLogUtil() {} protected DBLogUtil(org.talend.core.model.process.INode node) { super(node); conn = new DBConnLogUtil(node); table = new DBTableActionLogUtil(node); commit = new DBCommitLogUtil(node); batch = new DBBatchLogUtil(node); data = new DBDataActionLogUtil(node); state = new DBStateLogUtil(node); } public DBConnLogUtil conn() { return conn; } public DBTableActionLogUtil table() { return table; } public DBCommitLogUtil commit() { return commit; } public DBBatchLogUtil batch() { return batch; } public DBDataActionLogUtil data() { return data; } public DBStateLogUtil state() { return state; } } DBLogUtil dbLog = null; CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); dbLog = new DBLogUtil(node); String dbhost = ElementParameterParser.getValue(node, "__HOST__"); String dbport = ElementParameterParser.getValue(node, "__PORT__"); String dbname = ElementParameterParser.getValue(node, "__DBNAME__"); String dbuser = ElementParameterParser.getValue(node, "__USER__"); String spName = ElementParameterParser.getValue(node, "__SP_NAME__"); boolean isFunction = ("true").equals(ElementParameterParser.getValue(node, "__IS_FUNCTION__")); List<Map<String, String>> spArgs = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SP_ARGS__"); stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"); if (("true").equals(useExistingConn)) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); String conn = "conn_" + connection; stringBuffer.append(TEXT_45); stringBuffer.append(cid); stringBuffer.append(TEXT_46); stringBuffer.append(conn); stringBuffer.append(TEXT_47); INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection); boolean specify_alias = "true" .equals( ElementParameterParser.getValue(connectionNode, "__SPECIFY_DATASOURCE_ALIAS__")); if (specify_alias) { String alias = ElementParameterParser.getValue(connectionNode, "__DATASOURCE_ALIAS__"); String autoCommit = "true".equals(ElementParameterParser.getValue(connectionNode, "__AUTO_COMMIT__")) ? "true" : "false"; 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((null != alias && !("".equals(alias))) ? alias : "\"\""); stringBuffer.append(TEXT_53); } dbLog .conn() .useExistConn( "connection_" + cid + ".getMetaData().getURL()", "connection_" + cid + ".getMetaData().getUserName()"); } else { boolean specify_alias = "true".equals(ElementParameterParser.getValue(node, "__SPECIFY_DATASOURCE_ALIAS__")); if (specify_alias) { String alias = ElementParameterParser.getValue(node, "__DATASOURCE_ALIAS__"); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_58); stringBuffer.append((null != alias && !("".equals(alias))) ? alias : "\"\""); stringBuffer.append(TEXT_59); } String dbproperties = ElementParameterParser.getValue(node, "__PROPERTIES__"); if (dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) { stringBuffer.append(TEXT_60); stringBuffer.append(cid); stringBuffer.append(TEXT_61); stringBuffer.append(dbhost); stringBuffer.append(TEXT_62); stringBuffer.append(dbport); stringBuffer.append(TEXT_63); stringBuffer.append(dbname); stringBuffer.append(TEXT_64); } else { stringBuffer.append(TEXT_65); stringBuffer.append(cid); stringBuffer.append(TEXT_66); stringBuffer.append(dbhost); stringBuffer.append(TEXT_67); stringBuffer.append(dbport); stringBuffer.append(TEXT_68); stringBuffer.append(dbname); stringBuffer.append(TEXT_69); stringBuffer.append(dbproperties); stringBuffer.append(TEXT_70); } stringBuffer.append(TEXT_71); dbLog.conn().logJDBCDriver(dbLog.str("com.ibm.db2.jcc.DB2Driver")); String passwordFieldName = "__PASS__"; stringBuffer.append(TEXT_72); if (ElementParameterParser.canEncrypt(node, passwordFieldName)) { stringBuffer.append(TEXT_73); stringBuffer.append(cid); stringBuffer.append(TEXT_74); stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName)); stringBuffer.append(TEXT_75); } else { stringBuffer.append(TEXT_76); stringBuffer.append(cid); stringBuffer.append(TEXT_77); stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName)); stringBuffer.append(TEXT_78); } dbLog.conn().connTry(dbLog.var("url"), dbuser); stringBuffer.append(TEXT_79); stringBuffer.append(cid); stringBuffer.append(TEXT_80); stringBuffer.append(cid); stringBuffer.append(TEXT_81); stringBuffer.append(dbuser); stringBuffer.append(TEXT_82); stringBuffer.append(cid); stringBuffer.append(TEXT_83); dbLog.conn().connDone(dbLog.var("url")); if (specify_alias) { stringBuffer.append(TEXT_84); } } dbLog.commit().logAutoCommit("connection_" + cid + ".getAutoCommit()"); stringBuffer.append(TEXT_85); stringBuffer.append(cid); stringBuffer.append(TEXT_86); stringBuffer.append(cid); stringBuffer.append(TEXT_87); stringBuffer.append(isFunction ? "? = " : ""); stringBuffer.append(TEXT_88); stringBuffer.append(spName); stringBuffer.append(TEXT_89); boolean isFirstArg = true; for (int i = 0; i < spArgs.size(); i++) { if (!("RECORDSET").equals(spArgs.get(i).get("TYPE"))) { if (isFirstArg) { stringBuffer.append(TEXT_90); isFirstArg = false; } else { stringBuffer.append(TEXT_91); } } } stringBuffer.append(TEXT_92); stringBuffer.append(cid); stringBuffer.append(TEXT_93); stringBuffer.append(cid); stringBuffer.append(TEXT_94); stringBuffer.append(TEXT_95); 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<Map<String, String>> filelist = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__FILELIST__"); stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"); if (("true").equals(useExistingConn)) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); String conn = "conn_" + connection; stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); stringBuffer.append(conn); stringBuffer.append(TEXT_7); } else { stringBuffer.append(TEXT_8); String host = ElementParameterParser.getValue(node, "__HOST__"); String port = ElementParameterParser.getValue(node, "__PORT__"); String user = ElementParameterParser.getValue(node, "__USERNAME__"); String authMethod = ElementParameterParser.getValue(node, "__AUTH_METHOD__"); String privatekey = ElementParameterParser.getValue(node, "__PRIVATEKEY__"); String password = ElementParameterParser.getValue(node, "__PASSWORD__"); String passphrase = ElementParameterParser.getValue(node, "__PASSPHRASE__"); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(host); stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(user); stringBuffer.append(TEXT_13); if (("").equals(port)) { stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); } else { stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(port); stringBuffer.append(TEXT_20); } stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); if (("PUBLICKEY").equals(authMethod)) { stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(privatekey); 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(passphrase); stringBuffer.append(TEXT_30); stringBuffer.append(cid); stringBuffer.append(TEXT_31); } if (("PASSWORD").equals(authMethod)) { 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); stringBuffer.append(password); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); } if (("KEYBOARDINTERACTIVE").equals(authMethod)) { 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); stringBuffer.append(password); stringBuffer.append(TEXT_42); stringBuffer.append(cid); stringBuffer.append(TEXT_43); } } // if(isExistConnection) 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); for (Map<String, String> file : filelist) { stringBuffer.append(TEXT_48); stringBuffer.append(file.get("SOURCE")); stringBuffer.append(TEXT_49); stringBuffer.append(file.get("SOURCE")); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(file.get("SOURCE")); stringBuffer.append(TEXT_52); } 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(cid); 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(TEXT_64); return stringBuffer.toString(); }
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); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String dbhost = ElementParameterParser.getValue(node, "__HOST__"); String dbport = ElementParameterParser.getValue(node, "__PORT__"); String dbname = ElementParameterParser.getValue(node, "__DBNAME__"); String dbuser = ElementParameterParser.getValue(node, "__USER__"); String dbpwd = ElementParameterParser.getValue(node, "__PASS__"); String spName = ElementParameterParser.getValue(node, "__SP_NAME__"); boolean isFunction = ("true").equals(ElementParameterParser.getValue(node, "__IS_FUNCTION__")); List<Map<String, String>> spArgs = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SP_ARGS__"); String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"); if (("true").equals(useExistingConn)) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); String conn = "conn_" + connection; stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); stringBuffer.append(conn); stringBuffer.append(TEXT_4); } else { stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); stringBuffer.append(dbhost); stringBuffer.append(TEXT_7); stringBuffer.append(dbport); stringBuffer.append(TEXT_8); stringBuffer.append(dbname); stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); stringBuffer.append(dbuser); stringBuffer.append(TEXT_12); stringBuffer.append(dbpwd); stringBuffer.append(TEXT_13); } stringBuffer.append(TEXT_14); stringBuffer.append(cid); stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); stringBuffer.append(isFunction ? "? = " : ""); stringBuffer.append(TEXT_17); stringBuffer.append(spName); stringBuffer.append(TEXT_18); boolean isFirstArg = true; for (int i = 0; i < spArgs.size(); i++) { if (!("RECORDSET").equals(spArgs.get(i).get("TYPE"))) { if (isFirstArg) { stringBuffer.append(TEXT_19); isFirstArg = false; } else { stringBuffer.append(TEXT_20); } } } stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(TEXT_24); 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(); List<IMetadataTable> metadatas = node.getMetadataList(); if ((metadatas != null) && (metadatas.size() > 0)) { IMetadataTable metadata = metadatas.get(0); if (metadata != null) { // component id String cid = node.getUniqueName(); String filename = ElementParameterParser.getValue(node, "__FILENAME__"); String directory = ElementParameterParser.getValue(node, "__ATTACHMENT_PATH__"); List<Map<String, String>> mailParts = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__MAIL_PARTS__"); String dieOnErrorStr = ElementParameterParser.getValue(node, "__DIE_ON_ERROR__"); boolean dieOnError = (dieOnErrorStr != null && !("").equals(dieOnErrorStr)) ? ("true").equals(dieOnErrorStr) : false; stringBuffer.append(TEXT_2); stringBuffer.append(directory); stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append(directory); stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); stringBuffer.append(directory); stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); for (int i = 0; i < mailParts.size(); i++) { Map<String, String> lineValue = mailParts.get(i); stringBuffer.append(TEXT_9); stringBuffer.append(lineValue.get("MAIL_PART")); stringBuffer.append(TEXT_10); } stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); for (int i = 0; i < mailParts.size(); i++) { Map<String, String> lineValue = mailParts.get(i); stringBuffer.append(TEXT_13); stringBuffer.append(lineValue.get("MULTI_VALUE")); stringBuffer.append(TEXT_14); } stringBuffer.append(TEXT_15); stringBuffer.append(cid); stringBuffer.append(TEXT_16); for (int i = 0; i < mailParts.size(); i++) { Map<String, String> lineValue = mailParts.get(i); if (("").equals(lineValue.get("PART_SEPARATOR"))) { stringBuffer.append(TEXT_17); stringBuffer.append("\"\""); stringBuffer.append(TEXT_18); } else { stringBuffer.append(TEXT_19); stringBuffer.append(lineValue.get("PART_SEPARATOR")); stringBuffer.append(TEXT_20); } } stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(filename); 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(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); stringBuffer.append(cid); 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); 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); 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(cid); 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); // both picture and message context in the email body part, TDI-8651 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); 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(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(cid); stringBuffer.append(TEXT_84); stringBuffer.append(cid); stringBuffer.append(TEXT_85); stringBuffer.append(cid); stringBuffer.append(TEXT_86); // both attachment and message context in the email,bug TDI-19065 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(cid); stringBuffer.append(TEXT_94); stringBuffer.append(cid); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_101); stringBuffer.append(cid); stringBuffer.append(TEXT_102); stringBuffer.append(cid); 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); stringBuffer.append(cid); 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); 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(cid); stringBuffer.append(TEXT_141); stringBuffer.append(cid); stringBuffer.append(TEXT_142); stringBuffer.append(cid); stringBuffer.append(TEXT_143); stringBuffer.append(cid); stringBuffer.append(TEXT_144); // fixed bug TDI-8586,to deal with attachments download 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); stringBuffer.append(cid); 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); stringBuffer.append(cid); 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(cid); stringBuffer.append(TEXT_178); stringBuffer.append(cid); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_185); stringBuffer.append(cid); stringBuffer.append(TEXT_186); stringBuffer.append(cid); 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(directory); stringBuffer.append(TEXT_202); stringBuffer.append(cid); stringBuffer.append(TEXT_203); stringBuffer.append(directory); stringBuffer.append(TEXT_204); stringBuffer.append(cid); stringBuffer.append(TEXT_205); stringBuffer.append(directory); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_210); stringBuffer.append(cid); stringBuffer.append(TEXT_211); stringBuffer.append(cid); stringBuffer.append(TEXT_212); stringBuffer.append(cid); stringBuffer.append(TEXT_213); stringBuffer.append(cid); stringBuffer.append(TEXT_214); stringBuffer.append(cid); stringBuffer.append(TEXT_215); stringBuffer.append(cid); stringBuffer.append(TEXT_216); stringBuffer.append(cid); stringBuffer.append(TEXT_217); stringBuffer.append(cid); stringBuffer.append(TEXT_218); stringBuffer.append(cid); stringBuffer.append(TEXT_219); stringBuffer.append(cid); stringBuffer.append(TEXT_220); stringBuffer.append(cid); stringBuffer.append(TEXT_221); List<? extends IConnection> conns = node.getOutgoingSortedConnections(); String firstConnName = ""; if (conns != null) { // 1 if (conns.size() > 0) { // 2 IConnection conn = conns.get(0); // the first connection firstConnName = conn.getName(); if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { // 3 List<IMetadataColumn> columns = metadata.getListColumns(); int columnSize = columns.size(); for (int i = 0; i < columnSize; i++) { // 4 IMetadataColumn column = columns.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_222); stringBuffer.append(i); stringBuffer.append(TEXT_223); stringBuffer.append(cid); stringBuffer.append(TEXT_224); stringBuffer.append(cid); stringBuffer.append(TEXT_225); stringBuffer.append(i); stringBuffer.append(TEXT_226); if (javaType == JavaTypesManager.STRING || javaType == JavaTypesManager.OBJECT) { // String and Object stringBuffer.append(TEXT_227); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_228); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_229); stringBuffer.append(cid); stringBuffer.append(TEXT_230); stringBuffer.append(i); stringBuffer.append(TEXT_231); } else if (javaType == JavaTypesManager.DATE) { // Date stringBuffer.append(TEXT_232); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_233); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_234); stringBuffer.append(cid); stringBuffer.append(TEXT_235); stringBuffer.append(i); stringBuffer.append(TEXT_236); stringBuffer.append(patternValue); stringBuffer.append(TEXT_237); } else if (javaType == JavaTypesManager.BYTE_ARRAY) { // byte[] stringBuffer.append(TEXT_238); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_239); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_240); stringBuffer.append(cid); stringBuffer.append(TEXT_241); stringBuffer.append(i); stringBuffer.append(TEXT_242); } else { // other stringBuffer.append(TEXT_243); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_244); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_245); stringBuffer.append(typeToGenerate); stringBuffer.append(TEXT_246); stringBuffer.append(cid); stringBuffer.append(TEXT_247); stringBuffer.append(i); stringBuffer.append(TEXT_248); } stringBuffer.append(TEXT_249); stringBuffer.append(conn.getName()); stringBuffer.append(TEXT_250); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_251); stringBuffer.append(JavaTypesManager.getDefaultValueFromJavaType(typeToGenerate)); stringBuffer.append(TEXT_252); } // 4 } // 3 if (conns.size() > 1) { for (int i = 1; i < conns.size(); i++) { IConnection conn2 = conns.get(i); if ((conn2.getName().compareTo(firstConnName) != 0) && (conn2.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA))) { for (IMetadataColumn column : metadata.getListColumns()) { stringBuffer.append(TEXT_253); stringBuffer.append(conn2.getName()); stringBuffer.append(TEXT_254); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_255); stringBuffer.append(firstConnName); stringBuffer.append(TEXT_256); stringBuffer.append(column.getLabel()); stringBuffer.append(TEXT_257); } } } } } // 2 } // 1 stringBuffer.append(TEXT_258); if (!dieOnError) { stringBuffer.append(TEXT_259); stringBuffer.append(cid); stringBuffer.append(TEXT_260); } stringBuffer.append(TEXT_261); stringBuffer.append(cid); stringBuffer.append(TEXT_262); stringBuffer.append(cid); stringBuffer.append(TEXT_263); } } stringBuffer.append(TEXT_264); 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); /* 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(); String bucket = ElementParameterParser.getValue(node, "__BUCKET__"); String key = ElementParameterParser.getValue(node, "__KEY__"); String file = ElementParameterParser.getValue(node, "__FILE__"); boolean dieOnError = "true".equals(ElementParameterParser.getValue(node, "__DIE_ON_ERROR__")); stringBuffer.append(TEXT_2); boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__")); String accessKey = ElementParameterParser.getValue(node, "__ACCESS_KEY__"); boolean configClient = "true".equals(ElementParameterParser.getValue(node, "__CONFIG_CLIENT__")); String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"); List<Map<String, String>> clientConfiguration = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__CLIENT_CONFIGURATION__"); String region = ElementParameterParser.getValue(node, "__REGION__"); if (("true").equals(useExistingConn)) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); String conn = "conn_" + connection; ; stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append(conn); stringBuffer.append(TEXT_5); if (isLog4jEnabled) { stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(connection); stringBuffer.append(TEXT_8); } } else { stringBuffer.append(TEXT_9); if (isLog4jEnabled) { stringBuffer.append(TEXT_10); stringBuffer.append(cid); stringBuffer.append(TEXT_11); } String passwordFieldName = "__SECRET_KEY__"; stringBuffer.append(TEXT_12); if (ElementParameterParser.canEncrypt(node, passwordFieldName)) { stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName)); stringBuffer.append(TEXT_15); } else { stringBuffer.append(TEXT_16); stringBuffer.append(cid); stringBuffer.append(TEXT_17); stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName)); stringBuffer.append(TEXT_18); } stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); stringBuffer.append(accessKey); stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); if (configClient && clientConfiguration.size() > 0) { stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); boolean setBuffer = false; for (Map<String, String> map : clientConfiguration) { String client_parameter = map.get("CLIENT_PARAMETER"); String value = map.get("VALUE"); if (!setBuffer && ("SocketSendBufferSizeHints".equals(client_parameter) || "SocketReceiveBufferSizeHints".equals(client_parameter))) { setBuffer = true; stringBuffer.append(TEXT_25); stringBuffer.append(cid); stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); } if ("SocketSendBufferSizeHints".equals(client_parameter)) { stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(value); stringBuffer.append(TEXT_30); } else if ("SocketReceiveBufferSizeHints".equals(client_parameter)) { stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); stringBuffer.append(value); stringBuffer.append(TEXT_33); } else if ("Protocol".equals(client_parameter)) { stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); stringBuffer.append(value.toUpperCase().replaceAll("\"", "")); stringBuffer.append(TEXT_36); } else { stringBuffer.append(TEXT_37); stringBuffer.append(cid); stringBuffer.append(TEXT_38); stringBuffer.append(client_parameter); stringBuffer.append(TEXT_39); stringBuffer.append(value); stringBuffer.append(TEXT_40); } } if (setBuffer) { 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); } 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); } else { stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); } if (region != null && !region.isEmpty() && !"DEFAULT".equalsIgnoreCase(region)) { stringBuffer.append(TEXT_52); stringBuffer.append(cid); stringBuffer.append(TEXT_53); stringBuffer.append(region); stringBuffer.append(TEXT_54); } if (isLog4jEnabled) { stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); } } stringBuffer.append(TEXT_57); if (isLog4jEnabled) { stringBuffer.append(TEXT_58); stringBuffer.append(cid); stringBuffer.append(TEXT_59); stringBuffer.append(key); stringBuffer.append(TEXT_60); } stringBuffer.append(TEXT_61); stringBuffer.append(cid); stringBuffer.append(TEXT_62); stringBuffer.append(bucket); stringBuffer.append(TEXT_63); stringBuffer.append(key); stringBuffer.append(TEXT_64); stringBuffer.append(file); stringBuffer.append(TEXT_65); if (isLog4jEnabled) { stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); } stringBuffer.append(TEXT_68); stringBuffer.append(cid); stringBuffer.append(TEXT_69); if (dieOnError) { stringBuffer.append(TEXT_70); stringBuffer.append(cid); stringBuffer.append(TEXT_71); } else { if (isLog4jEnabled) { 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 (!("true").equals(useExistingConn)) { stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); stringBuffer.append(cid); stringBuffer.append(TEXT_79); } stringBuffer.append(TEXT_80); stringBuffer.append(TEXT_81); 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 dbhost = ElementParameterParser.getValue(node, "__HOST__"); String dbport = ElementParameterParser.getValue(node, "__PORT__"); String dbname = ElementParameterParser.getValue(node, "__DBNAME__"); String localServiceName = ElementParameterParser.getValue(node, "__LOCAL_SERVICE_NAME__"); String dbuser = ElementParameterParser.getValue(node, "__USER__"); String dbpwd = ElementParameterParser.getValue(node, "__PASS__"); String spName = ElementParameterParser.getValue(node, "__SP_NAME__"); boolean isFunction = ("true").equals(ElementParameterParser.getValue(node, "__IS_FUNCTION__")); List<Map<String, String>> spArgs = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__SP_ARGS__"); boolean useExistingConnection = ("true").equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); String dbproperties = ElementParameterParser.getValue(node, "__PROPERTIES__"); String nlsLanguage = ElementParameterParser.getValue(node, "__NLS_LANGUAGE__"); String nlsTerritory = ElementParameterParser.getValue(node, "__NLS_TERRITORY__"); String dbVersion = ElementParameterParser.getValue(node, "__DB_VERSION__"); if (useExistingConnection) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); String connectionName = "conn_" + connection; stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); stringBuffer.append(connectionName); stringBuffer.append(TEXT_4); } else { stringBuffer.append(TEXT_5); if ("ORACLE_11".equals(dbVersion) || "ORACLE_11-6".equals(dbVersion)) { stringBuffer.append(TEXT_6); } else { stringBuffer.append(TEXT_7); } stringBuffer.append(TEXT_8); String connectionType = ElementParameterParser.getValue(node, "__CONNECTION_TYPE__"); String rac_url = ElementParameterParser.getValue(node, "__RAC_URL__"); if ("ORACLE_RAC".equals(connectionType)) { stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(rac_url); stringBuffer.append(TEXT_11); } else if (("ORACLE_SID").equals(connectionType)) { stringBuffer.append(TEXT_12); stringBuffer.append(cid); stringBuffer.append(TEXT_13); stringBuffer.append(dbhost); stringBuffer.append(TEXT_14); stringBuffer.append(dbport); stringBuffer.append(TEXT_15); stringBuffer.append(dbname); stringBuffer.append(TEXT_16); } else if (("ORACLE_SERVICE_NAME").equals(connectionType)) { stringBuffer.append(TEXT_17); stringBuffer.append(cid); stringBuffer.append(TEXT_18); stringBuffer.append(dbhost); stringBuffer.append(TEXT_19); stringBuffer.append(dbport); stringBuffer.append(TEXT_20); stringBuffer.append(dbname); stringBuffer.append(TEXT_21); } else if (("ORACLE_OCI").equals(connectionType)) { stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(localServiceName); stringBuffer.append(TEXT_24); } stringBuffer.append(TEXT_25); if (dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) { stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(cid); stringBuffer.append(TEXT_28); stringBuffer.append(dbuser); stringBuffer.append(TEXT_29); stringBuffer.append(dbpwd); stringBuffer.append(TEXT_30); } else { stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); stringBuffer.append(dbproperties); stringBuffer.append(TEXT_33); stringBuffer.append(cid); stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); stringBuffer.append(dbuser); stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append(dbpwd); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_45); } stringBuffer.append(TEXT_46); } if (!("NONE").equals(nlsLanguage) || !("NONE").equals(nlsTerritory)) { stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); if (!("NONE").equals(nlsLanguage)) { stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(nlsLanguage); stringBuffer.append(TEXT_52); } if (!("NONE").equals(nlsTerritory)) { stringBuffer.append(TEXT_53); stringBuffer.append(cid); stringBuffer.append(TEXT_54); stringBuffer.append(nlsTerritory); stringBuffer.append(TEXT_55); } } stringBuffer.append(TEXT_56); stringBuffer.append(cid); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); stringBuffer.append(isFunction ? "? = " : ""); stringBuffer.append(TEXT_59); stringBuffer.append(spName); stringBuffer.append(TEXT_60); boolean isFirstArg = true; for (int i = 0; i < spArgs.size(); i++) { if (isFirstArg) { stringBuffer.append(TEXT_61); isFirstArg = false; } else { stringBuffer.append(TEXT_62); } } stringBuffer.append(TEXT_63); stringBuffer.append(cid); stringBuffer.append(TEXT_64); stringBuffer.append(cid); stringBuffer.append(TEXT_65); stringBuffer.append(TEXT_66); return stringBuffer.toString(); }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); class Neo4JTransactionHelper { private INode node; private String cid; private String dbVersion; private boolean batchImport; private boolean remoteServer; private String commitEvery; public Neo4JTransactionHelper(INode node) { this.node = node; this.cid = node.getUniqueName(); this.batchImport = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__BATCH_IMPORT__")); this.commitEvery = ElementParameterParser.getValue(node, "__COMMIT_EVERY__"); boolean useExistingConnection = "true" .equalsIgnoreCase( ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); if (useExistingConnection) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); for (INode targetNode : node.getProcess().getNodesOfType("tNeo4jConnection")) { if (targetNode.getUniqueName().equals(connection)) { this.dbVersion = ElementParameterParser.getValue(targetNode, "__DB_VERSION__"); this.remoteServer = "true" .equalsIgnoreCase( ElementParameterParser.getValue(targetNode, "__REMOTE_SERVER__")); break; } } } else { this.dbVersion = ElementParameterParser.getValue(node, "__DB_VERSION__"); this.remoteServer = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__REMOTE_SERVER__")); } } public String getDbVersion() { return this.dbVersion; } public void startTransaction() { if ("NEO4J_1_X_X".equals(this.dbVersion)) { stringBuffer.append(TEXT_1); stringBuffer.append(cid); stringBuffer.append(TEXT_2); stringBuffer.append(cid); stringBuffer.append(TEXT_3); } else { // NEO4J_2_1_X or NEO4J_2_2_X if (!this.batchImport) { stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); stringBuffer.append(cid); stringBuffer.append(TEXT_6); } } } public void restartTransaction() { if ("NEO4J_1_X_X".equals(this.dbVersion)) { stringBuffer.append(TEXT_7); stringBuffer.append(cid); stringBuffer.append(TEXT_8); stringBuffer.append(commitEvery); stringBuffer.append(TEXT_9); stringBuffer.append(this.cid); stringBuffer.append(TEXT_10); stringBuffer.append(this.cid); stringBuffer.append(TEXT_11); stringBuffer.append(this.cid); stringBuffer.append(TEXT_12); stringBuffer.append(this.cid); stringBuffer.append(TEXT_13); } else { // NEO4J_2_1_X or NEO4J_2_2_X if (!this.batchImport) { stringBuffer.append(TEXT_14); stringBuffer.append(this.cid); stringBuffer.append(TEXT_15); stringBuffer.append(commitEvery); stringBuffer.append(TEXT_16); stringBuffer.append(this.cid); stringBuffer.append(TEXT_17); stringBuffer.append(this.cid); stringBuffer.append(TEXT_18); stringBuffer.append(this.cid); stringBuffer.append(TEXT_19); stringBuffer.append(this.cid); stringBuffer.append(TEXT_20); } } } public void closeTransaction() { if ("NEO4J_1_X_X".equals(this.dbVersion)) { stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(commitEvery); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); } else { // NEO4J_2_1_X or NEO4J_2_2_X if (!this.batchImport) { stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(commitEvery); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(cid); stringBuffer.append(TEXT_30); } } } public void startEmbeddedTransaction() { if ("NEO4J_1_X_X".equals(this.dbVersion)) { // Nothing for neo4j 1.X.X } else { // NEO4J_2_1_X or NEO4J_2_2_X if (!remoteServer) { stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); stringBuffer.append(cid); stringBuffer.append(TEXT_33); } } } public void closeEmbeddedTransaction() { if ("NEO4J_1_X_X".equals(this.dbVersion)) { // Nothing for neo4j 1.X.X } else { // NEO4J_2_1_X or NEO4J_2_2_X if (!remoteServer) { stringBuffer.append(TEXT_34); stringBuffer.append(cid); stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); } } } } class Neo4JOutputUtil { private Neo4JTransactionHelper neo4JTransactionHelper; private INode node; private String cid; private boolean batchImport; private String dbConnectionName; private String dbVersion; private boolean useExistingConnection; private boolean remoteServer; public Neo4JOutputUtil(INode node) { this.node = node; this.cid = node.getUniqueName(); this.neo4JTransactionHelper = new Neo4JTransactionHelper(node); this.batchImport = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__BATCH_IMPORT__")); this.useExistingConnection = "true" .equalsIgnoreCase( ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); if (useExistingConnection) { String connection = ElementParameterParser.getValue(node, "__CONNECTION__"); this.dbConnectionName = "dbService_" + connection; for (INode targetNode : node.getProcess().getNodesOfType("tNeo4jConnection")) { if (targetNode.getUniqueName().equals(connection)) { this.dbVersion = ElementParameterParser.getValue(targetNode, "__DB_VERSION__"); this.remoteServer = "true" .equalsIgnoreCase( ElementParameterParser.getValue(targetNode, "__REMOTE_SERVER__")); break; } } } else { this.dbConnectionName = "dbService_" + cid; this.dbVersion = ElementParameterParser.getValue(node, "__DB_VERSION__"); this.remoteServer = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__REMOTE_SERVER__")); } } public void createDatabaseService() { if (this.useExistingConnection) { stringBuffer.append(TEXT_37); stringBuffer.append(cid); stringBuffer.append(TEXT_38); stringBuffer.append(dbConnectionName); stringBuffer.append(TEXT_39); } else { if (this.remoteServer) { String serverUrl = ElementParameterParser.getValue(node, "__SERVER_URL__"); boolean setUsername = ElementParameterParser.getBooleanValue(node, "__SET_USERNAME__"); String username = ElementParameterParser.getValue(node, "__USERNAME__"); String passwordFieldName = "__PASSWORD__"; if ((setUsername) || ("NEO4J_2_2_X".equals(dbVersion))) { if (ElementParameterParser.canEncrypt(node, passwordFieldName)) { stringBuffer.append(TEXT_40); stringBuffer.append(cid); stringBuffer.append(TEXT_41); stringBuffer.append( ElementParameterParser.getEncryptedValue(node, passwordFieldName)); stringBuffer.append(TEXT_42); } else { stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName)); stringBuffer.append(TEXT_45); } stringBuffer.append(TEXT_46); stringBuffer.append(cid); stringBuffer.append(TEXT_47); stringBuffer.append(serverUrl); stringBuffer.append(TEXT_48); stringBuffer.append(username); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); } else { stringBuffer.append(TEXT_51); stringBuffer.append(cid); stringBuffer.append(TEXT_52); stringBuffer.append(serverUrl); stringBuffer.append(TEXT_53); } } else { String databasePath = ElementParameterParser.getValue(node, "__DATABASE_PATH__"); stringBuffer.append(TEXT_54); stringBuffer.append(cid); stringBuffer.append(TEXT_55); stringBuffer.append(cid); stringBuffer.append(TEXT_56); stringBuffer.append(databasePath); stringBuffer.append(TEXT_57); } } } private void writeBatchModeVersion1_9( Set<String> indexNames, List<String> autoIndexedColumns) { 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); 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(cid); stringBuffer.append(TEXT_74); for (String indexName : indexNames) { stringBuffer.append(TEXT_75); stringBuffer.append(cid); stringBuffer.append(TEXT_76); stringBuffer.append(indexName); stringBuffer.append(TEXT_77); stringBuffer.append(cid); stringBuffer.append(TEXT_78); stringBuffer.append(indexName); stringBuffer.append(TEXT_79); } // Auto index configuration if (autoIndexedColumns.size() > 0) { 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); } for (String autoIndexedColumn : autoIndexedColumns) { stringBuffer.append(TEXT_84); stringBuffer.append(cid); stringBuffer.append(TEXT_85); stringBuffer.append(autoIndexedColumn); stringBuffer.append(TEXT_86); } neo4JTransactionHelper.startTransaction(); } private void writeBatchModeVersion2_1( Set<String> indexNames, List<String> autoIndexedColumns) { stringBuffer.append(TEXT_87); stringBuffer.append(cid); stringBuffer.append(TEXT_88); stringBuffer.append(dbConnectionName); 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(cid); stringBuffer.append(TEXT_94); stringBuffer.append(cid); stringBuffer.append(TEXT_95); stringBuffer.append(cid); stringBuffer.append(TEXT_96); stringBuffer.append(cid); stringBuffer.append(TEXT_97); stringBuffer.append(dbConnectionName); stringBuffer.append(TEXT_98); stringBuffer.append(cid); stringBuffer.append(TEXT_99); stringBuffer.append(dbConnectionName); stringBuffer.append(TEXT_100); stringBuffer.append(cid); stringBuffer.append(TEXT_101); stringBuffer.append(dbConnectionName); stringBuffer.append(TEXT_102); stringBuffer.append(dbConnectionName); stringBuffer.append(TEXT_103); stringBuffer.append(cid); stringBuffer.append(TEXT_104); stringBuffer.append(cid); stringBuffer.append(TEXT_105); stringBuffer.append(dbConnectionName); stringBuffer.append(TEXT_106); stringBuffer.append(cid); stringBuffer.append(TEXT_107); stringBuffer.append(cid); stringBuffer.append(TEXT_108); stringBuffer.append(dbConnectionName); 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); stringBuffer.append(cid); stringBuffer.append(TEXT_113); stringBuffer.append(cid); stringBuffer.append(TEXT_114); for (String indexName : indexNames) { stringBuffer.append(TEXT_115); stringBuffer.append(cid); stringBuffer.append(TEXT_116); stringBuffer.append(indexName); stringBuffer.append(TEXT_117); stringBuffer.append(cid); stringBuffer.append(TEXT_118); stringBuffer.append(indexName); stringBuffer.append(TEXT_119); } // There is no autoindex in batch mode, so we did it by hand. if (autoIndexedColumns.size() > 0) { 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); } } private void writeBatchMode(Set<String> indexNames, List<String> autoIndexedColumns) { String nodeMappedMemory = ElementParameterParser.getValue(node, "__NODE_MAPPED_MEMORY__"); String relationshipMappedMemory = ElementParameterParser.getValue(node, "__RELATIONSHIP_MAPPED_MEMORY__"); String propertyMappedMemory = ElementParameterParser.getValue(node, "__PROPERTY_MAPPED_MEMORY__"); String stringsMappedMemory = ElementParameterParser.getValue(node, "__STRINGS_MAPPED_MEMORY__"); String arraysMappedMemory = ElementParameterParser.getValue(node, "__ARRAYS_MAPPED_MEMORY__"); stringBuffer.append(TEXT_126); stringBuffer.append(cid); stringBuffer.append(TEXT_127); stringBuffer.append(cid); stringBuffer.append(TEXT_128); stringBuffer.append(nodeMappedMemory); stringBuffer.append(TEXT_129); stringBuffer.append(cid); stringBuffer.append(TEXT_130); stringBuffer.append(relationshipMappedMemory); stringBuffer.append(TEXT_131); stringBuffer.append(cid); stringBuffer.append(TEXT_132); stringBuffer.append(propertyMappedMemory); stringBuffer.append(TEXT_133); stringBuffer.append(cid); stringBuffer.append(TEXT_134); stringBuffer.append(stringsMappedMemory); stringBuffer.append(TEXT_135); stringBuffer.append(cid); stringBuffer.append(TEXT_136); stringBuffer.append(arraysMappedMemory); 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); if ("NEO4J_1_X_X".equals(dbVersion)) { writeBatchModeVersion1_9(indexNames, autoIndexedColumns); } else { // NEO4J_2_1_X writeBatchModeVersion2_1(indexNames, autoIndexedColumns); } } private void writeNormalMode(Set<String> indexNames, List<String> autoIndexedColumns) { stringBuffer.append(TEXT_141); stringBuffer.append(cid); stringBuffer.append(TEXT_142); neo4JTransactionHelper.startEmbeddedTransaction(); for (String indexName : indexNames) { stringBuffer.append(TEXT_143); stringBuffer.append(cid); stringBuffer.append(TEXT_144); stringBuffer.append(indexName); stringBuffer.append(TEXT_145); stringBuffer.append(cid); stringBuffer.append(TEXT_146); stringBuffer.append(indexName); stringBuffer.append(TEXT_147); } neo4JTransactionHelper.closeEmbeddedTransaction(); // Auto index configuration if (autoIndexedColumns.size() > 0) { 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); } for (String autoIndexedColumn : autoIndexedColumns) { stringBuffer.append(TEXT_152); stringBuffer.append(cid); stringBuffer.append(TEXT_153); stringBuffer.append(autoIndexedColumn); stringBuffer.append(TEXT_154); } neo4JTransactionHelper.startTransaction(); } } stringBuffer.append(TEXT_155); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); boolean batchImport = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__BATCH_IMPORT__")); boolean shutdownDb = "true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__SHUTDOWN_DB__")); List<Map<String, String>> values = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__VALUES__"); List<String> autoIndexedColumns = new ArrayList<String>(); Set<String> indexNames = new HashSet(); for (Map<String, String> value : values) { boolean autoIndexed = Boolean.valueOf(value.get("AUTO_INDEXED")); if (autoIndexed) { autoIndexedColumns.add(value.get("SCHEMA_COLUMN")); } String strIndexNames = value.get("INDEX_NAMES"); if (strIndexNames != null && !strIndexNames.isEmpty()) { indexNames.addAll(Arrays.asList(strIndexNames.split(","))); } } // Add update/delete index String action = (String) ElementParameterParser.getObjectValue(node, "__DATA_ACTION__"); if (!action.equals("INSERT")) { indexNames.add((String) ElementParameterParser.getObjectValue(node, "__INDEX_NAME__")); } boolean useExistingConnection = "true" .equalsIgnoreCase(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__")); Neo4JOutputUtil neo4JOutputUtil = new Neo4JOutputUtil(node); neo4JOutputUtil.createDatabaseService(); stringBuffer.append(TEXT_156); stringBuffer.append(cid); stringBuffer.append(TEXT_157); stringBuffer.append(cid); stringBuffer.append(TEXT_158); if (!batchImport && (!useExistingConnection || (useExistingConnection && shutdownDb))) { stringBuffer.append(TEXT_159); stringBuffer.append(cid); stringBuffer.append(TEXT_160); stringBuffer.append(cid); stringBuffer.append(TEXT_161); } // Index configuration if (batchImport) { neo4JOutputUtil.writeBatchMode(indexNames, autoIndexedColumns); } else { neo4JOutputUtil.writeNormalMode(indexNames, autoIndexedColumns); } stringBuffer.append(TEXT_162); 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); class DefaultConnectionUtil { protected String cid; protected String dbproperties; protected String dbhost; protected String dbport; protected String dbname; public void beforeComponentProcess(INode node) {} public void createURL(INode node) { cid = node.getUniqueName(); dbproperties = ElementParameterParser.getValue(node, "__PROPERTIES__"); dbhost = ElementParameterParser.getValue(node, "__HOST__"); dbport = ElementParameterParser.getValue(node, "__PORT__"); dbname = ElementParameterParser.getValue(node, "__DBNAME__"); } public String getDirverClassName(INode node) { return ""; } public void classForName(INode node) { stringBuffer.append(TEXT_2); stringBuffer.append(this.getDirverClassName(node)); stringBuffer.append(TEXT_3); } public void useShareConnection(INode node) { String sharedConnectionName = ElementParameterParser.getValue(node, "__SHARED_CONNECTION_NAME__"); stringBuffer.append(TEXT_4); stringBuffer.append(cid); stringBuffer.append(TEXT_5); stringBuffer.append(sharedConnectionName); stringBuffer.append(TEXT_6); stringBuffer.append(cid); stringBuffer.append(TEXT_7); stringBuffer.append(this.getDirverClassName(node)); 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); } public void createConnection(INode node) { 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); } public void setAutoCommit(INode node) { boolean setAutoCommit = "true".equals(ElementParameterParser.getValue(node, "__AUTO_COMMIT__")); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(setAutoCommit); stringBuffer.append(TEXT_20); } public void afterComponentProcess(INode node) {} } // end DefaultUtil class DefaultConnectionUtil connUtil = new DefaultConnectionUtil(); stringBuffer.append(TEXT_21); class ConnectionUtil extends DefaultConnectionUtil { private String javaDbDriver = "org.apache.hadoop.hive.jdbc.HiveDriver"; public void createConnection(INode node) { String connectionMode = ElementParameterParser.getValue(node, "__CONNECTION_MODE__"); String hiveVersion = ElementParameterParser.getValue(node, "__HIVE_VERSION__"); String hiveServer = ElementParameterParser.getValue(node, "__HIVE_SERVER__"); boolean isCustom = "CUSTOM".equals(ElementParameterParser.getValue(node, "__DISTRIBUTION__")); boolean useKrb = "true".equals(ElementParameterParser.getValue(node, "__USE_KRB__")); boolean cdh4CanBeSecured = "Cloudera_CDH4".equals(hiveVersion) && (("HIVE".equalsIgnoreCase(hiveServer) && "EMBEDDED".equalsIgnoreCase(connectionMode)) || "HIVE2".equalsIgnoreCase(hiveServer)); boolean securityIsEnabled = useKrb && (isCustom || ("HDP_1_0".equals(hiveVersion) || "HDP_1_2".equals(hiveVersion) || "HDP_1_3".equals(hiveVersion) || cdh4CanBeSecured)); boolean securedStandaloneHive2 = securityIsEnabled && "HIVE2".equalsIgnoreCase(hiveServer) && "STANDALONE".equalsIgnoreCase(connectionMode); if (securedStandaloneHive2) { stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(cid); stringBuffer.append(TEXT_24); } else { super.createConnection(node); } } public void createURL(INode node) { super.createURL(node); String connectionMode = ElementParameterParser.getValue(node, "__CONNECTION_MODE__"); String hiveVersion = ElementParameterParser.getValue(node, "__HIVE_VERSION__"); String fsDefalutName = "fs.default.name"; String hiveServer = ElementParameterParser.getValue(node, "__HIVE_SERVER__"); boolean setMapredJT = "true".equals(ElementParameterParser.getValue(node, "__SET_MAPRED_JT__")); boolean setNamenode = "true".equals(ElementParameterParser.getValue(node, "__SET_FS_DEFAULT_NAME__")); List<Map<String, String>> hadoopProps = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__HADOOP_ADVANCED_PROPERTIES__"); boolean isCustom = "CUSTOM".equals(ElementParameterParser.getValue(node, "__DISTRIBUTION__")); boolean useYarn = "true".equals(ElementParameterParser.getValue(node, "__USE_YARN__")); boolean useKrb = "true".equals(ElementParameterParser.getValue(node, "__USE_KRB__")); boolean cdh4CanBeSecured = "Cloudera_CDH4".equals(hiveVersion) && (("HIVE".equalsIgnoreCase(hiveServer) && "EMBEDDED".equalsIgnoreCase(connectionMode)) || "HIVE2".equalsIgnoreCase(hiveServer)); boolean securityIsEnabled = useKrb && (isCustom || ("HDP_1_0".equals(hiveVersion) || "HDP_1_2".equals(hiveVersion) || "HDP_1_3".equals(hiveVersion) || cdh4CanBeSecured)); boolean securedStandaloneHive2 = securityIsEnabled && "HIVE2".equalsIgnoreCase(hiveServer) && "STANDALONE".equalsIgnoreCase(connectionMode); boolean securedEmbedded = securityIsEnabled && "EMBEDDED".equalsIgnoreCase(connectionMode); String hivePrincipal = ElementParameterParser.getValue(node, "__HIVE_PRINCIPAL__"); if (hiveServer != null && !"".equals(hiveServer.trim()) && (isCustom || ("HDP_1_2".equals(hiveVersion) || "HDP_1_3".equals(hiveVersion) || "Cloudera_CDH4".equals(hiveVersion) || "Cloudera_CDH4_YARN".equals(hiveVersion) || "MAPR213".equals(hiveVersion) || "MAPR301".equals(hiveVersion) || "HDP_2_0".equals(hiveVersion)))) { hiveServer = hiveServer.toLowerCase(); if ("hive2".equals(hiveServer)) { javaDbDriver = "org.apache.hive.jdbc.HiveDriver"; } } else { hiveServer = "hive"; } if (!isCustom && (("HDP_1_0".equals(hiveVersion) && "STANDALONE".equals(connectionMode)) || ("HDP_1_2".equals(hiveVersion) && "STANDALONE".equals(connectionMode) && "HIVE".equalsIgnoreCase(hiveServer)) || ("HDP_1_3".equals(hiveVersion) && "STANDALONE".equals(connectionMode) && "HIVE".equalsIgnoreCase(hiveServer)) || ("HDP_2_0".equals(hiveVersion) && "STANDALONE".equals(connectionMode) && "HIVE".equalsIgnoreCase(hiveServer)) || ("APACHE_0_20_203".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)) || ("MAPR1".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)) || ("MapR_EMR".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)) || ("Cloudera_CDH3".equals(hiveVersion) && "EMBEDDED".equals(connectionMode)))) { stringBuffer.append(TEXT_25); } if (hadoopProps.size() > 0) { for (Map<String, String> item : hadoopProps) { stringBuffer.append(TEXT_26); stringBuffer.append(item.get("PROPERTY")); stringBuffer.append(TEXT_27); stringBuffer.append(item.get("VALUE")); stringBuffer.append(TEXT_28); } } if (securedEmbedded) { String metastoreUrl = ElementParameterParser.getValue(node, "__METASTORE_JDBC_URL__"); String driverClass = ElementParameterParser.getValue(node, "__METASTORE_CLASSNAME__"); String metastoreUsername = ElementParameterParser.getValue(node, "__METASTORE_USERNAME__"); String metastorePassword = ElementParameterParser.getValue(node, "__METASTORE_PASSWORD__"); boolean useKeytab = "true".equals(ElementParameterParser.getValue(node, "__USE_KEYTAB__")); String userPrincipal = ElementParameterParser.getValue(node, "__PRINCIPAL__"); String keytabPath = ElementParameterParser.getValue(node, "__KEYTAB_PATH__"); stringBuffer.append(TEXT_29); stringBuffer.append(driverClass); stringBuffer.append(TEXT_30); stringBuffer.append(metastoreUrl); stringBuffer.append(TEXT_31); stringBuffer.append(metastoreUsername); stringBuffer.append(TEXT_32); stringBuffer.append(metastorePassword); stringBuffer.append(TEXT_33); stringBuffer.append(hivePrincipal); stringBuffer.append(TEXT_34); if (useKeytab) { stringBuffer.append(TEXT_35); stringBuffer.append(userPrincipal); stringBuffer.append(TEXT_36); stringBuffer.append(keytabPath); stringBuffer.append(TEXT_37); } } if (((isCustom && !useYarn) || (!isCustom && !"PIVOTAL_HD_1_0_1".equals(hiveVersion) && !"HDP_2_0".equals(hiveVersion) && !"Cloudera_CDH4_YARN".equals(hiveVersion))) && setMapredJT) { String mapredJT = ElementParameterParser.getValue(node, "__MAPRED_JT__"); stringBuffer.append(TEXT_38); stringBuffer.append(mapredJT); stringBuffer.append(TEXT_39); } if (setNamenode) { String namenode = ElementParameterParser.getValue(node, "__FS_DEFAULT_NAME__"); stringBuffer.append(TEXT_40); stringBuffer.append(fsDefalutName); stringBuffer.append(TEXT_41); stringBuffer.append(namenode); stringBuffer.append(TEXT_42); } stringBuffer.append(TEXT_43); stringBuffer.append(cid); stringBuffer.append(TEXT_44); if ("EMBEDDED".equals(connectionMode)) { stringBuffer.append(TEXT_45); stringBuffer.append(dbhost); stringBuffer.append(TEXT_46); stringBuffer.append(dbport); stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(hiveServer); stringBuffer.append(TEXT_49); if (isCustom || (!isCustom && ("HDP_1_0,HDP_1_2,HDP_1_3,HDP_2_0,Cloudera_CDH4,Cloudera_CDH4_YARN,PIVOTAL_HD_1_0_1" .contains(hiveVersion)))) { String dbuser = ElementParameterParser.getValue(node, "__USER__"); stringBuffer.append(TEXT_50); stringBuffer.append(cid); stringBuffer.append(TEXT_51); stringBuffer.append(dbuser); 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(cid); stringBuffer.append(TEXT_57); stringBuffer.append(cid); stringBuffer.append(TEXT_58); } } else { if (securedStandaloneHive2) { stringBuffer.append(TEXT_59); stringBuffer.append(cid); stringBuffer.append(TEXT_60); stringBuffer.append(hiveServer); stringBuffer.append(TEXT_61); stringBuffer.append(dbhost); stringBuffer.append(TEXT_62); stringBuffer.append(dbport); stringBuffer.append(TEXT_63); stringBuffer.append(dbname); stringBuffer.append(TEXT_64); stringBuffer.append(hivePrincipal); stringBuffer.append(TEXT_65); } else { stringBuffer.append(TEXT_66); stringBuffer.append(cid); stringBuffer.append(TEXT_67); stringBuffer.append(hiveServer); stringBuffer.append(TEXT_68); stringBuffer.append(dbhost); stringBuffer.append(TEXT_69); stringBuffer.append(dbport); stringBuffer.append(TEXT_70); stringBuffer.append(dbname); stringBuffer.append(TEXT_71); } } } public void setAutoCommit(INode node) { boolean useTransaction = false; // ("true").equals(ElementParameterParser.getValue(node,"__IS_USE_AUTO_COMMIT__")); boolean setAutoCommit = "true".equals(ElementParameterParser.getValue(node, "__AUTO_COMMIT__")); if (useTransaction) { stringBuffer.append(TEXT_72); stringBuffer.append(cid); stringBuffer.append(TEXT_73); stringBuffer.append(setAutoCommit); stringBuffer.append(TEXT_74); } } public String getDirverClassName(INode node) { return javaDbDriver; } } // end class connUtil = new ConnectionUtil(); // ----------------------------component codes----------------------------------------- stringBuffer.append(TEXT_75); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String dbhost = ElementParameterParser.getValue(node, "__HOST__"); String dbport = ElementParameterParser.getValue(node, "__PORT__"); String dbschema = ElementParameterParser.getValue(node, "__DB_SCHEMA__"); if (dbschema == null || dbschema.trim().length() == 0) { dbschema = ElementParameterParser.getValue(node, "__SCHEMA_DB__"); } String dbname = ElementParameterParser.getValue(node, "__DBNAME__"); String dbuser = ElementParameterParser.getValue(node, "__USER__"); String dbpass = ElementParameterParser.getValue(node, "__PASS__"); String encoding = ElementParameterParser.getValue(node, "__ENCODING__"); boolean isUseSharedConnection = ("true").equals(ElementParameterParser.getValue(node, "__USE_SHARED_CONNECTION__")); connUtil.beforeComponentProcess(node); connUtil.createURL(node); stringBuffer.append(TEXT_76); stringBuffer.append(cid); stringBuffer.append(TEXT_77); stringBuffer.append((dbuser != null && dbuser.trim().length() == 0) ? "null" : dbuser); stringBuffer.append(TEXT_78); // the tSQLiteConnection component not contain user and pass return null stringBuffer.append(TEXT_79); stringBuffer.append(cid); stringBuffer.append(TEXT_80); stringBuffer.append((dbpass != null && dbpass.trim().length() == 0) ? "null" : dbpass); stringBuffer.append(TEXT_81); stringBuffer.append(cid); stringBuffer.append(TEXT_82); if (isUseSharedConnection) { stringBuffer.append(TEXT_83); connUtil.useShareConnection(node); } else { boolean specify_alias = "true".equals(ElementParameterParser.getValue(node, "__SPECIFY_DATASOURCE_ALIAS__")); if (specify_alias) { String alias = ElementParameterParser.getValue(node, "__DATASOURCE_ALIAS__"); stringBuffer.append(TEXT_84); stringBuffer.append((null != alias && !("".equals(alias))) ? alias : "\"\""); stringBuffer.append(TEXT_85); } stringBuffer.append(TEXT_86); connUtil.classForName(node); stringBuffer.append(TEXT_87); connUtil.createConnection(node); stringBuffer.append(TEXT_88); stringBuffer.append(cid); stringBuffer.append(TEXT_89); stringBuffer.append(cid); stringBuffer.append(TEXT_90); if (specify_alias) { stringBuffer.append(TEXT_91); } } stringBuffer.append(TEXT_92); stringBuffer.append(cid); stringBuffer.append(TEXT_93); connUtil.setAutoCommit(node); stringBuffer.append(TEXT_94); connUtil.afterComponentProcess(node); stringBuffer.append(TEXT_95); String storeByHBase = ElementParameterParser.getValue(node, "__STORE_BY_HBASE__"); String connectionMode = ElementParameterParser.getValue(node, "__CONNECTION_MODE__"); String hiveVersion = ElementParameterParser.getValue(node, "__HIVE_VERSION__"); String zookeeperQuorumForHBase = ElementParameterParser.getValue(node, "__ZOOKEEPER_QUORUM__"); String zookeeperClientPortForHBase = ElementParameterParser.getValue(node, "__ZOOKEEPER_CLIENT_PORT__"); String defineRegisterJar = ElementParameterParser.getValue(node, "__DEFINE_REGISTER_JAR__"); List<Map<String, String>> registerJarForHBase = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__REGISTER_JAR__"); String hiveServer = ElementParameterParser.getValue(node, "__HIVE_SERVER__"); boolean isCustom = "CUSTOM".equals(ElementParameterParser.getValue(node, "__DISTRIBUTION__")); boolean useYarn = "true".equals(ElementParameterParser.getValue(node, "__USE_YARN__")); boolean setResourceManager = "true".equals(ElementParameterParser.getValue(node, "__SET_RESOURCE_MANAGER__")); String yarnClasspathSeparator = ElementParameterParser.getValue(node, "__CLASSPATH_SEPARATOR__"); boolean useKrb = "true".equals(ElementParameterParser.getValue(node, "__USE_KRB__")); boolean cdh4CanBeSecured = "Cloudera_CDH4".equals(hiveVersion) && (("HIVE".equalsIgnoreCase(hiveServer) && "EMBEDDED".equalsIgnoreCase(connectionMode)) || "HIVE2".equalsIgnoreCase(hiveServer)); boolean securityIsEnabled = useKrb && (isCustom || ("HDP_1_0".equals(hiveVersion) || "HDP_1_2".equals(hiveVersion) || "HDP_1_3".equals(hiveVersion) || cdh4CanBeSecured)); boolean securedStandaloneHive2 = securityIsEnabled && "HIVE2".equalsIgnoreCase(hiveServer) && "STANDALONE".equalsIgnoreCase(connectionMode); boolean securedEmbedded = securityIsEnabled && "EMBEDDED".equalsIgnoreCase(connectionMode); stringBuffer.append(TEXT_96); stringBuffer.append(yarnClasspathSeparator); stringBuffer.append(TEXT_97); stringBuffer.append(cid); stringBuffer.append(TEXT_98); stringBuffer.append(cid); stringBuffer.append(TEXT_99); if (!isCustom && ("HDP_1_2".equals(hiveVersion) || "HDP_1_3".equals(hiveVersion))) { String mapMemory = ElementParameterParser.getValue(node, "__MAPRED_JOB_MAP_MEMORY_MB__"); String reduceMemory = ElementParameterParser.getValue(node, "__MAPRED_JOB_REDUCE_MEMORY_MB__"); stringBuffer.append(TEXT_100); stringBuffer.append(cid); stringBuffer.append(TEXT_101); stringBuffer.append(mapMemory); stringBuffer.append(TEXT_102); stringBuffer.append(cid); stringBuffer.append(TEXT_103); stringBuffer.append(reduceMemory); stringBuffer.append(TEXT_104); } if (securedEmbedded) { String namenodePrincipal = ElementParameterParser.getValue(node, "__NAMENODE_PRINCIPAL__"); String jobtrackerPrincipal = ElementParameterParser.getValue(node, "__JOBTRACKER_PRINCIPAL__"); stringBuffer.append(TEXT_105); stringBuffer.append(cid); stringBuffer.append(TEXT_106); stringBuffer.append(namenodePrincipal); stringBuffer.append(TEXT_107); stringBuffer.append(cid); stringBuffer.append(TEXT_108); stringBuffer.append(jobtrackerPrincipal); stringBuffer.append(TEXT_109); } if ((isCustom && useYarn) || (!isCustom && ("PIVOTAL_HD_1_0_1".equals(hiveVersion) || "HDP_2_0".equals(hiveVersion) || "Cloudera_CDH4_YARN".equals(hiveVersion)))) { if (setResourceManager) { String resourceManager = ElementParameterParser.getValue(node, "__RESOURCE_MANAGER__"); stringBuffer.append(TEXT_110); stringBuffer.append(cid); stringBuffer.append(TEXT_111); stringBuffer.append(cid); stringBuffer.append(TEXT_112); stringBuffer.append(resourceManager); stringBuffer.append(TEXT_113); } boolean setSchedulerAddress = "true".equals(ElementParameterParser.getValue(node, "__SET_SCHEDULER_ADDRESS__")); if (setSchedulerAddress) { String schedulerAddress = ElementParameterParser.getValue(node, "__RESOURCEMANAGER_SCHEDULER_ADDRESS__"); stringBuffer.append(TEXT_114); stringBuffer.append(cid); stringBuffer.append(TEXT_115); stringBuffer.append(schedulerAddress); stringBuffer.append(TEXT_116); } if ("EMBEDDED".equals(connectionMode)) { stringBuffer.append(TEXT_117); stringBuffer.append(cid); stringBuffer.append(TEXT_118); } boolean setMemory = "true".equals(ElementParameterParser.getValue(node, "__SET_MEMORY__")); if (setMemory) { String mapMemory = ElementParameterParser.getValue(node, "__MAPREDUCE_MAP_MEMORY_MB__"); String reduceMemory = ElementParameterParser.getValue(node, "__MAPREDUCE_REDUCE_MEMORY_MB__"); String amMemory = ElementParameterParser.getValue(node, "__YARN_APP_MAPREDUCE_AM_RESOURCE_MB__"); stringBuffer.append(TEXT_119); stringBuffer.append(cid); stringBuffer.append(TEXT_120); stringBuffer.append(mapMemory); stringBuffer.append(TEXT_121); stringBuffer.append(cid); stringBuffer.append(TEXT_122); stringBuffer.append(reduceMemory); stringBuffer.append(TEXT_123); stringBuffer.append(cid); stringBuffer.append(TEXT_124); stringBuffer.append(amMemory); stringBuffer.append(TEXT_125); } } List<Map<String, String>> advProps = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__ADVANCED_PROPERTIES__"); if (advProps != null) { for (Map<String, String> item : advProps) { stringBuffer.append(TEXT_126); stringBuffer.append(cid); stringBuffer.append(TEXT_127); stringBuffer.append(item.get("PROPERTY")); stringBuffer.append(TEXT_128); stringBuffer.append(item.get("VALUE")); stringBuffer.append(TEXT_129); } } stringBuffer.append(TEXT_130); stringBuffer.append(cid); stringBuffer.append(TEXT_131); if ("true".equalsIgnoreCase(storeByHBase) && !("EMBEDDED".equals(connectionMode) && "MAPR2".equals(hiveVersion))) { stringBuffer.append(TEXT_132); stringBuffer.append(cid); stringBuffer.append(TEXT_133); stringBuffer.append(cid); stringBuffer.append(TEXT_134); if (zookeeperQuorumForHBase != null && !"".equals(zookeeperQuorumForHBase) && !"\"\"".equals(zookeeperQuorumForHBase)) { stringBuffer.append(TEXT_135); stringBuffer.append(cid); stringBuffer.append(TEXT_136); stringBuffer.append(zookeeperQuorumForHBase); stringBuffer.append(TEXT_137); } stringBuffer.append(TEXT_138); if (zookeeperClientPortForHBase != null && !"".equals(zookeeperClientPortForHBase) && !"\"\"".equals(zookeeperClientPortForHBase)) { stringBuffer.append(TEXT_139); stringBuffer.append(cid); stringBuffer.append(TEXT_140); stringBuffer.append(zookeeperClientPortForHBase); stringBuffer.append(TEXT_141); } stringBuffer.append(TEXT_142); if ("true".equalsIgnoreCase(defineRegisterJar) && registerJarForHBase != null && registerJarForHBase.size() > 0) { for (Map<String, String> jar : registerJarForHBase) { String path = jar.get("JAR_PATH"); if (path == null || "".equals(path) || "\"\"".equals(path)) { continue; } stringBuffer.append(TEXT_143); stringBuffer.append(cid); stringBuffer.append(TEXT_144); stringBuffer.append(path); stringBuffer.append(TEXT_145); } } stringBuffer.append(TEXT_146); stringBuffer.append(cid); stringBuffer.append(TEXT_147); } 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(dbname); 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); return stringBuffer.toString(); }