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> connections = node.getOutgoingSortedConnections();
    String mode = ElementParameterParser.getValue(node, "__GENERATION_MODE__");

    if (connections != null && connections.size() > 0) {

      boolean hasConn = false;

      // get all the children collections of the loop node.
      for (IConnection conn : connections) {
        if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
          hasConn = true;
        }
      }
      if (hasConn == true && ("Dom4j").equals(mode)) {

        stringBuffer.append(TEXT_2);
      }
    }

    stringBuffer.append(TEXT_3);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_4);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_5);
    stringBuffer.append(TEXT_6);
    return stringBuffer.toString();
  }
 public static void checkPigLoadIfDefineFunctions(INode iNode, List<INode> iNodes) {
   if (iNode != null) {
     List<? extends IConnection> connections = iNode.getIncomingConnections();
     for (IConnection conn : connections) {
       INode oriNode = conn.getSource();
       if (oriNode != null) {
         if (oriNode.getUniqueName() != null
             && oriNode.getUniqueName().startsWith(PigMapConstants.TPIGLOAD_NODE)) {
           IElementParameter elementParameter =
               oriNode.getElementParameter(PigMapConstants.DEFINE_FUNCTION);
           if (elementParameter != null && elementParameter.getValue() instanceof List) {
             // we can add this direct.
             List<Map<String, String>> defineFunctions =
                 (List<Map<String, String>>) elementParameter.getValue();
             if (defineFunctions.size() >= 0) {
               iNodes.add(oriNode);
             }
           }
         }
         if (iNode.getIncomingConnections().size() > 0) {
           checkPigLoadIfDefineFunctions(oriNode, iNodes);
         }
       }
     }
   }
 }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    BigDataCodeGeneratorArgument codeGenArgument = (BigDataCodeGeneratorArgument) argument;

    INode node = (INode) codeGenArgument.getArgument();

    String cid = node.getUniqueName();

    List<IMetadataTable> metadatas = node.getMetadataList();

    if (metadatas != null && metadatas.size() > 0) {
      IMetadataTable metadata = metadatas.get(0);
      if (metadata != null) {

        String folder = ElementParameterParser.getValue(node, "__FILENAME__");
        String fileAction = ElementParameterParser.getValue(node, "__FILE_ACTION__");

        List<? extends IConnection> conns = node.getIncomingConnections();
        if (conns != null) {

          if (conns.size() > 0) {

            IConnection conn = conns.get(0);
            String connName = conn.getName();

            if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
              List<IMetadataColumn> columns = metadata.getListColumns();
              if (((org.talend.core.model.process.AbstractNode) node).isMapOnlyAfterReduce()) {

                stringBuffer.append(TEXT_1);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_2);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_3);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_4);

              } else {

                stringBuffer.append(TEXT_5);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_6);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_7);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_8);
              }
            }
          }
        }
      }
    }

    return stringBuffer.toString();
  }
 /*
  * use to synchronize column list for output connections.
  */
 private void syncOutputNodeColumnsList(List<ColumnNameChanged> columnNameChanged) {
   if (outputdataContainer == null) {
     return;
   }
   for (IConnection conn : node.getOutgoingConnections()) {
     INode targetNode = conn.getTarget();
     EConnectionType connStyle = conn.getLineStyle();
     if (EConnectionType.FLOW_MAIN.equals(connStyle)
         || EConnectionType.FLOW_MERGE.equals(connStyle)
         || EConnectionType.FLOW_REF.equals(connStyle)) {
       ColumnListController.updateColumnList(targetNode, columnNameChanged);
       // fix for TDI-23202
       // reset value in order to call "firePropertyChange(RETURNS_CHANGED, null, null)"
       IElementParameter defaultMap =
           targetNode.getElementParameter(EParameterName.DEFAULT_MAP.getName());
       if (defaultMap != null) {
         if ("tFlowToIterate".equals(targetNode.getComponent().getName())) {
           // update target properties incase any old columns are removed
           IElementParameter elementParameter = targetNode.getElementParameter("MAP");
           if (elementParameter != null) {
             Object value = elementParameter.getValue();
             if (value instanceof List) {
               for (Object obj : (List) value) {
                 if (obj instanceof Map) {
                   Object object = ((Map) obj).get("VALUE");
                   if (newOutputMetadata != null
                       && !newOutputMetadata.getListColumns().isEmpty()) {
                     boolean found = false;
                     for (IMetadataColumn column : newOutputMetadata.getListColumns()) {
                       if (column.getLabel().equals(object)) {
                         found = true;
                       }
                     }
                     if (!found) {
                       ((Map) obj)
                           .put("VALUE", newOutputMetadata.getListColumns().get(0).getLabel());
                     }
                   } else {
                     ((Map) obj).put("VALUE", "");
                   }
                 }
               }
             }
           }
         }
         targetNode.setPropertyValue(EParameterName.DEFAULT_MAP.getName(), defaultMap.getValue());
       }
     }
   }
 }
  public void rebuildModelInputs(List<? extends IConnection> inputConn, PigMapData mapData) {
    // remove no used input table
    if (mapData.getInputTables().size() != inputConn.size()) {
      List tableToRemove = new ArrayList();
      for (InputTable inputTable : mapData.getInputTables()) {
        boolean found = false;
        for (IConnection connection : inputConn) {
          if (inputTable.getName().equals(connection.getName())) {
            found = true;
          }
        }
        if (!found) {
          for (TableNode tableNode : inputTable.getNodes()) {
            PigMapUtil.detachNodeConnections(tableNode, mapData);
          }
          tableToRemove.add(inputTable);
          PigMapUtil.detachFilterSource(inputTable, mapData);
        }
      }
      mapData.getInputTables().removeAll(tableToRemove);
    }

    for (IConnection inData : inputConn) {
      String name = inData.getName();
      InputTable inputTable = null;
      for (InputTable in : mapData.getInputTables()) {
        if (in.getName() != null && in.getName().equals(name)) {
          inputTable = in;
          break;
        }
      }
      if (inputTable == null) {
        inputTable = PigmapFactory.eINSTANCE.createInputTable();
        inputTable.setName(name);
        inputTable.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
        mapData
            .getInputTables()
            .add(inputTable.isLookup() ? mapData.getInputTables().size() : 0, inputTable);
      } else {
        inputTable.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
      }
      // by default
      if (inputTable.isLookup() && inputTable.getJoinModel() == null) {
        inputTable.setJoinModel(TableSettingsConstant.LEFT_OUTER_JOIN);
      }
      if (inputTable.isLookup() && inputTable.getJoinOptimization() == null) {
        inputTable.setJoinOptimization(PIG_MAP_JOIN_OPTIMIZATION.NONE.toString());
      }
      rebuildInputTable(inputTable, inData.getMetadataTable(), mapData);
    }
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    // this util class use by set log4j debug paramters
    class DefaultLog4jFileUtil {

      INode node = null;
      String cid = null;
      boolean isLog4jEnabled = false;
      String label = null;

      public DefaultLog4jFileUtil() {}

      public DefaultLog4jFileUtil(INode node) {
        this.node = node;
        this.cid = node.getUniqueName();
        this.label = cid;
        this.isLog4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        node.getProcess(), "__LOG4J_ACTIVATE__"));
      }

      public void setCid(String cid) {
        this.cid = cid;
      }

      // for all tFileinput* components
      public void startRetriveDataInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_2);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_3);
        }
      }

      public void retrievedDataNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_4);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_6);
        }
      }

      public void retrievedDataNumberInfoFromGlobalMap(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_7);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_8);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_9);
        }
      }

      // for all tFileinput* components
      public void retrievedDataNumberInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_10);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_11);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_12);
        }
      }

      public void writeDataFinishInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_13);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_15);
        }
      }

      // TODO delete it and remove all log4jSb parameter from components
      public void componentStartInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_16);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_17);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node, boolean hasIncreased) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_18);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_19);
          stringBuffer.append(cid);
          stringBuffer.append(hasIncreased ? "" : "+1");
          stringBuffer.append(TEXT_20);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node) {
        debugRetriveData(node, true);
      }

      // TODO rename or delete it
      public void debugWriteData(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_21);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_22);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_23);
        }
      }

      public void logCurrentRowNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_24);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_25);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_26);
        }
      }

      public void logDataCountInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_27);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_28);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_29);
        }
      }
    }

    final DefaultLog4jFileUtil log4jFileUtil =
        new DefaultLog4jFileUtil(
            (INode)
                (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument)
                    .getArgument()));

    stringBuffer.append(TEXT_30);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    boolean customEncoding =
        "true".equals(ElementParameterParser.getValue(node, "__CUSTOM_ENCODING__"));
    String encoding = ElementParameterParser.getValue(node, "__ENCODING__");

    List<? extends IConnection> conns = node.getOutgoingSortedConnections();
    String firstConnName = "";
    if (conns != null) {
      if (conns.size() > 0) {
        IConnection conn = conns.get(0);
        if (conn != null && conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
          firstConnName = conn.getName();

          stringBuffer.append(TEXT_31);
          stringBuffer.append(firstConnName);
          stringBuffer.append(TEXT_32);
          stringBuffer.append(conn.getName());
          stringBuffer.append(TEXT_33);
        }
      }
    }

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0) && firstConnName.length() > 0) {
      IMetadataTable metadata = metadatas.get(0);

      String typeFile = ElementParameterParser.getValue(node, "__TYPEFILE__");
      if (typeFile.equals("SEQUENCE")) {

        String keyColumn = ElementParameterParser.getValue(node, "__KEYCOLUMN__");
        String valueColumn = ElementParameterParser.getValue(node, "__VALUECOLUMN__");

        List<IMetadataColumn> listColumns = metadata.getListColumns();
        String talendKeyClass = "";
        String talendValueClass = "";
        for (IMetadataColumn column : listColumns) {
          if (column.getLabel().equals(keyColumn)) {
            talendKeyClass = column.getTalendType();
          }
          if (column.getLabel().equals(valueColumn)) {
            talendValueClass = column.getTalendType();
          }
        }

        String hadoopVersion = null;
        String distribution = null;
        boolean useExistingConnection =
            "true".equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"));
        if (!useExistingConnection) {
          distribution = ElementParameterParser.getValue(node, "__DISTRIBUTION__");
          hadoopVersion = ElementParameterParser.getValue(node, "__DB_VERSION__");
        } else {
          String connectionSid = ElementParameterParser.getValue(node, "__CONNECTION__");
          List<? extends INode> nodes = node.getProcess().getGeneratingNodes();
          for (INode targetNode : nodes) {
            if (targetNode.getUniqueName().equals(connectionSid)) {
              hadoopVersion = ElementParameterParser.getValue(targetNode, "__DB_VERSION__");
              distribution = ElementParameterParser.getValue(targetNode, "__DISTRIBUTION__");
              break;
            }
          }
        }

        org.talend.hadoop.distribution.component.HDFSComponent hdfsDistrib = null;
        try {
          hdfsDistrib =
              (org.talend.hadoop.distribution.component.HDFSComponent)
                  org.talend.hadoop.distribution.DistributionFactory.buildDistribution(
                      distribution, hadoopVersion);
        } catch (java.lang.Exception e) {
          e.printStackTrace();
          return "";
        }
        boolean isCustom =
            hdfsDistrib instanceof org.talend.hadoop.distribution.custom.CustomDistribution;

        stringBuffer.append(TEXT_34);

        String keyClass = "org.apache.hadoop.io.Text";
        if (talendKeyClass.equals("id_Boolean")) keyClass = "org.apache.hadoop.io.BooleanWritable";
        if (talendKeyClass.equals("id_Byte")) keyClass = "org.apache.hadoop.io.ByteWritable";
        if (talendKeyClass.equals("id_byte[]")) keyClass = "org.apache.hadoop.io.BytesWritable";
        if (talendKeyClass.equals("id_Double")) keyClass = "org.apache.hadoop.io.DoubleWritable";
        if (talendKeyClass.equals("id_Float")) keyClass = "org.apache.hadoop.io.FloatWritable";
        if (talendKeyClass.equals("id_Integer")) keyClass = "org.apache.hadoop.io.IntWritable";
        if (talendKeyClass.equals("id_Long")) keyClass = "org.apache.hadoop.io.LongWritable";
        if (talendKeyClass.equals("id_String")) keyClass = "org.apache.hadoop.io.Text";
        if (talendKeyClass.equals("id_Short")) {
          if (isCustom || hdfsDistrib.doSupportSequenceFileShortType()) {
            keyClass = "org.apache.hadoop.io.ShortWritable";
          } else {
            keyClass = "org.apache.hadoop.io.IntWritable";
          }
        }

        String valueClass = "org.apache.hadoop.io.Text";
        if (talendValueClass.equals("id_Boolean"))
          valueClass = "org.apache.hadoop.io.BooleanWritable";
        if (talendValueClass.equals("id_Byte")) valueClass = "org.apache.hadoop.io.ByteWritable";
        if (talendValueClass.equals("id_byte[]")) valueClass = "org.apache.hadoop.io.BytesWritable";
        if (talendValueClass.equals("id_Double"))
          valueClass = "org.apache.hadoop.io.DoubleWritable";
        if (talendValueClass.equals("id_Float")) valueClass = "org.apache.hadoop.io.FloatWritable";
        if (talendValueClass.equals("id_Integer")) valueClass = "org.apache.hadoop.io.IntWritable";
        if (talendValueClass.equals("id_Long")) valueClass = "org.apache.hadoop.io.LongWritable";
        if (talendValueClass.equals("id_String")) valueClass = "org.apache.hadoop.io.Text";
        if (talendValueClass.equals("id_Short")) {
          if (isCustom || hdfsDistrib.doSupportSequenceFileShortType()) {
            valueClass = "org.apache.hadoop.io.ShortWritable";
          } else {
            valueClass = "org.apache.hadoop.io.IntWritable";
          }
        }

        stringBuffer.append(TEXT_35);
        stringBuffer.append(firstConnName);
        stringBuffer.append(TEXT_36);
        stringBuffer.append(keyColumn);
        stringBuffer.append(TEXT_37);
        stringBuffer.append(talendKeyClass.equals("id_Short") ? "(short)" : "");
        stringBuffer.append(TEXT_38);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_39);
        stringBuffer.append(
            ((keyClass.equals("org.apache.hadoop.io.Text")) ? "toString()" : "get()"));
        stringBuffer.append(TEXT_40);
        stringBuffer.append(firstConnName);
        stringBuffer.append(TEXT_41);
        stringBuffer.append(valueColumn);
        stringBuffer.append(TEXT_42);
        stringBuffer.append(talendValueClass.equals("id_Short") ? "(short)" : "");
        stringBuffer.append(TEXT_43);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_44);
        stringBuffer.append(
            ((valueClass.equals("org.apache.hadoop.io.Text")) ? "toString()" : "get()"));
        stringBuffer.append(TEXT_45);

      } else {
        if (metadata != null) {
          List<IMetadataColumn> listColumns = metadata.getListColumns();
          for (int valueN = 0; valueN < listColumns.size(); valueN++) {
            IMetadataColumn column = listColumns.get(valueN);

            String typeToGenerate =
                JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
            JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
            String patternValue =
                column.getPattern() == null || column.getPattern().trim().length() == 0
                    ? null
                    : column.getPattern();
            if (javaType == JavaTypesManager.STRING || javaType == JavaTypesManager.OBJECT) {

              stringBuffer.append(TEXT_46);
              stringBuffer.append(firstConnName);
              stringBuffer.append(TEXT_47);
              stringBuffer.append(column.getLabel());
              stringBuffer.append(TEXT_48);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_49);
              stringBuffer.append(valueN);
              stringBuffer.append(TEXT_50);

            } else {

              stringBuffer.append(TEXT_51);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_52);
              stringBuffer.append(valueN);
              stringBuffer.append(TEXT_53);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_54);
              stringBuffer.append(valueN);
              stringBuffer.append(TEXT_55);

              if (javaType == JavaTypesManager.DATE) {

                stringBuffer.append(TEXT_56);
                stringBuffer.append(firstConnName);
                stringBuffer.append(TEXT_57);
                stringBuffer.append(column.getLabel());
                stringBuffer.append(TEXT_58);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_59);
                stringBuffer.append(valueN);
                stringBuffer.append(TEXT_60);
                stringBuffer.append(patternValue);
                stringBuffer.append(TEXT_61);

              } else if (javaType == JavaTypesManager.BYTE_ARRAY) {

                stringBuffer.append(TEXT_62);
                stringBuffer.append(firstConnName);
                stringBuffer.append(TEXT_63);
                stringBuffer.append(column.getLabel());
                stringBuffer.append(TEXT_64);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_65);
                stringBuffer.append(valueN);
                stringBuffer.append(TEXT_66);
                stringBuffer.append((customEncoding ? encoding : "utf8Charset"));
                stringBuffer.append(TEXT_67);

              } else {

                stringBuffer.append(TEXT_68);
                stringBuffer.append(firstConnName);
                stringBuffer.append(TEXT_69);
                stringBuffer.append(column.getLabel());
                stringBuffer.append(TEXT_70);
                stringBuffer.append(typeToGenerate);
                stringBuffer.append(TEXT_71);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_72);
                stringBuffer.append(valueN);
                stringBuffer.append(TEXT_73);
              }

              stringBuffer.append(TEXT_74);
              stringBuffer.append(firstConnName);
              stringBuffer.append(TEXT_75);
              stringBuffer.append(column.getLabel());
              stringBuffer.append(TEXT_76);
              stringBuffer.append(JavaTypesManager.getDefaultValueFromJavaType(typeToGenerate));
              stringBuffer.append(TEXT_77);
            }
          } // for
        }
      }

      stringBuffer.append(TEXT_78);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_79);

      log4jFileUtil.debugRetriveData(node);
    }

    stringBuffer.append(TEXT_80);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();

    String cid = node.getUniqueName();

    List<? extends IConnection> conns = node.getOutgoingSortedConnections();

    String bufferSize = ElementParameterParser.getValue(node, "__RULES_BUFFER__");

    if (conns != null && conns.size() > 0) {

      // get the name of the incoming connection
      IConnection inConn = null;
      if (node.getIncomingConnections() != null) {
        for (IConnection incomingConn : node.getIncomingConnections()) {
          if (incomingConn.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
            inConn = incomingConn;
            break;
          }
        }
      }
      if (inConn == null) return "";

      for (IConnection conn : conns) {
        if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.MAIN)) {

          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(cid);
      stringBuffer.append(TEXT_6);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_7);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_8);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_9);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_10);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_11);
      stringBuffer.append(inConn.getName());
      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);

      for (int i = 0; i < conns.size(); i++) {
        IConnection conn = conns.get(i);
        if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.MAIN)) {

          stringBuffer.append(TEXT_19);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_20);
          stringBuffer.append(conn.getName());
          stringBuffer.append(TEXT_21);
          stringBuffer.append(conn.getName());
          stringBuffer.append(TEXT_22);
          stringBuffer.append(conn.getName());
          stringBuffer.append(TEXT_23);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_24);
        }
      }

      stringBuffer.append(TEXT_25);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_26);
    }

    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    // Parse the inputs to this javajet generator.
    final BigDataCodeGeneratorArgument codeGenArgument = (BigDataCodeGeneratorArgument) argument;
    final INode node = (INode) codeGenArgument.getArgument();
    final String cid = node.getUniqueName();

    TSqlRowUtil tSqlRowUtil = new TSqlRowUtil(node);
    IConnection inConn = tSqlRowUtil.getIncomingConnections().get(0);
    String inConnTypeName = codeGenArgument.getRecordStructName(inConn);
    String outConnTypeName =
        codeGenArgument.getRecordStructName(tSqlRowUtil.getOutgoingConnection());

    Integer topN = Integer.parseInt(ElementParameterParser.getValue(node, "__TOP_NB__"));
    String nameIDCol = ElementParameterParser.getValue(node, "__ID_COLUMN__");
    String modelPath = ElementParameterParser.getValue(node, "__MODEL_PATH__");

    String ctx =
        ("SPARKSTREAMING".equals(node.getComponent().getType()))
            ? "ctx.sparkContext().sc()"
            : "ctx.sc()";

    stringBuffer.append(TEXT_1);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(ctx);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(modelPath);
    stringBuffer.append(TEXT_4);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_5);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_6);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_8);

    if ("SPARKSTREAMING".equals(node.getComponent().getType())
        && !org.talend.designer.common.tmap.LookupUtil.isNodeInBatchMode(node)) {

      stringBuffer.append(TEXT_9);
      stringBuffer.append(outConnTypeName);
      stringBuffer.append(TEXT_10);
      stringBuffer.append(tSqlRowUtil.getOutgoingConnection().getName());
      stringBuffer.append(TEXT_11);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_12);
      stringBuffer.append(inConnTypeName);
      stringBuffer.append(TEXT_13);
      stringBuffer.append(outConnTypeName);
      stringBuffer.append(TEXT_14);
      stringBuffer.append(outConnTypeName);
      stringBuffer.append(TEXT_15);
      stringBuffer.append(inConnTypeName);
      stringBuffer.append(TEXT_16);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_17);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_18);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_19);
      stringBuffer.append(inConnTypeName);
      stringBuffer.append(TEXT_20);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_21);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_22);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_23);
      stringBuffer.append(topN);
      stringBuffer.append(TEXT_24);
      stringBuffer.append(nameIDCol);
      stringBuffer.append(TEXT_25);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_26);
      stringBuffer.append(outConnTypeName);
      stringBuffer.append(TEXT_27);

    } else {

      stringBuffer.append(TEXT_28);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_29);
      stringBuffer.append(ctx);
      stringBuffer.append(TEXT_30);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_31);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_32);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_33);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_34);
      stringBuffer.append(inConnTypeName);
      stringBuffer.append(TEXT_35);
      stringBuffer.append(outConnTypeName);
      stringBuffer.append(TEXT_36);
      stringBuffer.append(tSqlRowUtil.getOutgoingConnection().getName());
      stringBuffer.append(TEXT_37);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_38);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_39);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_40);
      stringBuffer.append(inConn.getName());
      stringBuffer.append(TEXT_41);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_42);
      stringBuffer.append(topN);
      stringBuffer.append(TEXT_43);
      stringBuffer.append(nameIDCol);
      stringBuffer.append(TEXT_44);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_45);
      stringBuffer.append(outConnTypeName);
      stringBuffer.append(TEXT_46);
    }

    stringBuffer.append(TEXT_47);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();
    String version_selection = ElementParameterParser.getValue(node, "__VERSION_SELECTION__");
    if (version_selection.equals("VTIGER_50")) {

      String serverAddr = ElementParameterParser.getValue(node, "__SERVERADDR__");
      String port = ElementParameterParser.getValue(node, "__PORT__");
      String vtigerPath = ElementParameterParser.getValue(node, "__VTIGERPATH__");
      String userName = ElementParameterParser.getValue(node, "__USERNAME__");
      String password = ElementParameterParser.getValue(node, "__PASSWORD__");
      String version = ElementParameterParser.getValue(node, "__VERSION__");
      String method = ElementParameterParser.getValue(node, "__METHODNAME__");
      String outgoingConnName = null;
      List<? extends IConnection> conns = node.getOutgoingSortedConnections();
      if (conns != null && conns.size() > 0) {
        IConnection conn = conns.get(0);
        outgoingConnName = conn.getName();
      }
      List<IMetadataColumn> metadataColumns = null;
      List<IMetadataTable> metadataTables = node.getMetadataList();

      stringBuffer.append(TEXT_1);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_2);
      stringBuffer.append(userName);
      stringBuffer.append(TEXT_3);
      stringBuffer.append(password);
      stringBuffer.append(TEXT_4);
      stringBuffer.append(version);
      stringBuffer.append(TEXT_5);
      stringBuffer.append(serverAddr);
      stringBuffer.append(TEXT_6);
      stringBuffer.append(port);
      stringBuffer.append(TEXT_7);
      stringBuffer.append(vtigerPath);
      stringBuffer.append(TEXT_8);

      if (metadataTables != null && metadataTables.size() > 0) {
        IMetadataTable metadataTable = metadataTables.get(0);
        if (metadataTable != null) {
          metadataColumns = metadataTable.getListColumns();
          if (("searchContactsByEmail").equals(method)
              || ("getContacts").equals(method)
              || ("getTasks").equals(method)
              || ("getClndr").equals(method)
              || ("get_KBase_details").equals(method)) {
            if (("searchContactsByEmail").equals(method) || ("getContacts").equals(method)) {

              stringBuffer.append(TEXT_9);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_10);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_11);
              stringBuffer.append(method);
              stringBuffer.append(TEXT_12);

            } else if (("getTasks").equals(method)) {

              stringBuffer.append(TEXT_13);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_14);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_15);
              stringBuffer.append(method);
              stringBuffer.append(TEXT_16);

            } else if (("getClndr").equals(method)) {

              stringBuffer.append(TEXT_17);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_18);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_19);
              stringBuffer.append(method);
              stringBuffer.append(TEXT_20);

            } else if (("get_KBase_details").equals(method)) {

              stringBuffer.append(TEXT_21);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_22);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_23);
              stringBuffer.append(method);
              stringBuffer.append(TEXT_24);
            }

            stringBuffer.append(TEXT_25);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_26);

            for (IMetadataColumn metadataColumn : metadataColumns) {
              if (("searchContactsByEmail").equals(method)
                  || ("getContacts").equals(method)
                  || ("getTasks").equals(method)
                  || ("getClndr").equals(method)) {

                stringBuffer.append(TEXT_27);
                stringBuffer.append(outgoingConnName);
                stringBuffer.append(TEXT_28);
                stringBuffer.append(metadataColumn.getLabel());
                stringBuffer.append(TEXT_29);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_30);
                stringBuffer.append(metadataColumn.getLabel().substring(0, 1).toUpperCase());
                stringBuffer.append(metadataColumn.getLabel().substring(1));
                stringBuffer.append(TEXT_31);

              } else if (("get_KBase_details").equals(method)) {

                stringBuffer.append(TEXT_32);
                stringBuffer.append(outgoingConnName);
                stringBuffer.append(TEXT_33);
                stringBuffer.append(metadataColumn.getLabel());
                stringBuffer.append(TEXT_34);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_35);
              }
            }

            stringBuffer.append(TEXT_36);

          } else {
            for (IMetadataColumn metadataColumn : metadataColumns) {

              stringBuffer.append(TEXT_37);
              stringBuffer.append(outgoingConnName);
              stringBuffer.append(TEXT_38);
              stringBuffer.append(metadataColumn.getLabel());
              stringBuffer.append(TEXT_39);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_40);
              stringBuffer.append(method);
              stringBuffer.append(TEXT_41);
            }
          }
        }
      }
      // *****************************************************version 5.1
      // start**************************************
    } else {

      stringBuffer.append(TEXT_42);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_43);

      List<IMetadataTable> metadatas = node.getMetadataList();
      if ((metadatas != null) && (metadatas.size() > 0)) {
        IMetadataTable metadata = metadatas.get(0);

        if (metadata != null) {
          List<IMetadataColumn> columnList = metadata.getListColumns();
          int nbSchemaColumns = columnList.size();
          List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections();

          // If output columns are defined
          if (nbSchemaColumns > 0 && outgoingConns != null && outgoingConns.size() > 0) {
            String endpoint = ElementParameterParser.getValue(node, "__ENDPOINT__");
            String username = ElementParameterParser.getValue(node, "__USERNAME_510__");
            String accessKey = ElementParameterParser.getValue(node, "__ACCESS_KEY__");

            stringBuffer.append(TEXT_44);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_45);
            stringBuffer.append(endpoint);
            stringBuffer.append(TEXT_46);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_47);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_48);
            stringBuffer.append(username);
            stringBuffer.append(TEXT_49);
            stringBuffer.append(accessKey);
            stringBuffer.append(TEXT_50);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_51);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_52);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_53);

            boolean bIsManualQuery =
                ("true").equals(ElementParameterParser.getValue(node, "__MANUAL_QUERY__"));
            String sql = "";

            // Build the request SQL
            if (bIsManualQuery) {
              sql = ElementParameterParser.getValue(node, "__QUERY__");
              sql = sql.replaceAll("\n", " ").replaceAll("\r", " ");
            } else {
              String modulename =
                  ElementParameterParser.getValue(node, "__MODULENAME_510__").trim();
              String condition = ElementParameterParser.getValue(node, "__CONDITION__").trim();

              StringBuilder sb = new StringBuilder("\"select ");
              for (IMetadataColumn column : columnList) {
                sb.append(column.getLabel());
                sb.append(",");
              }
              sb.deleteCharAt(sb.lastIndexOf(","));
              sb.append(" from ").append(modulename);
              if (condition != null && condition.length() > 3) {
                sb.append(" where ").append(condition.substring(1, condition.length() - 1));
              }
              sb.append("\"");
              sql = sb.toString();
            }

            IConnection outgoingConn = outgoingConns.get(0);
            if (outgoingConn
                .getLineStyle()
                .hasConnectionCategory(IConnectionCategory.DATA)) { // start 1

              stringBuffer.append(TEXT_54);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_55);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_56);
              stringBuffer.append(sql);
              stringBuffer.append(TEXT_57);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_58);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_59);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_60);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_61);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_62);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_63);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_64);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_65);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_66);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_67);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_68);

              for (int i = 0; i < columnList.size(); i++) {
                IMetadataColumn column = columnList.get(i);

                String typeToGenerate =
                    JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());

                JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());

                String patternValue =
                    column.getPattern() == null || column.getPattern().trim().length() == 0
                        ? null
                        : column.getPattern();

                stringBuffer.append(TEXT_69);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_70);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_71);
                stringBuffer.append(columnList.get(i).getLabel());
                stringBuffer.append(TEXT_72);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_73);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_74);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_75);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_76);

                if (javaType == JavaTypesManager.STRING
                    || javaType == JavaTypesManager.OBJECT) { // String or Object

                  stringBuffer.append(TEXT_77);
                  stringBuffer.append(outgoingConn.getName());
                  stringBuffer.append(TEXT_78);
                  stringBuffer.append(columnList.get(i).getLabel());
                  stringBuffer.append(TEXT_79);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_80);

                } else if (javaType == JavaTypesManager.DATE) { // Date

                  stringBuffer.append(TEXT_81);
                  stringBuffer.append(outgoingConn.getName());
                  stringBuffer.append(TEXT_82);
                  stringBuffer.append(columnList.get(i).getLabel());
                  stringBuffer.append(TEXT_83);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_84);
                  stringBuffer.append(patternValue);
                  stringBuffer.append(TEXT_85);

                } else if (javaType == JavaTypesManager.BYTE_ARRAY) { // byte[]

                  stringBuffer.append(TEXT_86);
                  stringBuffer.append(outgoingConn.getName());
                  stringBuffer.append(TEXT_87);
                  stringBuffer.append(columnList.get(i).getLabel());
                  stringBuffer.append(TEXT_88);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_89);

                } else { // other

                  stringBuffer.append(TEXT_90);
                  stringBuffer.append(outgoingConn.getName());
                  stringBuffer.append(TEXT_91);
                  stringBuffer.append(columnList.get(i).getLabel());
                  stringBuffer.append(TEXT_92);
                  stringBuffer.append(typeToGenerate);
                  stringBuffer.append(TEXT_93);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_94);
                }

                stringBuffer.append(TEXT_95);
                stringBuffer.append(outgoingConn.getName());
                stringBuffer.append(TEXT_96);
                stringBuffer.append(columnList.get(i).getLabel());
                stringBuffer.append(TEXT_97);
                stringBuffer.append(JavaTypesManager.getDefaultValueFromJavaType(typeToGenerate));
                stringBuffer.append(TEXT_98);
              }

              stringBuffer.append(TEXT_99);
            }
          }
        }
      }
    } // version 5.1.0 end

    stringBuffer.append(TEXT_100);
    stringBuffer.append(TEXT_101);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();

    String cid = node.getUniqueName();

    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);

    class BasicLogUtil {
      protected String cid = "";
      protected org.talend.core.model.process.INode node = null;
      protected boolean log4jEnabled = false;
      private String logID = "";

      private BasicLogUtil() {}

      public BasicLogUtil(org.talend.core.model.process.INode node) {
        this.node = node;
        String cidx = this.node.getUniqueName();
        if (cidx.matches("^.*?tAmazonAuroraOutput_\\d+_out$")) {
          cidx = cidx.substring(0, cidx.length() - 4); // 4 ==> "_out".length();
        }
        this.cid = cidx;
        this.log4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        this.node.getProcess(), "__LOG4J_ACTIVATE__"));
        this.log4jEnabled =
            this.log4jEnabled
                && this.node.getComponent().isLog4JEnabled()
                && !"JOBLET".equals(node.getComponent().getComponentType().toString());
        this.logID = this.cid;
      }

      public String var(String varName) {
        return varName + "_" + this.cid;
      }

      public String str(String content) {
        return "\"" + content + "\"";
      }

      public void info(String... message) {
        log4j("info", message);
      }

      public void debug(String... message) {
        log4j("debug", message);
      }

      public void warn(String... message) {
        log4j("warn", message);
      }

      public void error(String... message) {
        log4j("error", message);
      }

      public void fatal(String... message) {
        log4j("fatal", message);
      }

      public void trace(String... message) {
        log4j("trace", message);
      }

      java.util.List<String> checkableList =
          java.util.Arrays.asList(new String[] {"info", "debug", "trace"});

      public void log4j(String level, String... messages) {
        if (this.log4jEnabled) {
          if (checkableList.contains(level)) {

            stringBuffer.append(TEXT_2);
            stringBuffer.append(level.substring(0, 1).toUpperCase() + level.substring(1));
            stringBuffer.append(TEXT_3);
          }

          stringBuffer.append(TEXT_4);
          stringBuffer.append(level);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(logID);
          stringBuffer.append(TEXT_6);
          for (String message : messages) {
            stringBuffer.append(TEXT_7);
            stringBuffer.append(message);
            stringBuffer.append(TEXT_8);
          }
          stringBuffer.append(TEXT_9);
        }
      }

      public boolean isActive() {
        return this.log4jEnabled;
      }
    }

    class LogUtil extends BasicLogUtil {

      private LogUtil() {}

      public LogUtil(org.talend.core.model.process.INode node) {
        super(node);
      }

      public void startWork() {
        info(str("Start to work."));
      }

      public void endWork() {
        info(str("Done."));
      }

      public void logIgnoredException(String exception) {
        warn(exception);
      }

      public void logPrintedException(String exception) {
        error(exception);
      }

      public void logException(String exception) {
        fatal(exception);
      }

      public void logCompSetting() {
        if (log4jEnabled) {

          stringBuffer.append(TEXT_10);
          stringBuffer.append(var("log4jParamters"));
          stringBuffer.append(TEXT_11);
          stringBuffer.append(TEXT_12);
          stringBuffer.append(var("log4jParamters"));
          stringBuffer.append(TEXT_13);

          java.util.Set<org.talend.core.model.process.EParameterFieldType> ignoredParamsTypes =
              new java.util.HashSet<org.talend.core.model.process.EParameterFieldType>();
          ignoredParamsTypes.addAll(
              java.util.Arrays.asList(
                  org.talend.core.model.process.EParameterFieldType.SCHEMA_TYPE,
                  org.talend.core.model.process.EParameterFieldType.LABEL,
                  org.talend.core.model.process.EParameterFieldType.EXTERNAL,
                  org.talend.core.model.process.EParameterFieldType.MAPPING_TYPE,
                  org.talend.core.model.process.EParameterFieldType.IMAGE,
                  org.talend.core.model.process.EParameterFieldType.TNS_EDITOR,
                  org.talend.core.model.process.EParameterFieldType.WSDL2JAVA,
                  org.talend.core.model.process.EParameterFieldType.GENERATEGRAMMARCONTROLLER,
                  org.talend.core.model.process.EParameterFieldType
                      .GENERATE_SURVIVORSHIP_RULES_CONTROLLER,
                  org.talend.core.model.process.EParameterFieldType.REFRESH_REPORTS,
                  org.talend.core.model.process.EParameterFieldType.BROWSE_REPORTS,
                  org.talend.core.model.process.EParameterFieldType.PALO_DIM_SELECTION,
                  org.talend.core.model.process.EParameterFieldType.GUESS_SCHEMA,
                  org.talend.core.model.process.EParameterFieldType.MATCH_RULE_IMEX_CONTROLLER,
                  org.talend.core.model.process.EParameterFieldType.MEMO_PERL,
                  org.talend.core.model.process.EParameterFieldType.DBTYPE_LIST,
                  org.talend.core.model.process.EParameterFieldType.VERSION,
                  org.talend.core.model.process.EParameterFieldType.TECHNICAL,
                  org.talend.core.model.process.EParameterFieldType.ICON_SELECTION,
                  org.talend.core.model.process.EParameterFieldType.JAVA_COMMAND,
                  org.talend.core.model.process.EParameterFieldType.TREE_TABLE,
                  org.talend.core.model.process.EParameterFieldType.VALIDATION_RULE_TYPE,
                  org.talend.core.model.process.EParameterFieldType.DCSCHEMA,
                  org.talend.core.model.process.EParameterFieldType.SURVIVOR_RELATION,
                  org.talend.core.model.process.EParameterFieldType.REST_RESPONSE_SCHEMA_TYPE));
          for (org.talend.core.model.process.IElementParameter ep :
              org.talend.core.model.utils.NodeUtil.getDisplayedParameters(node)) {
            if (!ep.isLog4JEnabled() || ignoredParamsTypes.contains(ep.getFieldType())) {
              continue;
            }
            String name = ep.getName();
            if (org.talend.core.model.process.EParameterFieldType.PASSWORD.equals(
                ep.getFieldType())) {
              String epName = "__" + name + "__";
              String password = "";
              if (org.talend.core.model.process.ElementParameterParser.canEncrypt(node, epName)) {
                password =
                    org.talend.core.model.process.ElementParameterParser.getEncryptedValue(
                        node, epName);
              } else {
                String passwordValue =
                    org.talend.core.model.process.ElementParameterParser.getValue(node, epName);
                if (passwordValue == null
                    || "".equals(passwordValue.trim())) { // for the value which empty
                  passwordValue = "\"\"";
                }
                password =
                    "******" + passwordValue + ")";
              }

              stringBuffer.append(TEXT_14);
              stringBuffer.append(var("log4jParamters"));
              stringBuffer.append(TEXT_15);
              stringBuffer.append(name);
              stringBuffer.append(TEXT_16);
              stringBuffer.append(password);
              stringBuffer.append(TEXT_17);

            } else {
              String value =
                  org.talend.core.model.utils.NodeUtil.getNormalizeParameterValue(node, ep);

              stringBuffer.append(TEXT_18);
              stringBuffer.append(var("log4jParamters"));
              stringBuffer.append(TEXT_19);
              stringBuffer.append(name);
              stringBuffer.append(TEXT_20);
              stringBuffer.append(value);
              stringBuffer.append(TEXT_21);
            }

            stringBuffer.append(TEXT_22);
            stringBuffer.append(var("log4jParamters"));
            stringBuffer.append(TEXT_23);
          }
        }
        debug(var("log4jParamters"));
      }

      // no use for now, because we log the data by rowStruct
      public void traceData(
          String rowStruct,
          java.util.List<org.talend.core.model.metadata.IMetadataColumn> columnList,
          String nbline) {
        if (log4jEnabled) {

          stringBuffer.append(TEXT_24);
          stringBuffer.append(var("log4jSb"));
          stringBuffer.append(TEXT_25);

          for (org.talend.core.model.metadata.IMetadataColumn column : columnList) {
            org.talend.core.model.metadata.types.JavaType javaType =
                org.talend.core.model.metadata.types.JavaTypesManager.getJavaTypeFromId(
                    column.getTalendType());
            String columnName = column.getLabel();
            boolean isPrimit =
                org.talend.core.model.metadata.types.JavaTypesManager.isJavaPrimitiveType(
                    column.getTalendType(), column.isNullable());
            if (isPrimit) {

              stringBuffer.append(TEXT_26);
              stringBuffer.append(var("log4jSb"));
              stringBuffer.append(TEXT_27);
              stringBuffer.append(rowStruct);
              stringBuffer.append(TEXT_28);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_29);

            } else {

              stringBuffer.append(TEXT_30);
              stringBuffer.append(rowStruct);
              stringBuffer.append(TEXT_31);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_32);
              stringBuffer.append(TEXT_33);
              stringBuffer.append(var("log4jSb"));
              stringBuffer.append(TEXT_34);
              stringBuffer.append(TEXT_35);
              stringBuffer.append(var("log4jSb"));
              stringBuffer.append(TEXT_36);
              stringBuffer.append(rowStruct);
              stringBuffer.append(TEXT_37);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_38);
            }

            stringBuffer.append(TEXT_39);
            stringBuffer.append(var("log4jSb"));
            stringBuffer.append(TEXT_40);
          }
        }
        trace(str("Content of the record "), nbline, str(": "), var("log4jSb"));
      }
    }

    class LogHelper {

      java.util.Map<String, String> pastDict = null;

      public LogHelper() {
        pastDict = new java.util.HashMap<String, String>();
        pastDict.put("insert", "inserted");
        pastDict.put("update", "updated");
        pastDict.put("delete", "deleted");
        pastDict.put("upsert", "upserted");
      }

      public String upperFirstChar(String data) {
        return data.substring(0, 1).toUpperCase() + data.substring(1);
      }

      public String toPastTense(String data) {
        return pastDict.get(data);
      }
    }
    LogHelper logHelper = new LogHelper();

    LogUtil log = null;

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    log = new LogUtil(node);
    boolean useExistingConn =
        ("true").equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"));

    stringBuffer.append(TEXT_41);

    List<? extends IConnection> inputConnections = node.getIncomingConnections();
    if ((inputConnections == null) || (inputConnections.size() == 0)) {
      return "";
    }

    IConnection inputConnection = inputConnections.get(0);

    if (!inputConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
      return "";
    }

    List<? extends IConnection> outputConnections = node.getOutgoingSortedConnections();
    if ((outputConnections == null) || (outputConnections.size() == 0)) {
      return "";
    }
    IConnection outputConnection = outputConnections.get(0);

    if (!outputConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
      return "";
    }

    IMetadataTable inputMetadata = inputConnection.getMetadataTable();
    if (inputMetadata == null) {
      return "";
    }

    List<IMetadataColumn> inputColumnList = inputMetadata.getListColumns();
    if ((inputColumnList == null) || (inputColumnList.size() == 0)) {
      return "";
    }

    IMetadataTable outputMetadata = outputConnection.getMetadataTable();
    if (outputMetadata == null) {
      return "";
    }

    List<IMetadataColumn> outputColumnList = outputMetadata.getListColumns();
    if ((outputColumnList == null) || (outputColumnList.size() == 0)) {
      return "";
    }

    int count = 0;
    for (IConnection inConnection : inputConnections) {
      if (inConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
        count++;
      }
    }

    for (IConnection outConnection : outputConnections) {
      if (outConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
        count++;
      }
    }

    if (count != 2) {
      return "";
    }

    stringBuffer.append(TEXT_42);
    if (!useExistingConn) {
      stringBuffer.append(TEXT_43);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_44);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_45);
      log.info(log.str("Closing the connection."));
      stringBuffer.append(TEXT_46);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_47);
      log.info(log.str("Connection has closed."));
      stringBuffer.append(TEXT_48);
    }
    stringBuffer.append(TEXT_49);
    stringBuffer.append(TEXT_50);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    List<IConnection> connections = (List<IConnection>) node.getIncomingConnections();
    boolean includeParallelComps = false;
    if (connections != null && connections.size() > 0) {
      for (IConnection connection : connections) {
        String connectionName = connection.getName();
        INode validTarget = ((IDataConnection) connection).getLinkNodeForHash();
        INode partitionNode = null;
        if (validTarget != null) {
          partitionNode = validTarget.getDesignSubjobStartNode();
          if ("tCollector".equals(partitionNode.getComponent().getName())) {
            includeParallelComps = true;
            partitionNode =
                partitionNode.getIncomingConnections(EConnectionType.STARTS).get(0).getSource();
          }
        }
        if (includeParallelComps && partitionNode != null) {

          stringBuffer.append(TEXT_2);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_3);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_4);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_6);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_7);
          stringBuffer.append(partitionNode.getUniqueName());
          stringBuffer.append(TEXT_8);
          stringBuffer.append(partitionNode.getUniqueName());
          stringBuffer.append(TEXT_9);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_10);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_11);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_12);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_13);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_15);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_16);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_17);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_18);

        } else {

          stringBuffer.append(TEXT_19);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_20);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_21);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_22);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_23);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_24);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_25);
          stringBuffer.append(connectionName);
          stringBuffer.append(TEXT_26);
        }
      }
    }

    stringBuffer.append(TEXT_27);
    stringBuffer.append(TEXT_28);
    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);

    // this util class use by set log4j debug paramters
    class DefaultLog4jFileUtil {

      INode node = null;
      String cid = null;
      boolean isLog4jEnabled = false;
      String label = null;

      public DefaultLog4jFileUtil() {}

      public DefaultLog4jFileUtil(INode node) {
        this.node = node;
        this.cid = node.getUniqueName();
        this.label = cid;
        this.isLog4jEnabled =
            ("true")
                .equals(
                    org.talend.core.model.process.ElementParameterParser.getValue(
                        node.getProcess(), "__LOG4J_ACTIVATE__"));
      }

      public void setCid(String cid) {
        this.cid = cid;
      }

      // for all tFileinput* components
      public void startRetriveDataInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_2);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_3);
        }
      }

      public void retrievedDataNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_4);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_5);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_6);
        }
      }

      public void retrievedDataNumberInfoFromGlobalMap(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_7);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_8);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_9);
        }
      }

      // for all tFileinput* components
      public void retrievedDataNumberInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_10);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_11);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_12);
        }
      }

      public void writeDataFinishInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_13);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_15);
        }
      }

      // TODO delete it and remove all log4jSb parameter from components
      public void componentStartInfo(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_16);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_17);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node, boolean hasIncreased) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_18);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_19);
          stringBuffer.append(cid);
          stringBuffer.append(hasIncreased ? "" : "+1");
          stringBuffer.append(TEXT_20);
        }
      }

      // TODO rename or delete it
      public void debugRetriveData(INode node) {
        debugRetriveData(node, true);
      }

      // TODO rename or delete it
      public void debugWriteData(INode node) {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_21);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_22);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_23);
        }
      }

      public void logCurrentRowNumberInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_24);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_25);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_26);
        }
      }

      public void logDataCountInfo() {
        if (isLog4jEnabled) {

          stringBuffer.append(TEXT_27);
          stringBuffer.append(label);
          stringBuffer.append(TEXT_28);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_29);
        }
      }
    }

    final DefaultLog4jFileUtil log4jFileUtil =
        new DefaultLog4jFileUtil(
            (INode)
                (((org.talend.designer.codegen.config.CodeGeneratorArgument) argument)
                    .getArgument()));

    stringBuffer.append(TEXT_30);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;

    INode node = (INode) codeGenArgument.getArgument();

    String cid = node.getUniqueName();

    String clientId = ElementParameterParser.getValue(node, "__CLIENT_ID__");
    String clientSecret = ElementParameterParser.getValue(node, "__CLIENT_SECRET__");
    String projectId = ElementParameterParser.getValue(node, "__PROJECT_ID__");
    String authorizationCode = ElementParameterParser.getValue(node, "__AUTHORIZATION_CODE__");
    String query = ElementParameterParser.getValue(node, "__QUERY__");
    query = query.replaceAll("\n", " ");
    query = query.replaceAll("\r", " ");

    String tokenFile = ElementParameterParser.getValue(node, "__TOKEN_NAME__");
    boolean isLog4jEnabled =
        ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));

    stringBuffer.append(TEXT_31);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_32);
    stringBuffer.append(clientId);
    stringBuffer.append(TEXT_33);

    String passwordFieldName = "__CLIENT_SECRET__";

    stringBuffer.append(TEXT_34);
    if (ElementParameterParser.canEncrypt(node, passwordFieldName)) {
      stringBuffer.append(TEXT_35);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_36);
      stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName));
      stringBuffer.append(TEXT_37);
    } else {
      stringBuffer.append(TEXT_38);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_39);
      stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName));
      stringBuffer.append(TEXT_40);
    }
    stringBuffer.append(TEXT_41);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_42);
    stringBuffer.append(clientId);
    stringBuffer.append(TEXT_43);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_44);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_45);
    stringBuffer.append(projectId);
    stringBuffer.append(TEXT_46);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_47);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_48);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_49);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_50);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_51);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_52);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_53);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_54);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_55);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_56);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_57);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_58);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_59);
    }

    stringBuffer.append(TEXT_60);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_61);
    stringBuffer.append(tokenFile);
    stringBuffer.append(TEXT_62);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_63);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_64);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_65);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_66);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_67);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_68);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_69);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_70);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_71);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_72);
    }

    stringBuffer.append(TEXT_73);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_74);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_75);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_76);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_77);
    }

    stringBuffer.append(TEXT_78);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_79);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_80);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_81);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_82);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_83);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_84);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_85);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_86);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_87);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_88);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_89);
    }

    stringBuffer.append(TEXT_90);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_91);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_92);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_93);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_94);
    }
    if (authorizationCode == null
        || "".equals(authorizationCode)
        || "\"\"".equals(authorizationCode)) {

      stringBuffer.append(TEXT_95);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_96);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_97);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_98);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_99);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_100);

      if (isLog4jEnabled) {

        stringBuffer.append(TEXT_101);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_102);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_103);
      }

      stringBuffer.append(TEXT_104);

    } else {

      stringBuffer.append(TEXT_105);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_106);
      stringBuffer.append(authorizationCode);
      stringBuffer.append(TEXT_107);

      if (isLog4jEnabled) {

        stringBuffer.append(TEXT_108);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_109);
      }

      stringBuffer.append(TEXT_110);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_111);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_112);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_113);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_114);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_115);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_116);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_117);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_118);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_119);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_120);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_121);

      if (isLog4jEnabled) {

        stringBuffer.append(TEXT_122);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_123);
      }

      stringBuffer.append(TEXT_124);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_125);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_126);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_127);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_128);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_129);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_130);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_131);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_132);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_133);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_134);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_135);
    }

    stringBuffer.append(TEXT_136);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_137);
    stringBuffer.append(query);
    stringBuffer.append(TEXT_138);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_139);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_140);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_141);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_142);
    }

    stringBuffer.append(TEXT_143);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_144);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_145);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_146);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_147);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_148);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_149);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_150);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_151);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_152);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_153);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_154);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_155);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_156);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_157);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_158);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_159);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_160);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_161);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_162);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_163);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_164);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_165);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_166);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_167);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_168);
    }

    stringBuffer.append(TEXT_169);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_170);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_171);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_172);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_173);
    }

    stringBuffer.append(TEXT_174);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_175);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_176);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_177);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_178);
    }

    stringBuffer.append(TEXT_179);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_180);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_181);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_182);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_183);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_184);

    if (isLog4jEnabled) {

      stringBuffer.append(TEXT_185);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_186);
    }

    stringBuffer.append(TEXT_187);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_188);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_189);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_190);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_191);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_192);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_193);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_194);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_195);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_196);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_197);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_198);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_199);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_200);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_201);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_202);

    List<? extends IConnection> conns = node.getOutgoingSortedConnections();
    if (conns != null) {
      if (conns.size() > 0) {
        IConnection conn = conns.get(0);
        String connName = conn.getName();
        if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
          List<IMetadataTable> metadatas = node.getMetadataList();
          if ((metadatas != null) && (metadatas.size() > 0)) {
            IMetadataTable metadata = metadatas.get(0);
            if (metadata != null) {
              String encoding = ElementParameterParser.getValue(node, "__ENCODING__");
              String advancedSeparatorStr =
                  ElementParameterParser.getValue(node, "__ADVANCED_SEPARATOR__");
              boolean advancedSeparator =
                  (advancedSeparatorStr != null && !("").equals(advancedSeparatorStr))
                      ? ("true").equals(advancedSeparatorStr)
                      : false;
              String thousandsSeparator =
                  ElementParameterParser.getValueWithJavaType(
                      node, "__THOUSANDS_SEPARATOR__", JavaTypesManager.CHARACTER);
              String decimalSeparator =
                  ElementParameterParser.getValueWithJavaType(
                      node, "__DECIMAL_SEPARATOR__", JavaTypesManager.CHARACTER);

              List<IMetadataColumn> columns = metadata.getListColumns();
              int nbColumns = columns.size();
              for (int i = 0; i < nbColumns; i++) {
                IMetadataColumn column = columns.get(i);
                String columnName = column.getLabel();

                String typeToGenerate =
                    JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
                JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
                String patternValue =
                    column.getPattern() == null || column.getPattern().trim().length() == 0
                        ? null
                        : column.getPattern();

                stringBuffer.append(TEXT_203);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_204);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_205);
                stringBuffer.append(i);
                stringBuffer.append(TEXT_206);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_207);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_208);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_209);

                if (javaType == JavaTypesManager.STRING) {

                  stringBuffer.append(TEXT_210);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_211);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_212);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_213);

                } else if (javaType == JavaTypesManager.OBJECT) {

                  stringBuffer.append(TEXT_214);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_215);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_216);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_217);

                } else if (javaType == JavaTypesManager.DATE) {

                  stringBuffer.append(TEXT_218);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_219);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_220);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_221);
                  stringBuffer.append(patternValue);
                  stringBuffer.append(TEXT_222);

                } else if (advancedSeparator && JavaTypesManager.isNumberType(javaType)) {

                  stringBuffer.append(TEXT_223);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_224);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_225);
                  stringBuffer.append(typeToGenerate);
                  stringBuffer.append(TEXT_226);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_227);
                  stringBuffer.append(thousandsSeparator);
                  stringBuffer.append(TEXT_228);
                  stringBuffer.append(decimalSeparator);
                  stringBuffer.append(TEXT_229);

                } else if (javaType == JavaTypesManager.BYTE_ARRAY) {

                  stringBuffer.append(TEXT_230);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_231);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_232);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_233);
                  stringBuffer.append(encoding);
                  stringBuffer.append(TEXT_234);

                } else {

                  stringBuffer.append(TEXT_235);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_236);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_237);
                  stringBuffer.append(typeToGenerate);
                  stringBuffer.append(TEXT_238);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_239);
                }

                stringBuffer.append(TEXT_240);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_241);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_242);
                stringBuffer.append(
                    JavaTypesManager.getDefaultValueFromJavaType(
                        typeToGenerate, column.getDefault()));
                stringBuffer.append(TEXT_243);
              }
              log4jFileUtil.debugRetriveData(node);
            }
          }
        }
      }
    }

    stringBuffer.append(TEXT_244);
    return stringBuffer.toString();
  }
  private void propagateDatas(boolean isExecute) {
    String baseConnectorForCurrentNode =
        node.getConnectorFromName(currentConnector).getBaseSchema();

    // Propagate :
    if (outputdataContainer != null
        && (!outputdataContainer.getInputs().isEmpty()
            || !outputdataContainer.getOuputs().isEmpty())) {
      for (IODataComponent currentIO : outputdataContainer.getInputs()) {
        INode sourceNode = currentIO.getSource();
        if (currentIO.hasChanged()
            && (sourceNode
                .getConnectorFromName(currentIO.getConnection().getConnectorName())
                .getBaseSchema()
                .equals(baseConnectorForCurrentNode))) {
          sourceNode.metadataOutputChanged(currentIO, currentIO.getName());
          if (isExecute) {
            currentIO.setTable(oldInputMetadata);
            currentIO.setColumnNameChanged(null);
          } else {
            currentIO.setTable(newInputMetadata);
            currentIO.setColumnNameChanged(null);
          }
        }
      }
      for (IODataComponent currentIO : outputdataContainer.getOuputs()) {
        INodeConnector nodeConnector = null;
        String baseConnector = null;

        Node sourceNode = (Node) currentIO.getSource();
        nodeConnector =
            sourceNode.getConnectorFromName(currentIO.getConnection().getConnectorName());
        baseConnector = nodeConnector.getBaseSchema();

        INode targetNode = currentIO.getTarget();

        boolean sourceIsBuiltIn =
            ((Node) currentIO.getSource())
                .getConnectorFromType(currentIO.getConnection().getLineStyle())
                .isMultiSchema();

        boolean targetIsBuiltIn =
            ((Node) targetNode)
                .getConnectorFromType(currentIO.getConnection().getLineStyle())
                .isMultiSchema();
        boolean isJoblet = ((Node) targetNode).isJoblet();
        if (!isJoblet
            && baseConnector.equals(baseConnectorForCurrentNode)
            && (targetIsBuiltIn
                || (targetNode.getMetadataFromConnector(baseConnector) != null
                    && !targetNode
                        .getMetadataFromConnector(baseConnector)
                        .sameMetadataAs(newOutputMetadata)))) {

          targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName());
          if (isExecute) {
            if (targetNode instanceof Node) {
              if (((Node) targetNode).getComponent().isSchemaAutoPropagated()
                  && getPropagate()
                  && targetNode.getMetadataList().size() > 0) {
                IMetadataTable tmpClone;
                if (sourceIsBuiltIn) {
                  IMetadataTable tab =
                      node.getMetadataTable(
                          currentIO.getConnection().getMetadataTable().getTableName());
                  if (tab == null && node.getJobletNode() != null) {
                    tab =
                        node.getJobletNode()
                            .getMetadataTable(
                                currentIO.getConnection().getMetadataTable().getTableName());
                  }
                  tmpClone = tab.clone(true);
                } else {
                  IMetadataTable tab =
                      node.getMetadataFromConnector(currentIO.getConnection().getConnectorName());
                  if (tab == null && node.getJobletNode() != null) {
                    tab =
                        node.getJobletNode()
                            .getMetadataFromConnector(currentIO.getConnection().getConnectorName());
                  }
                  tmpClone = tab.clone(true);
                }
                IMetadataTable toCopy = newOutputMetadata.clone();

                // wzhang modify to add feature 7611

                String dbmsId = null;
                IMetadataTable copy;
                if (((Node) targetNode).getMetadataFromConnector(baseConnector) != null) {
                  dbmsId = targetNode.getMetadataFromConnector(baseConnector).getDbms();
                  MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
                  toCopy = tmpClone;

                  // only if the target node have exactly the same connector
                  copy = ((Node) targetNode).getMetadataFromConnector(baseConnector).clone(true);
                } else {
                  final String mainConnector =
                      "FLOW"; // can only be FLOW right now for this case. //$NON-NLS-1$

                  dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms();
                  MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
                  toCopy = tmpClone;
                  // if don't have the same connector, take the main connector of the component.

                  copy = ((Node) targetNode).getMetadataFromConnector(mainConnector).clone(true);
                }
                // MetadataTool.copyTable(toCopy, copy);
                // wzhang modify to add feature 7611
                MetadataToolHelper.copyTable(dbmsId, toCopy, copy);
                ChangeMetadataCommand cmd =
                    new ChangeMetadataCommand(targetNode, null, null, copy, inputSchemaParam);
                if (outputdataContainer.getOuputs().size() > 0) {
                  List<ColumnNameChanged> columnNameChanged =
                      outputdataContainer.getOuputs().get(0).getColumnNameChanged();
                  for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) {
                    dataComp.setColumnNameChanged(columnNameChanged);
                  }
                }
                cmd.execute(true);
                propagatedChange.add(cmd);
              }
            }
            currentIO.setTable(oldOutputMetadata);
            currentIO.setColumnNameChanged(null);
          } else {
            if (targetNode instanceof Node) {
              if (!targetIsBuiltIn && getPropagate()) {
                if (((Node) targetNode).getComponent().isSchemaAutoPropagated()) {
                  if (outputdataContainer.getOuputs().size() > 0) {
                    List<ColumnNameChanged> columnNameChanged =
                        outputdataContainer.getOuputs().get(0).getColumnNameChanged();
                    for (ChangeMetadataCommand cmd : propagatedChange) {
                      for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) {
                        dataComp.setColumnNameChanged(columnNameChanged);
                      }
                    }
                  }
                }
              }
            }

            currentIO.setTable(newOutputMetadata);
            currentIO.setColumnNameChanged(null);
          }
        }
      }
    } else if (dataComponent != null) {
      for (IConnection outgoingConnection : node.getOutgoingConnections()) {
        if (outgoingConnection.getConnectorName().equals(currentConnector)) {
          outgoingConnection
              .getTarget()
              .metadataInputChanged(dataComponent, outgoingConnection.getName());
        }
      }
    } else {
      if (!node.getOutgoingConnections().isEmpty()) {
        IMetadataTable relativeOldOutputMetadata = null;
        IMetadataTable relativeNewOutputMetadata = null;
        if (isExecute) {
          relativeOldOutputMetadata = oldOutputMetadata;
          relativeNewOutputMetadata = newOutputMetadata;
        } else {
          relativeOldOutputMetadata = newOutputMetadata;
          relativeNewOutputMetadata = oldOutputMetadata;
        }
        for (IConnection outgoingConnection : node.getOutgoingConnections()) {
          final Node target = (Node) outgoingConnection.getTarget();
          if (target != null && target.getExternalNode() != null) {
            List<IMetadataColumn> oldListColumns = relativeOldOutputMetadata.getListColumns();
            List<IMetadataColumn> newListColumns = relativeNewOutputMetadata.getListColumns();
            List<ColumnNameChanged> columnNameChanges = new ArrayList<ColumnNameChanged>();
            int size = oldListColumns.size();
            int newSize = newListColumns.size();
            if (newSize < size) {
              size = newSize;
            }
            IODataComponent output =
                new IODataComponent(outgoingConnection, relativeNewOutputMetadata);
            if (newListColumns != null) {
              List<ColumnNameChanged> newColumnsList = output.getNewMetadataColumns();
              // new added columns list
              Set<String> newAddedColumns = new HashSet<String>();
              // newest columns after user changed
              Set<String> newestColumns = new HashSet<String>();

              // init
              if (newColumnsList != null) {
                for (ColumnNameChanged columnChanged : newColumnsList) {
                  newAddedColumns.add(columnChanged.getNewName());
                }
              }
              for (IMetadataColumn metadataColumn : newListColumns) {
                newestColumns.add(metadataColumn.getLabel());
              }

              // check
              for (int i = 0; i < size; i++) {
                IMetadataColumn oldMetadataColumn = oldListColumns.get(i);
                String columnName = oldMetadataColumn.getLabel();
                // if this column(before changing) is not exists in the new columns(after changing),
                // there are two possible truth: 1. this column has been renamed; 2. this column has
                // been removed
                if (!newestColumns.contains(columnName)) {
                  IMetadataColumn newMetadataColumn = newListColumns.get(i);
                  String newColumnNameAtThisIndex = newMetadataColumn.getLabel();
                  // if the column at the same position in new table is a new column(two possible
                  // truth: 1. an old column's name has been changed; 2. user add a new column);
                  // For now, Seems it is very hard to judge whether it is a renamed column or a new
                  // column, so we suppose the more possible truth is that it is a renamed column
                  if (newAddedColumns.contains(newColumnNameAtThisIndex)) {
                    columnNameChanges.add(
                        new ColumnNameChanged(columnName, newColumnNameAtThisIndex));
                  }
                }
              }
            }

            if (GlobalServiceRegister.getDefault().isServiceRegistered(IXmlMapService.class)) {
              final IXmlMapService service =
                  (IXmlMapService)
                      GlobalServiceRegister.getDefault().getService(IXmlMapService.class);
              if (service.isXmlMapComponent(target.getExternalNode())) {
                output.setColumnNameChanged(columnNameChanges);
                target.metadataInputChanged(output, outgoingConnection.getName());
              }
            }
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkMapService.class)) {
              final ISparkMapService service =
                  (ISparkMapService)
                      GlobalServiceRegister.getDefault().getService(ISparkMapService.class);
              if (service.isSparkMapComponent(target.getExternalNode())) {
                output.setColumnNameChanged(columnNameChanges);
                target.metadataInputChanged(output, outgoingConnection.getName());
              }
            }

            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDbMapService.class)) {
              final IDbMapService service =
                  (IDbMapService)
                      GlobalServiceRegister.getDefault().getService(IDbMapService.class);
              if (service.isDbMapComponent(target.getExternalNode())) {
                // TDI-25307:should setColumNameChanged here for ELtDbMap in case the propagate
                // schema
                // does not affect it.
                output.setColumnNameChanged(columnNameChanges);
                target.metadataInputChanged(output, outgoingConnection.getName());
              }
            }
          }
        }
      }
    }

    if (inputdataContainer != null) {
      for (IODataComponent currentIO : inputdataContainer.getOuputs()) {
        if (currentIO.hasChanged()
            && (currentIO
                .getSource()
                .getConnectorFromName(currentIO.getConnection().getConnectorName())
                .getBaseSchema()
                .equals(currentConnector))) {
          INode targetNode = currentIO.getTarget();
          targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName());
          if (isExecute) {
            currentIO.setTable(oldInputMetadata);
            currentIO.setColumnNameChanged(null);
          } else {
            currentIO.setTable(newInputMetadata);
            currentIO.setColumnNameChanged(null);
          }
        }
      }
    }
    // End propagate
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();

    String cid = node.getUniqueName();

    String dbtable = null;
    String dbschema = ElementParameterParser.getValue(node, "__ELT_SCHEMA_NAME__");
    String uniqueNameConnection = null;
    INode previousNode = null;

    String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
    boolean useDifferentTable =
        "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));

    stringBuffer.append(TEXT_2);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_3);

    List<IConnection> connections = (List<IConnection>) node.getIncomingConnections();
    if (connections != null && connections.size() > 0 && connections.get(0) != null) {
      IConnection connection = connections.get(0);
      previousNode = connection.getSource();
      String previousComponentName = previousNode.getUniqueName();
      dbtable = connection.getName();
      uniqueNameConnection = connection.getUniqueName();

      stringBuffer.append(TEXT_4);
      stringBuffer.append(previousComponentName);
      stringBuffer.append(TEXT_5);
      stringBuffer.append(uniqueNameConnection);
      stringBuffer.append(TEXT_6);
      stringBuffer.append(previousComponentName);
      stringBuffer.append(TEXT_7);
      stringBuffer.append(uniqueNameConnection);
      stringBuffer.append(TEXT_8);
    }

    stringBuffer.append(TEXT_9);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_10);
    stringBuffer.append(dbschema);
    stringBuffer.append(TEXT_11);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_12);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_13);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_14);
    stringBuffer.append(dbschema);
    stringBuffer.append(TEXT_15);
    stringBuffer.append(useDifferentTable ? differenttable : "\"" + dbtable + "\"");
    stringBuffer.append(TEXT_16);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_17);
    stringBuffer.append(useDifferentTable ? differenttable : "\"" + dbtable + "\"");
    stringBuffer.append(TEXT_18);

    String dataAction = ElementParameterParser.getValue(node, "__DATA_ACTION__");

    String dbhost = null;
    String dbport = null;
    String dbname = null;
    String dbuser = null;
    String dbpwd = null;
    boolean useExistingConn = false;
    if (previousNode != null) {
      dbhost = ElementParameterParser.getValue(previousNode, "__HOST__");
      dbport = ElementParameterParser.getValue(previousNode, "__PORT__");
      dbname = ElementParameterParser.getValue(previousNode, "__DBNAME__");
      dbuser = ElementParameterParser.getValue(previousNode, "__USER__");
      dbpwd = ElementParameterParser.getValue(previousNode, "__PASS__");
      useExistingConn =
          ("true")
              .equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__"));
    }
    String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");

    stringBuffer.append(TEXT_19);

    if (useExistingConn) {
      String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__");
      String conn = "conn_" + connection;

      stringBuffer.append(TEXT_20);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_21);
      stringBuffer.append(conn);
      stringBuffer.append(TEXT_22);

    } else {

      stringBuffer.append(TEXT_23);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_24);
      stringBuffer.append(dbhost);
      stringBuffer.append(TEXT_25);
      stringBuffer.append(dbport);
      stringBuffer.append(TEXT_26);
      stringBuffer.append(dbname);
      stringBuffer.append(TEXT_27);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_28);
      stringBuffer.append(dbuser);
      stringBuffer.append(TEXT_29);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_30);
      stringBuffer.append(dbpwd);
      stringBuffer.append(TEXT_31);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_32);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_33);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_34);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_35);
    }
    List<IMetadataColumn> columnList = null;
    List<IMetadataTable> metadatas = node.getMetadataList();
    if (metadatas != null && metadatas.size() > 0) {
      IMetadataTable metadata = metadatas.get(0);
      if (metadata != null) {
        columnList = metadata.getListColumns();
      }
    }

    stringBuffer.append(TEXT_36);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_37);

    if (columnList != null && columnList.size() > 0) {

      class Column {

        IMetadataColumn column;

        String name;

        String sqlStmt;

        String value;

        boolean addCol;

        List<Column> replacement = new ArrayList<Column>();

        public Column(IMetadataColumn column) {
          this.column = column;
          String columname = column.getOriginalDbColumnName();
          if (columname != null && columname.trim().length() > 0) {
            this.name = columname;
          } else {
            this.name = column.getLabel();
          }
          this.sqlStmt = "=?";
          this.value = "?";
          this.addCol = false;
        }

        public boolean isReplaced() {
          return replacement.size() > 0;
        }

        public List<Column> getReplacement() {
          return this.replacement;
        }

        public IMetadataColumn getColumn() {
          return this.column;
        }

        public void setName(String name) {
          this.name = name;
        }

        public String getName() {
          return this.name;
        }

        public boolean isAddCol() {
          return this.addCol;
        }

        public String getSqlStmt() {
          return this.sqlStmt;
        }

        public String getValue() {
          return this.value;
        }
      }

      StringBuilder insertColName = new StringBuilder();

      StringBuilder insertValueStmt = new StringBuilder();

      StringBuilder updateSetStmt = new StringBuilder();

      StringBuilder updateWhereStmt = new StringBuilder();

      List<Column> stmtStructure = new LinkedList<Column>();

      for (IMetadataColumn column : columnList) {

        stmtStructure.add(new Column(column));
      }

      int counterOuter = 0;
      boolean firstKey = true;
      boolean firstNoneKey = true;
      boolean isfirstKey = true;
      for (Column colStmt : stmtStructure) {
        String suffix = ",";
        String colName = "\\\"" + colStmt.getName() + "\\\"";
        colStmt.setName(colName);
        if (colStmt.getColumn().isKey()) {
          if (isfirstKey) {
            isfirstKey = false;
          }
        }
        if (colStmt.isReplaced()) {
          List<Column> replacedColumns = colStmt.getReplacement();
          int counterReplace = 0;
          if (counterOuter == (stmtStructure.size() - 1)
              && counterReplace == (replacedColumns.size() - 1)) {
            suffix = "";
          }
          for (Column replacement : replacedColumns) {
            insertColName.append(replacement.getName() + suffix);
            insertValueStmt.append(replacement.getSqlStmt() + suffix);
            if (!colStmt.getColumn().isKey()) {
              if (!firstNoneKey) {
                updateSetStmt.append(",");
              } else {
                firstNoneKey = false;
              }
              updateSetStmt.append(replacement.getName());
              updateSetStmt.append(replacement.getSqlStmt());
            } else {
              if (!firstKey) {
                updateWhereStmt.append(" AND ");
              } else {
                firstKey = false;
              }
              updateWhereStmt.append(replacement.getName());
              updateWhereStmt.append(replacement.getSqlStmt());
            }
            counterReplace++;
          }
        } else {
          if (counterOuter == (stmtStructure.size() - 1)) {
            suffix = "";
          }
          if (colStmt.isAddCol()) {
            insertColName.append(colStmt.getName() + suffix);
            insertValueStmt.append(colStmt.getSqlStmt() + suffix);
            updateSetStmt.append(colStmt.getName());
            updateSetStmt.append(colStmt.getSqlStmt() + suffix);
          } else {
            insertColName.append(colStmt.getName() + suffix);
            insertValueStmt.append(colStmt.getValue() + suffix);
            if (!colStmt.getColumn().isKey()) {
              updateSetStmt.append(
                  colStmt.getName()
                      + "=\"+selectQueryColumnsName.split(\",\")[ "
                      + counterOuter
                      + "]+\""
                      + suffix);
            }
          }
        }
        counterOuter++;
      }

      if (("INSERT").equals(dataAction)) {

        stringBuffer.append(TEXT_38);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_39);
        stringBuffer.append(insertColName.toString());
        stringBuffer.append(TEXT_40);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_41);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_42);

      } else if (("UPDATE").equals(dataAction)) {

        stringBuffer.append(TEXT_43);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_44);
        stringBuffer.append(updateSetStmt.toString());
        stringBuffer.append(TEXT_45);

        if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {

          stringBuffer.append(TEXT_46);
          stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause));
          stringBuffer.append(TEXT_47);
        }

        stringBuffer.append(TEXT_48);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_49);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_50);

      } else if (("DELETE").equals(dataAction)) {

        stringBuffer.append(TEXT_51);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_52);

        if (CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {

          stringBuffer.append(TEXT_53);
          stringBuffer.append(CodeGenerationUtils.replaceAllCrBySpace(whereClause));
          stringBuffer.append(TEXT_54);
        }

        stringBuffer.append(TEXT_55);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_56);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_57);
      }

      stringBuffer.append(TEXT_58);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_59);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_60);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_61);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_62);
    }
    if (dbtable != null && columnList != null) {
      if (("INSERT").equals(dataAction)) {

        stringBuffer.append(TEXT_63);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_64);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_65);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_66);

      } else if (("UPDATE").equals(dataAction)) {

        stringBuffer.append(TEXT_67);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_68);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_69);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_70);

      } else if (("DELETE").equals(dataAction)) {

        stringBuffer.append(TEXT_71);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_72);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_73);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_74);
      }
    }

    stringBuffer.append(TEXT_75);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_76);

    if (!useExistingConn) {

      stringBuffer.append(TEXT_77);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_78);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_79);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_80);
    }

    stringBuffer.append(TEXT_81);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_82);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_83);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_84);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_85);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_86);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_87);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_88);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_89);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_90);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_91);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_92);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_93);
    stringBuffer.append(TEXT_94);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();
    String dieOnError = ElementParameterParser.getValue(node, "__DIE_ON_ERROR__");
    String commitEvery = ElementParameterParser.getValue(node, "__COMMIT_EVERY__");
    String propagateRecordset = ElementParameterParser.getValue(node, "__PROPAGATE_RECORD_SET__");
    String recordsetColumn = ElementParameterParser.getValue(node, "__RECORD_SET_COLUMN__");
    String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");

    String incomingConnName = null;

    List<IMetadataColumn> columnList = null;

    String rejectConnName = null;
    List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT");
    if (rejectConns != null && rejectConns.size() > 0) {
      IConnection rejectConn = rejectConns.get(0);
      rejectConnName = rejectConn.getName();
    }
    List<IMetadataColumn> rejectColumnList = null;
    IMetadataTable metadataTable = node.getMetadataFromConnector("REJECT");
    if (metadataTable != null) {
      rejectColumnList = metadataTable.getListColumns();
    }

    List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections();

    boolean hasOutgoingDataConnection = false;
    for (IConnection conn : outgoingConns) {
      if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
        if (!hasOutgoingDataConnection) {
          hasOutgoingDataConnection = true;
        }

        stringBuffer.append(TEXT_2);
        stringBuffer.append(conn.getName());
        stringBuffer.append(TEXT_3);
      }
    }
    String dbquery = ElementParameterParser.getValue(node, "__QUERY__");
    dbquery = dbquery.replaceAll("\n", " ");
    dbquery = dbquery.replaceAll("\r", " ");

    stringBuffer.append(TEXT_4);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_5);

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0)) {
      IMetadataTable metadata = metadatas.get(0);
      if (metadata != null) {
        List<? extends IConnection> conns = node.getIncomingConnections();
        columnList = metadata.getListColumns();
        if (conns != null && conns.size() > 0) {
          IConnection conn = conns.get(0);
          if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            incomingConnName = conn.getName();
          }
        } // end of connection size.
      } // end of metadatas
    }
    if (!hasOutgoingDataConnection || columnList == null || columnList.size() < 1) {
      propagateRecordset = "false";
    }

    stringBuffer.append(TEXT_6);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(dbquery);
    stringBuffer.append(TEXT_8);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_9);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_10);

    if (propagateRecordset.equals("true")) {

      stringBuffer.append(TEXT_11);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_12);
    }

    stringBuffer.append(TEXT_13);

    if (propagateRecordset.equals("true")) {

      stringBuffer.append(TEXT_14);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_15);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_16);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_17);

    } else {

      stringBuffer.append(TEXT_18);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_19);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_20);
    }

    stringBuffer.append(TEXT_21);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_22);

    if (dieOnError.equals("true")) {

      stringBuffer.append(TEXT_23);

    } else {
      if (rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {

        stringBuffer.append(TEXT_24);
        stringBuffer.append(rejectConnName);
        stringBuffer.append(TEXT_25);
        stringBuffer.append(rejectConnName);
        stringBuffer.append(TEXT_26);

        if (incomingConnName != null) {
          for (IMetadataColumn column : columnList) {

            stringBuffer.append(TEXT_27);
            stringBuffer.append(rejectConnName);
            stringBuffer.append(TEXT_28);
            stringBuffer.append(column.getLabel());
            stringBuffer.append(TEXT_29);
            stringBuffer.append(incomingConnName);
            stringBuffer.append(TEXT_30);
            stringBuffer.append(column.getLabel());
            stringBuffer.append(TEXT_31);
          }
        }

        stringBuffer.append(TEXT_32);
        stringBuffer.append(rejectConnName);
        stringBuffer.append(TEXT_33);

      } else {

        stringBuffer.append(TEXT_34);
      }
    }

    stringBuffer.append(TEXT_35);

    if (outgoingConns != null && outgoingConns.size() > 0) {

      stringBuffer.append(TEXT_36);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_37);

      for (IConnection outgoingConn : outgoingConns) {
        if (rejectConnName == null
            || (rejectConnName != null && !outgoingConn.getName().equals(rejectConnName))) {
          if (outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {

            stringBuffer.append(TEXT_38);
            stringBuffer.append(outgoingConn.getName());
            stringBuffer.append(TEXT_39);
            stringBuffer.append(outgoingConn.getName());
            stringBuffer.append(TEXT_40);

            for (IMetadataColumn column : columnList) {
              if (propagateRecordset.equals("true") && column.getLabel().equals(recordsetColumn)) {

                stringBuffer.append(TEXT_41);
                stringBuffer.append(outgoingConn.getName());
                stringBuffer.append(TEXT_42);
                stringBuffer.append(column.getLabel());
                stringBuffer.append(TEXT_43);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_44);

              } else {
                if (incomingConnName != null) {

                  stringBuffer.append(TEXT_45);
                  stringBuffer.append(outgoingConn.getName());
                  stringBuffer.append(TEXT_46);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_47);
                  stringBuffer.append(incomingConnName);
                  stringBuffer.append(TEXT_48);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_49);
                }
              }
            }
          }
        }
      }

      stringBuffer.append(TEXT_50);
    }
    if (!useExistingConn.equals("true")) {
      if (!commitEvery.equals("") && !commitEvery.equals("0")) {

        stringBuffer.append(TEXT_51);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_52);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_53);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_54);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_55);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_56);
      }
    }

    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    String processID = ElementParameterParser.getValue(node, "__PROCESS_ID__");

    boolean dieOnError = ("true").equals(ElementParameterParser.getValue(node, "__DIE_ON_ERROR__"));

    stringBuffer.append(TEXT_2);

    List<? extends IConnection> conns = node.getIncomingConnections();
    if (conns != null && conns.size() > 0 && conns.get(0) != null) {
      IConnection conn = conns.get(0);
      if (conn != null && conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
        INode previousNode = conn.getSource();
        if (previousNode != null) {
          List<IMetadataTable> metadatas = previousNode.getMetadataList();
          if ((metadatas != null) && (metadatas.size() > 0)) {
            IMetadataTable metadata = metadatas.get(0);
            if (metadata != null) {
              List<IMetadataColumn> columns = metadata.getListColumns();
              int sizeColumns = columns.size();
              for (int i = 0; i < sizeColumns; i++) {

                stringBuffer.append(TEXT_3);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_4);
                stringBuffer.append((columns.get(i)).getLabel());
                stringBuffer.append(TEXT_5);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_6);
                stringBuffer.append((columns.get(i)).getLabel());
                stringBuffer.append(TEXT_7);
              }
            }
          }
        }
      }
    }

    stringBuffer.append(TEXT_8);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_9);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_10);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_11);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_12);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_13);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_14);

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0)) {
      IMetadataTable metadata = metadatas.get(0);
      if (metadata != null) {
        List<? extends IConnection> conns_out = node.getOutgoingConnections();
        for (IConnection conn : conns_out) {
          String connName = conn.getName();
          if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            List<IMetadataColumn> columns = metadata.getListColumns();
            int sizeColumns = columns.size();
            for (int i = 0; i < sizeColumns; i++) {
              if ("ProcessInstanceUUID".equals(columns.get(i).getLabel())) {

                stringBuffer.append(TEXT_15);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_16);
                stringBuffer.append((columns.get(i)).getLabel());
                stringBuffer.append(TEXT_17);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_18);

                break;
              }
            }
          }
        }
      }
    }

    stringBuffer.append(TEXT_19);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_20);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_21);

    if (dieOnError) {

      stringBuffer.append(TEXT_22);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_23);

    } else {

      stringBuffer.append(TEXT_24);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_25);
    }

    stringBuffer.append(TEXT_26);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_27);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_28);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_29);
    stringBuffer.append(TEXT_30);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();
    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0)) {
      IMetadataTable metadata = metadatas.get(0);
      List<? extends IConnection> conns = node.getIncomingConnections();
      IMetadataTable inMetadata = null;
      String connName = "";
      if (conns != null) {
        for (IConnection conn : conns) {
          if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            connName = conn.getName();
            inMetadata = conn.getMetadataTable();
            break;
          }
        }
        if (metadata != null && inMetadata != null) {
          List<IMetadataColumn> columns = inMetadata.getListColumns();
          Map<String, String> typesMap = new HashMap<String, String>();
          Map<String, String> patternsMap = new HashMap<String, String>();
          for (IMetadataColumn column : columns) {
            String type =
                JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
            typesMap.put(column.getLabel(), type);
            String pattern =
                ((column.getPattern() == null) || (column.getPattern().trim().length() == 0))
                    ? ""
                    : column.getPattern();
            patternsMap.put(column.getLabel(), pattern);
          }
          String rowCount =
              ElementParameterParser.getValue(node, "__ROW_COUNT__"); // ?? i think we need it

          List<Map<String, String>> denormalizes =
              (List<Map<String, String>>)
                  ElementParameterParser.getObjectValue(node, "__DENORMALIZE_COLUMNS__");
          List<String> denormalizeColumns = new ArrayList<String>();
          List<String> denormalizeColumnsType = new ArrayList<String>();
          List<String> denormalizeDelimiters = new ArrayList<String>();
          List<Boolean> denormalizeMergeFlags = new ArrayList<Boolean>();
          List<IMetadataColumn> groupColumns = new ArrayList<IMetadataColumn>();
          for (Map<String, String> denormalize : denormalizes) {
            String columnName = denormalize.get("INPUT_COLUMN");
            if (denormalizeColumns.contains(columnName)) {
              continue;
            }
            denormalizeColumns.add(columnName);
            denormalizeColumnsType.add(typesMap.get(columnName));
            denormalizeDelimiters.add(denormalize.get("DELIMITER"));
            denormalizeMergeFlags.add(("true").equals(denormalize.get("MERGE")));
          }
          for (IMetadataColumn column : columns) {
            String columnName = column.getLabel();
            if (denormalizeColumns.contains(columnName)) {
              continue;
            }
            groupColumns.add(column);
          }

          stringBuffer.append(TEXT_2);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_3);

          if (groupColumns.size() > 0) {

            stringBuffer.append(TEXT_4);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_5);
          }

          stringBuffer.append(TEXT_6);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_7);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_8);

          for (IMetadataColumn column : groupColumns) {

            stringBuffer.append(TEXT_9);
            stringBuffer.append(column.getLabel());
            stringBuffer.append(TEXT_10);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_11);
            stringBuffer.append(connName);
            stringBuffer.append(TEXT_12);
            stringBuffer.append(column.getLabel());
            stringBuffer.append(TEXT_13);
          }
          for (int i = 0; i < denormalizeColumns.size(); i++) {
            String columnName = denormalizeColumns.get(i);
            String columnType = denormalizeColumnsType.get(i);
            if (denormalizeMergeFlags.get(i)) {

              stringBuffer.append(TEXT_14);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_15);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_16);
              stringBuffer.append(connName);
              stringBuffer.append(TEXT_17);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_18);

            } else {
              if ((("java.util.Date").equals(columnType))
                  && (patternsMap.get(columnName).length() != 0)) {

                stringBuffer.append(TEXT_19);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_20);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_21);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_22);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_23);
                stringBuffer.append(patternsMap.get(columnName));
                stringBuffer.append(TEXT_24);

              } else {

                stringBuffer.append(TEXT_25);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_26);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_27);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_28);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_29);
              }
            }
          }

          stringBuffer.append(TEXT_30);

          if (groupColumns.size() > 0) { // while loop

            stringBuffer.append(TEXT_31);
            for (int i = 0; i < groupColumns.size(); i++) {
              String columnName = groupColumns.get(i).getLabel();
              if (!JavaTypesManager.isJavaPrimitiveType(
                  groupColumns.get(i).getTalendType(), groupColumns.get(i).isNullable())) {

                stringBuffer.append(TEXT_32);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_33);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_34);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_35);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_36);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_37);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_38);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_39);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_40);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_41);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_42);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_43);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_44);
              } else {

                stringBuffer.append(TEXT_45);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_46);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_47);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_48);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_49);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_50);
              }
              if (i + 1 == groupColumns.size()) {

                stringBuffer.append(TEXT_51);
              }
            }

            stringBuffer.append(TEXT_52);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_53);
          } // while loop end

          for (int i = 0; i < denormalizeColumns.size(); i++) {
            String columnName = denormalizeColumns.get(i);
            String columnType = denormalizeColumnsType.get(i);
            if (denormalizeMergeFlags.get(i)) {

              stringBuffer.append(TEXT_54);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_55);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_56);
              stringBuffer.append(connName);
              stringBuffer.append(TEXT_57);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_58);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_59);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_60);
              stringBuffer.append(connName);
              stringBuffer.append(TEXT_61);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_62);

            } else {

              stringBuffer.append(TEXT_63);
              stringBuffer.append(columnName);
              stringBuffer.append(TEXT_64);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_65);
              stringBuffer.append(denormalizeDelimiters.get(i));
              stringBuffer.append(TEXT_66);

              if ((("java.util.Date").equals(columnType))
                  && (patternsMap.get(columnName).length() != 0)) {

                stringBuffer.append(TEXT_67);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_68);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_69);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_70);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_71);
                stringBuffer.append(patternsMap.get(columnName));
                stringBuffer.append(TEXT_72);

              } else {

                stringBuffer.append(TEXT_73);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_74);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_75);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_76);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_77);
              }
            }
          }

          if (groupColumns.size() > 0) {

            stringBuffer.append(TEXT_78);
          }

          stringBuffer.append(TEXT_79);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_80);

          if (groupColumns.size() > 0) {
            // ??

            stringBuffer.append(TEXT_81);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_82);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_83);

            // do out start ...
            conns = null;
            conns = node.getOutgoingSortedConnections();
            if (conns != null) {
              if (conns.size() > 0) {
                IConnection conn = conns.get(0);
                if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
                  for (IMetadataColumn column : groupColumns) {

                    stringBuffer.append(TEXT_84);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_85);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_86);
                    stringBuffer.append(column.getLabel());
                    stringBuffer.append(TEXT_87);
                    stringBuffer.append(column.getLabel());
                    stringBuffer.append(TEXT_88);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_89);
                  }

                  for (int i = 0; i < denormalizeColumns.size(); i++) {
                    String columnName = denormalizeColumns.get(i);
                    String columnType = denormalizeColumnsType.get(i);
                    if (denormalizeMergeFlags.get(i)) {

                      stringBuffer.append(TEXT_90);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_91);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_92);
                      stringBuffer.append(typesMap.get(columnName));
                      stringBuffer.append(TEXT_93);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_94);
                      stringBuffer.append(columnName);
                      stringBuffer.append(TEXT_95);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_96);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_97);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_98);
                      stringBuffer.append(denormalizeDelimiters.get(i));
                      stringBuffer.append(TEXT_99);

                      if ((("java.util.Date").equals(columnType))
                          && (patternsMap.get(columnName).length() != 0)) {

                        stringBuffer.append(TEXT_100);
                        stringBuffer.append(cid);
                        stringBuffer.append(TEXT_101);
                        stringBuffer.append(cid);
                        stringBuffer.append(TEXT_102);
                        stringBuffer.append(patternsMap.get(columnName));
                        stringBuffer.append(TEXT_103);

                      } else {

                        stringBuffer.append(TEXT_104);
                        stringBuffer.append(cid);
                        stringBuffer.append(TEXT_105);
                        stringBuffer.append(cid);
                        stringBuffer.append(TEXT_106);
                      }

                      stringBuffer.append(TEXT_107);
                      stringBuffer.append(columnName);
                      stringBuffer.append(TEXT_108);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_109);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_110);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_111);
                      stringBuffer.append(columnName);
                      stringBuffer.append(TEXT_112);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_113);

                    } else {

                      stringBuffer.append(TEXT_114);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_115);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_116);
                      stringBuffer.append(columnName);
                      stringBuffer.append(TEXT_117);
                      stringBuffer.append(columnName);
                      stringBuffer.append(TEXT_118);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_119);
                      stringBuffer.append(columnName);
                      stringBuffer.append(TEXT_120);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_121);
                      stringBuffer.append(columnName);
                      stringBuffer.append(TEXT_122);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_123);
                    }
                  }
                }
              }
            }
            // do out end ...

            // do first
            for (IMetadataColumn column : groupColumns) {

              stringBuffer.append(TEXT_124);
              stringBuffer.append(column.getLabel());
              stringBuffer.append(TEXT_125);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_126);
              stringBuffer.append(connName);
              stringBuffer.append(TEXT_127);
              stringBuffer.append(column.getLabel());
              stringBuffer.append(TEXT_128);
            }
            for (int i = 0; i < denormalizeColumns.size(); i++) {
              String columnName = denormalizeColumns.get(i);
              String columnType = denormalizeColumnsType.get(i);
              if (denormalizeMergeFlags.get(i)) {

                stringBuffer.append(TEXT_129);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_130);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_131);
                stringBuffer.append(connName);
                stringBuffer.append(TEXT_132);
                stringBuffer.append(columnName);
                stringBuffer.append(TEXT_133);

              } else {
                if ((("java.util.Date").equals(columnType))
                    && (patternsMap.get(columnName).length() != 0)) {

                  stringBuffer.append(TEXT_134);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_135);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_136);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_137);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_138);
                  stringBuffer.append(patternsMap.get(columnName));
                  stringBuffer.append(TEXT_139);

                } else {

                  stringBuffer.append(TEXT_140);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_141);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_142);
                  stringBuffer.append(connName);
                  stringBuffer.append(TEXT_143);
                  stringBuffer.append(columnName);
                  stringBuffer.append(TEXT_144);
                }
              }
            }

            stringBuffer.append(TEXT_145);
          }
          /////////////////////////////////////////////////

          stringBuffer.append(TEXT_146);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_147);
          stringBuffer.append(rowCount);
          stringBuffer.append(TEXT_148);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_149);

          // do out start ...
          conns = null;
          conns = node.getOutgoingSortedConnections();
          if (conns != null) {
            if (conns.size() > 0) {
              IConnection conn = conns.get(0);
              if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
                for (IMetadataColumn column : groupColumns) {

                  stringBuffer.append(TEXT_150);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_151);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_152);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_153);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_154);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_155);
                }

                for (int i = 0; i < denormalizeColumns.size(); i++) {
                  String columnName = denormalizeColumns.get(i);
                  String columnType = denormalizeColumnsType.get(i);
                  if (denormalizeMergeFlags.get(i)) {

                    stringBuffer.append(TEXT_156);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_157);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_158);
                    stringBuffer.append(typesMap.get(columnName));
                    stringBuffer.append(TEXT_159);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_160);
                    stringBuffer.append(columnName);
                    stringBuffer.append(TEXT_161);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_162);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_163);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_164);
                    stringBuffer.append(denormalizeDelimiters.get(i));
                    stringBuffer.append(TEXT_165);

                    if ((("java.util.Date").equals(columnType))
                        && (patternsMap.get(columnName).length() != 0)) {

                      stringBuffer.append(TEXT_166);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_167);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_168);
                      stringBuffer.append(patternsMap.get(columnName));
                      stringBuffer.append(TEXT_169);

                    } else {

                      stringBuffer.append(TEXT_170);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_171);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_172);
                    }

                    stringBuffer.append(TEXT_173);
                    stringBuffer.append(columnName);
                    stringBuffer.append(TEXT_174);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_175);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_176);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_177);
                    stringBuffer.append(columnName);
                    stringBuffer.append(TEXT_178);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_179);

                  } else {

                    stringBuffer.append(TEXT_180);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_181);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_182);
                    stringBuffer.append(columnName);
                    stringBuffer.append(TEXT_183);
                    stringBuffer.append(columnName);
                    stringBuffer.append(TEXT_184);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_185);
                    stringBuffer.append(columnName);
                    stringBuffer.append(TEXT_186);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_187);
                    stringBuffer.append(columnName);
                    stringBuffer.append(TEXT_188);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_189);
                  }
                }
              }
            }
          }
          // do out end ...

          stringBuffer.append(TEXT_190);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_191);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_192);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_193);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_194);

          conns = null;
          conns = node.getOutgoingSortedConnections();
          if (conns != null) {
            for (int i = 0; i < conns.size(); i++) {
              IConnection conn = conns.get(i);
              if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
                for (IMetadataColumn column : metadata.getListColumns()) {

                  stringBuffer.append(conn.getName());
                  stringBuffer.append(TEXT_195);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_196);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_197);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_198);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_199);
                }
              }
            }
          }

          stringBuffer.append(TEXT_200);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_201);
        }
      }
    }

    stringBuffer.append(TEXT_202);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    stringBuffer.append(TEXT_2);

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0)) {
      IMetadataTable metadata = metadatas.get(0);
      if (metadata != null) {
        String encoding = ElementParameterParser.getValue(node, "__ENCODING__");
        String delim1 = ElementParameterParser.getValue(node, "__FIELDSEPARATOR__");
        boolean compress = ("true").equals(ElementParameterParser.getValue(node, "__COMPRESS__"));
        String delim = delim1.substring(1, delim1.length() - 1);
        String rowSeparator1 = ElementParameterParser.getValue(node, "__ROWSEPARATOR__");
        String rowSeparator = rowSeparator1.substring(1, rowSeparator1.length() - 1);
        String escapeChar1 = ElementParameterParser.getValue(node, "__ESCAPE_CHAR__");
        String escapeChar = escapeChar1.substring(1, escapeChar1.length() - 1);
        String textEnclosure1 = ElementParameterParser.getValue(node, "__TEXT_ENCLOSURE__");
        String textEnclosure = textEnclosure1.substring(1, textEnclosure1.length() - 1);
        if ("".equals(textEnclosure)) textEnclosure = "\0";

        List<? extends IConnection> conns = node.getIncomingConnections();
        if (!("\\n").equals(rowSeparator) && !("\\r").equals(rowSeparator)) {

          stringBuffer.append(TEXT_3);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_4);
          stringBuffer.append(rowSeparator);
          stringBuffer.append(TEXT_5);
        }
        if (("\\\\").equals(escapeChar)) {

          stringBuffer.append(TEXT_6);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_7);

        } else if (escapeChar.equals(textEnclosure)) {

          stringBuffer.append(TEXT_8);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_9);
          stringBuffer.append(textEnclosure);
          stringBuffer.append(TEXT_10);

        } else {

          stringBuffer.append(TEXT_11);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_12);
          stringBuffer.append(textEnclosure);
          stringBuffer.append(TEXT_13);
        }

        stringBuffer.append(TEXT_14);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_15);
        stringBuffer.append(textEnclosure);
        stringBuffer.append(TEXT_16);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_17);

        if (conns != null) {
          if (conns.size() > 0) {
            IConnection conn = conns.get(0);
            if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
              List<IMetadataColumn> columns = metadata.getListColumns();
              int sizeColumns = columns.size();

              stringBuffer.append(TEXT_18);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_19);
              stringBuffer.append(sizeColumns);
              stringBuffer.append(TEXT_20);

              for (int i = 0; i < sizeColumns; i++) {
                IMetadataColumn column = columns.get(i);
                JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
                String pattern =
                    column.getPattern() == null || column.getPattern().trim().length() == 0
                        ? null
                        : column.getPattern();
                if (JavaTypesManager.isJavaPrimitiveType(
                    column.getTalendType(), column.isNullable())) {

                  stringBuffer.append(TEXT_21);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_22);
                  stringBuffer.append(i);
                  stringBuffer.append(TEXT_23);
                  stringBuffer.append(conn.getName());
                  stringBuffer.append(TEXT_24);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_25);

                } else {

                  stringBuffer.append(TEXT_26);
                  stringBuffer.append(conn.getName());
                  stringBuffer.append(TEXT_27);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_28);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_29);
                  stringBuffer.append(i);
                  stringBuffer.append(TEXT_30);

                  if (javaType == JavaTypesManager.STRING) {

                    stringBuffer.append(TEXT_31);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_32);
                    stringBuffer.append(i);
                    stringBuffer.append(TEXT_33);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_34);
                    stringBuffer.append(column.getLabel());
                    stringBuffer.append(TEXT_35);

                  } else if (javaType == JavaTypesManager.DATE && pattern != null) {

                    stringBuffer.append(TEXT_36);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_37);
                    stringBuffer.append(i);
                    stringBuffer.append(TEXT_38);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_39);
                    stringBuffer.append(column.getLabel());
                    stringBuffer.append(TEXT_40);
                    stringBuffer.append(pattern);
                    stringBuffer.append(TEXT_41);

                  } else if (javaType == JavaTypesManager.BYTE_ARRAY) {

                    stringBuffer.append(TEXT_42);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_43);
                    stringBuffer.append(i);
                    stringBuffer.append(TEXT_44);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_45);
                    stringBuffer.append(column.getLabel());
                    stringBuffer.append(TEXT_46);

                  } else {

                    stringBuffer.append(TEXT_47);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_48);
                    stringBuffer.append(i);
                    stringBuffer.append(TEXT_49);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_50);
                    stringBuffer.append(column.getLabel());
                    stringBuffer.append(TEXT_51);
                  }

                  stringBuffer.append(TEXT_52);
                }
              }

              if (compress) {
                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(encoding);
                stringBuffer.append(TEXT_58);
              }
              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);
    stringBuffer.append(TEXT_65);
    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();

    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();
  }
