@SuppressWarnings("unchecked")
  protected void updateColumnList(IMetadataTable oldTable, IMetadataTable newTable) {
    final List<ColumnNameChanged> columnNameChanged =
        MetadataToolHelper.getColumnNameChanged(oldTable, newTable);

    if (inputNode != null) {
      List<IElementParameter> eps = (List<IElementParameter>) inputNode.getElementParameters();
      if (eps != null) {
        boolean end = false;
        for (int i = 0; i < eps.size() && !end; i++) {
          IElementParameter parameter = eps.get(i);
          if (parameter.getFieldType() == EParameterFieldType.TABLE) {
            end = true;
            if (parameter != null) {
              List<Map<String, Object>> map2 = (List<Map<String, Object>>) parameter.getValue();
              if (map2 != null
                  && inputNode.getMetadataList().get(0).getListColumns().size() != map2.size()) {
                ColumnListController.updateColumnList(inputNode, columnNameChanged);
              }
            }
          }
        }
      }
      inputNode.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
    }
    node.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
  }
  /**
   * Ensures that fields are set. Update checkEnable / use to checkConnection().
   *
   * @return
   */
  @Override
  protected boolean checkFieldsValue() {

    if (metadataNameText.getCharCount() == 0) {
      metadataNameText.forceFocus();
      updateStatus(IStatus.ERROR, Messages.getString("FileStep1.nameAlert")); // $NON-NLS-1$
      return false;
    } else if (!MetadataToolHelper.isValidSchemaName(metadataNameText.getText())) {
      metadataNameText.forceFocus();
      updateStatus(
          IStatus.ERROR, Messages.getString("FileStep1.nameAlertIllegalChar")); // $NON-NLS-1$
      return false;
    } else if (nameExist(metadataNameText.getText())) {
      updateStatus(
          IStatus.ERROR, Messages.getString("CommonWizard.nameAlreadyExist")); // $NON-NLS-1$
      return false;
    }

    if (tableEditorView.getMetadataEditor().getBeanCount() > 0) {
      updateStatus(IStatus.OK, null);
      return true;
    }
    updateStatus(IStatus.ERROR, Messages.getString("FileStep3.itemAlert")); // $NON-NLS-1$

    return false;
  }
 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 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);
 }
  @Override
  public void undo() {
    propagateDatas(false);

    if (currentInputMetadata != null) {
      if (!currentInputMetadata.sameMetadataAs(oldInputMetadata, IMetadataColumn.OPTIONS_NONE)) {
        currentInputMetadata.setListColumns(oldInputMetadata.getListColumns());
        if (inputWasRepository) {
          inputNode.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.REPOSITORY);
        }
      }
    }
    if (!currentOutputMetadata.sameMetadataAs(oldOutputMetadata, IMetadataColumn.OPTIONS_NONE)) {
      List<IMetadataColumn> currentColumns =
          new ArrayList<IMetadataColumn>(oldOutputMetadata.getListColumns());
      currentOutputMetadata.setListColumns(currentColumns);
      MetadataToolHelper.copyTable(oldOutputMetadata, currentOutputMetadata);
    }

    for (INodeConnector connector : node.getListConnector()) {
      if ((!connector.getName().equals(currentConnector))
          && connector.getBaseSchema().equals(currentConnector)) {
        MetadataToolHelper.copyTable(
            oldOutputMetadata, node.getMetadataFromConnector(connector.getName()));
      }
    }
    if (outputWasRepository) {
      node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.REPOSITORY);
    }
    for (ChangeMetadataCommand cmd : propagatedChange) {
      cmd.undo();
    }

    List<ColumnNameChanged> columnNameChanged =
        MetadataToolHelper.getColumnNameChanged(oldOutputMetadata, newOutputMetadata);
    ColumnListController.updateColumnList(node, columnNameChanged, true);
    // newOutputMetadata.setListColumns(new
    // ArrayList<IMetadataColumn>(oldOutputMetadata.getListColumns()));

    if (!internal) {
      updateColumnList(newOutputMetadata, oldOutputMetadata);
      ((Process) node.getProcess()).checkProcess();
    }
    refreshMetadataChanged();
  }
  /** Initialize value, forceFocus first field. */
  @Override
  protected void initialize() {
    // init the metadata Table
    String label = MetadataToolHelper.validateValue(metadataTable.getLabel());
    metadataNameText.setText(label);
    metadataCommentText.setText(metadataTable.getComment());
    metadataEditor.setMetadataTable(metadataTable);
    tableEditorView.setMetadataEditor(metadataEditor);
    tableEditorView.getTableViewerCreator().layout();

    if (getConnection().isReadOnly()) {
      adaptFormToReadOnly();
    } else {
      updateStatus(IStatus.OK, null);
    }
  }
  @Override
  public void execute() {
    propagatedChange.clear();

    propagateDatas(true);
    if (currentInputMetadata != null) {
      if (!currentInputMetadata.sameMetadataAs(newInputMetadata, IMetadataColumn.OPTIONS_NONE)) {
        if (!currentInputMetadata.sameMetadataAs(
            newInputMetadata, IMetadataColumn.OPTIONS_IGNORE_USED)) {
          String type = (String) inputNode.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
          if (type != null) {
            if (type.equals(EmfComponent.REPOSITORY)) {
              inputWasRepository = true;
              inputNode.setPropertyValue(
                  EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
            }
          }
        }
        MetadataToolHelper.copyTable(newInputMetadata, currentInputMetadata);
      }
    }

    if (!currentOutputMetadata.sameMetadataAs(newOutputMetadata, IMetadataColumn.OPTIONS_NONE)) {
      if (!currentOutputMetadata.sameMetadataAs(
          newOutputMetadata, IMetadataColumn.OPTIONS_IGNORE_USED)) {
        String type = (String) node.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
        if (type != null && type.equals(EmfComponent.REPOSITORY) && !repositoryMode) {
          // for one node has several schema_type,set mode for the current one
          if ((node.getElementParameter("SCHEMA_TYPE")
              .getContext()
              .equals(currentOutputMetadata.getAttachedConnector()))) {
            outputWasRepository = true;
            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
          }
        }
      }
      MetadataToolHelper.copyTable(newOutputMetadata, currentOutputMetadata);
    }
    if (inputSchemaParam != null
        && inputSchemaParam.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()) != null
        && EmfComponent.REPOSITORY.equals(
            inputSchemaParam
                .getChildParameters()
                .get(EParameterName.SCHEMA_TYPE.getName())
                .getValue())) {
      // add by wzhang to fix bug 7898.
      IElementParameter elementParameter =
          node.getElementParameter(EParameterName.MAPPING.getName());
      if (elementParameter != null) {
        if (elementParameter.getValue() instanceof String) {
          String value = (String) elementParameter.getValue();
          if (!isDBComponent(value)) {
            schemaParam
                .getChildParameters()
                .get(EParameterName.SCHEMA_TYPE.getName())
                .setValue(EmfComponent.REPOSITORY);
            schemaParam
                .getChildParameters()
                .get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName())
                .setValue(
                    inputSchemaParam
                        .getChildParameters()
                        .get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName())
                        .getValue());
          }
        }
      }
    }

    for (INodeConnector connector : node.getListConnector()) {
      if ((!connector.getName().equals(currentConnector))
          && connector.getBaseSchema().equals(currentConnector)) {
        if (node.getComponent() != null
            && "tSalesforceOutput".equals(node.getComponent().getName())
            && "REJECT".equals(connector.getName())) {
          IMetadataTable clone = newOutputMetadata.clone(true);
          Iterator<IMetadataColumn> iterator = clone.getListColumns().iterator();
          while (iterator.hasNext()) {
            IMetadataColumn column = iterator.next();
            if (column.isCustom()) {
              iterator.remove();
            }
          }
          MetadataToolHelper.copyTable(clone, node.getMetadataFromConnector(connector.getName()));
        } else {
          // if there is some other schema dependant of this one, modify them
          MetadataToolHelper.copyTable(
              newOutputMetadata, node.getMetadataFromConnector(connector.getName()));
        }
      }
    }

    List<ColumnNameChanged> columnNameChanged =
        MetadataToolHelper.getColumnNameChanged(oldOutputMetadata, newOutputMetadata);
    ColumnListController.updateColumnList(node, columnNameChanged, true);

    if (inputNode != null) {
      List<ColumnNameChanged> inputColumnNameChangedExt =
          MetadataToolHelper.getColumnNameChangedExt(inputNode, oldInputMetadata, newInputMetadata);
      ColumnListController.updateColumnList(node, inputColumnNameChangedExt);
    }
    //
    List<ColumnNameChanged> outputColumnNameChangedExt =
        MetadataToolHelper.getColumnNameChangedExt(node, oldOutputMetadata, newOutputMetadata);
    syncOutputNodeColumnsList(outputColumnNameChangedExt);

    setXMLMAPPING();

    if (!internal) {
      updateColumnList(oldOutputMetadata, newOutputMetadata);
      ((Process) node.getProcess()).checkProcess();
    }
    refreshMetadataChanged();
  }
  private void propagateDatas(boolean isExecute) {
    String baseConnectorForCurrentNode =
        node.getConnectorFromName(currentConnector).getBaseSchema();

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

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

        INode targetNode = currentIO.getTarget();

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

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

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

                // wzhang modify to add feature 7611

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

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

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

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

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

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

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

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

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

    if (inputdataContainer != null) {
      for (IODataComponent currentIO : inputdataContainer.getOuputs()) {
        if (currentIO.hasChanged()
            && (currentIO
                .getSource()
                .getConnectorFromName(currentIO.getConnection().getConnectorName())
                .getBaseSchema()
                .equals(currentConnector))) {
          INode targetNode = currentIO.getTarget();
          targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName());
          if (isExecute) {
            currentIO.setTable(oldInputMetadata);
            currentIO.setColumnNameChanged(null);
          } else {
            currentIO.setTable(newInputMetadata);
            currentIO.setColumnNameChanged(null);
          }
        }
      }
    }
    // End propagate
  }
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    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();
  }
 /**
  * Validates column name to avoid special characters.
  *
  * <p>qli modified to fix the bug 4456.
  *
  * @param columnName
  * @param index
  */
 public static String validateColumnNameFormat(String columnName, int index) {
   return MetadataToolHelper.validateColumnName(columnName, index);
 }