/**
   * Generate UPDATE statement
   *
   * @return
   */
  private String buildUpdateSQL() {
    StringBuffer resultSQL = new StringBuffer();
    if (chkComment.getSelection()) resultSQL.append("/* Tadpole SQL Generator */"); // $NON-NLS-1$

    int cnt = 0;

    resultSQL.append(
        "UPDATE "
            + this.tableDAO.getSysName()
            + " "
            + this.textTableAlias.getText().trim()); // $NON-NLS-1$ //$NON-NLS-2$

    ExtendTableColumnDAO firstDao = (ExtendTableColumnDAO) tableViewer.getElementAt(0);
    if (firstDao.isCheck()) {
      for (ExtendTableColumnDAO allDao : (List<ExtendTableColumnDAO>) tableViewer.getInput()) {
        if ("*".equals(allDao.getField())) continue; // $NON-NLS-1$

        if (cnt == 0) resultSQL.append(" SET "); // $NON-NLS-1$
        else resultSQL.append(" , "); // $NON-NLS-1$

        resultSQL.append(allDao.getColumnNamebyTableAlias()).append(" = ? "); // $NON-NLS-1$
        if (chkComment.getSelection()) {
          resultSQL.append("/* " + allDao.getType() + " */"); // $NON-NLS-1$ //$NON-NLS-2$
        }
        cnt++;
      }

    } else {

      for (ExtendTableColumnDAO allDao : (List<ExtendTableColumnDAO>) tableViewer.getInput()) {
        if (allDao.isCheck()) {
          if (cnt == 0) resultSQL.append(" SET "); // $NON-NLS-1$
          else resultSQL.append(", "); // $NON-NLS-1$

          resultSQL.append(allDao.getColumnNamebyTableAlias()).append(" = ? "); // $NON-NLS-1$
          if (chkComment.getSelection()) {
            resultSQL.append("/* " + allDao.getType() + " */"); // $NON-NLS-1$ //$NON-NLS-2$
          }
          cnt++;
        }
      }
    }
    cnt = 0;
    for (ExtendTableColumnDAO allDao : (List<ExtendTableColumnDAO>) tableViewer.getInput()) {
      if ("PK".equals(allDao.getKey())) { // $NON-NLS-1$

        if (cnt == 0) resultSQL.append(" WHERE "); // $NON-NLS-1$
        else resultSQL.append(" AND "); // $NON-NLS-1$

        resultSQL.append(allDao.getColumnNamebyTableAlias()).append(" = ? "); // $NON-NLS-1$

        if (chkComment.getSelection()) {
          resultSQL.append("/* " + allDao.getType() + " */"); // $NON-NLS-1$ //$NON-NLS-2$
        }
        cnt++;
      }
    }

    return lastSQLGen(resultSQL.toString());
  }
  /**
   * Generate SELECT statment
   *
   * @return
   */
  private String buildSelectSQL() {
    StringBuffer resultSQL = new StringBuffer();
    if (chkComment.getSelection()) {
      resultSQL.append("/* Tadpole SQL Generator */"); // $NON-NLS-1$
    }
    resultSQL.append("SELECT "); // $NON-NLS-1$
    int cnt = 0;

    StringBuffer sbColumn = new StringBuffer();
    for (ExtendTableColumnDAO allDao : (List<ExtendTableColumnDAO>) tableViewer.getInput()) {
      if (allDao.isCheck()) {
        if (cnt != 0) sbColumn.append("\t, "); // $NON-NLS-1$

        if ("*".equals(allDao.getField())) { // $NON-NLS-1$
          sbColumn.append(allDao.getSysName());
        } else {
          String strTableAlias =
              !"".equals(textTableAlias.getText().trim())
                  ? //$NON-NLS-1$
                  textTableAlias.getText().trim()
                      + "."
                      + allDao.getSysName()
                      + " as "
                      + allDao.getColumnAlias()
                  : //$NON-NLS-1$ //$NON-NLS-2$
                  allDao.getSysName() + " as " + allDao.getColumnAlias(); // $NON-NLS-1$

          sbColumn.append(strTableAlias);
        }
        cnt++;
      }
    }
    if (StringUtils.isEmpty(StringUtils.trim(sbColumn.toString())))
      sbColumn.append(" * "); // $NON-NLS-1$

    resultSQL.append(sbColumn.toString());
    resultSQL.append(
        "  FROM "
            + this.tableDAO.getSysName()
            + " "
            + this.textTableAlias.getText().trim()); // $NON-NLS-1$ //$NON-NLS-2$
    cnt = 0;
    for (ExtendTableColumnDAO allDao : (List<ExtendTableColumnDAO>) tableViewer.getInput()) {
      if ("PK".equals(allDao.getKey())) { // $NON-NLS-1$

        if (cnt == 0) {
          resultSQL.append(" WHERE "); // $NON-NLS-1$
        } else {
          resultSQL.append(" AND "); // $NON-NLS-1$
        }
        resultSQL.append(allDao.getColumnNamebyTableAlias()).append(" = ? "); // $NON-NLS-1$
        if (chkComment.getSelection()) {
          resultSQL.append("/* " + allDao.getType() + " */"); // $NON-NLS-1$ //$NON-NLS-2$
        }
        cnt++;
      }
    }

    return lastSQLGen(resultSQL.toString());
  }
  @Override
  public String getColumnText(Object element, int columnIndex) {
    ExtendTableColumnDAO dao = (ExtendTableColumnDAO) element;

    switch (columnIndex) {
      case 0:
        return dao.getColumnNamebyTableAlias();
      case 1:
        return dao.getType();
      case 2:
        return dao.getKey();
      case 3:
        return dao.getSysName();
      case 4:
        return dao.getComment();
    }

    return "*** not set column value ***"; //$NON-NLS-1$
  }