Example #23
0
  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();

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;

    INode node = (INode) codeGenArgument.getArgument();

    String cid = node.getUniqueName();

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0)) {
      IMetadataTable metadata = metadatas.get(0);

      if (metadata != null) {
        List<IMetadataColumn> columnList = metadata.getListColumns();
        int nbSchemaColumns = columnList.size();

        List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections();

        // if output columns are defined
        if (nbSchemaColumns > 0 && outgoingConns != null && outgoingConns.size() > 0) {

          IConnection outgoingConn = outgoingConns.get(0);

          if (outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            String authType = ElementParameterParser.getValue(node, "__AUTH_TYPE__");
            boolean isAPI2011 =
                ("API_2011").equals(ElementParameterParser.getValue(node, "__API_VERSION__"));
            String discWSDL = ElementParameterParser.getValue(node, "__DISC_WSDL__");
            if (!isAPI2011 || ("ON_PREMISE").equals(authType)) {

              stringBuffer.append(TEXT_1);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_2);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_3);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_4);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_5);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_6);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_7);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_8);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_9);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_10);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_11);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_12);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_13);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_14);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_15);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_16);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_17);

            } else {

              stringBuffer.append(TEXT_18);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_19);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_20);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_21);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_22);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_23);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_24);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_25);
            }
          }
        }
      }
    }

    stringBuffer.append(TEXT_26);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_27);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_28);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    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();
  }
Example #26
0
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    Vector v = (Vector) codeGenArgument.getArgument();
    IProcess process = (IProcess) v.get(0);
    String version = (String) v.get(1);
    String exportAsOSGI = (String) v.get(2);

    List<? extends INode> processNodes = (List<? extends INode>) process.getGeneratingNodes();
    boolean stats = codeGenArgument.isStatistics();
    boolean trace = codeGenArgument.isTrace();
    boolean isRunInMultiThread = codeGenArgument.getIsRunInMultiThread();
    List<IContextParameter> params = new ArrayList<IContextParameter>();
    params = process.getContextManager().getDefaultContext().getContextParameterList();

    IBrandingService service =
        (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    if (service instanceof AbstractBrandingService) {

      stringBuffer.append(TEXT_1);
      stringBuffer.append(((AbstractBrandingService) service).getJobLicenseHeader(version));
    }
    String jobFolderName =
        JavaResourcesHelper.getJobFolderName(process.getName(), process.getVersion());
    String packageName =
        codeGenArgument.getCurrentProjectName().toLowerCase() + "." + jobFolderName;

    stringBuffer.append(TEXT_2);
    stringBuffer.append(packageName);
    stringBuffer.append(TEXT_3);
    for (String routine : CodeGeneratorRoutine.getRequiredRoutineName(process)) {
      if (!routine.equals(ITalendSynchronizer.TEMPLATE)) {
        stringBuffer.append(TEXT_4);
        stringBuffer.append(routine);
        stringBuffer.append(TEXT_5);
      }
    }
    stringBuffer.append(TEXT_6);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(ElementParameterParser.getValue(process, "__HEADER_IMPORT__"));
    stringBuffer.append(TEXT_8);
    stringBuffer.append(ElementParameterParser.getValue(process, "__FOOTER_IMPORT__"));
    stringBuffer.append(TEXT_9);

    List<INode> nodesWithImport = process.getNodesWithImport();
    if (nodesWithImport != null) {
      for (INode node : nodesWithImport) {

        stringBuffer.append(TEXT_10);
        stringBuffer.append(node.getUniqueName());
        stringBuffer.append(TEXT_11);
        stringBuffer.append(ElementParameterParser.getValue(node, "__IMPORT__"));
        stringBuffer.append(TEXT_12);
      }
    }

    stringBuffer.append(TEXT_13);
    stringBuffer.append(process.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(ElementParameterParser.getValue(process, "__PURPOSE__"));
    stringBuffer.append(TEXT_15);
    stringBuffer.append(ElementParameterParser.getValue(process, "__DESCRIPTION__"));
    stringBuffer.append(TEXT_16);
    stringBuffer.append(ElementParameterParser.getValue(process, "__AUTHOR__"));
    stringBuffer.append(TEXT_17);
    stringBuffer.append(version);
    stringBuffer.append(TEXT_18);
    stringBuffer.append(ElementParameterParser.getValue(process, "__STATUS__"));
    stringBuffer.append(TEXT_19);

    String talendJobInterfaces = "TalendJob";

    boolean talendMdmJob =
        !process.getNodesOfType("tMDMTriggerInput").isEmpty()
            || !process.getNodesOfType("tMDMTriggerOutput").isEmpty();
    boolean talendEsbJob =
        !process.getNodesOfType("tESBProviderRequest").isEmpty()
            || !process.getNodesOfType("tESBConsumer").isEmpty();
    boolean talendEsbJobFactory = !process.getNodesOfType("tESBProviderRequest").isEmpty();

    if (talendMdmJob) {
      talendJobInterfaces += ", TalendMDMJob"; // Talend MDM job
    }
    if (talendEsbJob) {
      talendJobInterfaces += ", TalendESBJob"; // Talend ESB job
    }
    if (talendEsbJobFactory) {
      talendJobInterfaces += ", TalendESBJobFactory"; // Talend ESB provider job
    }

    stringBuffer.append(TEXT_20);
    stringBuffer.append(process.getName());
    stringBuffer.append(TEXT_21);
    stringBuffer.append(talendJobInterfaces);
    stringBuffer.append(TEXT_22);
    if (talendEsbJobFactory) {
      stringBuffer.append(TEXT_23);
      stringBuffer.append(process.getName());
      stringBuffer.append(TEXT_24);
      stringBuffer.append(process.getName());
      stringBuffer.append(TEXT_25);
    }
    stringBuffer.append(TEXT_26);

    if (isRunInMultiThread) {

      stringBuffer.append(TEXT_27);
    }

    stringBuffer.append(TEXT_28);
    // it will be use in job setting.
    stringBuffer.append(TEXT_29);
    // uft-8 is for temp file, for example: tSortRow, tMap. Because they need keep reversibility.
    stringBuffer.append(TEXT_30);
    for (IContextParameter ctxParam : params) {
      String cParaName = ctxParam.getName();

      stringBuffer.append(TEXT_31);
      stringBuffer.append(cParaName);
      stringBuffer.append(TEXT_32);
      if (ctxParam.getType().equals("id_Date")) {
        stringBuffer.append(TEXT_33);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_34);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_35);
        stringBuffer.append(ctxParam.getValue());
        stringBuffer.append(TEXT_36);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_37);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_38);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_39);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_40);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_41);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_42);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_43);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_44);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_45);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_46);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_47);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_48);
      } else {
        stringBuffer.append(TEXT_49);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_50);
        stringBuffer.append(cParaName);
        stringBuffer.append(TEXT_51);
      }
      stringBuffer.append(TEXT_52);
    }
    stringBuffer.append(TEXT_53);

    for (IContextParameter ctxParam : params) {
      if (ctxParam.getType().equals("id_List Of Value")
          || ctxParam.getType().equals("id_File")
          || ctxParam.getType().equals("id_Directory")) {

        stringBuffer.append(TEXT_54);
        stringBuffer.append(ctxParam.getName());
        stringBuffer.append(TEXT_55);
        stringBuffer.append(
            Character.toUpperCase(ctxParam.getName().charAt(0)) + ctxParam.getName().substring(1));
        stringBuffer.append(TEXT_56);
        stringBuffer.append(ctxParam.getName());
        stringBuffer.append(TEXT_57);

      } else {

        stringBuffer.append(TEXT_58);
        stringBuffer.append(JavaTypesManager.getTypeToGenerate(ctxParam.getType(), true));
        stringBuffer.append(TEXT_59);
        stringBuffer.append(ctxParam.getName());
        stringBuffer.append(TEXT_60);
        stringBuffer.append(JavaTypesManager.getTypeToGenerate(ctxParam.getType(), true));
        stringBuffer.append(TEXT_61);
        stringBuffer.append(
            Character.toUpperCase(ctxParam.getName().charAt(0)) + ctxParam.getName().substring(1));
        stringBuffer.append(TEXT_62);
        stringBuffer.append(ctxParam.getName());
        stringBuffer.append(TEXT_63);
      }
    }

    stringBuffer.append(TEXT_64);
    stringBuffer.append(process.getVersion());
    stringBuffer.append(TEXT_65);
    stringBuffer.append(codeGenArgument.getJobName());
    stringBuffer.append(TEXT_66);
    stringBuffer.append(codeGenArgument.getCurrentProjectName());
    stringBuffer.append(TEXT_67);

    if (!isRunInMultiThread) {

      stringBuffer.append(TEXT_68);

    } else {

      stringBuffer.append(TEXT_69);
    }
    stringBuffer.append(TEXT_70);

    if (stats) {

      stringBuffer.append(TEXT_71);
    }

    if (trace) {

      stringBuffer.append(TEXT_72);
    }

    stringBuffer.append(TEXT_73);
    stringBuffer.append(exportAsOSGI);
    stringBuffer.append(TEXT_74);

    for (INode logCatcher : process.getNodesOfType("tLogCatcher")) {

      stringBuffer.append(TEXT_75);
      stringBuffer.append(logCatcher.getUniqueName());
      stringBuffer.append(TEXT_76);
    }

    for (INode statCatcher : process.getNodesOfType("tStatCatcher")) {

      stringBuffer.append(TEXT_77);
      stringBuffer.append(statCatcher.getUniqueName());
      stringBuffer.append(TEXT_78);
      stringBuffer.append(process.getId());
      stringBuffer.append(TEXT_79);
      stringBuffer.append(process.getVersion());
      stringBuffer.append(TEXT_80);
    }

    for (INode metterCatcher : process.getNodesOfType("tFlowMeterCatcher")) {

      stringBuffer.append(TEXT_81);
      stringBuffer.append(metterCatcher.getUniqueName());
      stringBuffer.append(TEXT_82);
      stringBuffer.append(process.getId());
      stringBuffer.append(TEXT_83);
      stringBuffer.append(process.getVersion());
      stringBuffer.append(TEXT_84);
    }

    for (INode assertCatcher : process.getNodesOfType("tAssertCatcher")) {

      stringBuffer.append(TEXT_85);
      stringBuffer.append(assertCatcher.getUniqueName());
      stringBuffer.append(TEXT_86);
    }

    stringBuffer.append(TEXT_87);
    stringBuffer.append(process.getName());
    stringBuffer.append(TEXT_88);
    stringBuffer.append(process.getName());
    stringBuffer.append(TEXT_89);

    if (process.getNodesOfType("tLogCatcher").size() > 0) {
      List<INode> logCatchers = (List<INode>) process.getNodesOfType("tLogCatcher");
      for (INode logCatcher : logCatchers) {
        if (ElementParameterParser.getValue(logCatcher, "__CATCH_JAVA_EXCEPTION__")
            .equals("true")) {
          // 1) add the message to the stack

          stringBuffer.append(TEXT_90);
          stringBuffer.append(logCatcher.getUniqueName());
          stringBuffer.append(TEXT_91);
        }
      }

      INode virtualNCatchNode = null;
      boolean hasRealCatchNode = false;
      for (INode logCatcher : logCatchers) {
        if (ElementParameterParser.getValue(logCatcher, "__CATCH_JAVA_EXCEPTION__")
            .equals("true")) {
          if (logCatcher.isVirtualGenerateNode()) {
            virtualNCatchNode = logCatcher;
          } else {
            hasRealCatchNode = true;
          }
        }
      }
      if (hasRealCatchNode && virtualNCatchNode != null) {

        stringBuffer.append(TEXT_92);
      }
      for (INode logCatcher : logCatchers) {
        if (ElementParameterParser.getValue(logCatcher, "__CATCH_JAVA_EXCEPTION__")
            .equals("true")) {
          if (logCatcher != virtualNCatchNode) {
            // 2) launch logCatcher subProcess

            stringBuffer.append(TEXT_93);
            stringBuffer.append(logCatcher.getDesignSubjobStartNode().getUniqueName());
            stringBuffer.append(TEXT_94);
          }
        }
      }
      if (hasRealCatchNode && virtualNCatchNode != null) {

        stringBuffer.append(TEXT_95);
      }
      if (virtualNCatchNode != null) {

        stringBuffer.append(TEXT_96);
        stringBuffer.append(virtualNCatchNode.getDesignSubjobStartNode().getUniqueName());
        stringBuffer.append(TEXT_97);
      }
      if (hasRealCatchNode && virtualNCatchNode != null) {

        stringBuffer.append(TEXT_98);
      }
    }

    stringBuffer.append(TEXT_99);

    boolean needCatchTalendException = false;
    if (process.getNodesOfType("tLogCatcher").size() > 0) {
      for (INode node : process.getNodesOfType("tLogCatcher")) {
        if (ElementParameterParser.getValue(node, "__CATCH_JAVA_EXCEPTION__").equals("true")) {
          needCatchTalendException = true;
          break;
        }
      }
    }

    if ((!needCatchTalendException) && (process.getNodesOfType("tAssertCatcher").size() > 0)) {
      for (INode node : process.getNodesOfType("tAssertCatcher")) {
        if (ElementParameterParser.getValue(node, "__CATCH_JAVA_EXCEPTION__").equals("true")) {
          needCatchTalendException = true;
          break;
        }
      }
    }
    if (needCatchTalendException) {
      if (process.getNodesOfType("tLogCatcher").size() > 0) {

        stringBuffer.append(TEXT_100);
      }
    }

    stringBuffer.append(TEXT_101);

    if (isRunInMultiThread) {

      stringBuffer.append(TEXT_102);

    } else {
      stringBuffer.append(TEXT_103);
    }

    stringBuffer.append(TEXT_104);
    // Methods for RUN IF Error links

    for (INode node : processNodes) {
      if (node.isActivate()) {

        stringBuffer.append(TEXT_105);
        stringBuffer.append(node.getUniqueName());
        stringBuffer.append(TEXT_106);
        stringBuffer.append(node.getUniqueName());
        stringBuffer.append(TEXT_107);

        boolean ifBeforRunError = NodeUtil.checkComponentErrorConnectionAfterNode(node);
        if (!ifBeforRunError) {
          if (process.getNodesOfType("tAssertCatcher").size() > 0) {
            List<INode> assertCatchers = (List<INode>) process.getNodesOfType("tAssertCatcher");
            for (INode assertCatcher : assertCatchers) {
              if (ElementParameterParser.getValue(assertCatcher, "__CATCH_JAVA_EXCEPTION__")
                  .equals("true")) {
                // 1) add the message to the stack

                stringBuffer.append(TEXT_108);
                stringBuffer.append(assertCatcher.getUniqueName());
                stringBuffer.append(TEXT_109);
                stringBuffer.append(assertCatcher.getDesignSubjobStartNode().getUniqueName());
                stringBuffer.append(TEXT_110);
              }
            }
          }
        }
        if (!node.getComponent().getName().equals("tDie")) {
          String statCatcher = ElementParameterParser.getValue(node, "__TSTATCATCHER_STATS__");
          if (statCatcher.compareTo("true") == 0) {
            for (INode statCatcherNode : node.getProcess().getNodesOfType("tStatCatcher")) {

              stringBuffer.append(TEXT_111);
              stringBuffer.append(statCatcherNode.getUniqueName());
              stringBuffer.append(TEXT_112);
              stringBuffer.append(node.getUniqueName());
              stringBuffer.append(TEXT_113);
              stringBuffer.append(node.getUniqueName());
              stringBuffer.append(TEXT_114);
              stringBuffer.append(node.getUniqueName());
              stringBuffer.append(TEXT_115);
              stringBuffer.append(statCatcherNode.getDesignSubjobStartNode().getUniqueName());
              stringBuffer.append(TEXT_116);
            }
          }
        }
        boolean isExistOnCompErrorLink = false;
        List<? extends IConnection> conns = node.getOutgoingConnections();
        for (IConnection conn : conns) {
          if (conn.getLineStyle().equals(EConnectionType.ON_COMPONENT_ERROR)) {
            isExistOnCompErrorLink = true;

            stringBuffer.append(TEXT_117);
            if (stats) {
              stringBuffer.append(TEXT_118);
              stringBuffer.append(conn.getUniqueName());
              stringBuffer.append(TEXT_119);
            }
            stringBuffer.append(TEXT_120);

            if (isRunInMultiThread) {

              stringBuffer.append(TEXT_121);
              stringBuffer.append(conn.getTarget().getUniqueName());
              stringBuffer.append(TEXT_122);

            } else {

              stringBuffer.append(TEXT_123);
              stringBuffer.append(conn.getTarget().getUniqueName());
              stringBuffer.append(TEXT_124);
            }

            stringBuffer.append(TEXT_125);
          }
        }
        boolean isSubjobHasOnSubJobError = false;
        if (!isExistOnCompErrorLink) {
          INode subJobStartNode = node.getDesignSubjobStartNode();
          if (subJobStartNode != null) {
            List<? extends IConnection> tempConns = subJobStartNode.getOutgoingConnections();
            for (IConnection conn : tempConns) {
              if (conn.getLineStyle().equals(EConnectionType.ON_SUBJOB_ERROR)) {
                isSubjobHasOnSubJobError = true;
                break;
              }
            }
          }
        }

        if (!isSubjobHasOnSubJobError
            && !isExistOnCompErrorLink) { // when there is no subjoberror and no onComponentError
          if (isRunInMultiThread) {

            stringBuffer.append(TEXT_126);

          } else {

            stringBuffer.append(TEXT_127);
          }
        }
        // when use parallelize will add virtual components(tAsyncIn and tAsyncOut) but in graphical
        // these is visable=false
        if ("true".equals(ElementParameterParser.getValue(node, "__PARALLELIZE__"))) {
          for (INode gNode : node.getProcess().getGeneratingNodes()) {
            if (gNode.getUniqueName().equals(node.getUniqueName())) {
              if (gNode.getIncomingConnections(EConnectionType.FLOW_MAIN).size() != 0) {
                INode gSourceNode =
                    gNode.getIncomingConnections(EConnectionType.FLOW_MAIN).get(0).getSource();
                node = gSourceNode;
              }
            }
          }
        }
        // end

        stringBuffer.append(TEXT_128);
        stringBuffer.append(node.getDesignSubjobStartNode().getUniqueName());
        stringBuffer.append(TEXT_129);
      }
    }
    for (INode node : processNodes) {
      if (node.isDesignSubjobStartNode()) {

        stringBuffer.append(TEXT_130);
        stringBuffer.append(node.getUniqueName());
        stringBuffer.append(TEXT_131);

        List<? extends IConnection> conns = node.getOutgoingConnections();
        int count = 0;
        for (IConnection conn : conns) {
          if (conn.getLineStyle().equals(EConnectionType.ON_SUBJOB_ERROR)) {
            count++;
          }
        }

        String label = "ERROR";

        if (count == 0) { // FATAL
          label = "FATAL";
        } else { // ERROR------>RunSubJobError
          label = "ERROR";
        }

        stringBuffer.append(TEXT_132);
        stringBuffer.append(label);
        stringBuffer.append(TEXT_133);

        for (IConnection conn : conns) {
          if (conn.getLineStyle().equals(EConnectionType.ON_SUBJOB_ERROR)) {

            stringBuffer.append(TEXT_134);
            if (stats) {
              stringBuffer.append(TEXT_135);
              stringBuffer.append(conn.getUniqueName());
              stringBuffer.append(TEXT_136);
            }

            if (isRunInMultiThread) {

              stringBuffer.append(TEXT_137);
              stringBuffer.append(conn.getTarget().getUniqueName());
              stringBuffer.append(TEXT_138);

            } else {

              stringBuffer.append(TEXT_139);
              stringBuffer.append(conn.getTarget().getUniqueName());
              stringBuffer.append(TEXT_140);
            }

            stringBuffer.append(TEXT_141);
          }
        }

        stringBuffer.append(TEXT_142);
      }
    }

    stringBuffer.append(TEXT_143);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    String operation = ElementParameterParser.getValue(node, "__OPERATION__");
    boolean mutipleOperation =
        ("true").equals(ElementParameterParser.getValue(node, "__MUTIPLE_OPERATION__"));
    boolean isMutiple = false;
    if (mutipleOperation && !operation.equals("ISMEMBEROFLIST")) {
      isMutiple = true;
    }
    boolean strict = ("true").equals(ElementParameterParser.getValue(node, "__STRICT__"));

    String rejectConnName = null;
    List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT");
    if (rejectConns != null && rejectConns.size() > 0) {
      IConnection rejectConn = rejectConns.get(0);
      rejectConnName = rejectConn.getName();
    }

    String mainConnName = null;
    List<? extends IConnection> mainConns = node.getOutgoingConnections("OUTPUT_MAIN");
    if (mainConns != null && mainConns.size() > 0) {
      IConnection mainConn = mainConns.get(0);
      mainConnName = mainConn.getName();
    }

    List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections();
    if (outgoingConns != null) {
      for (int i = 0; i < outgoingConns.size(); i++) {
        IConnection outgoingConn = outgoingConns.get(i);
        if (outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {

          stringBuffer.append(TEXT_1);
          stringBuffer.append(outgoingConn.getName());
          stringBuffer.append(TEXT_2);
        }
      }
    }

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas != null) && (metadatas.size() > 0)) { // 1
      IMetadataTable metadata = metadatas.get(0);

      if (metadata != null) { // 2
        List<? extends IConnection> conns = node.getIncomingConnections();

        for (IConnection conn : conns) { // 3
          if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) { // 4
            boolean useSoapAPI =
                ("true").equals(ElementParameterParser.getValue(node, "__USE_SOAP_API__"));
            boolean useRestAPI =
                ("true").equals(ElementParameterParser.getValue(node, "__USE_REST_API__"));
            if (useSoapAPI) {

              stringBuffer.append(TEXT_3);
              if (isMutiple) {
                stringBuffer.append(TEXT_4);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_5);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_6);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_7);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_8);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_9);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_10);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_11);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_12);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_13);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_14);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_15);
                stringBuffer.append(operation);
                stringBuffer.append(TEXT_16);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_17);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_18);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_19);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_20);
                stringBuffer.append(strict);
                stringBuffer.append(TEXT_21);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_22);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_23);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_24);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_25);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_26);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_27);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_28);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_29);

                if (strict) {

                  stringBuffer.append(TEXT_30);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_31);

                } else {

                  stringBuffer.append(TEXT_32);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_33);
                }

                stringBuffer.append(TEXT_34);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_35);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_36);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_37);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_38);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_39);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_40);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_41);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_42);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_43);
              } else {
                stringBuffer.append(TEXT_44);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_45);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_46);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_47);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_48);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_49);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_50);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_51);
                stringBuffer.append(operation);
                stringBuffer.append(TEXT_52);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_53);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_54);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_55);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_56);
                stringBuffer.append(strict);
                stringBuffer.append(TEXT_57);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_58);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_59);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_60);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_61);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_62);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_63);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_64);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_65);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_66);

                if (strict) {

                  stringBuffer.append(TEXT_67);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_68);

                } else {
                  if (rejectConnName != null) {

                    stringBuffer.append(TEXT_69);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_70);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_71);
                    stringBuffer.append(TEXT_72);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_73);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_74);
                    stringBuffer.append(TEXT_75);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_76);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_77);
                    stringBuffer.append(TEXT_78);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_79);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_80);
                    stringBuffer.append(TEXT_81);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_82);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_83);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_84);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_85);

                  } else {

                    stringBuffer.append(TEXT_86);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_87);
                  }
                }

                stringBuffer.append(TEXT_88);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_89);
              }
              if (mainConnName != null) {

                stringBuffer.append(TEXT_90);
                if (!isMutiple) {
                  stringBuffer.append(TEXT_91);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_92);
                }
                stringBuffer.append(TEXT_93);
                stringBuffer.append(mainConnName);
                stringBuffer.append(TEXT_94);
                stringBuffer.append(mainConnName);
                stringBuffer.append(TEXT_95);
                if (!isMutiple) {
                  stringBuffer.append(TEXT_96);
                  stringBuffer.append(mainConnName);
                  stringBuffer.append(TEXT_97);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_98);
                }
                stringBuffer.append(TEXT_99);

                for (IMetadataColumn column : metadata.getListColumns()) {
                  if (!isMutiple) {
                    if ("Success".equals(column.getLabel())) continue;
                  }

                  stringBuffer.append(TEXT_100);
                  stringBuffer.append(mainConnName);
                  stringBuffer.append(TEXT_101);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_102);
                  stringBuffer.append(conn.getName());
                  stringBuffer.append(TEXT_103);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_104);
                }

                stringBuffer.append(TEXT_105);
                if (!isMutiple) {
                  stringBuffer.append(TEXT_106);
                }
              }

              stringBuffer.append(TEXT_107);
            }
            if (useRestAPI) {

              stringBuffer.append(TEXT_108);
              if (isMutiple) {
                stringBuffer.append(TEXT_109);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_110);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_111);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_112);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_113);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_114);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_115);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_116);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_117);
                stringBuffer.append(operation);
                stringBuffer.append(TEXT_118);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_119);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_120);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_121);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_122);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_123);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_124);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_125);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_126);

                if (strict) {

                  stringBuffer.append(TEXT_127);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_128);

                } else {

                  stringBuffer.append(TEXT_129);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_130);
                }

                stringBuffer.append(TEXT_131);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_132);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_133);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_134);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_135);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_136);
              } else {
                stringBuffer.append(TEXT_137);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_138);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_139);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_140);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_141);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_142);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_143);
                stringBuffer.append(operation);
                stringBuffer.append(TEXT_144);
                stringBuffer.append(conn.getName());
                stringBuffer.append(TEXT_145);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_146);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_147);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_148);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_149);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_150);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_151);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_152);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_153);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_154);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_155);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_156);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_157);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_158);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_159);

                if (strict) {

                  stringBuffer.append(TEXT_160);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_161);

                } else {
                  if (rejectConnName != null) {

                    stringBuffer.append(TEXT_162);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_163);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_164);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_165);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_166);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_167);
                    stringBuffer.append(conn.getName());
                    stringBuffer.append(TEXT_168);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_169);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_170);
                    stringBuffer.append(rejectConnName);
                    stringBuffer.append(TEXT_171);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_172);

                  } else {

                    stringBuffer.append(TEXT_173);
                    stringBuffer.append(cid);
                    stringBuffer.append(TEXT_174);
                  }
                }

                stringBuffer.append(TEXT_175);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_176);
              }
              if (mainConnName != null) {

                stringBuffer.append(TEXT_177);
                if (!isMutiple) {
                  stringBuffer.append(TEXT_178);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_179);
                }
                stringBuffer.append(TEXT_180);
                stringBuffer.append(mainConnName);
                stringBuffer.append(TEXT_181);
                stringBuffer.append(mainConnName);
                stringBuffer.append(TEXT_182);

                for (IMetadataColumn column : metadata.getListColumns()) {
                  if (!isMutiple) {
                    if ("Status".equals(column.getLabel())) {

                      stringBuffer.append(TEXT_183);
                      stringBuffer.append(mainConnName);
                      stringBuffer.append(TEXT_184);
                      stringBuffer.append(cid);
                      stringBuffer.append(TEXT_185);
                    }
                  }

                  stringBuffer.append(TEXT_186);
                  stringBuffer.append(mainConnName);
                  stringBuffer.append(TEXT_187);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_188);
                  stringBuffer.append(conn.getName());
                  stringBuffer.append(TEXT_189);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_190);
                }

                stringBuffer.append(TEXT_191);
                if (!isMutiple) {
                  stringBuffer.append(TEXT_192);
                }
              }

              stringBuffer.append(TEXT_193);
            }
          } // 4
        } // 3
      } // 2
    } // 1

    stringBuffer.append(TEXT_194);
    stringBuffer.append(TEXT_195);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    boolean isStaging =
        "STAGING".equalsIgnoreCase(ElementParameterParser.getValue(node, "__CONTAINER_TYPE__"));

    String destination = ElementParameterParser.getValue(node, "__DESTINATION__");
    boolean withReport = ("true").equals(ElementParameterParser.getValue(node, "__WITHREPORT__"));
    String needCheck = ElementParameterParser.getValue(node, "__ISINVOKE__");
    boolean isMassInsert =
        ("true").equals(ElementParameterParser.getValue(node, "__EXTENDINSERT__"));
    String numMassInsert = ElementParameterParser.getValue(node, "__COMMIT_LEVEL__");
    String sourceName = ElementParameterParser.getValue(node, "__SOURCE__");
    boolean dieOnError = ("true").equals(ElementParameterParser.getValue(node, "__DIE_ON_ERROR__"));
    String isUpdate = ElementParameterParser.getValue(node, "__ISUPDATE__");
    List<Map<String, String>> keysReturn =
        (List<Map<String, String>>) ElementParameterParser.getObjectValue(node, "__RETURN_IDS__");

    boolean addTaskID = ("true").equals(ElementParameterParser.getValue(node, "__ADD_TASKID__"));
    boolean isCustom = "true".equals(ElementParameterParser.getValue(node, "__CUSTOM__"));
    String taskID = ElementParameterParser.getValue(node, "__TASKID__");
    String prevColumn = ElementParameterParser.getValue(node, "__PREV_COLUMN_TASK_ID__");

    boolean usePartialUpdate =
        ("true").equals(ElementParameterParser.getValue(node, "__USE_PARTIAL_UPDATE__"));
    boolean usePartialDelete =
        ("true").equals(ElementParameterParser.getValue(node, "__PARTIAL_DELETE__"));
    String pivot = ElementParameterParser.getValue(node, "__PIVOT__");
    boolean overwrite = ("true").equals(ElementParameterParser.getValue(node, "__OVERWRITE__"));
    String key = ElementParameterParser.getValue(node, "__KEY__");
    String position = ElementParameterParser.getValue(node, "__POSITION__");
    String dataModel = ElementParameterParser.getValue(node, "__DATAMODEL__");
    String dataCluster = ElementParameterParser.getValue(node, "__DATACLUSTER__");

    String doc = ElementParameterParser.getValue(node, "__DOCUMENT__");

    List<IMetadataTable> metadatas = node.getMetadataList();

    if (destination != null && !"".equals(destination)) {
      cid = destination;
    }

    if (metadatas != null && metadatas.size() > 0) {
      IMetadataTable metadata = metadatas.get(0);
      if (metadata != null) {

        List<? extends IConnection> outputConns =
            node.getOutgoingConnections(EConnectionType.FLOW_MAIN);
        List<IMetadataColumn> inputColumnList = null;
        List<IMetadataColumn> outputColumnList = null;
        List<IMetadataColumn> columnList = metadata.getListColumns();

        String rejectConnName = null;
        List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT");
        List<IMetadataColumn> rejectColumnList = null;
        if (rejectConns != null && rejectConns.size() > 0) {
          IConnection rejectConn = rejectConns.get(0);
          if (rejectConn != null) {
            rejectConnName = rejectConn.getName();
            IMetadataTable metadataTable = rejectConn.getMetadataTable();
            if (metadataTable != null) {
              rejectColumnList = metadataTable.getListColumns();
            }
          }
        }

        String outConnName = null;
        String inputConnName = null;
        List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections();

        for (IConnection tmpconn : outgoingConns) {
          if (tmpconn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            if (rejectConnName == null || !rejectConnName.equals(tmpconn.getName())) {
              outConnName = tmpconn.getName();
              IMetadataTable outputMetadata = tmpconn.getMetadataTable();
              if (outputMetadata != null) {
                outputColumnList = outputMetadata.getListColumns();
              }
            }
            stringBuffer.append(TEXT_1);
            stringBuffer.append(tmpconn.getName());
            stringBuffer.append(TEXT_2);
          }
        }

        List<? extends IConnection> inputConns = node.getIncomingConnections();
        if (inputConns != null && inputConns.size() > 0) {
          IConnection inputConn = inputConns.get(0);
          if (inputConn != null) {
            inputConnName = inputConn.getName();
            IMetadataTable inputMetadata = inputConn.getMetadataTable();
            if (inputMetadata != null) {
              inputColumnList = inputMetadata.getListColumns();
            }
          }
        }

        if (outConnName != null && inputConnName != null) {

          stringBuffer.append(TEXT_3);
          stringBuffer.append(outConnName);
          stringBuffer.append(TEXT_4);
          stringBuffer.append(outConnName);
          stringBuffer.append(TEXT_5);

          for (IMetadataColumn outputColumn : outputColumnList) {
            for (IMetadataColumn inputColumn : inputColumnList) {
              if (outputColumn.getLabel().equals(inputColumn.getLabel())) {
                if (doc != null && doc.equals(outputColumn.getLabel())) {
                  if ("id_Document".equals(outputColumn.getTalendType())) {

                    stringBuffer.append(TEXT_6);
                    stringBuffer.append(outConnName);
                    stringBuffer.append(TEXT_7);
                    stringBuffer.append(doc);
                    stringBuffer.append(TEXT_8);
                    stringBuffer.append(inputConnName);
                    stringBuffer.append(TEXT_9);
                    stringBuffer.append(doc);
                    stringBuffer.append(TEXT_10);

                  } else {

                    stringBuffer.append(TEXT_11);
                    stringBuffer.append(outConnName);
                    stringBuffer.append(TEXT_12);
                    stringBuffer.append(doc);
                    stringBuffer.append(TEXT_13);
                    stringBuffer.append(inputConnName);
                    stringBuffer.append(TEXT_14);
                    stringBuffer.append(doc);
                    stringBuffer.append(TEXT_15);
                  }
                } else { // to those which do not match doc columns

                  stringBuffer.append(TEXT_16);
                  stringBuffer.append(outConnName);
                  stringBuffer.append(TEXT_17);
                  stringBuffer.append(outputColumn.getLabel());
                  stringBuffer.append(TEXT_18);
                  stringBuffer.append(inputConnName);
                  stringBuffer.append(TEXT_19);
                  stringBuffer.append(inputColumn.getLabel());
                  stringBuffer.append(TEXT_20);
                }
              } // if input column matches output column
            } // for input column
          } // for output column
        }
        stringBuffer.append(TEXT_21);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_22);
        stringBuffer.append(inputConnName);
        stringBuffer.append(TEXT_23);
        stringBuffer.append(doc);
        stringBuffer.append(TEXT_24);
        if (usePartialUpdate) { // partial

          String dataclusterString = "";
          if (isStaging) {
            dataclusterString = dataCluster + " + \"#STAGING\"";
          } else {
            dataclusterString = dataCluster;
          }

          stringBuffer.append(TEXT_25);
          stringBuffer.append(usePartialDelete);
          stringBuffer.append(TEXT_26);
          stringBuffer.append(position.equals("") ? null : position);
          stringBuffer.append(TEXT_27);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_28);
          stringBuffer.append(dataclusterString);
          stringBuffer.append(TEXT_29);
          stringBuffer.append(dataModel);
          stringBuffer.append(TEXT_30);
          stringBuffer.append(usePartialDelete);
          stringBuffer.append(TEXT_31);
          stringBuffer.append(key.equals("") ? null : key);
          stringBuffer.append(TEXT_32);
          stringBuffer.append(overwrite);
          stringBuffer.append(TEXT_33);
          stringBuffer.append(pivot);
          stringBuffer.append(TEXT_34);
          stringBuffer.append(true == isStaging ? false : withReport);
          stringBuffer.append(TEXT_35);
          stringBuffer.append(sourceName);
          stringBuffer.append(TEXT_36);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_37);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_38);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_39);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_40);

          if (outConnName != null && !isMassInsert && keysReturn.size() > 0) {
            for (int i = 0; i < keysReturn.size(); i++) {
              Map<String, String> map = keysReturn.get(i);

              stringBuffer.append(TEXT_41);
              stringBuffer.append(outConnName);
              stringBuffer.append(TEXT_42);
              stringBuffer.append(map.get("OUTPUT_COLUMN"));
              stringBuffer.append(TEXT_43);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_44);
              stringBuffer.append(i);
              stringBuffer.append(TEXT_45);
            }
          }

          stringBuffer.append(TEXT_46);
        } else { // not partial
          stringBuffer.append(TEXT_47);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_48);
          stringBuffer.append(isUpdate);
          stringBuffer.append(TEXT_49);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_50);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_51);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_52);

          if (!isStaging && withReport) {
            stringBuffer.append(TEXT_53);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_54);
            stringBuffer.append(needCheck);
            stringBuffer.append(TEXT_55);
            stringBuffer.append(sourceName);
            stringBuffer.append(TEXT_56);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_57);
            if (isMassInsert) {
              stringBuffer.append(TEXT_58);
              if (addTaskID) {
                stringBuffer.append(TEXT_59);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_60);
                stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn);
                stringBuffer.append(TEXT_61);
              }
              stringBuffer.append(TEXT_62);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_63);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_64);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_65);
              stringBuffer.append(numMassInsert);
              stringBuffer.append(TEXT_66);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_67);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_68);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_69);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_70);
              if (addTaskID) {
                stringBuffer.append(TEXT_71);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_72);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_73);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_74);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_75);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_76);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_77);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_78);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_79);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_80);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_81);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_82);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_83);
              }
              stringBuffer.append(TEXT_84);
            } else {
              stringBuffer.append(TEXT_85);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_86);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_87);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_88);
              if (addTaskID) {
                stringBuffer.append(TEXT_89);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_90);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_91);
                stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn);
                stringBuffer.append(TEXT_92);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_93);
              }
              stringBuffer.append(TEXT_94);
            }

            if (outConnName != null && !isMassInsert && keysReturn.size() > 0) {

              for (int i = 0; i < keysReturn.size(); i++) {
                Map<String, String> map = keysReturn.get(i);

                stringBuffer.append(TEXT_95);
                stringBuffer.append(outConnName);
                stringBuffer.append(TEXT_96);
                stringBuffer.append(map.get("OUTPUT_COLUMN"));
                stringBuffer.append(TEXT_97);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_98);
                stringBuffer.append(i);
                stringBuffer.append(TEXT_99);
              }
            }
          } else {

            if (isMassInsert) {

              stringBuffer.append(TEXT_100);
              if (addTaskID) {
                stringBuffer.append(TEXT_101);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_102);
                stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn);
                stringBuffer.append(TEXT_103);
              }
              stringBuffer.append(TEXT_104);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_105);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_106);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_107);
              stringBuffer.append(numMassInsert);
              stringBuffer.append(TEXT_108);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_109);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_110);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_111);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_112);
              if (addTaskID) {
                stringBuffer.append(TEXT_113);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_114);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_115);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_116);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_117);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_118);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_119);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_120);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_121);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_122);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_123);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_124);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_125);
              }
              stringBuffer.append(TEXT_126);

            } else {
              stringBuffer.append(TEXT_127);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_128);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_129);
              stringBuffer.append(cid);
              stringBuffer.append(TEXT_130);
              if (addTaskID) {
                stringBuffer.append(TEXT_131);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_132);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_133);
                stringBuffer.append(isCustom ? taskID : inputConnName + "." + prevColumn);
                stringBuffer.append(TEXT_134);
                stringBuffer.append(cid);
                stringBuffer.append(TEXT_135);
              }
              stringBuffer.append(TEXT_136);

              if (outConnName != null && !isMassInsert && keysReturn.size() > 0) {
                for (int i = 0; i < keysReturn.size(); i++) {
                  Map<String, String> map = keysReturn.get(i);

                  stringBuffer.append(TEXT_137);
                  stringBuffer.append(outConnName);
                  stringBuffer.append(TEXT_138);
                  stringBuffer.append(map.get("OUTPUT_COLUMN"));
                  stringBuffer.append(TEXT_139);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_140);
                  stringBuffer.append(i);
                  stringBuffer.append(TEXT_141);
                }
              }
            }
          }

          stringBuffer.append(TEXT_142);
        } // end partial
        stringBuffer.append(TEXT_143);
        if (dieOnError) {
          stringBuffer.append(TEXT_144);
        } else {

          if (rejectConnName != null) {
            if (outConnName != null) {
              stringBuffer.append(TEXT_145);
              stringBuffer.append(outConnName);
              stringBuffer.append(TEXT_146);
            }
            stringBuffer.append(TEXT_147);
            stringBuffer.append(rejectConnName);
            stringBuffer.append(TEXT_148);
            stringBuffer.append(rejectConnName);
            stringBuffer.append(TEXT_149);

            for (IMetadataColumn column : columnList) {
              if (!"xml".equals(column.getLabel())
                  && !"errorCode".equals(column.getLabel())
                  && !"errorMessage".equals(column.getLabel())) {
                if (column.getLabel().equals(doc) && "id_String".equals(column.getTalendType())) {

                  stringBuffer.append(TEXT_150);
                  stringBuffer.append(rejectConnName);
                  stringBuffer.append(TEXT_151);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_152);
                  stringBuffer.append(inputConnName);
                  stringBuffer.append(TEXT_153);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_154);

                } else {

                  stringBuffer.append(TEXT_155);
                  stringBuffer.append(rejectConnName);
                  stringBuffer.append(TEXT_156);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_157);
                  stringBuffer.append(inputConnName);
                  stringBuffer.append(TEXT_158);
                  stringBuffer.append(column.getLabel());
                  stringBuffer.append(TEXT_159);
                }
              }
              if ("xml".equals(column.getLabel())) {
                if ("id_String".equals(column.getTalendType())) {

                  stringBuffer.append(TEXT_160);
                  stringBuffer.append(rejectConnName);
                  stringBuffer.append(TEXT_161);
                  stringBuffer.append(cid);
                  stringBuffer.append(TEXT_162);

                } else {

                  stringBuffer.append(TEXT_163);
                  stringBuffer.append(rejectConnName);
                  stringBuffer.append(TEXT_164);
                  stringBuffer.append(inputConnName);
                  stringBuffer.append(TEXT_165);
                }
              }
            }

            stringBuffer.append(TEXT_166);
            stringBuffer.append(cid);
            stringBuffer.append(TEXT_167);
            stringBuffer.append(TEXT_168);
            stringBuffer.append(rejectConnName);
            stringBuffer.append(TEXT_169);
            stringBuffer.append(node.getUniqueName());
            stringBuffer.append(TEXT_170);
          } else {
            stringBuffer.append(TEXT_171);
          }
        }
        stringBuffer.append(TEXT_172);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_173);
      }
    }
    stringBuffer.append(TEXT_174);
    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    List<? extends IConnection> outputConnections = node.getOutgoingSortedConnections();
    if ((outputConnections == null) || (outputConnections.size() == 0)) {
      return "";
    }
    IConnection outputConnection = outputConnections.get(0);

    if (!outputConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
      return "";
    }

    List<IMetadataTable> metadatas = node.getMetadataList();
    if ((metadatas == null) && (metadatas.size() == 0) || (metadatas.get(0) == null)) {
      return "";
    }
    IMetadataTable metadata = metadatas.get(0);

    List<IMetadataColumn> columnList = metadata.getListColumns();
    if ((columnList == null) || (columnList.size() == 0)) {
      return "";
    }

    String client = ElementParameterParser.getValue(node, "__CLIENT__");
    String userid = ElementParameterParser.getValue(node, "__USERID__");
    String password = ElementParameterParser.getValue(node, "__PASSWORD__");
    String language = ElementParameterParser.getValue(node, "__LANGUAGE__");
    String hostname = ElementParameterParser.getValue(node, "__HOSTNAME__");
    String systemnumber = ElementParameterParser.getValue(node, "__SYSTEMNUMBER__");

    String systemId = ElementParameterParser.getValue(node, "__SYSTEMID__");
    String groupName = ElementParameterParser.getValue(node, "__GROUPNAME__");

    String serverType = ElementParameterParser.getValue(node, "__SERVERTYPE__");

    String tableName = ElementParameterParser.getValue(node, "__TABLE__");
    String filter = ElementParameterParser.getValue(node, "__FILTER__");

    String startRowNumber = ElementParameterParser.getValue(node, "__START_ROW__");
    String maxRowCount = ElementParameterParser.getValue(node, "__MAX_ROW_COUNT__");

    List<Map<String, String>> sapProps =
        (List<Map<String, String>>)
            ElementParameterParser.getObjectValue(node, "__SAP_PROPERTIES__");

    String passwordFieldName = "__PASSWORD__";

    boolean activeSNC = ("true").equals(ElementParameterParser.getValue(node, "__SNC_ACTIVE__"));
    String partnerSNCName = ElementParameterParser.getValue(node, "__SNC_PARTNER_NAME__");
    String mySNCName = ElementParameterParser.getValue(node, "__SNC_MY_NAME__");
    String sncLevel = ElementParameterParser.getValue(node, "__SNC_LEVEL__");
    String sncLibPath = ElementParameterParser.getValue(node, "__SNC_LIB_PATH__");
    boolean hasSNCLibPath = sncLibPath != null && !"".equals(sncLibPath);
    boolean hasMySNCName = mySNCName != null && !"".equals(mySNCName);

    boolean useExistingConn =
        ("true").equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"));
    String connection = ElementParameterParser.getValue(node, "__CONNECTION__");

    stringBuffer.append(TEXT_2);
    if (useExistingConn) {
      stringBuffer.append(TEXT_3);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_4);
      stringBuffer.append(connection);
      stringBuffer.append(TEXT_5);

      INode connectionNode = null;
      for (INode processNode : node.getProcess().getGeneratingNodes()) {
        if (connection.equals(processNode.getUniqueName())) {
          connectionNode = processNode;
          break;
        }
      }
      boolean specify_alias =
          "true"
              .equals(
                  ElementParameterParser.getValue(connectionNode, "__SPECIFY_DATASOURCE_ALIAS__"));
      if (specify_alias) {
        String alias = ElementParameterParser.getValue(connectionNode, "__SAP_DATASOURCE_ALIAS__");
        if (null != alias && !("".equals(alias))) {

          stringBuffer.append(TEXT_6);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_7);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_8);
          stringBuffer.append(alias);
          stringBuffer.append(TEXT_9);
        }
      }

      stringBuffer.append(TEXT_10);
    } else {
      stringBuffer.append(TEXT_11);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_12);

      boolean specify_alias =
          "true".equals(ElementParameterParser.getValue(node, "__SPECIFY_DATASOURCE_ALIAS__"));
      if (specify_alias) {
        String alias = ElementParameterParser.getValue(node, "__SAP_DATASOURCE_ALIAS__");
        if (null != alias && !("".equals(alias))) {

          stringBuffer.append(TEXT_13);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_14);
          stringBuffer.append(alias);
          stringBuffer.append(TEXT_15);
        }

        stringBuffer.append(TEXT_16);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_17);
      }

      stringBuffer.append(TEXT_18);
      if (ElementParameterParser.canEncrypt(node, passwordFieldName)) {
        stringBuffer.append(TEXT_19);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_20);
        stringBuffer.append(ElementParameterParser.getEncryptedValue(node, passwordFieldName));
        stringBuffer.append(TEXT_21);
      } else {
        stringBuffer.append(TEXT_22);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_23);
        stringBuffer.append(ElementParameterParser.getValue(node, passwordFieldName));
        stringBuffer.append(TEXT_24);
      }
      stringBuffer.append(TEXT_25);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_26);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_27);
      stringBuffer.append(client);
      stringBuffer.append(TEXT_28);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_29);
      stringBuffer.append(userid);
      stringBuffer.append(TEXT_30);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_31);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_32);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_33);
      stringBuffer.append(language);
      stringBuffer.append(TEXT_34);
      if ("ApplicationServer".equals(serverType)) {
        stringBuffer.append(TEXT_35);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_36);
        stringBuffer.append(hostname);
        stringBuffer.append(TEXT_37);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_38);
        stringBuffer.append(systemnumber);
        stringBuffer.append(TEXT_39);
      } else {
        stringBuffer.append(TEXT_40);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_41);
        stringBuffer.append(hostname);
        stringBuffer.append(TEXT_42);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_43);
        stringBuffer.append(systemId);
        stringBuffer.append(TEXT_44);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_45);
        stringBuffer.append(groupName);
        stringBuffer.append(TEXT_46);
      }
      stringBuffer.append(TEXT_47);

      if (activeSNC) {

        stringBuffer.append(TEXT_48);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_49);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_50);
        stringBuffer.append(partnerSNCName);
        stringBuffer.append(TEXT_51);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_52);
        stringBuffer.append(sncLevel);
        stringBuffer.append(TEXT_53);
        if (hasMySNCName) {
          stringBuffer.append(TEXT_54);
          stringBuffer.append(mySNCName);
          stringBuffer.append(TEXT_55);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_56);
          stringBuffer.append(mySNCName);
          stringBuffer.append(TEXT_57);
        }
        stringBuffer.append(TEXT_58);
        if (hasSNCLibPath) {
          stringBuffer.append(TEXT_59);
          stringBuffer.append(sncLibPath);
          stringBuffer.append(TEXT_60);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_61);
          stringBuffer.append(sncLibPath);
          stringBuffer.append(TEXT_62);
        }
        stringBuffer.append(TEXT_63);
      }

      stringBuffer.append(TEXT_64);

      if (sapProps != null) {
        for (Map<String, String> item : sapProps) {

          stringBuffer.append(TEXT_65);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_66);
          stringBuffer.append(item.get("PROPERTY"));
          stringBuffer.append(TEXT_67);
          stringBuffer.append(item.get("VALUE"));
          stringBuffer.append(TEXT_68);
        }
      }

      stringBuffer.append(TEXT_69);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_70);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_71);

      if (specify_alias) {

        stringBuffer.append(TEXT_72);
      }
    }

    stringBuffer.append(TEXT_73);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_74);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_75);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_76);

    for (int i = 0; i < columnList.size(); i++) {
      IMetadataColumn column = columnList.get(i);

      String tableField = column.getOriginalDbColumnName();

      stringBuffer.append(TEXT_77);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_78);
      stringBuffer.append(tableField);
      stringBuffer.append(TEXT_79);
    }

    stringBuffer.append(TEXT_80);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_81);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_82);
    stringBuffer.append(tableName);
    stringBuffer.append(TEXT_83);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_84);
    stringBuffer.append(filter);
    stringBuffer.append(TEXT_85);
    stringBuffer.append(maxRowCount);
    stringBuffer.append(TEXT_86);
    stringBuffer.append(startRowNumber);
    stringBuffer.append(TEXT_87);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_88);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_89);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_90);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_91);
    stringBuffer.append(cid);
    stringBuffer.append(TEXT_92);

    for (int i = 0; i < columnList.size(); i++) {
      IMetadataColumn column = columnList.get(i);
      String typeToGenerate =
          JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
      JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
      String dbType = column.getType();

      if (javaType == JavaTypesManager.STRING) {

        stringBuffer.append(TEXT_93);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_94);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_95);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_96);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_97);

      } else if (javaType == JavaTypesManager.INTEGER) {

        stringBuffer.append(TEXT_98);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_99);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_100);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_101);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_102);

      } else if (javaType == JavaTypesManager.SHORT) {

        stringBuffer.append(TEXT_103);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_104);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_105);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_106);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_107);

      } else if (javaType == JavaTypesManager.DATE) {

        stringBuffer.append(TEXT_108);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_109);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_110);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_111);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_112);

      } else if (javaType == JavaTypesManager.BYTE) {

        stringBuffer.append(TEXT_113);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_114);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_115);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_116);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_117);

      } else if (javaType == JavaTypesManager.BYTE_ARRAY) {

        stringBuffer.append(TEXT_118);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_119);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_120);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_121);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_122);

      } else if (javaType == JavaTypesManager.DOUBLE) {

        stringBuffer.append(TEXT_123);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_124);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_125);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_126);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_127);

      } else if (javaType == JavaTypesManager.BIGDECIMAL) {

        stringBuffer.append(TEXT_128);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_129);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_130);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_131);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_132);

      } else if (javaType == JavaTypesManager.OBJECT && "BIG_INTEGER".equals(dbType)) {

        stringBuffer.append(TEXT_133);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_134);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_135);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_136);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_137);

      } else if (javaType == JavaTypesManager.OBJECT) {

        stringBuffer.append(TEXT_138);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_139);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_140);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_141);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_142);

      } else {

        stringBuffer.append(TEXT_143);
        stringBuffer.append(outputConnection.getName());
        stringBuffer.append(TEXT_144);
        stringBuffer.append(column.getLabel());
        stringBuffer.append(TEXT_145);
        stringBuffer.append(typeToGenerate);
        stringBuffer.append(TEXT_146);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_147);
        stringBuffer.append(i);
        stringBuffer.append(TEXT_148);
      }
    }

    return stringBuffer.toString();
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode) codeGenArgument.getArgument();
    String cid = node.getUniqueName();

    String dataAction = ElementParameterParser.getValue(node, "__DATA_ACTION__");
    String commitEvery = ElementParameterParser.getValue(node, "__COMMIT_EVERY__");
    String dieOnError = ElementParameterParser.getValue(node, "__DIE_ON_ERROR__");
    String useBatchSize = ElementParameterParser.getValue(node, "__USE_BATCH_SIZE__");
    boolean useExistingConnection =
        ("true").equals(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"));

    // ------get first reject name
    String rejectConnName = null;
    List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT");
    if (rejectConns != null && rejectConns.size() > 0) {
      IConnection rejectConn = rejectConns.get(0);
      rejectConnName = rejectConn.getName();
    }

    // Close SQL statements
    if (("INSERT_OR_UPDATE").equals(dataAction)) {

      stringBuffer.append(TEXT_2);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_3);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_4);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_5);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_6);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_7);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_8);

    } else if (("UPDATE_OR_INSERT").equals(dataAction)) {

      stringBuffer.append(TEXT_9);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_10);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_11);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_12);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_13);

    } else {
      // ----------------------batch size
      if ((rejectConnName == null && ("true").equals(useBatchSize) && !useExistingConnection)
          && (("INSERT").equals(dataAction)
              || ("UPDATE").equals(dataAction)
              || ("DELETE").equals(dataAction))) {

        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(cid);
        stringBuffer.append(TEXT_19);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_20);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_21);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_22);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_23);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_24);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_25);

        if (("true").equals(dieOnError)) {

          stringBuffer.append(TEXT_26);

        } else {

          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(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);
        if (("INSERT").equals(dataAction)) {

          stringBuffer.append(TEXT_42);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_43);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_44);

        } else if (("UPDATE").equals(dataAction)) {

          stringBuffer.append(TEXT_45);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_46);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_47);

        } else if (("DELETE").equals(dataAction)) {

          stringBuffer.append(TEXT_48);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_49);
          stringBuffer.append(cid);
          stringBuffer.append(TEXT_50);
        }
        stringBuffer.append(TEXT_51);
      } // --------end batch

      stringBuffer.append(TEXT_52);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_53);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_54);
    }

    stringBuffer.append(TEXT_55);

    String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
    if (("false").equals(useExistingConn)) {
      // Commit if needed
      if (!("").equals(commitEvery) && !("0").equals(commitEvery)) {

        stringBuffer.append(TEXT_56);
        stringBuffer.append(cid);
        stringBuffer.append(TEXT_57);
      }

      stringBuffer.append(TEXT_58);
      stringBuffer.append(cid);
      stringBuffer.append(TEXT_59);
    }

    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);
    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(TEXT_83);
    return stringBuffer.toString();
  }